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 newJKAbstractDataSourcewith a name and properties. - 
Method Summary
Modifier and TypeMethodDescriptionprotected voidThis method cleans up specific database resources based on the database type.voidclose()This method closes the data source.voidclose(Connection con) This method closes a database connection.voidclose(Connection connection, boolean commit) This method close a database connection with an option to commit the transaction.protected voidThis 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.EntityManagerFactorygetEmf()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.intThis 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 voidinit()This method initializes the data source.protected voidinitProperties(Properties properties) This method initializes the properties for the data source, including default values and configuration fixes.booleanisEntityAvailable(Class<?> clas) This method checks whether the entity is available or not.protected voidprocessProperty(Properties properties, String key, String value) This method processes a property and its value.protected voidThis method scans for JPA entities in the entities packages.protected voidsetEmf(jakarta.persistence.EntityManagerFactory emf) This method sets the entity manager factory instance to the provided one.voidThis method sets the data source name.voidsetProperty(String key, String value) This method sets a property in the data source configuration.protected voidsetPropertyIfNull(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, waitMethods 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 newJKAbstractDataSourcewith 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:
 initin 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:
 getPropertiesin 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:
 closein 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:
 closein 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:
 getConnectionin 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:
 getMaxAllowedConnectionsin interfaceJKDataSource- Returns:
 - the maximum allowed connections for the data source.
 
 - 
setProperty
This method sets a property in the data source configuration.- Specified by:
 setPropertyin 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:
 isEntityAvailablein 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:
 getDatabaseTypein 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:
 closein interfaceJKDataSource
 - 
getQueryConnection
This method gets a query-specific database connection.- Specified by:
 getQueryConnectionin interfaceJKDataSource- Returns:
 - a query-specific database connection.
 - Throws:
 JKDataAccessException
 
 -