Skip to main content

Tech Conversant Weekly Jun 05 - Jun 17

Topic: General                                                                                                                Level: All

Welcome to the world of cutting-edge technology! Every bi-week, we bring you the latest and most incredible advancements in the tech industry that are sure to leave you feeling inspired and empowered.

Stay ahead of the game and be the first to know about the newest innovations shaping our world. Discover new ways to improve your daily life, become more efficient, and enjoy new experiences.

This time, we've got some exciting news to share with you!

When there is a need to promote/release the local database changes along with code changes. 
Creating a DB migration schema script (a point time snapshot defined by the state of the DB) on the given code version helps in synchronizing the data evolution with the code.
With this feature, we can work on a particular code and data version, as well as a rollback to a later version without worrying about stale data changes.
Liquibase is a DB migration tool that generates a ChangeLog XML file with changeSet tags to model and export your table model. And use this script file for local developer application setup with the proper data model. 
A version-based database migration process allows you to evolve your database together with your code and to automatically apply database updates when you deploy a new release. Liquibase is one of the available tools that help you to define and execute the required update steps.

There are diverse ways to write code but is it Efficient? Optimized? Require tuning? Can be enhanced? Make it more futuristic.
How can all these be accounted for when writing code that powers software?
The answer is the IntelliJ Inspection tool, which analysis the code, module, and project, and offers alternatives to the code.
We can create new rules for inspection, update existing rules, and create profiles for inspection.  

JPA entity mapping with hibernate and Spring can be validated during the application startup to ensure the DDL schema correctness.
The hibernate SchemaManagementTool offers validate strategy to check the JPA entity mapping with DB schema compatibility. 
This can be enabled by, 
spring.jpa.hibernate.ddl-auto=validate
Alternatively, we can use an automatic schema management tool like Flyway, Liquibase to manage the DB schema.
@DataJpaTest(properties = "spring.jpa.hibernate.ddl-auto=validate")
@AutoConfigureTestDatabase(replace = Replace.NONE)
With this definition, we can enable the DB schema compatibility with JPA entity mapping validation only on specific classes or tests and not bootstrap it at the application level, thereby also defining (instead of doing it every time the JPA EntityManagerFactory is bootstrapped)
spring.jpa.hibernate.ddl-auto=none

Short-circuiting the related tasks running in different threads so as avoid unnecessary processing, optimal resource utilization, logical cancellation, and observability.
Structured Concurrency API with StructuredTaskScope definition in JDK21 as a preview-enabled option answers for such thread processing simplification.

Ways to create a thread,
1. By extending the Thread class - and overriding the run() with the implementation of task details for the thread and invoking the start()
2. By implementing a Runnable interface - and implementing run() for the tasks to be performed and passing this Runnable interface type to overloaded Thread constructor
3. By creating a thread pool - with Executors invoking static ThreadPool implementations and returning the ExecutorService to which tasks can be submitted.
4. By using ExecutorService with Callable and Future - to retrieve the results from the submitted tasks to the  ExecutorService, that is a Future and the submitted task should be of Callable type
5. By using CompletableFuture - for nonblocking retrieval of Future results  
6. Daemon thread - threads that keep running in the background and never exits 

When creating subclass object instances, implicitly the parent class constructor is invoked followed by the instance initializer blocks, then the parent constructor, and eventually back to the subclass constructor (from where it all started).
From the child class to the parent class invocation from the child class constructor happens implicitly via the super() which could take method arguments. However, the catch here is the arguments should not refer to 'this' reference as it would be uninitialized.
"The argument list to these calls must not refer to this either explicitly or indirectly by an unqualified identifier that would be resolved using an implicit this reference. The super prefix, which is essentially a reference to this but with a different type, is also prohibited"
it has always been permitted to place expressions as actual parameters to this(...) and super(...) calls, provided they make no direct or indirect reference to this. Such expressions can make unrestricted use of static members (methods and fields) of the class being initialized or other classes.
JDK17 prohibits the addition of any code before,
this() and super() invocations, as these should always precede any statements in the constructor.  

The benefits of having a one-to-one entity association in which the primary key column of the parent table references a foreign key constraint for the primary key column in the child table.
1. Conditionality in setting the optional column values
2. Optimistic locking in which a single table with multiple columns gets updated from different requests, breaking the columns to respective child tables and maintaining the entity relationship association would remediate the issue.
3. Pessimistic locking - with multiple tables, locking the row entry for DML is isolated to the specific table thus allowing concurrency rather than single table row block until transaction completion 
4. Buffer pool and dirty pages - by selectively updating the modified columns split across the tables we can avoid unrelated column updates in the memory 

For secure communications between different systems SSL and TLS stands inevitable. 
The source trust material can be any Java keystore format such as JKS, PKCS12, PEM encoded files and applications might require the trust to be presented in any of the below formats,
1. KeyStore and TrustStore instances
2. KeyManager and TrustManager instances
3. SSLContext instance
Enabling SSL for Spring requires defining, ClientHttpRequestFactory with 
HttpComponentsClientHttpRequestFactory, OkHttp3ClientHttpRequestFactory or SimpleClientHttpRequestFactory.
With Spring 3.1, SSL is property resolved with the prefix spring.ssl.bundle from the application properties specification, and from here we can define properties for jks and pem under bundle.
Spring Boot uses the spring.ssl.bundle properties to create objects that provide access to the specified trust material.
1. The REST endpoints can also be wrapped with SSL by using RestTemplate or WebClient implementations
2. The DB service connections can also be SSL wrapped by defining the property
3. Embedded web servers can also be secured with SSL by using server.ssl.bundle property prefix 

