org.springframework.datastore.redis.engine
Class RedisEntityPersister

java.lang.Object
  extended by org.springframework.datastore.engine.EntityPersister
      extended by org.springframework.datastore.engine.LockableEntityPersister
          extended by org.springframework.datastore.keyvalue.engine.AbstractKeyValueEntityPesister<Map,Long>
              extended by org.springframework.datastore.redis.engine.RedisEntityPersister
All Implemented Interfaces:
EntityInterceptorAware, Persister

public class RedisEntityPersister
extends AbstractKeyValueEntityPesister<Map,Long>

An EntityPersister for the Redis NoSQL datastore

Since:
1.0

Field Summary
static String DISCRIMINATOR
           
 
Fields inherited from class org.springframework.datastore.keyvalue.engine.AbstractKeyValueEntityPesister
classMapping, entityFamily
 
Fields inherited from class org.springframework.datastore.engine.LockableEntityPersister
DEFAULT_TIMEOUT
 
Fields inherited from class org.springframework.datastore.engine.EntityPersister
interceptors, proxyFactory, session
 
Constructor Summary
RedisEntityPersister(MappingContext context, PersistentEntity entity, RedisSession conn, RedisTemplate template)
           
 
Method Summary
protected  Serializable convertToNativeKey(Serializable nativeKey)
           
protected  RedisEntry createNewEntry(String family)
          Creates a new entry for the given family.
 Query createQuery()
          Creates a query for the entity
protected  void deleteEntries(String family, List<Long> keys)
          Deletes one or many entries for the given list of Keys
protected  void deleteEntry(String family, Long key)
          Deletes a single entry
protected  PersistentEntity discriminatePersistentEntity(PersistentEntity persistentEntity, Map nativeEntry)
          Subclasses should override to customize how entities in hierarchies are discriminated
protected  Long generateIdentifier(PersistentEntity persistentEntity, Map entry)
           
protected  Long generateIdentifier(String family)
           
 RedisCollection getAllEntityIndex()
           
 AssociationIndexer getAssociationIndexer(Association oneToMany)
          Obtains an indexer for the given association
 String getEntityBaseKey()
           
protected  Object getEntryValue(Map nativeEntry, String property)
          Reads a value for the given key from the native entry
 String getFamily()
           
 PropertyValueIndexer getPropertyIndexer(PersistentProperty property)
          Obtains an indexer for a particular property
 String getPropertySortKey(PersistentProperty property)
           
 RedisTemplate getRedisTemplate()
           
 boolean isLocked(Object o)
          Subclasses can override to provide locking semantics
protected  void lockEntry(PersistentEntity persistentEntity, String entityFamily, Serializable id, int timeout)
          Subclasses can override to provide locking semantics
protected  List<Object> retrieveAllEntities(PersistentEntity persistentEntity, Iterable<Serializable> keys)
          Simplistic default implementation of retrieveAllEntities that iterates over each key and retrieves the entities one-by-one.
protected  Map retrieveEntry(PersistentEntity persistentEntity, String family, Serializable key)
          Reads the native form of a Key/value datastore entry.
protected  void setEntryValue(Map nativeEntry, String key, Object value)
          Sets a value on an entry
protected  Long storeEntry(PersistentEntity persistentEntity, Long storeId, Map nativeEntry)
          Stores the native form of a Key/value datastore to the actual data store
protected  void unlockEntry(PersistentEntity persistentEntity, String entityFamily, Serializable id)
          Subclasses to override to provide locking semantics
protected  void updateEntry(PersistentEntity persistentEntity, Long key, Map nativeEntry)
          Updates an existing entry to the actual datastore
 
Methods inherited from class org.springframework.datastore.keyvalue.engine.AbstractKeyValueEntityPesister
createEntityAccess, createEntityAccess, createObjectFromNativeEntry, deleteEntities, deleteEntity, getClassMapping, getEntityFamily, getFamily, getIdentifierName, getKeyspace, inferNativeKey, lock, lock, persistEntities, persistEntity, proxy, readObjectIdentifier, refresh, refreshObjectStateFromNativeEntry, retrieveAllEntities, retrieveEntity, unlock
 
