org.springframework.datastore.core
Class AbstractDatastore

java.lang.Object
  extended by org.springframework.datastore.core.AbstractDatastore
All Implemented Interfaces:
Datastore, EntityInterceptorAware
Direct Known Subclasses:
RedisDatastore, SimpleMapDatastore

public abstract class AbstractDatastore
extends Object
implements Datastore, EntityInterceptorAware

Abstract Datastore implementation that deals with binding the Session to thread locale upon creation.

Since:
1.0

Field Summary
protected  Map<String,String> connectionDetails
           
protected  List<EntityInterceptor> interceptors
           
protected  MappingContext mappingContext
           
 
Constructor Summary
AbstractDatastore()
           
AbstractDatastore(MappingContext mappingContext)
           
AbstractDatastore(MappingContext mappingContext, Map<String,String> connectionDetails)
           
 
Method Summary
 void addEntityInterceptor(EntityInterceptor interceptor)
          Adds an EntityInterceptor
static void bindSession(Session session)
          Binds the session to the current thread local
static void clearCurrentConnection()
          Clears the thread bound session, should be called by the Session.disconnect()
 Session connect()
          Connects to the datastore with the default connection details, normally provided via the datastore implementations constructor
 Session connect(Map<String,String> connectionDetails)
           
protected abstract  Session createSession(Map<String,String> connectionDetails)
          Creates the native session
 Session getCurrentSession()
          Obtains the current session (if any)
 MappingContext getMappingContext()
          Obtains the MappingContext object
static Session retrieveSession()
          Static way to retrieve the session
 void setConnectionDetails(Map<String,String> connectionDetails)
           
 void setEntityInterceptors(List<EntityInterceptor> interceptors)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mappingContext

protected MappingContext mappingContext

connectionDetails

protected Map<String,String> connectionDetails

interceptors

protected List<EntityInterceptor> interceptors
Constructor Detail

AbstractDatastore

public AbstractDatastore(MappingContext mappingContext)

AbstractDatastore

public AbstractDatastore(MappingContext mappingContext,
                         Map<String,String> connectionDetails)

AbstractDatastore

public AbstractDatastore()
Method Detail

setConnectionDetails

public void setConnectionDetails(Map<String,String> connectionDetails)

connect

public Session connect()
Description copied from interface: Datastore
Connects to the datastore with the default connection details, normally provided via the datastore implementations constructor

Specified by:
connect in interface Datastore
Returns:
The session created using the default connection details.

addEntityInterceptor

public void addEntityInterceptor(EntityInterceptor interceptor)
Description copied from interface: EntityInterceptorAware
Adds an EntityInterceptor

Specified by:
addEntityInterceptor in interface EntityInterceptorAware
Parameters:
interceptor - The interceptor to add

setEntityInterceptors

public void setEntityInterceptors(List<EntityInterceptor> interceptors)
Specified by:
setEntityInterceptors in interface EntityInterceptorAware
Parameters:
interceptors - A list of entity interceptors

connect

public final Session connect(Map<String,String> connectionDetails)

createSession

protected abstract Session createSession(Map<String,String> connectionDetails)
Creates the native session

Parameters:
connectionDetails - The session details
Returns:
The session object

getCurrentSession

public final Session getCurrentSession()
                                throws ConnectionNotFoundException
Description copied from interface: Datastore
Obtains the current session (if any)

Specified by:
getCurrentSession in interface Datastore
Returns:
The current thread bound session
Throws:
ConnectionNotFoundException - Thrown if the Datastore.connect() method has not yet been called

retrieveSession

public static Session retrieveSession()
                               throws ConnectionNotFoundException
Static way to retrieve the session

Returns:
The session instance
Throws:
ConnectionNotFoundException - If no session has been created

bindSession

public static void bindSession(Session session)
Binds the session to the current thread local

Parameters:
session - The session

getMappingContext

public MappingContext getMappingContext()
Description copied from interface: Datastore
Obtains the MappingContext object

Specified by:
getMappingContext in interface Datastore
Returns:
The MappingContext object

clearCurrentConnection

public static void clearCurrentConnection()
Clears the thread bound session, should be called by the Session.disconnect()