Class ContextAdapter
java.lang.Object
ch.tocco.nice2.persist.core.impl.hibernate.legacy.ContextAdapter
- All Implemented Interfaces:
Context,AutoCloseable
Adapter between a hibernate
Session and a nice2 Context
There might be multiple instances per Session.-
Nested Class Summary
Nested classes/interfaces inherited from interface ch.tocco.nice2.persist.core.api.Context
Context.Tx -
Constructor Summary
ConstructorsConstructorDescriptionContextAdapter(TypeManager typeManager, SessionFactoryManager sessionFactoryManager, PersistenceService persistService, NiceDataModel dataModel, PersistenceSessionImplementor session, QueryCompiler queryCompiler) -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidaddContextListener(ContextListener listener) voidAdds anEntityFacadeListenerto a global list of listeners that are used for allEntityManagersthis context creates.voidAdds anEntityListenerto be used in allEntityManagers.beginTx()voidvoidclear()Clear all cached data from this context.voidclose()compileQuery(String query) Compile the specified query string to an executable query.getAttribute(String key) getEntityManager(String model) getId()@Nullable IntegergetTx()booleanbooleanvoidvoidremoveContextListener(ContextListener listener) voidRemoves anEntityFacadeListenerfrom the list of global listeners (previously added byContext.addEntityFacadeListener(ch.tocco.nice2.persist.core.api.entity.events.EntityFacadeListener)voidRemoves anEntityListenerthat was added usingContext.addEntityListener(ch.tocco.nice2.persist.core.api.entity.events.EntityListener).voidresume()Bind the context to the current thread.voidsetAttribute(String key, Object value) voidsetQueryTimeout(int queryTimeout) voidsuspend()Unbind the context from the current thread.tx()unwrap()
-
Constructor Details
-
ContextAdapter
public ContextAdapter(TypeManager typeManager, SessionFactoryManager sessionFactoryManager, PersistenceService persistService, NiceDataModel dataModel, PersistenceSessionImplementor session, QueryCompiler queryCompiler)
-
-
Method Details
-
getPersistenceSession
- Specified by:
getPersistenceSessionin interfaceContext
-
getPersistenceSessionImplementor
-
getId
-
getTx
- Specified by:
getTxin interfaceContext- Returns:
- The
TransactionManagerfor this context.
-
tx
Description copied from interface:Context -
getEntityManager
- Specified by:
getEntityManagerin interfaceContext- Parameters:
model- The name of the entity type.- Returns:
- The entity manager of the entity type.
- Throws:
PersistException
-
getCacheControl
- Specified by:
getCacheControlin interfaceContext- Returns:
- CacheControl allows manual invalidating of cached entities.
-
compileQuery
Description copied from interface:ContextCompile the specified query string to an executable query.- Specified by:
compileQueryin interfaceContext- Parameters:
query- The query string.- Returns:
- The executable query.
- Throws:
PersistException
-
addContextListener
- Specified by:
addContextListenerin interfaceContext
-
removeContextListener
- Specified by:
removeContextListenerin interfaceContext
-
addCommitListener
- Specified by:
addCommitListenerin interfaceContext
-
removeCommitListener
- Specified by:
removeCommitListenerin interfaceContext
-
suspend
public void suspend()Description copied from interface:ContextUnbind the context from the current thread. -
resume
public void resume()Description copied from interface:ContextBind the context to the current thread. -
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceContext
-
isDestroyed
public boolean isDestroyed()- Specified by:
isDestroyedin interfaceContext- Returns:
- true if the underlying
Sessionis closed
-
isCurrent
public boolean isCurrent() -
checkCurrent
public void checkCurrent()- Specified by:
checkCurrentin interfaceContext
-
setAttribute
- Specified by:
setAttributein interfaceContext
-
getAttribute
- Specified by:
getAttributein interfaceContext
-
setQueryTimeout
public void setQueryTimeout(int queryTimeout) - Specified by:
setQueryTimeoutin interfaceContext
-
getQueryTimeout
- Specified by:
getQueryTimeoutin interfaceContext
-
addEntityListener
Description copied from interface:ContextAdds anEntityListenerto be used in allEntityManagers.- Specified by:
addEntityListenerin interfaceContext
-
removeEntityListener
Description copied from interface:ContextRemoves anEntityListenerthat was added usingContext.addEntityListener(ch.tocco.nice2.persist.core.api.entity.events.EntityListener).- Specified by:
removeEntityListenerin interfaceContext
-
addEntityFacadeListener
Description copied from interface:ContextAdds anEntityFacadeListenerto a global list of listeners that are used for allEntityManagersthis context creates.- Specified by:
addEntityFacadeListenerin interfaceContext
-
removeEntityFacadeListener
Description copied from interface:ContextRemoves anEntityFacadeListenerfrom the list of global listeners (previously added byContext.addEntityFacadeListener(ch.tocco.nice2.persist.core.api.entity.events.EntityFacadeListener)Be sure to perform this in a finally clause so that the remove is not skipped!
- Specified by:
removeEntityFacadeListenerin interfaceContext
-
unwrap
-
beginTx
-
clear
public void clear()Description copied from interface:ContextClear all cached data from this context. This should be used to free memory if a lot of entities are used. Depending on the implementation, the entities might become detached. -
createSqlWriter
- Specified by:
createSqlWriterin interfaceContext- Returns:
- a
SqlWriterconfigured for the current database.
-
getPersistenceService
- Specified by:
getPersistenceServicein interfaceContext
-