Package com.jk.data.datasource.impl
Class JKAbstractDataSource
java.lang.Object
com.jk.data.datasource.impl.JKAbstractDataSource
- All Implemented Interfaces:
Synchronizable
,JKDataSource
- Direct Known Subclasses:
JKHibernateDataSource
This class is an abstract base class that implements the
JKDataSource
interface.
It provides common functionality for data sources and allows for the configuration of database connections.
- Version:
- 1.0
- Author:
- Dr. Jalal H. Kiswani
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionThis method constructs a newJKAbstractDataSource
.JKAbstractDataSource
(String name, Properties properties) This method constructs a newJKAbstractDataSource
with a name and properties. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
This method cleans up specific database resources based on the database type.void
close()
This method closes the data source.void
close
(Connection con) This method closes a database connection.void
close
(Connection connection, boolean commit) This method close a database connection with an option to commit the transaction.protected void
This method applies fixes and configurations to the data source properties.This method gets client information properties for the database connection.This method gets the configuration for this data source.This method gets a database connection.This method gets the type of database.jakarta.persistence.EntityManagerFactory
getEmf()
This method gets the entity manager factory instance.This method gets the list of entity class names associated with this data source.getEntities
(boolean initIfNull) This method gets the list of entity class names associated with this data source and initiates it if its null.int
This method gets the maximum allowed connections for the data source.getName()
This method gets the data source name.This method gets the properties associated with the data source.This method gets a query-specific database connection.abstract void
init()
This method initializes the data source.protected void
initProperties
(Properties properties) This method initializes the properties for the data source, including default values and configuration fixes.boolean
isEntityAvailable
(Class<?> clas) This method checks whether the entity is available or not.protected void
processProperty
(Properties properties, String key, String value) This method processes a property and its value.protected void
This method scans for JPA entities in the entities packages.protected void
setEmf
(jakarta.persistence.EntityManagerFactory emf) This method sets the entity manager factory instance to the provided one.void
This method sets the data source name.void
setProperty
(String key, String value) This method sets a property in the data source configuration.protected void
setPropertyIfNull
(String property, String value) This method sets a property in the configuration if it's null to the provided value.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.jk.data.datasource.JKDataSource
close, createConnection, createEntityManager, getBaseScriptPath, getDatabaseName, getDatabasepassword, getDatabaseUrl, getDatabaseUsername, getRowsLimit
-
Field Details
-
logger
Represents this class logger.
-
-
Constructor Details
-
JKAbstractDataSource
public JKAbstractDataSource()This method constructs a newJKAbstractDataSource
. -
JKAbstractDataSource
This method constructs a newJKAbstractDataSource
with a name and properties.- Parameters:
name
- Specifies the name of the data source.properties
- Specifies the properties used for configuration.
-
-
Method Details
-
initProperties
This method initializes the properties for the data source, including default values and configuration fixes.- Parameters:
properties
- Specifies the properties to initialize.
-
fixProperties
protected void fixProperties()This method applies fixes and configurations to the data source properties. -
processProperty
This method processes a property and its value.- Parameters:
properties
- Specifies the properties to process.key
- Specifies the key of the property.value
- Specifies the value of the property.
-
init
public abstract void init()This method initializes the data source.- Specified by:
init
in interfaceJKDataSource
-
getName
This method gets the data source name.- Returns:
- the data source name.
-
setName
This method sets the data source name.- Parameters:
name
- Specifies the new data source name.
-
getEntities
This method gets the list of entity class names associated with this data source.- Returns:
- the list of entity class names associated with this data source.
-
getEntities
This method gets the list of entity class names associated with this data source and initiates it if its null.- Parameters:
initIfNull
- Indicates whether the list should be initiated if its null or not.- Returns:
- the list of entity class names.
-
getProperties
This method gets the properties associated with the data source.- Specified by:
getProperties
in interfaceJKDataSource
- Returns:
- the properties.
-
cleanSpecificDatabaseResources
protected void cleanSpecificDatabaseResources()This method cleans up specific database resources based on the database type. -
close
This method closes a database connection.- Specified by:
close
in interfaceJKDataSource
- Parameters:
con
- Specifies the database connection to close.
-
close
This method close a database connection with an option to commit the transaction.- Specified by:
close
in interfaceJKDataSource
- Parameters:
connection
- Specifies the database connection to close.commit
- Indicates whether to commit the transaction (true), or not (false).
-
getConnection
This method gets a database connection.- Specified by:
getConnection
in interfaceJKDataSource
- Returns:
- a database connection.
- Throws:
JKDataAccessException
-
getClientInfoProperties
This method gets client information properties for the database connection.- Returns:
- the client information properties.
-
getEmf
public jakarta.persistence.EntityManagerFactory getEmf()This method gets the entity manager factory instance.- Returns:
- the entity manager factory instance.
-
setEmf
protected void setEmf(jakarta.persistence.EntityManagerFactory emf) This method sets the entity manager factory instance to the provided one.- Parameters:
emf
- Specifies the new entity manager factory instance.
-
scanJpaEntities
protected void scanJpaEntities()This method scans for JPA entities in the entities packages. -
getMaxAllowedConnections
public int getMaxAllowedConnections()This method gets the maximum allowed connections for the data source.- Specified by:
getMaxAllowedConnections
in interfaceJKDataSource
- Returns:
- the maximum allowed connections for the data source.
-
setProperty
This method sets a property in the data source configuration.- Specified by:
setProperty
in interfaceJKDataSource
- Parameters:
key
- Specifies the key of the property.value
- Specifies the value of the property.
-
isEntityAvailable
This method checks whether the entity is available or not.- Specified by:
isEntityAvailable
in interfaceJKDataSource
- Parameters:
clas
- Specifies the class of the entity to check.- Returns:
- true, if the entity is available, false otherwise.
-
getDatabaseType
This method gets the type of database.- Specified by:
getDatabaseType
in interfaceJKDataSource
- Returns:
- the database type.
-
getConfig
This method gets the configuration for this data source.- Returns:
- the configuration for this data source.
-
setPropertyIfNull
This method sets a property in the configuration if it's null to the provided value.- Parameters:
property
- Specifies the property key.value
- Specifies the property value.
-
close
public void close()This method closes the data source.- Specified by:
close
in interfaceJKDataSource
-
getQueryConnection
This method gets a query-specific database connection.- Specified by:
getQueryConnection
in interfaceJKDataSource
- Returns:
- a query-specific database connection.
- Throws:
JKDataAccessException
-