Package ch.tocco.nice2.persist.core.api
Interface Context
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
ContextAdapter,ContextService
The main entry point into the old persistence API.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceThis gives acces to a simple transaction api. -
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()Deprecated.voidvoidclear()Clear all cached data from this context.voidclose()compileQuery(String query) Deprecated.getAttribute(String key) getEntityManager(String model) getId()@Nullable IntegergetTx()booleanbooleanvoidvoidremoveContextListener(ContextListener listener) voidRemoves anEntityFacadeListenerfrom the list of global listeners (previously added byaddEntityFacadeListener(ch.tocco.nice2.persist.core.api.entity.events.EntityFacadeListener)voidRemoves anEntityListenerthat was added usingaddEntityListener(ch.tocco.nice2.persist.core.api.entity.events.EntityListener).voidresume()Bind the context to the current thread.voidsetAttribute(String key, @Nullable Object value) voidsetQueryTimeout(int queryTimeout) voidsuspend()Unbind the context from the current thread.tx()unwrap()
-
Method Details
-
getPersistenceSession
PersistenceSession getPersistenceSession() -
getId
String getId()- Returns:
- The id of the context.
-
getTx
TransactionManager getTx()- Returns:
- The
TransactionManagerfor this context.
-
tx
Invoker tx() -
getEntityManager
- Parameters:
model- The name of the entity type.- Returns:
- The entity manager of the entity type.
-
getCacheControl
CacheControl getCacheControl()- Returns:
- CacheControl allows manual invalidating of cached entities.
-
compileQuery
Deprecated.Compile the specified query string to an executable query.- Parameters:
query- The query string.- Returns:
- The executable query.
- Throws:
CompileException- If the query strings contains errors.
-
addContextListener
-
removeContextListener
-
addCommitListener
-
removeCommitListener
-
suspend
void suspend()Unbind the context from the current thread. -
resume
void resume()Bind the context to the current thread. -
close
void close()- Specified by:
closein interfaceAutoCloseable
-
isDestroyed
boolean isDestroyed()- Returns:
- true if the underlying
Sessionis closed
-
isCurrent
boolean isCurrent()- Returns:
- true if the context is bound to the current thread.
-
checkCurrent
void checkCurrent()- Throws:
IllegalStateException- If the context is not bound to the current thread.
-
setAttribute
-
getAttribute
-
setQueryTimeout
void setQueryTimeout(int queryTimeout) -
getQueryTimeout
-
addEntityListener
Adds anEntityListenerto be used in allEntityManagers. -
removeEntityListener
Removes anEntityListenerthat was added usingaddEntityListener(ch.tocco.nice2.persist.core.api.entity.events.EntityListener). -
addEntityFacadeListener
Adds anEntityFacadeListenerto a global list of listeners that are used for allEntityManagersthis context creates. -
removeEntityFacadeListener
Removes anEntityFacadeListenerfrom the list of global listeners (previously added byaddEntityFacadeListener(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!
-
unwrap
Context unwrap() -
beginTx
Deprecated.usetx() -
clear
void clear()Clear 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
SqlWriter createSqlWriter()- Returns:
- a
SqlWriterconfigured for the current database.
-
getPersistenceService
PersistenceService getPersistenceService()
-
tx()