Package io.dropwizard.hibernate.dual
Class DualSessionFactory
- java.lang.Object
-
- io.dropwizard.hibernate.dual.DualSessionFactory
-
- All Implemented Interfaces:
jakarta.persistence.EntityManagerFactory
,Closeable
,Serializable
,AutoCloseable
,Referenceable
,org.hibernate.SessionFactory
public class DualSessionFactory extends Object implements org.hibernate.SessionFactory
Represents a wrapper/decorator class for a Hibernate session factory that can manage both a primary session factory and a read-only session factory.- Since:
- 2.1
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description DualSessionFactory(org.hibernate.SessionFactory primary, org.hibernate.SessionFactory reader)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> void
addNamedEntityGraph(String graphName, jakarta.persistence.EntityGraph<T> entityGraph)
void
addNamedQuery(String name, jakarta.persistence.Query query)
void
close()
boolean
containsFetchProfileDefinition(String name)
jakarta.persistence.EntityManager
createEntityManager()
jakarta.persistence.EntityManager
createEntityManager(jakarta.persistence.SynchronizationType synchronizationType)
jakarta.persistence.EntityManager
createEntityManager(jakarta.persistence.SynchronizationType synchronizationType, Map map)
jakarta.persistence.EntityManager
createEntityManager(Map map)
org.hibernate.SessionFactory
current()
<T> List<jakarta.persistence.EntityGraph<? super T>>
findEntityGraphsByType(Class<T> entityClass)
<R> R
fromSession(Function<org.hibernate.Session,R> action)
<R> R
fromTransaction(Function<org.hibernate.Session,R> action)
org.hibernate.Cache
getCache()
jakarta.persistence.criteria.CriteriaBuilder
getCriteriaBuilder()
org.hibernate.Session
getCurrentSession()
Set
getDefinedFilterNames()
org.hibernate.engine.spi.FilterDefinition
getFilterDefinition(String filterName)
jakarta.persistence.metamodel.Metamodel
getMetamodel()
jakarta.persistence.PersistenceUnitUtil
getPersistenceUnitUtil()
Map<String,Object>
getProperties()
Reference
getReference()
org.hibernate.boot.spi.SessionFactoryOptions
getSessionFactoryOptions()
org.hibernate.stat.Statistics
getStatistics()
void
inSession(Consumer<org.hibernate.Session> action)
void
inTransaction(Consumer<org.hibernate.Session> action)
boolean
isClosed()
boolean
isOpen()
org.hibernate.Session
openSession()
org.hibernate.StatelessSession
openStatelessSession()
org.hibernate.StatelessSession
openStatelessSession(Connection connection)
org.hibernate.SessionFactory
prepare(boolean readOnly)
Activates either the primary or the reader session factory depending on the readOnly parameter.<T> T
unwrap(Class<T> cls)
org.hibernate.SessionBuilder
withOptions()
org.hibernate.StatelessSessionBuilder
withStatelessOptions()
-
-
-
Method Detail
-
prepare
public org.hibernate.SessionFactory prepare(boolean readOnly)
Activates either the primary or the reader session factory depending on the readOnly parameter.- Parameters:
readOnly
-- Returns:
- the session factory in use
-
current
public org.hibernate.SessionFactory current()
-
createEntityManager
public jakarta.persistence.EntityManager createEntityManager()
- Specified by:
createEntityManager
in interfacejakarta.persistence.EntityManagerFactory
-
createEntityManager
public jakarta.persistence.EntityManager createEntityManager(Map map)
- Specified by:
createEntityManager
in interfacejakarta.persistence.EntityManagerFactory
-
createEntityManager
public jakarta.persistence.EntityManager createEntityManager(jakarta.persistence.SynchronizationType synchronizationType)
- Specified by:
createEntityManager
in interfacejakarta.persistence.EntityManagerFactory
-
createEntityManager
public jakarta.persistence.EntityManager createEntityManager(jakarta.persistence.SynchronizationType synchronizationType, Map map)
- Specified by:
createEntityManager
in interfacejakarta.persistence.EntityManagerFactory
-
getCriteriaBuilder
public jakarta.persistence.criteria.CriteriaBuilder getCriteriaBuilder()
- Specified by:
getCriteriaBuilder
in interfacejakarta.persistence.EntityManagerFactory
-
getMetamodel
public jakarta.persistence.metamodel.Metamodel getMetamodel()
- Specified by:
getMetamodel
in interfacejakarta.persistence.EntityManagerFactory
-
isOpen
public boolean isOpen()
- Specified by:
isOpen
in interfacejakarta.persistence.EntityManagerFactory
-
getProperties
public Map<String,Object> getProperties()
- Specified by:
getProperties
in interfacejakarta.persistence.EntityManagerFactory
-
getPersistenceUnitUtil
public jakarta.persistence.PersistenceUnitUtil getPersistenceUnitUtil()
- Specified by:
getPersistenceUnitUtil
in interfacejakarta.persistence.EntityManagerFactory
-
addNamedQuery
public void addNamedQuery(String name, jakarta.persistence.Query query)
- Specified by:
addNamedQuery
in interfacejakarta.persistence.EntityManagerFactory
-
unwrap
public <T> T unwrap(Class<T> cls)
- Specified by:
unwrap
in interfacejakarta.persistence.EntityManagerFactory
-
addNamedEntityGraph
public <T> void addNamedEntityGraph(String graphName, jakarta.persistence.EntityGraph<T> entityGraph)
- Specified by:
addNamedEntityGraph
in interfacejakarta.persistence.EntityManagerFactory
-
findEntityGraphsByType
public <T> List<jakarta.persistence.EntityGraph<? super T>> findEntityGraphsByType(Class<T> entityClass)
- Specified by:
findEntityGraphsByType
in interfaceorg.hibernate.SessionFactory
-
getReference
public Reference getReference() throws NamingException
- Specified by:
getReference
in interfaceReferenceable
- Throws:
NamingException
-
getSessionFactoryOptions
public org.hibernate.boot.spi.SessionFactoryOptions getSessionFactoryOptions()
- Specified by:
getSessionFactoryOptions
in interfaceorg.hibernate.SessionFactory
-
withOptions
public org.hibernate.SessionBuilder withOptions()
- Specified by:
withOptions
in interfaceorg.hibernate.SessionFactory
-
openSession
public org.hibernate.Session openSession() throws org.hibernate.HibernateException
- Specified by:
openSession
in interfaceorg.hibernate.SessionFactory
- Throws:
org.hibernate.HibernateException
-
getCurrentSession
public org.hibernate.Session getCurrentSession() throws org.hibernate.HibernateException
- Specified by:
getCurrentSession
in interfaceorg.hibernate.SessionFactory
- Throws:
org.hibernate.HibernateException
-
withStatelessOptions
public org.hibernate.StatelessSessionBuilder withStatelessOptions()
- Specified by:
withStatelessOptions
in interfaceorg.hibernate.SessionFactory
-
openStatelessSession
public org.hibernate.StatelessSession openStatelessSession()
- Specified by:
openStatelessSession
in interfaceorg.hibernate.SessionFactory
-
openStatelessSession
public org.hibernate.StatelessSession openStatelessSession(Connection connection)
- Specified by:
openStatelessSession
in interfaceorg.hibernate.SessionFactory
-
inSession
public void inSession(Consumer<org.hibernate.Session> action)
- Specified by:
inSession
in interfaceorg.hibernate.SessionFactory
-
inTransaction
public void inTransaction(Consumer<org.hibernate.Session> action)
- Specified by:
inTransaction
in interfaceorg.hibernate.SessionFactory
-
fromSession
public <R> R fromSession(Function<org.hibernate.Session,R> action)
- Specified by:
fromSession
in interfaceorg.hibernate.SessionFactory
-
fromTransaction
public <R> R fromTransaction(Function<org.hibernate.Session,R> action)
- Specified by:
fromTransaction
in interfaceorg.hibernate.SessionFactory
-
getStatistics
public org.hibernate.stat.Statistics getStatistics()
- Specified by:
getStatistics
in interfaceorg.hibernate.SessionFactory
-
close
public void close() throws org.hibernate.HibernateException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfacejakarta.persistence.EntityManagerFactory
- Specified by:
close
in interfaceorg.hibernate.SessionFactory
- Throws:
org.hibernate.HibernateException
-
isClosed
public boolean isClosed()
- Specified by:
isClosed
in interfaceorg.hibernate.SessionFactory
-
getCache
public org.hibernate.Cache getCache()
- Specified by:
getCache
in interfacejakarta.persistence.EntityManagerFactory
- Specified by:
getCache
in interfaceorg.hibernate.SessionFactory
-
getDefinedFilterNames
public Set getDefinedFilterNames()
- Specified by:
getDefinedFilterNames
in interfaceorg.hibernate.SessionFactory
-
getFilterDefinition
public org.hibernate.engine.spi.FilterDefinition getFilterDefinition(String filterName) throws org.hibernate.HibernateException
- Specified by:
getFilterDefinition
in interfaceorg.hibernate.SessionFactory
- Throws:
org.hibernate.HibernateException
-
containsFetchProfileDefinition
public boolean containsFetchProfileDefinition(String name)
- Specified by:
containsFetchProfileDefinition
in interfaceorg.hibernate.SessionFactory
-
-