org.apache.openjpa.datacache
Class DataCacheStoreManager

java.lang.Object
  extended by org.apache.openjpa.kernel.DelegatingStoreManager
      extended by org.apache.openjpa.datacache.DataCacheStoreManager
All Implemented Interfaces:
StoreManager, Closeable

public class DataCacheStoreManager
extends DelegatingStoreManager

StoreManager proxy that delegates to a data cache when possible.

Author:
Patrick Linskey

Field Summary
 
Fields inherited from interface org.apache.openjpa.kernel.StoreManager
FORCE_LOAD_ALL, FORCE_LOAD_DFG, FORCE_LOAD_NONE, FORCE_LOAD_REFRESH, VERSION_DIFFERENT, VERSION_EARLIER, VERSION_LATER, VERSION_SAME
 
Constructor Summary
DataCacheStoreManager(StoreManager sm)
          Constructor.
 
Method Summary
 void begin()
          Begin a data store transaction.
(package private)  boolean bypass(FetchConfiguration fetch, int load)
          Affirms if a load operation must bypass the L2 cache.
 void commit()
          Commit the current data store transaction.
 boolean exists(OpenJPAStateManager sm, Object edata)
          Verify that the given instance exists in the data store; return false if it does not.
 Collection<Exception> flush(Collection<OpenJPAStateManager> states)
          Flush the given state manager collection to the datastore, returning a collection of exceptions encountered during flushing.
 boolean initialize(OpenJPAStateManager sm, PCState state, FetchConfiguration fetch, Object edata)
          Initialize the given state manager.
 boolean isCached(List<Object> oids, BitSet edata)
          Verify that the given instance exists in the data store in memory; return false if it does not.
 boolean load(OpenJPAStateManager sm, BitSet fields, FetchConfiguration fetch, int lockLevel, Object edata)
          Load the given state manager.
 Collection<Object> loadAll(Collection<OpenJPAStateManager> sms, PCState state, int load, FetchConfiguration fetch, Object edata)
          Initialize, load, or validate the existance of all of the given objects.
 void rollback()
          Rollback the current data store transaction.
 void setContext(StoreContext ctx)
          Set a reference to the corresponding context.
 boolean syncVersion(OpenJPAStateManager sm, Object edata)
          Update the version information in the given state manager to the version stored in the data store.
 
Methods inherited from class org.apache.openjpa.kernel.DelegatingStoreManager
assignField, assignObjectId, beforeStateChange, beginOptimistic, cancelAll, close, compareVersion, copyDataStoreId, equals, executeExtent, getClientConnection, getDataStoreIdSequence, getDataStoreIdType, getDelegate, getInnermostDelegate, getManagedType, getValueSequence, hashCode, newDataStoreId, newFetchConfiguration, newQuery, releaseConnection, retainConnection, rollbackOptimistic
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataCacheStoreManager

public DataCacheStoreManager(StoreManager sm)
Constructor.

Parameters:
sm - the store manager to delegate to
Method Detail

setContext

public void setContext(StoreContext ctx)
Description copied from interface: StoreManager
Set a reference to the corresponding context. This method will be called before the store manager is used. The store manager is responsible for pulling any necessary configuration data from the context, including the transaction mode and connection retain mode.

Specified by:
setContext in interface StoreManager
Overrides:
setContext in class DelegatingStoreManager

begin

public void begin()
Description copied from interface: StoreManager
Begin a data store transaction. After this method is called, it is assumed that all further operations are operating in a single transaction that can be committed or rolled back. If optimistic transactions are in use, this method will only be called when the system requires a transactionally consistent connection due to a user request to flush or commit the transaction. In this case, it is possible that the optimistic transaction does not have the latest versions of all instances (i.e. another transaction has modified the same instances and committed since the optimistic transaction started). On commit, an exception must be thrown on any attempt to overwrite data for an instance with an older version.

Specified by:
begin in interface StoreManager
Overrides:
begin in class DelegatingStoreManager

commit

public void commit()
Description copied from interface: StoreManager
Commit the current data store transaction.

Specified by:
commit in interface StoreManager
Overrides:
commit in class DelegatingStoreManager

rollback

public void rollback()
Description copied from interface: StoreManager
Rollback the current data store transaction.

Specified by:
rollback in interface StoreManager
Overrides:
rollback in class DelegatingStoreManager

exists

public boolean exists(OpenJPAStateManager sm,
                      Object edata)
Description copied from interface: StoreManager
Verify that the given instance exists in the data store; return false if it does not.

Specified by:
exists in interface StoreManager
Overrides:
exists in class DelegatingStoreManager

isCached

public boolean isCached(List<Object> oids,
                        BitSet edata)
Description copied from interface: StoreManager
Verify that the given instance exists in the data store in memory; return false if it does not. When an object is found in memory the corresponding element of the BitSet is set to 1.

Specified by:
isCached in interface StoreManager
Overrides:
isCached in class DelegatingStoreManager

syncVersion

public boolean syncVersion(OpenJPAStateManager sm,
                           Object edata)
Description copied from interface: StoreManager
Update the version information in the given state manager to the version stored in the data store.

Specified by:
syncVersion in interface StoreManager
Overrides:
syncVersion in class DelegatingStoreManager
Parameters:
sm - the instance to check
edata - the current execution data, or null if not given to the calling method of the context
Returns:
true if the instance still exists in the datastore and is up-to-date, false otherwise

