public final class HibernateService extends Object implements AutoCloseable
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes all Cached Factories
|
boolean |
connect(IHibernateConfig hibernateConfig)
Tries to set up a factory for given configuration
|
boolean |
disconnect(IHibernateConfig hibernateConfig)
Tries to disconnect and close factory
|
void |
exportSchema(HibernateConfig config,
String exportFile)
Creates Schema of given Config in given File.
|
javax.persistence.EntityManager |
getEntityManager(JPAConfig config)
Returns a new
EntityManager. |
javax.persistence.EntityManagerFactory |
getEntityManagerFactory(JPAConfig config)
Returns a Entity Manager Factory Cached by this Service
Returns like specified in ConcurrentHashMap.get(Object) |
String[] |
getFullStatistics()
Returns statistics for every database connections.
|
static HibernateService |
getInstance() |
org.hibernate.Session |
getSession(IHibernateConfig config)
Returns a new open and valid
Session. |
org.hibernate.SessionFactory |
getSessionFactory(IHibernateConfig hconfig)
Returns a Session Factory Cached by this Service
Returns like specified in ConcurrentHashMap.get(Object)
if given parameter is a instance of JPAConfig this method will
cast a given HibernateEntityManagerFactory to a
SessionFactory if necessery. |
org.hibernate.StatelessSession |
getStatelessSession(IHibernateConfig config)
Returns a new open and valid
StatelessSession. |
static void |
persistList(List<?> list,
HibernateConfig conf)
Calls
Session.saveOrUpdate(Object) on every object in given list. |
static void |
persistListParallel(List<?> list,
HibernateConfig conf,
double loadFactor)
Calls
persistList(List, HibernateConfig) concurrently. |
boolean |
reloadConfiguration(IHibernateConfig hibernateConfig)
Tries to reload given connection
|
String |
toString() |
public boolean connect(IHibernateConfig hibernateConfig)
hibernateConfig - configuration with connection propertiesIllegalArgumentException - if parameter is nullorg.hibernate.HibernateException - if Session Factory could not be created (if parameter is
instance of HibernateConfig)javax.persistence.PersistenceException - if Entity Manager could not be created (if parameter is
instance of JPAConfig)SessionFactory}public boolean disconnect(IHibernateConfig hibernateConfig)
hibernateConfig - configuration with connection propertiesIllegalArgumentException - if parameter is nullpublic boolean reloadConfiguration(IHibernateConfig hibernateConfig)
hibernateConfig - configuration to reloadIllegalArgumentException - if parameter is nullorg.hibernate.HibernateException - if Session Factory could not be createdjavax.persistence.PersistenceException - if Entity Manager could not be createdHibernateService#connect(IHibernateConfig)},
HibernateService#disconnect(IHibernateConfig)}public org.hibernate.SessionFactory getSessionFactory(IHibernateConfig hconfig)
ConcurrentHashMap.get(Object)
if given parameter is a instance of JPAConfig this method will
cast a given HibernateEntityManagerFactory to a
SessionFactory if necessery.
hconfig - configuration to look forIllegalArgumentException - if parameter is nullpublic javax.persistence.EntityManagerFactory getEntityManagerFactory(JPAConfig config)
ConcurrentHashMap.get(Object)config - configuration to look forIllegalArgumentException - if parameter is nullpublic org.hibernate.Session getSession(IHibernateConfig config)
Session. Calls
connect(IHibernateConfig) if needed.config - configurationIllegalArgumentException - if parameter is nullorg.hibernate.HibernateException - if Session Factory could not be created (if parameter is
instance of HibernateConfig) -
connect(IHibernateConfig)javax.persistence.PersistenceException - if Entity Manager could not be created (if parameter is
instance of JPAConfig) -
connect(IHibernateConfig)NullPointerException - if no SessionFactory could be obtained, when
connect(IHibernateConfig) was calledNullPointerException - if config is no instance of HibernateConfig or
JPAConfigHibernateService#connect(IHibernateConfig)},
HibernateService#disconnect(IHibernateConfig)}public org.hibernate.StatelessSession getStatelessSession(IHibernateConfig config)
StatelessSession. Calls
connect(IHibernateConfig) if needed.config - configurationIllegalArgumentException - if parameter is nullorg.hibernate.HibernateException - if Session Factory could not be created (if parameter is
instance of HibernateConfig) -
connect(IHibernateConfig)javax.persistence.PersistenceException - if Entity Manager could not be created (if parameter is
instance of JPAConfig) -
connect(IHibernateConfig)NullPointerException - if no SessionFactory could be obtained, when
connect(IHibernateConfig) was calledNullPointerException - if config is no instance of HibernateConfig or
JPAConfigNotSupportedException - if config is a isntance of OGMConfig since Stateless
sessions are not supported in ogm databasesHibernateService#connect(IHibernateConfig)},
HibernateService#disconnect(IHibernateConfig)}public javax.persistence.EntityManager getEntityManager(JPAConfig config)
EntityManager. Calls
connect(IHibernateConfig) if needed.config - configurationIllegalArgumentException - if parameter is nulljavax.persistence.PersistenceException - if Entity Manager could not be created -
connect(IHibernateConfig)NullPointerException - if no SessionFactory could be obtained, when
connect(IHibernateConfig) was calledHibernateService#connect(IHibernateConfig)},
HibernateService#disconnect(IHibernateConfig)}public void exportSchema(HibernateConfig config, String exportFile)
config - HibernateConfig config. Must be HibernateConfig.exportFile - Export File Directoryorg.hibernate.HibernateException - of config is no HibernateConfigpublic String[] getFullStatistics()
HibernateConfig.GENERATE_STATISTICSpublic static void persistListParallel(List<?> list, HibernateConfig conf, double loadFactor)
persistList(List, HibernateConfig) concurrently. HibernateConfig.C3P0_MAX_SIZE * laodFactor Threads. persistList(List, HibernateConfig) insteadlist - object list to persistconf - database connection configurationloadFactor - % of used Sessions. HibernateConfig.C3P0_MAX_SIZE used sessions.
0 equals 1 used session. Use
persistList(List, HibernateConfig) in this case.IllegalArgumentException - if loadFactor 0s > 1d || <= 0dException - as specified in persistList(List, HibernateConfig)persistList(List, HibernateConfig)public static void persistList(List<?> list, HibernateConfig conf)
Session.saveOrUpdate(Object) on every object in given list. getSession(IHibernateConfig) HibernateConfig.STATEMENT_BATCH_SIZE for batch processinglist - object list to persistconf - database connection configurationException - as specified in getSession(IHibernateConfig)Exception - as specified in Session.saveOrUpdate(Object)Exception - as specified in Session#flush(Object)Exception - as specified in Session#close(Object)Exception - as specified in SharedSessionContract.getTransaction()Exception - as specified in Transaction.begin()Exception - as specified in Transaction.rollback()getSession(IHibernateConfig),
HibernateConfig.STATEMENT_BATCH_SIZEpublic void close()
throws Exception
close in interface AutoCloseableExceptionAutoCloseable.close()public String toString()
toString in class ObjectObject.toString()public static HibernateService getInstance()
Copyright © 2014–2015. All rights reserved.