Class HibernateDaoMaster

java.lang.Object
rs.data.impl.AbstractDaoMaster
rs.data.hibernate.HibernateDaoMaster
All Implemented Interfaces:
IConfigurable, IDaoMaster

public class HibernateDaoMaster
extends AbstractDaoMaster
The DAO Master holding information about the DB connection and Hibernate instance.
Author:
ralph
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static java.lang.String DEFAULT_CONFIG_FILE  
    static java.lang.String FACTORY_KEY  
  • Constructor Summary

    Constructors 
    Constructor Description
    HibernateDaoMaster()
    Constructor.
  • Method Summary

    Modifier and Type Method Description
    void configure​(org.apache.commons.configuration.Configuration cfg)
    static org.hibernate.cfg.Configuration createConfiguration​(java.io.File file, java.util.Properties overriddenProperties)
    Creates the Hibernate configuration.
    static org.hibernate.cfg.Configuration createConfiguration​(java.lang.String configFile, java.util.Properties overriddenProperties)
    Creates the Hibernate configuration.
    static org.hibernate.cfg.Configuration createConfiguration​(java.net.URL url, java.util.Properties overriddenProperties)
    Creates the Hibernate configuration.
    static org.hibernate.SessionFactory createSessionFactory()
    Returns a new session factory from default Hibernate config file.
    static org.hibernate.SessionFactory createSessionFactory​(java.io.File configFile)
    Returns a new session factory from given Hibernate config file.
    static org.hibernate.SessionFactory createSessionFactory​(java.io.File configFile, java.util.Properties overriddenProperties)
    Returns a new session factory.
    static org.hibernate.SessionFactory createSessionFactory​(java.lang.String configFile)
    Returns a new session factory from given Hibernate config file.
    static org.hibernate.SessionFactory createSessionFactory​(java.lang.String configFile, java.util.Properties overriddenProperties)
    Returns a new session factory.
    static org.hibernate.SessionFactory createSessionFactory​(java.net.URL configFile)
    Returns a new session factory from given Hibernate config file.
    static org.hibernate.SessionFactory createSessionFactory​(java.net.URL configFile, java.util.Properties overriddenProperties)
    Returns a new session factory.
    static org.hibernate.SessionFactory createSessionFactory​(java.util.Properties overriddenProperties)
    Returns a new session factory from default Hibernate config file.
    static org.hibernate.SessionFactory createSessionFactory​(org.hibernate.cfg.Configuration config)
    Returns a new session factory.
    javax.sql.DataSource getDatasource()
    Returns the datasource.
    org.hibernate.Session getSession()
    Returns the Hibernate session.
    org.hibernate.SessionFactory getSessionFactory()
    Returns the sessionFactory.
    protected void loadDataSource​(org.apache.commons.configuration.SubnodeConfiguration dbconfig)
    Load the data source configuration and inject it for hibernate.
    void setSessionFactory​(org.hibernate.SessionFactory sessionFactory)
    Sets the sessionFactory.
    void shutdown()
    protected java.net.URL toURL​(java.lang.String key)
    Tries to get the URL from the factory.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • configure

      public void configure​(org.apache.commons.configuration.Configuration cfg) throws org.apache.commons.configuration.ConfigurationException

      hbmconfig-file and dbconfig-file properties will support the env: syntax for evaluating environment values, and class: for programmatic configuration.

      db config file supports the $ENV{name} syntax in its properties.

      Specified by:
      configure in interface IConfigurable
      Overrides:
      configure in class AbstractDaoMaster
      Throws:
      org.apache.commons.configuration.ConfigurationException
    • toURL

      protected java.net.URL toURL​(java.lang.String key) throws org.apache.commons.configuration.ConfigurationException
      Tries to get the URL from the factory. If the URL cannot be constructed by the factory then a File URL will be assumed.
      Parameters:
      key - parameter key in factory
      Returns:
      URL
      Throws:
      org.apache.commons.configuration.ConfigurationException - if the transformation fails
    • loadDataSource

      protected void loadDataSource​(org.apache.commons.configuration.SubnodeConfiguration dbconfig)
      Load the data source configuration and inject it for hibernate.
      Parameters:
      dbconfig - - the subnode configuration for the db configuration
    • getDatasource

      public javax.sql.DataSource getDatasource()
      Returns the datasource.
      Returns:
      the datasource
    • getSessionFactory

      public org.hibernate.SessionFactory getSessionFactory()
      Returns the sessionFactory.
      Returns:
      the sessionFactory
    • setSessionFactory

      public void setSessionFactory​(org.hibernate.SessionFactory sessionFactory)
      Sets the sessionFactory.
      Parameters:
      sessionFactory - the sessionFactory to set
    • shutdown

      public void shutdown()
      Specified by:
      shutdown in interface IDaoMaster
      Overrides:
      shutdown in class AbstractDaoMaster
    • getSession

      public org.hibernate.Session getSession()
      Returns the Hibernate session. This method will start a new transaction if required.
      Returns:
      hibernate session.
    • createSessionFactory

      public static org.hibernate.SessionFactory createSessionFactory()
      Returns a new session factory from default Hibernate config file.
      Returns:
      session factory
    • createSessionFactory

      public static org.hibernate.SessionFactory createSessionFactory​(java.lang.String configFile)
      Returns a new session factory from given Hibernate config file.
      Parameters:
      configFile - - Hibernate configuration file
      Returns:
      session factory
    • createSessionFactory

      public static org.hibernate.SessionFactory createSessionFactory​(java.net.URL configFile)
      Returns a new session factory from given Hibernate config file.
      Parameters:
      configFile - - Hibernate configuration file
      Returns:
      session factory
    • createSessionFactory

      public static org.hibernate.SessionFactory createSessionFactory​(java.io.File configFile)
      Returns a new session factory from given Hibernate config file.
      Parameters:
      configFile - - Hibernate configuration file
      Returns:
      session factory
    • createSessionFactory

      public static org.hibernate.SessionFactory createSessionFactory​(java.util.Properties overriddenProperties)
      Returns a new session factory from default Hibernate config file.
      Parameters:
      overriddenProperties - - Properties that must be overridden on Hibernate's config file
      Returns:
      session factory
    • createSessionFactory

      public static org.hibernate.SessionFactory createSessionFactory​(java.lang.String configFile, java.util.Properties overriddenProperties)
      Returns a new session factory.
      Parameters:
      configFile - - Hibernate configuration file
      overriddenProperties - - Properties that must be overridden on Hibernate's config file
      Returns:
      session factory
    • createSessionFactory

      public static org.hibernate.SessionFactory createSessionFactory​(java.net.URL configFile, java.util.Properties overriddenProperties)
      Returns a new session factory.
      Parameters:
      configFile - - Hibernate configuration file
      overriddenProperties - - Properties that must be overridden on Hibernate's config file
      Returns:
      session factory
    • createSessionFactory

      public static org.hibernate.SessionFactory createSessionFactory​(java.io.File configFile, java.util.Properties overriddenProperties)
      Returns a new session factory.
      Parameters:
      configFile - - Hibernate configuration file
      overriddenProperties - - Properties that must be overridden on Hibernate's config file
      Returns:
      session factory
    • createSessionFactory

      public static org.hibernate.SessionFactory createSessionFactory​(org.hibernate.cfg.Configuration config)
      Returns a new session factory.
      Parameters:
      config - - Hibernate configuration
      Returns:
      session factory
    • createConfiguration

      public static org.hibernate.cfg.Configuration createConfiguration​(java.lang.String configFile, java.util.Properties overriddenProperties)
      Creates the Hibernate configuration.
      Parameters:
      configFile - - Hibernate configuration file
      overriddenProperties - - Properties that must be overridden on Hibernate's config file
      Returns:
      configuration object
    • createConfiguration

      public static org.hibernate.cfg.Configuration createConfiguration​(java.io.File file, java.util.Properties overriddenProperties)
      Creates the Hibernate configuration.
      Parameters:
      file - - Hibernate configuration file
      overriddenProperties - - Properties that must be overridden on Hibernate's config file
      Returns:
      configuration object
    • createConfiguration

      public static org.hibernate.cfg.Configuration createConfiguration​(java.net.URL url, java.util.Properties overriddenProperties)
      Creates the Hibernate configuration.
      Parameters:
      url - - URL of Hibernate configuration file
      overriddenProperties - - Properties that must be overridden on Hibernate's config file
      Returns:
      configuration object