Helper class for obtaining Datastore sessions. Based on similar work for Hibernate such as SessionFactoryUtils
Type Params | Return Type | Name and description |
---|---|---|
|
static Session |
bindNewSession(Session session) Adds the session to the current SessionHolder's list of sessions, making it the current session. |
|
static Session |
bindSession(Session session) Bind the session to the thread with a SessionHolder keyed by its Datastore. |
|
static Session |
bindSession(Session session, java.lang.Object creator) Bind the session to the thread with a SessionHolder keyed by its Datastore. |
|
static void |
closeSession(Session session) Perform actual closing of the Session, catching and logging any cleanup exceptions thrown. |
|
static void |
closeSessionOrRegisterDeferredClose(Session session, Datastore datastore) Close the given Session or register it for deferred close. |
|
static org.springframework.core.env.PropertyResolver |
createPropertyResolver(java.util.Map<java.lang.String, java.lang.Object> configuration) Creates a org.springframework.core.env.PropertyResolver from the given configuration |
|
static org.springframework.core.env.PropertyResolver |
createPropertyResolvers(java.util.Map<java.lang.String, java.lang.Object>... configurations) Creates a org.springframework.core.env.PropertyResolver from the given configuration |
|
static org.springframework.core.env.PropertyResolver |
createPropertyResolvers(java.util.Collection<java.util.Map<java.lang.String, java.lang.Object>> configurations) Creates a org.springframework.core.env.PropertyResolver from the given configuration |
|
static Session |
doGetSession(Datastore datastore, boolean allowCreate) Get a Datastore Session for the given Datastore. |
|
static java.lang.Object |
doWithSession(Datastore datastore, groovy.lang.Closure c) Execute the closure in the current session if it exists, or create a new one and close it otherwise. |
<T> |
static T |
execute(Datastore datastore, SessionCallback<T> callback) Execute the callback in the current session if it exists, or create a new one and close it otherwise. |
|
static void |
execute(Datastore datastore, VoidSessionCallback callback) Execute the callback in the current session if it exists, or create a new one and close it otherwise. |
|
static Session |
getSession(Datastore datastore, boolean allowCreate) Get a Datastore Session for the given Datastore. |
|
static void |
initDeferredClose(Datastore datastore) Initialize deferred close for the current thread and the given Datastore. |
|
static boolean |
isSessionTransactional(Session session, Datastore datastore) Return whether the given Datastore Session is transactional, that is, bound to the current thread by Spring's transaction facilities. |
|
static org.springframework.core.env.PropertyResolver |
preparePropertyResolver(org.springframework.core.env.PropertyResolver propertyResolver) Prepares a property resolver and ensures it is suitable for GORM configuration |
|
static org.springframework.core.env.PropertyResolver |
preparePropertyResolver(org.springframework.core.env.PropertyResolver propertyResolver, java.lang.String... keyPrefixes) Prepares a property resolver and ensures it is suitable for GORM configuration |
|
static void |
processDeferredClose(Datastore datastore) Process all Datastore Sessions that have been registered for deferred close for the given SessionFactory. |
|
static void |
releaseSession(Session session, Datastore datastore) Close the given Session, created via the given factory, if it is not managed externally (i.e. not bound to the thread). |
|
static void |
unbindSession(Session session) Unbinds and closes a session. |
Methods inherited from class | Name |
---|---|
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Adds the session to the current SessionHolder's list of sessions, making it the current session. If there's no current session, calls bindSession.
session
- the sessionBind the session to the thread with a SessionHolder keyed by its Datastore.
session
- the sessionBind the session to the thread with a SessionHolder keyed by its Datastore.
session
- the sessionPerform actual closing of the Session, catching and logging any cleanup exceptions thrown.
session
- The Session instanceClose the given Session or register it for deferred close.
session
- the Datastore Session to closedatastore
- Datastore that the Session was created with
(may be null
)Creates a org.springframework.core.env.PropertyResolver from the given configuration
configuration
- The configurationCreates a org.springframework.core.env.PropertyResolver from the given configuration
configurations
- The configurationCreates a org.springframework.core.env.PropertyResolver from the given configuration
configurations
- The configuration Get a Datastore Session for the given Datastore. Is aware of and will
return any existing corresponding Session bound to the current thread, for
example when using DatastoreTransactionManager. Will create a new
Session otherwise, if "allowCreate" is true
.
false
datastore
- Datastore to create the session with
Session on transaction synchronization (may be null
)allowCreate
- whether a non-transactional Session should be created
when no transactional Session can be found for the current threadExecute the closure in the current session if it exists, or create a new one and close it otherwise.
datastore
- the datastorec
- the closure to executeExecute the callback in the current session if it exists, or create a new one and close it otherwise.
- the return typedatastore
- the datastorecallback
- the callback to executeExecute the callback in the current session if it exists, or create a new one and close it otherwise.
datastore
- the datastorecallback
- the callback to execute Get a Datastore Session for the given Datastore. Is aware of and will
return any existing corresponding Session bound to the current thread, for
example when using DatastoreTransactionManager. Will create a new
Session otherwise, if "allowCreate" is true
.
This is the getSession
method used by typical data access code,
in combination with releaseSession
called when done with
the Session.
false
datastore
- Datastore to create the session withallowCreate
- whether a non-transactional Session should be created
when no transactional Session can be found for the current threadInitialize deferred close for the current thread and the given Datastore. Sessions will not be actually closed on close calls then, but rather at a processDeferredClose call at a finishing point (like request completion).
datastore
- the Datastore to initialize deferred close forReturn whether the given Datastore Session is transactional, that is, bound to the current thread by Spring's transaction facilities.
session
- the Datastore Session to checkdatastore
- Datastore that the Session was created with
(may be null
)Prepares a property resolver and ensures it is suitable for GORM configuration
propertyResolver
- The property resolverPrepares a property resolver and ensures it is suitable for GORM configuration
propertyResolver
- The property resolverkeyPrefixes
- The configuration prefixesProcess all Datastore Sessions that have been registered for deferred close for the given SessionFactory.
datastore
- the Datastore to process deferred close forClose the given Session, created via the given factory, if it is not managed externally (i.e. not bound to the thread).
session
- the Datastore Session to close (may be null
)datastore
- Datastore that the Session was created with
(may be null
)Unbinds and closes a session. If it's the only session in the SessionHolder, unbinds the SessionHolder, otherwise just removes the session from the holder's list.
session
- the session