Package com.jk.data.datasource.impl
Class JKHibernateDataSource
java.lang.Object
com.jk.data.datasource.impl.JKAbstractDataSource
com.jk.data.datasource.impl.JKHibernateDataSource
- All Implemented Interfaces:
Synchronizable
,JKDataSource
- Direct Known Subclasses:
JKPlainDataSource
This class extends
JKAbstractDataSource
and provides specific
functionality for configuring and managing Hibernate-based data sources.- Version:
- 1.0
- Author:
- Dr. Jalal H. Kiswani
-
Field Summary
Fields inherited from class com.jk.data.datasource.impl.JKAbstractDataSource
logger
-
Constructor Summary
ConstructorsConstructorDescriptionJKHibernateDataSource
(String name, Properties properties) This method constructs a newJKHibernateDataSource
with name and configuration properties. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
This method closes the data source.void
close
(jakarta.persistence.EntityManager session, boolean commit) This method close an entity manager with an option to commit the transaction.This method creates a database connection.jakarta.persistence.EntityManager
This method creates an entity manager.protected org.hibernate.cfg.Configuration
This method creates a Hibernate configuration with properties and annotated entity classes.protected Map
This method gets extra Hibernate configuration settings.protected String
This method gets the naming strategy to be used by Hibernate, setting a default if not specified.protected org.hibernate.SessionFactory
This method gets the Hibernate session factory, initializing it if it was null.protected void
This method guesses and sets missing properties based on the database type.void
init()
This method initializes the data source.protected void
This method is supposed to initializes the connection pool for the data source.protected void
This method initializes Hibernate.protected void
processProperty
(Properties properties, String key, String value) This method processes a property and its value.Methods inherited from class com.jk.data.datasource.impl.JKAbstractDataSource
cleanSpecificDatabaseResources, close, close, fixProperties, getClientInfoProperties, getConfig, getConnection, getDatabaseType, getEmf, getEntities, getEntities, getMaxAllowedConnections, getName, getProperties, getQueryConnection, initProperties, isEntityAvailable, scanJpaEntities, setEmf, setName, setProperty, setPropertyIfNull
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
getBaseScriptPath, getDatabaseName, getDatabasepassword, getDatabaseUrl, getDatabaseUsername, getRowsLimit
-
Constructor Details
-
JKHibernateDataSource
This method constructs a newJKHibernateDataSource
with name and configuration properties.- Parameters:
name
- Specifies the name of the data source.properties
- Specifies the properties used for configuration.
-
-
Method Details
-
init
public void init()This method initializes the data source.- Specified by:
init
in interfaceJKDataSource
- Specified by:
init
in classJKAbstractDataSource
-
getNamingStrategy
This method gets the naming strategy to be used by Hibernate, setting a default if not specified.- Returns:
- the naming strategy class name.
-
guessMissingProperties
protected void guessMissingProperties()This method guesses and sets missing properties based on the database type. -
initConnectinoPool
protected void initConnectinoPool()This method is supposed to initializes the connection pool for the data source.Subclasses can override this method to create wrapped connection pools.
-
initHibernate
protected void initHibernate()This method initializes Hibernate. -
createHibernateConfig
protected org.hibernate.cfg.Configuration createHibernateConfig()This method creates a Hibernate configuration with properties and annotated entity classes.- Returns:
- the Hibernate configuration.
-
getHibernateExtraConfig
This method gets extra Hibernate configuration settings.Subclasses can override this method to provide additional configuration.
- Returns:
- the extra Hibernate configuration settings.
-
createEntityManager
public jakarta.persistence.EntityManager createEntityManager()This method creates an entity manager.- Returns:
- an entity manager.
-
close
public void close(jakarta.persistence.EntityManager session, boolean commit) This method close an entity manager with an option to commit the transaction.- Parameters:
session
- Specifies the entity manager to close.commit
- Indicates whether to commit the transaction (true) or not (false).
-
createConnection
This method creates a database connection.- Returns:
- a database connection.
-
getSessionFactory
protected org.hibernate.SessionFactory getSessionFactory()This method gets the Hibernate session factory, initializing it if it was null.- Returns:
- the Hibernate session factory.
-
processProperty
This method processes a property and its value.- Overrides:
processProperty
in classJKAbstractDataSource
- Parameters:
properties
- Specifies the properties to process.key
- Specifies the key of the property.value
- Specifies the value of the property.
-
close
public void close()This method closes the data source.- Specified by:
close
in interfaceJKDataSource
- Overrides:
close
in classJKAbstractDataSource
-