Class ContextService
java.lang.Object
ch.tocco.nice2.persist.core.impl.hibernate.legacy.ContextService
- All Implemented Interfaces:
Context
,AutoCloseable
An injectable service that delegates all calls to the
Context
that is bound to the current thread.-
Nested Class Summary
Nested classes/interfaces inherited from interface ch.tocco.nice2.persist.core.api.Context
Context.Tx
-
Constructor Summary
-
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()
void
void
clear()
Clear all cached data from this context.void
close()
compileQuery
(String query) Compile the specified query string to an executable query.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 byContext.addEntityFacadeListener(ch.tocco.nice2.persist.core.api.entity.events.EntityFacadeListener)
void
Removes anEntityListener
that was added usingContext.addEntityListener(ch.tocco.nice2.persist.core.api.entity.events.EntityListener)
.void
resume()
Bind the context to the current thread.void
setAttribute
(String key, Object value) void
setQueryTimeout
(int queryTimeout) void
suspend()
Unbind the context from the current thread.tx()
unwrap()
-
Constructor Details
-
ContextService
-
-
Method Details
-
getPersistenceSession
- Specified by:
getPersistenceSession
in interfaceContext
-
getId
-
getTx
- Specified by:
getTx
in interfaceContext
- Returns:
- The
TransactionManager
for this context.
-
tx
Description copied from interface:Context
-
getEntityManager
- Specified by:
getEntityManager
in interfaceContext
- Parameters:
model
- The name of the entity type.- Returns:
- The entity manager of the entity type.
-
getCacheControl
- Specified by:
getCacheControl
in interfaceContext
- Returns:
- CacheControl allows manual invalidating of cached entities.
-
compileQuery
Description copied from interface:Context
Compile the specified query string to an executable query.- Specified by:
compileQuery
in interfaceContext
- Parameters:
query
- The query string.- Returns:
- The executable query.
- Throws:
PersistException
-
addContextListener
- Specified by:
addContextListener
in interfaceContext
-
removeContextListener
- Specified by:
removeContextListener
in interfaceContext
-
addCommitListener
- Specified by:
addCommitListener
in interfaceContext
-
removeCommitListener
- Specified by:
removeCommitListener
in interfaceContext
-
suspend
public void suspend()Description copied from interface:Context
Unbind the context from the current thread. -
resume
public void resume()Description copied from interface:Context
Bind the context to the current thread. -
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceContext
-
isDestroyed
public boolean isDestroyed()- Specified by:
isDestroyed
in interfaceContext
- Returns:
- true if the underlying
Session
is closed
-
isCurrent
public boolean isCurrent() -
checkCurrent
public void checkCurrent()- Specified by:
checkCurrent
in interfaceContext
-
setAttribute
- Specified by:
setAttribute
in interfaceContext
-
getAttribute
- Specified by:
getAttribute
in interfaceContext
-
setQueryTimeout
public void setQueryTimeout(int queryTimeout) - Specified by:
setQueryTimeout
in interfaceContext
-
getQueryTimeout
- Specified by:
getQueryTimeout
in interfaceContext
-
addEntityListener
Description copied from interface:Context
Adds anEntityListener
to be used in allEntityManagers
.- Specified by:
addEntityListener
in interfaceContext
-
removeEntityListener
Description copied from interface:Context
Removes anEntityListener
that was added usingContext.addEntityListener(ch.tocco.nice2.persist.core.api.entity.events.EntityListener)
.- Specified by:
removeEntityListener
in interfaceContext
-
addEntityFacadeListener
Description copied from interface:Context
Adds anEntityFacadeListener
to a global list of listeners that are used for allEntityManagers
this context creates.- Specified by:
addEntityFacadeListener
in interfaceContext
-
removeEntityFacadeListener
Description copied from interface:Context
Removes anEntityFacadeListener
from 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:
removeEntityFacadeListener
in interfaceContext
-
unwrap
-
beginTx
-
clear
public void clear()Description copied from interface:Context
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
- Specified by:
createSqlWriter
in interfaceContext
- Returns:
- a
SqlWriter
configured for the current database.
-
getPersistenceService
- Specified by:
getPersistenceService
in interfaceContext
-