Methods inherited from class org.springframework.datastore.engine.EntityPersister
addEntityInterceptor, delete, delete, getMappingContext, getObjectIdentifier, getPersistentEntity, getProxyFactory, getType, persist, persist, retrieve, retrieveAll, retrieveAll, setEntityInterceptors
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DISCRIMINATOR

public static final String DISCRIMINATOR
See Also:
Constant Field Values
Constructor Detail

RedisEntityPersister

public RedisEntityPersister(MappingContext context,
                            PersistentEntity entity,
                            RedisSession conn,
                            RedisTemplate template)
Method Detail

createNewEntry

protected RedisEntry createNewEntry(String family)
Description copied from class: AbstractKeyValueEntityPesister
Creates a new entry for the given family.

Specified by:
createNewEntry in class AbstractKeyValueEntityPesister<Map,Long>
Parameters:
family - The family
Returns:
An entry such as a BigTable Entity, ColumnFamily etc.

getEntryValue

protected Object getEntryValue(Map nativeEntry,
                               String property)
Description copied from class: AbstractKeyValueEntityPesister
Reads a value for the given key from the native entry

Specified by:
getEntryValue in class AbstractKeyValueEntityPesister<Map,Long>
Parameters:
nativeEntry - The native entry. Could be a ColumnFamily, a BigTable entity, a Map etc.
property - The property key
Returns:
The value

setEntryValue

protected void setEntryValue(Map nativeEntry,
                             String key,
                             Object value)
Description copied from class: AbstractKeyValueEntityPesister
Sets a value on an entry

Specified by:
setEntryValue in class AbstractKeyValueEntityPesister<Map,Long>
Parameters:
nativeEntry - The native entry such as a BigTable Entity, ColumnFamily etc.
key - The key
value - The value

isLocked

public boolean isLocked(Object o)
Description copied from class: AbstractKeyValueEntityPesister
Subclasses can override to provide locking semantics

Overrides:
isLocked in class AbstractKeyValueEntityPesister<Map,Long>
Parameters:
o - The object
Returns:
True if the object is locked

lockEntry

protected void lockEntry(PersistentEntity persistentEntity,
                         String entityFamily,
                         Serializable id,
                         int timeout)
Description copied from class: AbstractKeyValueEntityPesister
Subclasses can override to provide locking semantics

Overrides:
lockEntry in class AbstractKeyValueEntityPesister<Map,Long>
Parameters:
persistentEntity - The PesistentEntity instnace
entityFamily - The family
id - The identifer
timeout - The lock timeout in seconds

unlockEntry

protected void unlockEntry(PersistentEntity persistentEntity,
                           String entityFamily,
                           Serializable id)
Description copied from class: AbstractKeyValueEntityPesister
Subclasses to override to provide locking semantics

Overrides:
unlockEntry in class AbstractKeyValueEntityPesister<Map,Long>
Parameters:
persistentEntity - The persistent entity
entityFamily - The entity family
id - The identifer

convertToNativeKey

protected Serializable convertToNativeKey(Serializable nativeKey)
Overrides:
convertToNativeKey in class AbstractKeyValueEntityPesister<Map,Long>

discriminatePersistentEntity

protected PersistentEntity discriminatePersistentEntity(PersistentEntity persistentEntity,
                                                        Map nativeEntry)
Description copied from class: AbstractKeyValueEntityPesister
Subclasses should override to customize how entities in hierarchies are discriminated

Overrides:
discriminatePersistentEntity in class AbstractKeyValueEntityPesister<Map,Long>
Parameters:
persistentEntity - The PersistentEntity
nativeEntry - The native entry
Returns:
The discriminated entity

retrieveEntry

