Class LevelOneCache<K,​T>

  • Type Parameters:
    K - primary key class
    T - transfer object class

    public class LevelOneCache<K,​T>
    extends Object
    Provides a transactional cache for use with Stout's rest client.
    • Constructor Detail

      • LevelOneCache

        public LevelOneCache()
    • 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 update
        entity - 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 update
        entity - 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.