Class HibernateProvider

java.lang.Object
org.nuiton.topia.persistence.internal.HibernateProvider

public class HibernateProvider extends Object
Author:
Arnaud Thimel (Code Lutin)
  • Field Details

    • hibernateSessionFactory

      protected org.hibernate.SessionFactory hibernateSessionFactory
    • hibernateConfiguration

      protected org.hibernate.cfg.Configuration hibernateConfiguration
    • topiaConfiguration

      protected TopiaConfiguration topiaConfiguration
    • topiaServiceSupport

      protected TopiaServiceSupport topiaServiceSupport
    • sessionRegistry

      protected TopiaHibernateSessionRegistry sessionRegistry
    • persistenceClasses

      protected Set<Class<?>> persistenceClasses
      List of persistent classes (TopiaEntity or not)
    • metaData

      protected org.hibernate.boot.Metadata metaData
  • Constructor Details

  • Method Details

    • getHibernateConfiguration

      public org.hibernate.cfg.Configuration getHibernateConfiguration()
      Get the current Hibernate Configuration. The Configuration instance is lazy-initialized using the newHibernateConfiguration() method. The returned instance is always initialized and mapping are built.
      Returns:
      the Hibernate Configuration instance with built mappings.
    • newHibernateConfiguration

      public org.hibernate.cfg.Configuration newHibernateConfiguration()
      Creates a new Configuration instance. The instance is create but mappings are not built yet to avoid unwanted database access.
      Returns:
      a new Hibernate Configuration instance without built mappings.
    • getHibernateDialect

      public static String getHibernateDialect(TopiaConfiguration topiaConfiguration)
      Get Hibernate Dialect to use for given TopiaConfiguration. Prefer user defined dialect over dialect guessed by ToPIA; Warn user if dialect declared seems wrong (H2 dialect for a PostgreSQL database)
      Throws:
      TopiaMisconfigurationException - if user must add dialect to its configuration (because it can not be guessed)
    • guessHibernateDialect

      @Deprecated public static String guessHibernateDialect(String jdbcConnectionUrl)
      Deprecated.
      Hibernate can do a much better job at guessing the dialect by calling JDBC and discovering the actual DBMS version and the dialect to use.
    • getStandardServiceRegistry

      public static org.hibernate.boot.registry.StandardServiceRegistry getStandardServiceRegistry(org.hibernate.SessionFactory sessionFactory)
      Method to extract from the given Hibernate SessionFactory a working instance of StandardServiceRegistry IMPORTANT : As much as possible, prefer using the getSessionFactoryServiceRegistry(org.hibernate.SessionFactory) mthod instead of the current one because the SessionFactoryServiceRegistry is a child of the StandardServiceRegistry NB: This method is static to make sure it does not depend on the current instance
      Parameters:
      sessionFactory - the Hibernate's SessionFactory instance
      Returns:
      the StandardServiceRegistry instance used by the given SessionFactory
    • getSessionFactoryServiceRegistry

      protected static org.hibernate.service.spi.SessionFactoryServiceRegistry getSessionFactoryServiceRegistry(org.hibernate.SessionFactory sessionFactory)
      Method to extract from the given Hibernate SessionFactory a working instance of SessionFactoryServiceRegistry IMPORTANT : If possible, prefer using this method instead of getStandardServiceRegistry(org.hibernate.SessionFactory) because the SessionFactoryServiceRegistry is a child of the StandardServiceRegistry NB: This method is static to make sure it does not depend on the current instance
      Parameters:
      sessionFactory - the Hibernate's SessionFactory instance
      Returns:
      the SessionFactoryServiceRegistry instance used by the given SessionFactory
    • getHibernateService

      public static <S extends org.hibernate.service.Service> S getHibernateService(org.hibernate.SessionFactory sessionFactory, Class<S> serviceClass)
      Method to get an Hibernate service instance from a given Hibernate SessionFactory NB: This method is static to make sure it does not depend on the current instance
      Type Parameters:
      S - type of service
      Parameters:
      sessionFactory - the Hibernate's SessionFactory instance
      serviceClass - the expected service class
      Returns:
      the found service instance
      Throws:
      org.hibernate.service.UnknownServiceException - Indicates the service was not known.
      See Also:
      • ServiceRegistry.getService(Class)
    • close

      public void close()
    • getSessionFactory

      public org.hibernate.SessionFactory getSessionFactory()
    • newSessionFactory

      public org.hibernate.SessionFactory newSessionFactory(org.hibernate.cfg.Configuration effectiveHibernateConfiguration)
    • getMetaData

      public org.hibernate.boot.Metadata getMetaData()
    • newMetaData

      public org.hibernate.boot.Metadata newMetaData(org.hibernate.cfg.Configuration configuration, org.hibernate.SessionFactory sessionFactory)
    • newMetaData

      public org.hibernate.boot.Metadata newMetaData(org.hibernate.cfg.Configuration configuration, org.hibernate.SessionFactory sessionFactory, Collection<Class<?>> persistenceClasses)