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
Modifier and TypeInterfaceDescriptionstatic interface
This gives acces to a simple transaction api. -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
addContextListener
(ContextListener listener) void
Adds anEntityFacadeListener
to a global list of listeners that are used for allEntityManagers
this context creates.void
Adds anEntityListener
to be used in allEntityManagers
.beginTx()
Deprecated.void
void
clear()
Clear all cached data from this context.void
close()
compileQuery
(String query) Deprecated.getAttribute
(String key) getEntityManager
(String model) getId()
@Nullable Integer
getTx()
boolean
boolean
void
void
removeContextListener
(ContextListener listener) void
Removes anEntityFacadeListener
from the list of global listeners (previously added byaddEntityFacadeListener(ch.tocco.nice2.persist.core.api.entity.events.EntityFacadeListener)
void
Removes anEntityListener
that was added usingaddEntityListener(ch.tocco.nice2.persist.core.api.entity.events.EntityListener)
.void
resume()
Bind the context to the current thread.void
setAttribute
(String key, @Nullable Object value) void
setQueryTimeout
(int queryTimeout) void
suspend()
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
TransactionManager
for 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:
close
in interfaceAutoCloseable
-
isDestroyed
boolean isDestroyed()- Returns:
- true if the underlying
Session
is 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 anEntityListener
to be used in allEntityManagers
. -
removeEntityListener
Removes anEntityListener
that was added usingaddEntityListener(ch.tocco.nice2.persist.core.api.entity.events.EntityListener)
. -
addEntityFacadeListener
Adds anEntityFacadeListener
to a global list of listeners that are used for allEntityManagers
this context creates. -
removeEntityFacadeListener
Removes anEntityFacadeListener
from 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
SqlWriter
configured for the current database.
-
getPersistenceService
PersistenceService getPersistenceService()
-
tx()