Class LevelOneCache<K,T>
- java.lang.Object
-
- org.technologybrewery.fermenter.stout.client.service.LevelOneCache<K,T>
-
- Type Parameters:
K- primary key classT- transfer object class
public class LevelOneCache<K,T> extends Object
Provides a transactional cache for use with Stout's rest client.
-
-
Constructor Summary
Constructors Constructor Description LevelOneCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcache(K primaryKey, T entity)Allows the cache to be updated with a specific instance.voidclearPendingActions()Returns all pending actions.voidclearPendingDeletes()Removes pending deletes.voidclearPendingInsertsAndUpdates()Removes pending inserts and updates.voidcreate(T instance)Queue an entity for create.voidcreateAndCache(K primaryKey, T instance)Queue an entity for create.voiddelete(Collection<K> primaryKeys)Queues a collection for delete.voiddelete(K primaryKey)Queues a delete.Collection<K>getPendingDeletes()Returns all entities that are pending a delete.Collection<T>getPendingInserts()Returns all entities that are pending an insert.Collection<T>getPendingUpdates()Returns all entities that are pending an update.Tretrieve(K id)Retrieves an entity based on the passed primary key from the pending list of object maintained by this cache.voidupdate(K primaryKey, T entity)Queue an update.
-
-
-
Method Detail
-
create
public void create(T instance)
Queue an entity for create. Entities will NOT be available via the cache unless they are flushed as they cannot be guaranteed to have a primary key by which to look them up.- Parameters:
instance- instance to create
-
createAndCache
public void createAndCache(K primaryKey, T instance)
Queue an entity for create. Entities WILL be available via the cache in this case. NOTE: you CANNOT use generated keys without manually flushing.- Parameters:
instance- instance to create
-
retrieve
public T retrieve(K id)
Retrieves an entity based on the passed primary key from the pending list of object maintained by this cache.- Parameters:
id- primary key to look up- Returns:
- entity or null if no match found
-
getPendingInserts
public Collection<T> getPendingInserts()
Returns all entities that are pending an insert.- Returns:
- pending inserts
-
update
public void update(K primaryKey, T entity)
Queue an update. These items WILL be returned via call to the entity maintenance service to retrieve.- Parameters:
primaryKey- key of the entity to updateentity- the entity to update
-
cache
public void cache(K primaryKey, T entity)
Allows the cache to be updated with a specific instance.- Parameters:
primaryKey- key of the entity to updateentity- the entity to update
-
getPendingUpdates
public Collection<T> getPendingUpdates()
Returns all entities that are pending an update.- Returns:
- pending updates
-
delete
public void delete(K primaryKey)
Queues a delete. These items will NOT be returned via call to the entity maintenance service to retrieve as they have been "removed" from a transactional perspective.- Parameters:
primaryKey- key of the entity to delete
-
delete
public void delete(Collection<K> primaryKeys)
Queues a collection for delete. These items will NOT be returned via call to the entity maintenance service to retrieve as they have been "removed" from a transactional perspective.- Parameters:
primaryKey- key of the entity to delete
-
getPendingDeletes
public Collection<K> getPendingDeletes()
Returns all entities that are pending a delete.- Returns:
- pending deletes
-
clearPendingInsertsAndUpdates
public void clearPendingInsertsAndUpdates()
Removes pending inserts and updates.
-
clearPendingDeletes
public void clearPendingDeletes()
Removes pending deletes.
-
clearPendingActions
public void clearPendingActions()
Returns all pending actions.
-
-