Class JKAbstractDataSource

java.lang.Object
com.jk.data.datasource.impl.JKAbstractDataSource
All Implemented Interfaces:
Synchronizable, JKDataSource
Direct Known Subclasses:
JKHibernateDataSource

public abstract class JKAbstractDataSource extends Object implements JKDataSource
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 Details

    • logger

      protected JKLogger logger
      Represents this class logger.
  • Constructor Details

    • JKAbstractDataSource

      public JKAbstractDataSource()
      This method constructs a new JKAbstractDataSource.
    • JKAbstractDataSource

      public JKAbstractDataSource(String name, Properties properties)
      This method constructs a new JKAbstractDataSource with a name and properties.
      Parameters:
      name - Specifies the name of the data source.
      properties - Specifies the properties used for configuration.
  • Method Details

    • initProperties

      protected void initProperties(Properties properties)
      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

      protected void processProperty(Properties properties, String key, String value)
      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 interface JKDataSource
    • getName

      public String getName()
      This method gets the data source name.
      Returns:
      the data source name.
    • setName

      public void setName(String name)
      This method sets the data source name.
      Parameters:
      name - Specifies the new data source name.
    • getEntities

      public List<String> 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

      public List<String> getEntities(boolean initIfNull)
      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

      public Properties getProperties()
      This method gets the properties associated with the data source.
      Specified by:
      getProperties in interface JKDataSource
      Returns:
      the properties.
    • cleanSpecificDatabaseResources

      protected void cleanSpecificDatabaseResources()
      This method cleans up specific database resources based on the database type.
    • close

      public void close(Connection con)
      This method closes a database connection.
      Specified by:
      close in interface JKDataSource
      Parameters:
      con - Specifies the database connection to close.
    • close

      public void close(Connection connection, boolean commit)
      This method close a database connection with an option to commit the transaction.
      Specified by:
      close in interface JKDataSource
      Parameters:
      connection - Specifies the database connection to close.
      commit - Indicates whether to commit the transaction (true), or not (false).
    • getConnection

      public Connection getConnection() throws JKDataAccessException
      This method gets a database connection.
      Specified by:
      getConnection in interface JKDataSource
      Returns:
      a database connection.
      Throws:
      JKDataAccessException
    • getClientInfoProperties

      public Properties 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 interface JKDataSource
      Returns:
      the maximum allowed connections for the data source.
    • setProperty

      public void setProperty(String key, String value)
      This method sets a property in the data source configuration.
      Specified by:
      setProperty in interface JKDataSource
      Parameters:
      key - Specifies the key of the property.
      value - Specifies the value of the property.
    • isEntityAvailable

      public boolean isEntityAvailable(Class<?> clas)
      This method checks whether the entity is available or not.
      Specified by:
      isEntityAvailable in interface JKDataSource
      Parameters:
      clas - Specifies the class of the entity to check.
      Returns:
      true, if the entity is available, false otherwise.
    • getDatabaseType

      public JKDatabase getDatabaseType()
      This method gets the type of database.
      Specified by:
      getDatabaseType in interface JKDataSource
      Returns:
      the database type.
    • getConfig

      public JKConfig getConfig()
      This method gets the configuration for this data source.
      Returns:
      the configuration for this data source.
    • setPropertyIfNull

      protected void setPropertyIfNull(String property, String value)
      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 interface JKDataSource
    • getQueryConnection

      public Connection getQueryConnection() throws JKDataAccessException
      This method gets a query-specific database connection.
      Specified by:
      getQueryConnection in interface JKDataSource
      Returns:
      a query-specific database connection.
      Throws:
      JKDataAccessException