| java.lang.Object org.apache.openjpa.abstractstore.AbstractStoreManager
All known Subclasses: org.apache.openjpa.xmlstore.XMLStoreManager,
AbstractStoreManager | abstract public class AbstractStoreManager implements StoreManager(Code) | | Abstract store manager implementation to ease development of custom
OpenJPA back-ends. A concrete subclass must define implementations for the
following methods:
Additionally, subclasses should not attempt to acquire resources
until
AbstractStoreManager.open has been called. Store manager instances might be
created to call metadata methods such as
AbstractStoreManager.newConfiguration or
AbstractStoreManager.getUnsupportedOptions and never opened. These instances should
not consume any data store resources.
Notes:
- The
StoreManager.initialize method is responsible
for creating new instances of objects freshly loaded from the
database. The method will be invoked with a
OpenJPAStateManager that the newly-loaded object should be associated with. To create the
new object and set up this association correctly, the implementation
should use the
OpenJPAStateManager.initialize method.
- If your data store supports some sort of transaction or
unit of work, you should override the
AbstractStoreManager.begin ,
AbstractStoreManager.commit ,
and
AbstractStoreManager.rollback methods.
- This class provides no infrastructure support for optimistic
transactions. To provide optimistic transaction support:
- If your data store supports a mechanism for automatically
generating and managing identity values (or if you want to
provide that facility on top of your data store), implement
the
AbstractStoreManager.getDataStoreIdSequence method if you want to use a
long as your datastore identity type and are
happy with OpenJPA's
Id class. To use another datastore identity
type, override
AbstractStoreManager.getManagedType ,
AbstractStoreManager.getDataStoreIdType ,
AbstractStoreManager.copyDataStoreId , and
AbstractStoreManager.newDataStoreId instead. In either case, override
AbstractStoreManager.getUnsupportedOptions to not include
OpenJPAConfiguration.OPTION_ID_DATASTORE in the list of
unsupported options.
- If your data store does not support queries (or if you do
not want to convert OpenJPA's query parse tree into a
datastore-specific query), you still have two options in terms
of query execution:
- In-memory execution: If you
execute a query against an extent or a class, OpenJPA will
automatically load the full extent of objects into memory and
execute the query in memory.
- openjpa.MethodQL: MethodQL allows
you to use the query APIs to execute a method that finds
data in your back-end and returns that data as a
org.apache.openjpa.lib.rop.ResultList . For more details on
MethodQL, see the OpenJPA Reference Guide.
since: 0.3.1 |
Method Summary | |
protected boolean | assignDataStoreId(OpenJPAStateManager sm, Object val) Assign a new datastore identity to the given instance. | public boolean | assignField(OpenJPAStateManager sm, int field, boolean preFlush) | public boolean | assignObjectId(OpenJPAStateManager sm, boolean preFlush) | public void | beforeStateChange(OpenJPAStateManager sm, PCState fromState, PCState toState) | public void | begin() OpenJPA assumes that after this method is invoked, all data
accesses through this store manager will be part of a single
unit of work that can be rolled back.
This is a no-op implementation. | public void | beginOptimistic() No-op implementation. | public boolean | cancelAll() Returns false . | public void | close() | public void | commit() This is a no-op implementation. | public int | compareVersion(OpenJPAStateManager state, Object v1, Object v2) Casts v1 and v2 to
Comparable , and
invokes v1.compareTo (v2) . | public Object | copyDataStoreId(Object oid, ClassMetaData meta) | abstract public ResultObjectProvider | executeExtent(ClassMetaData meta, boolean subs, FetchConfiguration fetch) Create a
ResultObjectProvider that can return all instances
of type , optionally including subclasses as defined
by subclasses .
The implementation of the result provider will typically execute
some sort of data store query to find all the applicable objects, loop
through the results, extracting object IDs from the data, and invoke
StoreContext.find(ObjectFetchConfigurationBitSetObjectint) on each OID. | public Collection | flush(Collection sms) Breaks down states based on the objects' current
states, and delegates to
AbstractStoreManager.flush(Collection,Collection,Collection,Collection,Collection) . | abstract protected Collection | flush(Collection pNew, Collection pNewUpdated, Collection pNewFlushedDeleted, Collection pDirty, Collection pDeleted) Responsible for writing modifications happened back to the data
store. | public Object | getClientConnection() Returns null . | public StoreContext | getContext() Returns the
StoreContext that this store manager is
associated with. | public Seq | getDataStoreIdSequence(ClassMetaData forClass) Returns the system-configured sequence. | public Class | getDataStoreIdType(ClassMetaData meta) | public Class | getManagedType(Object oid) | protected String | getPlatform() Returns a string name to identify the platform of this
store manager. | protected Collection | getUnsupportedOptions() Returns a set of option names that this store manager does
not support. | public Seq | getValueSequence(FieldMetaData forField) Returns null. | abstract public boolean | initialize(OpenJPAStateManager sm, PCState state, FetchConfiguration fetch, Object edata) This method is invoked when OpenJPA needs to load an object whose
identity is known but which has not yet been loaded from the data
store. | abstract public boolean | load(OpenJPAStateManager sm, BitSet fields, FetchConfiguration fetch, int lockLevel, Object edata) This method is invoked when OpenJPA needs to load additional data
into an object that has already been at least partially loaded by
a previous
AbstractStoreManager.initialize invocation. | public Collection | loadAll(Collection sms, PCState state, int load, FetchConfiguration fetch, Object edata) This implementation just delegates to the proper singular
method (
StoreManager.initialize or
StoreManager.load )
depending on each state manager's state. | protected OpenJPAConfiguration | newConfiguration() Return a new configuration instance for this runtime. | public Object | newDataStoreId(Object val, ClassMetaData meta) | public FetchConfiguration | newFetchConfiguration() | public StoreQuery | newQuery(String language) | protected void | open() No-op implementation. | public void | releaseConnection() Override to release previously-retained connection. | public void | retainConnection() Override to retain a dedicated connection. | public void | rollback() This is a no-op implementation. | public void | rollbackOptimistic() No-op implementation. | final public void | setContext(StoreContext ctx) | public boolean | syncVersion(OpenJPAStateManager sm, Object edata) Since this store manager does not provide optimistic locking
support, this method always returns true . |
assignDataStoreId | protected boolean assignDataStoreId(OpenJPAStateManager sm, Object val)(Code) | | Assign a new datastore identity to the given instance. This given
value may be null.
|
begin | public void begin()(Code) | | OpenJPA assumes that after this method is invoked, all data
accesses through this store manager will be part of a single
unit of work that can be rolled back.
This is a no-op implementation. If your data store does not
support any concept of locking or transactions, you need not
override this method.
|
beginOptimistic | public void beginOptimistic()(Code) | | No-op implementation. Override this method to provide optimistic
locking semantics for your data store if you need notification of
the beginning of an optimistic transaction.
|
cancelAll | public boolean cancelAll()(Code) | | Returns false . If your data store supports
cancelling queries, this method should cancel any
currently-running queries and return true if any
were cancelled.
|
close | public void close()(Code) | | |
commit | public void commit()(Code) | | This is a no-op implementation. If your data store does not
have a concept of transactions or a unit of work, you need not
override this method. If it does, then override this method to
notify the data store that the current transaction should be committed.
|
executeExtent | abstract public ResultObjectProvider executeExtent(ClassMetaData meta, boolean subs, FetchConfiguration fetch)(Code) | | Create a
ResultObjectProvider that can return all instances
of type , optionally including subclasses as defined
by subclasses .
The implementation of the result provider will typically execute
some sort of data store query to find all the applicable objects, loop
through the results, extracting object IDs from the data, and invoke
StoreContext.find(ObjectFetchConfigurationBitSetObjectint) on each OID. When invoking this method, the first argument is the OID.
The second is the given fetch configuration. The
third argument is a mask of fields to exclude from loading; it will
typically be null. The fourth argument is an object that will be passed
through to
AbstractStoreManager.initialize or
AbstractStoreManager.load , and typically will
contain the actual data to load. For example, for a JDBC-based store
manager, this might be the result set that is being iterated over. If
this argument is null , then the
AbstractStoreManager.initialize or
AbstractStoreManager.load method will have to issue another command to the data
store in order to fetch the data to be loaded.
|
flush | abstract protected Collection flush(Collection pNew, Collection pNewUpdated, Collection pNewFlushedDeleted, Collection pDirty, Collection pDeleted)(Code) | | Responsible for writing modifications happened back to the data
store. If you do not remove the
OpenJPAConfiguration.OPTION_INC_FLUSH option in
AbstractStoreManager.getUnsupportedOptions , this will be called only once at the
end of a transaction. Otherwise, it may be called periodically
throughout the course of a transaction.
If this store manager supports optimistic transactions, datastore
version information should be updated during flush, and the state
manager's version indicator should be updated through the
OpenJPAStateManager.setNextVersion method.
This method will only be invoked if there are meaningful changes
to store. This differs from the behavior of
StoreManager.flush ,
which may be invoked with a collection of objects in states that
do not require any datastore action (for example, objects in the
transient-transactional state).
Parameters: pNew - Objects that should be added to the store,and that have not previously been flushed. Parameters: pNewUpdated - New objects that have been modified sincethey were initially flushed. These werein persistentNew in an earlier flush invocation. Parameters: pNewFlushedDeleted - New objects that have been deleted sincethey were initially flushed. These werein persistentNew in an earlier flush invocation. Parameters: pDirty - Objects that were loaded from the datastore and have since been modified. Parameters: pDeleted - Objects that were loaded from the datastore and have since been deleted. Thesemay have been in a previous flush invocation's persistentDirty list. a collection of exceptions encountered during flushing. |
getClientConnection | public Object getClientConnection()(Code) | | Returns null . If your data store can provide a
distinct connection object, return it here.
|
getPlatform | protected String getPlatform()(Code) | | Returns a string name to identify the platform of this
store manager. Returns the class name of this store manager by default.
|
getUnsupportedOptions | protected Collection getUnsupportedOptions()(Code) | | Returns a set of option names that this store manager does
not support. By default, returns the following:
|
initialize | abstract public boolean initialize(OpenJPAStateManager sm, PCState state, FetchConfiguration fetch, Object edata)(Code) | | This method is invoked when OpenJPA needs to load an object whose
identity is known but which has not yet been loaded from the data
store. sm is a partially-set-up state manager for this
object. The ID and least-derived type information for the instance
to load can be obtained by invoking
sm.getObjectId() and sm.getMetaData() .
When implementing this method, load the data for this object from
the data store, determine the most-derived subclass of the newly-loaded
data, and then use the
OpenJPAStateManager.initialize method to
populate sm with a new instance of the appropriate type.
Once
OpenJPAStateManager.initialize has been invoked, proceed to
load field data into sm as in the
AbstractStoreManager.load method, by
using
OpenJPAStateManager.store (or the appropriate
OpenJPAStateManager.storetype method) to put the
data into the object.
|
newConfiguration | protected OpenJPAConfiguration newConfiguration()(Code) | | Return a new configuration instance for this runtime. Configuration
data is maintained at the factory level and is available to all OpenJPA
components; therefore it is a good place to maintain shared resources
such as connection pools, etc.
|
open | protected void open()(Code) | | No-op implementation. Ready this store manager for persistent operations.
|
releaseConnection | public void releaseConnection()(Code) | | Override to release previously-retained connection.
|
retainConnection | public void retainConnection()(Code) | | Override to retain a dedicated connection.
|
rollback | public void rollback()(Code) | | This is a no-op implementation. If your data store does not
have a concept of transactions or a unit of work, you need not
override this method. If it does, then override this method to
notify the data store that the current transaction should be rolled back.
|
rollbackOptimistic | public void rollbackOptimistic()(Code) | | No-op implementation. Override this method to provide optimistic
locking semantics for your data store if you need notification of
a rollback of an optimistic transaction before
AbstractStoreManager.begin is invoked.
|
syncVersion | public boolean syncVersion(OpenJPAStateManager sm, Object edata)(Code) | | Since this store manager does not provide optimistic locking
support, this method always returns true .
|
|
|