The downsides of Field Injection with @Autowired annotation introduces,
1. Nullness issues of the injected field bean when the hosted class is instantiated with the new keyword
2. Immutability
3. Single Responsibility Principle violation as beans expose functionality within the injected class
4. Circular dependency - with constructor injection this can be identified at the compile time
5. Unit Testing - using InjectMocks annotation open mocks of the class with reflection

Sorting and Ordering are two separate operations that can be performed on the associated DB entity. When there is an entity association relationship between tables and fetching requires defining the sequence in which the associated entity should return values. 
By Sorting, you have to implement a Comparable interface and override compareTo define the column on which the sort is required, given the associated entity should be of SortedSet or SortedMap type implementation. Additionally, @SortNatural can be applied to the entity association or @SortComparator which takes in a Comparator implementation class that overrides the compare method.
With the Sorting strategy, the JVM applies a comparator/comparable sort mechanism on the DB retrieved entries.
Now with Ordering the entity association can be decorated with @OrderBy with an attribute of column name to be ordered and the sequence of order, such that when fetching the generated SQL statement will have an ORDER BY clause (and not in the case of Sorting).
It is advisable to use Ordering on entity association fetch in which the DB runs an efficient mechanism rather than sorting which delegates to comparator/comparable interface implementations that operate in-memory and that are process intensive as well.

Complete collection of Java releases summarising, support specification, documentation details, JDK/JRE downloadable links, and collective comparison with all the predecessor versions

Spring Security is a proxy interceptor acting as a filter between the client request and the servlet mapping applying authentication and authorization. Specifically, the SecurityFilterChain defines the security-related filters via FilterChainProxy from the DelegatingFilterProxy and further drilling down on the details for SecurityFilterChain has AuthenticationFilter with SecurityContext, AuthenticationManager and AuthenticationProvider with UserDetails and PasswordEncoder

Hacks to enhance your Java code, 

Comprehensive setup and execution of Spring Cloud Kubernetes with Spring Boot 3

Compiling and running native images with GraalVM in Spring Boot 3

Disclaimer: 
This is a personal blog. Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in a professional or personal capacity, unless explicitly stated. Any views or opinions are not intended to malign any religion, ethnic group, club, organization, company, or individual. All content provided on this blog is for informational purposes only. The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of this information.

Downloadable Files and ImagesAny downloadable file, including but not limited to pdfs, docs, jpegs, pngs, is provided at the user’s own risk. The owner will not be liable for any losses, injuries, or damages resulting from a corrupted or damaged file.

  • Comments are welcome. However, the blog owner reserves the right to edit or delete any comments submitted to this blog without notice due to :
  • Comments deemed to be spam or questionable spam.
  • Comments including profanity.
  • Comments containing language or concepts that could be deemed offensive.
  • Comments containing hate speech, credible threats, or direct attacks on an individual or group.

The blog owner is not responsible for the content in the comments. This blog disclaimer is subject to change at any time.

Comments

Popular posts from this blog

Tech Conversant Weekly Jul 03 - Jul 15

Topic: General                                                                                                                                              Level: All Welcome to the world of cutting-edge technology! Every bi-week, we bring you the latest and most incredible advancements in the tech industry that are sure to leave you feeling inspired and empowered. Stay ahead of the game and be the first to know about the newest innovations shaping our world. Discover new ways to improve your daily life, become more efficient, and enjoy new experiences. This time, we've got some exciting news to share with you! Boosting Java startup with Class Data Sharing (CDS) https://www.youtube.com/watch?v=vvlQv1Dh-HU JDK21 LTS Maintenance and Support https://www.youtube.com/watch?v=3bfR22iv8Pc Health checking of multiple cloud applications with Spring Cloud Gateway https://spring.io/blog/2023/07/05/active-health-check-strategies-with-spring-cloud-gateway Functional Style Non-reactive HTTP clie

Tech Conversant Weekly Jun 19 - Jul 01

Topic: General                                                                                                                                              Level: All Welcome to the world of cutting-edge technology! Every bi-week, we bring you the latest and most incredible advancements in the tech industry that are sure to leave you feeling inspired and empowered. Stay ahead of the game and be the first to know about the newest innovations shaping our world. Discover new ways to improve your daily life, become more efficient, and enjoy new experiences. This time, we've got some exciting news to share with you! Modelling common behaviors between the List and the Set interface has been partially provided by LinkedHashSet. Now from JDK21 with the new interface SequencedCollection extending the Collection interface and is also extended by the List, SortedSet via SequencedSet (for reversal operation), Deque. The SequencedMap interface extends the Map interface by providing the below me

Microservices - Design Patterns

Topic: Software Design                                                                                                        Level: Intermediate Microservices - What? Microservice is a software design methodology, delegated to perform an isolated decoupled single functionality (following the Single-Responsibility Principle from object-oriented SOLID design principles).  Moreover, microservices by design, are decoupled making it easy to develop, test, maintain, deploy, configure, monitor and scale modules independently. Microservices - Why? Having one microservice would not be helpful without it being able to interact with other microservices, to aid in bringing an end-to-end business solution. So arises a question, how can I design a software system that is resilient, decentralized, fault-tolerant, scalable, maintainable, and extensible that complies with the microservice architecture? Design Patterns - What? Design patterns are solutions for commonly occurring problems within a given