initialize

public boolean initialize(OpenJPAStateManager sm,
                          PCState state,
                          FetchConfiguration fetch,
                          Object edata)
Description copied from interface: StoreManager
Initialize the given state manager. The object id of the state manager will be set, and the state manager's metadata be set to the class of the instance to load, or possibly one of its superclasses. Initialization involves first calling the OpenJPAStateManager.initialize(java.lang.Class, org.apache.openjpa.kernel.PCState) method with a new instance of the correct type constructed with the PCRegistry.newInstance(Class, org.apache.openjpa.enhance.StateManager, boolean) method (this will reset the state manager's metadata if the actual type was a subclass). After instance initialization, load any the fields for the given fetch configuration that can be efficiently retrieved. If any of the configured fields are not loaded in this method, they will be loaded with a subsequent call to StoreManager.load(org.apache.openjpa.kernel.OpenJPAStateManager, java.util.BitSet, org.apache.openjpa.kernel.FetchConfiguration, int, java.lang.Object). If this method is called during a data store transaction, the instance's database record should be locked. Version information can be loaded if desired through the OpenJPAStateManager.setVersion(java.lang.Object) method.

Specified by:
initialize in interface StoreManager
Overrides:
initialize in class DelegatingStoreManager
Parameters:
sm - the instance to initialize
state - the lifecycle state to initialize the state manager with
fetch - configuration for how to load the instance
edata - the current execution data, or null if not given to the calling method of the broker
Returns:
true if the matching instance exists in the data store, false otherwise

load

public boolean load(OpenJPAStateManager sm,
                    BitSet fields,
                    FetchConfiguration fetch,
                    int lockLevel,
                    Object edata)
Description copied from interface: StoreManager
Load the given state manager. Note that any collection or map types loaded into the state manager will be proxied with the correct type; therefore the store manager does not have to load the same concrete collection/map types as the instance declares. However, array types must be consistent with the array type stored by the persistence capable instance. If this method is called during a data store transaction, the instance should be locked. If the given state manager does not have its version set already, version information can be loaded if desired through the OpenJPAStateManager.setVersion(java.lang.Object) method.

Specified by:
load in interface StoreManager
Overrides:
load in class DelegatingStoreManager
Parameters:
sm - the instance to load
fields - set of fields to load; all field indexes in this set must be loaded; this set is mutable
fetch - the fetch configuration to use when loading related objects
lockLevel - attempt to load simple fields at this lock level; relations should be loaded at the read lock level of the fetch configuration
edata - the current execution data, or null if not given to the calling method of the broker
Returns:
false if the object no longer exists in the database, true otherwise

loadAll

public Collection<Object> loadAll(Collection<OpenJPAStateManager> sms,
                                  PCState state,
                                  int load,
                                  FetchConfiguration fetch,
                                  Object edata)
Description copied from interface: StoreManager
Initialize, load, or validate the existance of all of the given objects. This method is called from various broker methods that act on multiple objects, such as StoreContext.retrieveAll(java.util.Collection, boolean, org.apache.openjpa.kernel.OpCallbacks). It gives the store manager an opportunity to efficiently batch-load data for several objects. Each of the given state managers will be in one of three states, each requiring a different action: Store managers that cannot efficiently batch load can simply test for these conditions and delegate to the proper methods.

Specified by:
loadAll in interface StoreManager
Overrides:
loadAll in class DelegatingStoreManager
Parameters:
sms - the state manager instances to load
state - the lifecycle state to initialize uninitialized state managers with; may be null if no uninitialized instances are included in sms
load - one of the FORCE_LOAD_* constants describing the fields to force-load if this is a refresh or retrieve action
fetch - the current fetch configuration to use when loading related objects
edata - the current execution data, or null if not given to the calling method of the broker
Returns:
a collection of the state manager identities for which no data store record exists
See Also:
ImplHelper.loadAll(java.util.Collection, org.apache.openjpa.kernel.StoreManager, org.apache.openjpa.kernel.PCState, int, org.apache.openjpa.kernel.FetchConfiguration, java.lang.Object)

flush

public Collection<Exception> flush(Collection<OpenJPAStateManager> states)
Description copied from interface: StoreManager
Flush the given state manager collection to the datastore, returning a collection of exceptions encountered during flushing. The given collection may include states that do not require data store action, such as persistent-clean instances or persistent-dirty instances that have not been modified since they were last flushed. For datastore updates and inserts, the dirty, non-flushed fields of each state should be flushed. New instances without an assigned object id should be given one via OpenJPAStateManager.setObjectId(java.lang.Object). New instances with value-strategy fields that have not been assigned yet should have their fields set. Datastore version information should be updated during flush, and the state manager's version indicator updated through the OpenJPAStateManager.setNextVersion(java.lang.Object) method. The current version will roll over to this next version upon successful commit.

Specified by:
flush in interface StoreManager
Overrides:
flush in class DelegatingStoreManager
See Also:
org.apache.openjpa.util.ApplicationIds#assign()

bypass

boolean bypass(FetchConfiguration fetch,
               int load)
Affirms if a load operation must bypass the L2 cache. If lock is active, always bypass.



Copyright © 2006-2012 Apache Software Foundation. All Rights Reserved.