"Welcome To Ashok IT"
"Spring Boot and MicroServices"
Topic : Connection Pooling
Date : 06/11/2024
(Session - 60)
_____________________________________________________________________________________________________________________________
Yesterday Session
=================
* We Just Completed working with Association in Spring Data JPA.
1) one to one UniDirection
2) one to one Bidirection
3) one to many unidirection
4) one to many Bidirection(@ManyToOne Annotation)
Today Session
=============
* Whenever developing Plain Jdbc Application we used DriverManager Service to get Database connection object.In those application as programmer He/she need to taken care of opening database connection & closing Database connection.
* If the programmer forgot to close the Database object and it will leads to "Connection Exhausted Problem" in Jdbc Application inorder to avoid these always recommended to collect the Database connection from connection pool.
* Connection pool is nothing but the set of readily available database connection objects.
* When we are working with Connection pool as programmer we need to worry about opening database connection and closing database connection and it will taken care "Pool Manager".
* In the entire Spring eco system(Spring Jdbc,Spring ORM,Spring data(JPA,Jdbc) always we are getting connection object through connection pool itself i.e., Indirectly working with DataSource Interface
javax.sql.DataSource(I) >>>>>>>>>>>>>>>>>>>>>>>>>>>DriverManagerDataSource >>>>>>>>>>>>>>>>>>Spring Vendor
>>>>>>>>>>>>>>>>>>>>>>>>>>>BasicDataSource >>>>>>>>>>>>>>>>>>>>>>>>>>> Apache Software Vendor
>>>>>>>>>>>>>>>>>>>>>>>>>>>HiKariDataSource >>>>>>>>>>>>>>>>>>>>>>>>>>>Hikari(SpringBoot)
* We have N of implementation related to Connection pool Mechanism
1) Hikari connection pool datasource.
2) Tomcat Connection pool Datasource.
3) Apache dbcp2 Connection Pool Datasource.
4) Oracle UCP Connection Pool Datasource.
* When we are working with Spring boot 2.x & 3.x version by default will gives Datasource object from "Hikari Connection pool" using hikari-cp-version.jar.
* If we want to get the Datasource object other than Hikari means we have to exclude the hikaricp-version.jar from build path.
org.springframework.boot
spring-boot-starter-data-jpa
com.zaxxer
HikariCP
* If we want the DataSource Object from Tomcat Connection pool, we have to add that below dependency manually in pom.xml
org.apache.tomcat
tomcat-jdbc
* If we want the Datasource object other than Hikari & Tomcat Jdbc, we have to add dpcp2 maven dependency in pom.xml
org.apache.commons
commons-dbcp2
* In Spring Boot Application development(2.x & 3.x) we have following alogrthim for getting the DataSource object
1) Hikari Datasource
2) tomcat Jdbc
3) Apache dpcp2
4) oracle ucp (Oracle Database)
* In Spring Boot Application development(1.x) we have following alogrthim for getting the DataSource object
1) tomcat Jdbc
2) Hikari Datasource
3) Apache dpcp2
4) oracle ucp
@Transient Annotation
=====================
* When persisting Java objects into database records using an Object-Relational Mapping (ORM) framework sometimes some of fields in the entity class won't participate in Database operations in ORM Framework.
* If Field not to be participate in Database operations that field to be declare as @Transient Annotation.
Example
========
@Entity
@Table(name="ashokit_customers")
public class Customers {
@Id
@Column(name="customer_id")
@GeneratedValue
private Integer customerId;
@Column(name="first_name")
private String firsName;
@Column(name="last_name")
private String lastName;
@Column(name="customer_location")
private String customerLcoation;
@Transient
private String fullName;
public String getFullName() {
fullName = firsName + " "+ lastName;
return fullName;
}
}
NOTE
=====
* In the above entity class fullName property is not participating in Database operation.
* we can populate the full name as firstName & lastName property in entity class.