protected Map retrieveEntry(PersistentEntity persistentEntity,
                            String family,
                            Serializable key)
Description copied from class: AbstractKeyValueEntityPesister
Reads the native form of a Key/value datastore entry. This could be a ColumnFamily, a BigTable Entity, a Map etc.

Specified by:
retrieveEntry in class AbstractKeyValueEntityPesister<Map,Long>
Parameters:
persistentEntity - The persistent entity
family - The family
key - The key
Returns:
The native form

retrieveAllEntities

protected List<Object> retrieveAllEntities(PersistentEntity persistentEntity,
                                           Iterable<Serializable> keys)
Description copied from class: AbstractKeyValueEntityPesister
Simplistic default implementation of retrieveAllEntities that iterates over each key and retrieves the entities one-by-one. Data stores that support batch retrieval can optimize this to retrieve all entities in one go.

Overrides:
retrieveAllEntities in class AbstractKeyValueEntityPesister<Map,Long>
Parameters:
persistentEntity - The persist entity
keys - The keys
Returns:
A list of entities

updateEntry

protected void updateEntry(PersistentEntity persistentEntity,
                           Long key,
                           Map nativeEntry)
Description copied from class: AbstractKeyValueEntityPesister
Updates an existing entry to the actual datastore

Specified by:
updateEntry in class AbstractKeyValueEntityPesister<Map,Long>
Parameters:
persistentEntity - The PersistentEntity
key - The key of the object to update
nativeEntry - The entry

storeEntry

protected Long storeEntry(PersistentEntity persistentEntity,
                          Long storeId,
                          Map nativeEntry)
Description copied from class: AbstractKeyValueEntityPesister
Stores the native form of a Key/value datastore to the actual data store

Specified by:
storeEntry in class AbstractKeyValueEntityPesister<Map,Long>
Parameters:
persistentEntity - The persistent entity
nativeEntry - The native form. Could be a a ColumnFamily, BigTable Entity etc.
Returns:
The native key

generateIdentifier

protected Long generateIdentifier(PersistentEntity persistentEntity,
                                  Map entry)
Specified by:
generateIdentifier in class AbstractKeyValueEntityPesister<Map,Long>

getAllEntityIndex

public RedisCollection getAllEntityIndex()

getFamily

public String getFamily()

generateIdentifier

protected Long generateIdentifier(String family)

deleteEntries

protected void deleteEntries(String family,
                             List<Long> keys)
Description copied from class: AbstractKeyValueEntityPesister
Deletes one or many entries for the given list of Keys

Specified by:
deleteEntries in class AbstractKeyValueEntityPesister<Map,Long>
Parameters:
family - The family
keys - The keys

deleteEntry

protected void deleteEntry(String family,
                           Long key)
Description copied from class: AbstractKeyValueEntityPesister
Deletes a single entry

Specified by:
deleteEntry in class AbstractKeyValueEntityPesister<Map,Long>
Parameters:
family - The family
key - The key

getPropertyIndexer

public PropertyValueIndexer getPropertyIndexer(PersistentProperty property)
Description copied from class: AbstractKeyValueEntityPesister
Obtains an indexer for a particular property

Specified by:
getPropertyIndexer in class AbstractKeyValueEntityPesister<Map,Long>
Parameters:
property - The property to index
Returns:
The indexer

getAssociationIndexer

public AssociationIndexer getAssociationIndexer(Association oneToMany)
Description copied from class: AbstractKeyValueEntityPesister
Obtains an indexer for the given association

Specified by:
getAssociationIndexer in class AbstractKeyValueEntityPesister<Map,Long>
Parameters:
oneToMany - The association
Returns:
An indexer

createQuery

public Query createQuery()
Description copied from interface: Persister
Creates a query for the entity

Returns:
The Query object

getRedisTemplate

public RedisTemplate getRedisTemplate()

getEntityBaseKey

public String getEntityBaseKey()

getPropertySortKey

public String getPropertySortKey(PersistentProperty property)