Class HibernateProvider
java.lang.Object
org.nuiton.topia.persistence.internal.HibernateProvider
- Author:
- Arnaud Thimel (Code Lutin)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.hibernate.cfg.Configurationprotected org.hibernate.SessionFactoryprotected org.hibernate.boot.MetadataList of persistent classes (TopiaEntity or not)protected TopiaHibernateSessionRegistryprotected TopiaConfigurationprotected TopiaServiceSupport -
Constructor Summary
ConstructorsConstructorDescriptionHibernateProvider(TopiaConfiguration topiaConfiguration, TopiaServiceSupport topiaServiceSupport, TopiaHibernateSessionRegistry sessionRegistry, Iterable<Class<?>> persistenceClasses) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()org.hibernate.cfg.ConfigurationGet the current Hibernate Configuration.static StringgetHibernateDialect(TopiaConfiguration topiaConfiguration) Get HibernateDialectto use for givenTopiaConfiguration.static <S extends org.hibernate.service.Service>
SgetHibernateService(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 instanceorg.hibernate.boot.Metadataorg.hibernate.SessionFactoryprotected static org.hibernate.service.spi.SessionFactoryServiceRegistrygetSessionFactoryServiceRegistry(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 ofgetStandardServiceRegistry(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 instancestatic org.hibernate.boot.registry.StandardServiceRegistrygetStandardServiceRegistry(org.hibernate.SessionFactory sessionFactory) Method to extract from the given Hibernate SessionFactory a working instance of StandardServiceRegistry IMPORTANT : As much as possible, prefer using thegetSessionFactoryServiceRegistry(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 instancestatic StringguessHibernateDialect(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.org.hibernate.cfg.ConfigurationCreates a new Configuration instance.org.hibernate.boot.MetadatanewMetaData(org.hibernate.cfg.Configuration configuration, org.hibernate.SessionFactory sessionFactory) org.hibernate.boot.MetadatanewMetaData(org.hibernate.cfg.Configuration configuration, org.hibernate.SessionFactory sessionFactory, Collection<Class<?>> persistenceClasses) org.hibernate.SessionFactorynewSessionFactory(org.hibernate.cfg.Configuration effectiveHibernateConfiguration)
-
Field Details
-
hibernateSessionFactory
protected org.hibernate.SessionFactory hibernateSessionFactory -
hibernateConfiguration
protected org.hibernate.cfg.Configuration hibernateConfiguration -
topiaConfiguration
-
topiaServiceSupport
-
sessionRegistry
-
persistenceClasses
List of persistent classes (TopiaEntity or not) -
metaData
protected org.hibernate.boot.Metadata metaData
-
-
Constructor Details
-
HibernateProvider
public HibernateProvider(TopiaConfiguration topiaConfiguration, TopiaServiceSupport topiaServiceSupport, TopiaHibernateSessionRegistry sessionRegistry, Iterable<Class<?>> persistenceClasses)
-
-
Method Details
-
getHibernateConfiguration
public org.hibernate.cfg.Configuration getHibernateConfiguration()Get the current Hibernate Configuration. The Configuration instance is lazy-initialized using thenewHibernateConfiguration()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
Get HibernateDialectto use for givenTopiaConfiguration. 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.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 thegetSessionFactoryServiceRegistry(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 ofgetStandardServiceRegistry(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 instanceserviceClass- 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)
-