org.springframework.datastore.core
Interface Session

All Superinterfaces:
EntityInterceptorAware
All Known Subinterfaces:
KeyValueSession<T>
All Known Implementing Classes:
AbstractSession, RedisSession, SimpleMapSession

public interface Session
extends EntityInterceptorAware

The Session represents the active interaction with a datastore.

Since:
1.0

Method Summary
 void attach(Object o)
          Attaches an object the current session
 Transaction beginTransaction()
          Starts a transaction
 void clear()
          Clears any pending changes to the datastore
 void clear(Object o)
          Clear a specific object
 boolean contains(Object o)
          Whether the object is contained within the first level cache
 Query createQuery(Class type)
          Creates a query instance for the give type
 void delete(Iterable objects)
          Deletes one or many objects
 void delete(Object obj)
          Deletes a single object
 void disconnect()
          Disconnects from the datastore.
 void flush()
          Flushes any pending changes to the datastore
 Object getAttribute(Object entity, String attributeName)
          Obtains an attribute for the given entity
 Datastore getDatastore()
          The Datastore that created this Session
 javax.persistence.FlushModeType getFlushMode()
          Obtains the current FlushModeType
 MappingContext getMappingContext()
          Obtains the MappingContext instance
 Object getNativeInterface()
           
 Persister getPersister(Object o)
          The persister for the given object
 Transaction getTransaction()
          Obtains the current transaction instance
 boolean isConnected()
           
<T> T
lock(Class<T> type, Serializable key)
          Retrieves an individual object, using a write lock to prevent loss of updates
 void lock(Object o)
          Obtains a write lock on the given object
 List<Serializable> persist(Iterable objects)
          Persists several objects returning their identifiers in the order specified by the Iterable
 Serializable persist(Object o)
          Stores and object and returns its key
<T> T
proxy(Class<T> type, Serializable key)
          Retrieves a proxy for the given key
 void refresh(Object o)
          Refreshes the given objects state
<T> T
retrieve(Class<T> type, Serializable key)
          Retrieves an individual object
 List retrieveAll(Class type, Iterable keys)
          Retrieves several objects for the specified keys
 List retrieveAll(Class type, Serializable... keys)
          Retrieves several objects for the specified keys
 void setAttribute(Object entity, String attributeName, Object value)
          Associates an attribute with the given persistent entity.
 void setFlushMode(javax.persistence.FlushModeType flushMode)
          The flush mode, defaults to FlushModeType.AUTO
 void unlock(Object o)
          Releases a lock, if not called all locked objects should be released by disconnect()
 
Methods inherited from interface org.springframework.datastore.engine.EntityInterceptorAware
addEntityInterceptor, setEntityInterceptors
 

Method Detail

setAttribute

void setAttribute(Object entity,
                  String attributeName,
                  Object value)
Associates an attribute with the given persistent entity. Attributes will be cleared out when the Session is closed or cleared.

Parameters:
entity - The persistent instance (must be associated with this Session)
attributeName - The attribute name
value - The value

getAttribute

Object getAttribute(Object entity,
                    String attributeName)
Obtains an attribute for the given entity

Parameters:
entity - The entity
attributeName - The attribute
Returns:
The attribute value

isConnected

boolean isConnected()
Returns:
true if connected to the datastore

disconnect

void disconnect()
Disconnects from the datastore.


beginTransaction

Transaction beginTransaction()
Starts a transaction

Returns:
The transaction

getMappingContext

MappingContext getMappingContext()
Obtains the MappingContext instance

Returns:
The MappingContext

persist

Serializable persist(Object o)
Stores and object and returns its key

Parameters:
o - The object
Returns:
The the generated key

refresh

void refresh(Object o)
Refreshes the given objects state

Parameters:
o - The object to refresh

attach

void attach(Object o)
Attaches an object the current session

Parameters:
o - The object to attach

flush

void flush()
Flushes any pending changes to the datastore


clear

void clear()
Clears any pending changes to the datastore


clear

void clear(Object o)
Clear a specific object

Parameters:
o - The object to clear

contains

boolean contains(Object o)
Whether the object is contained within the first level cache

Parameters:
o - The object to check
Returns:
True if it is

setFlushMode

void setFlushMode(javax.persistence.FlushModeType flushMode)
The flush mode, defaults to FlushModeType.AUTO

Parameters:
flushMode - The FlushModeType

getFlushMode

javax.persistence.FlushModeType getFlushMode()
Obtains the current FlushModeType

Returns:
The FlushModeType instance

lock

void lock(Object o)
Obtains a write lock on the given object

Parameters:
o - The object to lock

unlock

void unlock(Object o)
Releases a lock, if not called all locked objects should be released by disconnect()

Parameters:
o - The object to unlock

persist

List<Serializable> persist(Iterable objects)
Persists several objects returning their identifiers in the order specified by the Iterable

Parameters:
objects - The Objects
Returns:
The identifiers

retrieve

<T> T retrieve(Class<T> type,
               Serializable key)
Retrieves an individual object

Parameters:
type - The type
key - The key
Returns:
The object

proxy

<T> T proxy(Class<T> type,
            Serializable key)
Retrieves a proxy for the given key

Parameters:
type - The type
key - The key
Returns:
The object

lock

<T> T lock(Class<T> type,
           Serializable key)
Retrieves an individual object, using a write lock to prevent loss of updates

Parameters:
type - The type
key - The key
Returns:
The object

delete

void delete(Iterable objects)
Deletes one or many objects

Parameters:
objects - The objects to delete

delete

void delete(Object obj)
Deletes a single object

Parameters:
obj - The object to delete

retrieveAll

List retrieveAll(Class type,
                 Iterable keys)
Retrieves several objects for the specified keys

Parameters:
type - The type
keys - The keys
Returns:
A list of objects

retrieveAll

List retrieveAll(Class type,
                 Serializable... keys)
Retrieves several objects for the specified keys

Parameters:
type - The type
keys - The keys
Returns:
A list of objects

createQuery

Query createQuery(Class type)
Creates a query instance for the give type

Parameters:
type - The type
Returns:
The query

getNativeInterface

Object getNativeInterface()
Returns:
The native interface to the datastore

getPersister

Persister getPersister(Object o)
The persister for the given object

Parameters:
o - The object
Returns:
The persister

getTransaction

Transaction getTransaction()
Obtains the current transaction instance

Returns:
The Transaction instance

getDatastore

Datastore getDatastore()
The Datastore that created this Session

Returns:
The Datastore instance