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

public class JKHibernateDataSource extends JKAbstractDataSource
This class extends JKAbstractDataSource and provides specific functionality for configuring and managing Hibernate-based data sources.
Version:
1.0
Author:
Dr. Jalal H. Kiswani
  • Constructor Details

    • JKHibernateDataSource

      public JKHibernateDataSource(String name, Properties properties)
      This method constructs a new JKHibernateDataSource 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 interface JKDataSource
      Specified by:
      init in class JKAbstractDataSource
    • getNamingStrategy

      protected String 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

      protected Map 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

      public Connection 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

      protected void processProperty(Properties properties, String key, String value)
      This method processes a property and its value.
      Overrides:
      processProperty in class JKAbstractDataSource
      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 interface JKDataSource
      Overrides:
      close in class JKAbstractDataSource