org.camunda.bpm.engine.impl.db.entitymanager.cache
Class DbEntityCache

java.lang.Object
  extended by org.camunda.bpm.engine.impl.db.entitymanager.cache.DbEntityCache

public class DbEntityCache
extends Object

A simple first level cache for Entities.

Author:
Daniel Meyer

Field Summary
protected  Map<Class<?>,Map<String,CachedDbEntity>> cachedEntites
          The cache itself: maps entity types (classes) to maps indexed by id (primary key).
protected  DbEntityCacheKeyMapping cacheKeyMapping
           
protected static EnginePersistenceLogger LOG
           
 
Constructor Summary
DbEntityCache()
           
DbEntityCache(DbEntityCacheKeyMapping cacheKeyMapping)
           
 
Method Summary
 boolean contains(DbEntity dbEntity)
          Allows checking whether the provided entity is present in the cache
<T extends DbEntity>
T
get(Class<T> type, String id)
          get an object from the cache
 List<CachedDbEntity> getCachedEntities()
           
 CachedDbEntity getCachedEntity(Class<?> type, String id)
          Looks up an entity in the cache.
 CachedDbEntity getCachedEntity(DbEntity dbEntity)
          Looks up an entity in the cache.
<T extends DbEntity>
List<T>
getEntitiesByType(Class<T> type)
           
 boolean isDeleted(DbEntity dbEntity)
          Allows checking whether the provided entity is present in the cache and is marked to be deleted.
 boolean isPersistent(DbEntity dbEntity)
          Allows checking whether the provided entity is present in the cache and is DbEntityState.PERSISTENT.
 boolean isTransient(DbEntity dbEntity)
          Allows checking whether the provided entity is present in the cache and is DbEntityState.TRANSIENT.
protected  void putInternal(CachedDbEntity entityToAdd)
           
 void putMerged(DbEntity e)
          Put a DbEntityState.MERGED object into the cache.
 void putPersistent(DbEntity e)
          Put a DbEntityState.PERSISTENT object into the cache.
 void putTransient(DbEntity e)
          Put a new, DbEntityState.TRANSIENT object into the cache.
 void remove(CachedDbEntity cachedDbEntity)
           
 boolean remove(DbEntity e)
          Remove an entity from the cache
 void setDeleted(DbEntity dbEntity)
          Sets an object to a deleted state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected static final EnginePersistenceLogger LOG

cachedEntites

protected Map<Class<?>,Map<String,CachedDbEntity>> cachedEntites
The cache itself: maps entity types (classes) to maps indexed by id (primary key). The motivation for indexing by type (class) is a) multiple entities of different types could have the same value as primary key. In the process engine, TaskEntity and HistoricTaskEntity have the same id value. b) performance (?)


cacheKeyMapping

protected DbEntityCacheKeyMapping cacheKeyMapping
Constructor Detail

DbEntityCache

public DbEntityCache()

DbEntityCache

public DbEntityCache(DbEntityCacheKeyMapping cacheKeyMapping)
Method Detail

get

public <T extends DbEntity> T get(Class<T> type,
                                  String id)
get an object from the cache

Parameters:
type - the type of the object
id - the id of the object
Returns:
the object or 'null' if the object is not in the cache
Throws:
ProcessEngineException - if an object for the given id can be found but is of the wrong type.

getEntitiesByType

public <T extends DbEntity> List<T> getEntitiesByType(Class<T> type)

getCachedEntity

public CachedDbEntity getCachedEntity(Class<?> type,
                                      String id)
Looks up an entity in the cache.

Parameters:
type - the type of the object
id - the id of the CachedEntity to lookup
Returns:
the cached entity or null if the entity does not exist.

getCachedEntity

public CachedDbEntity getCachedEntity(DbEntity dbEntity)
Looks up an entity in the cache.

Parameters:
dbEntity - the entity for which the CachedEntity should be looked up
Returns:
the cached entity or null if the entity does not exist.

putTransient

public void putTransient(DbEntity e)
Put a new, DbEntityState.TRANSIENT object into the cache.

Parameters:
e - the object to put into the cache

putPersistent

public void putPersistent(DbEntity e)
Put a DbEntityState.PERSISTENT object into the cache.

Parameters:
e - the object to put into the cache

putMerged

public void putMerged(DbEntity e)
Put a DbEntityState.MERGED object into the cache.

Parameters:
e - the object to put into the cache

putInternal

protected void putInternal(CachedDbEntity entityToAdd)

remove

public boolean remove(DbEntity e)
Remove an entity from the cache

Parameters:
e - the entity to remove
Returns:

remove

public void remove(CachedDbEntity cachedDbEntity)
Parameters:
cachedDbEntity -

contains

public boolean contains(DbEntity dbEntity)
Allows checking whether the provided entity is present in the cache

Parameters:
dbEntity - the entity to check
Returns:
true if the the provided entity is present in the cache

isPersistent

public boolean isPersistent(DbEntity dbEntity)
Allows checking whether the provided entity is present in the cache and is DbEntityState.PERSISTENT.

Parameters:
dbEntity - the entity to check
Returns:
true if the provided entity is present in the cache and is DbEntityState.PERSISTENT.

isDeleted

public boolean isDeleted(DbEntity dbEntity)
Allows checking whether the provided entity is present in the cache and is marked to be deleted.

Parameters:
dbEntity - the entity to check
Returns:
true if the provided entity is present in the cache and is marked to be deleted

isTransient

public boolean isTransient(DbEntity dbEntity)
Allows checking whether the provided entity is present in the cache and is DbEntityState.TRANSIENT.

Parameters:
dbEntity - the entity to check
Returns:
true if the provided entity is present in the cache and is DbEntityState.TRANSIENT.

getCachedEntities

public List<CachedDbEntity> getCachedEntities()

setDeleted

public void setDeleted(DbEntity dbEntity)
Sets an object to a deleted state. It will not be removed from the cache but transition to one of the DELETED states, depending on it's current state.

Parameters:
dbEntity - the object to mark deleted.


Copyright © 2015 camunda services GmbH. All rights reserved.