public class JDBCStoreManager extends Object implements StoreManager, JDBCStore
| Modifier and Type | Class and Description |
|---|---|
static class |
JDBCStoreManager.ClientConnection
Connection returned to client code.
|
protected class |
JDBCStoreManager.RefCountConnection
Connection wrapper that keeps an internal ref count so that it knows
when to really close.
|
FORCE_LOAD_ALL, FORCE_LOAD_DFG, FORCE_LOAD_NONE, FORCE_LOAD_REFRESH, VERSION_DIFFERENT, VERSION_EARLIER, VERSION_LATER, VERSION_SAME| Constructor and Description |
|---|
JDBCStoreManager() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
assignField(OpenJPAStateManager sm,
int field,
boolean preFlush)
Assign a value to the given field.
|
boolean |
assignObjectId(OpenJPAStateManager sm,
boolean preFlush)
Assign an object id to the given new instance.
|
void |
beforeStateChange(OpenJPAStateManager sm,
PCState fromState,
PCState toState)
Notification that the given state manager is about to change its
lifecycle state.
|
void |
begin()
Begin a data store transaction.
|
void |
beginOptimistic()
Notification that an optimistic transaction has started.
|
boolean |
cancelAll()
Cancel all pending data store statements.
|
void |
close()
Free any resources this store manager is using.
|
void |
commit()
Commit the current data store transaction.
|
int |
compareVersion(OpenJPAStateManager state,
Object v1,
Object v2)
Compare the two version objects.
|
protected JDBCStoreManager.RefCountConnection |
connectInternal()
Connect to the database.
|
Object |
copyDataStoreId(Object oid,
ClassMetaData meta)
Copy the given object id value.
|
ResultObjectProvider |
executeExtent(ClassMetaData meta,
boolean subclasses,
FetchConfiguration fetch)
Return a provider for all instances of the given candidate class,
optionally including subclasses.
|
boolean |
exists(OpenJPAStateManager sm,
Object context)
Verify that the given instance exists in the data store; return false
if it does not.
|
Object |
find(Object oid,
ValueMapping vm,
JDBCFetchConfiguration fetch)
Find the object with the given oid.
|
Collection |
flush(Collection<OpenJPAStateManager> sms)
Flush the given state manager collection to the datastore, returning
a collection of exceptions encountered during flushing.
|
Object |
getClientConnection()
Return a connection to the data store suitable for client use.
|
JDBCConfiguration |
getConfiguration()
Return the configuration for this runtime.
|
Connection |
getConnection()
Return a SQL connection to the database.
|
StoreContext |
getContext()
Current persistence context.
|
protected DataSource |
getDataSource() |
Seq |
getDataStoreIdSequence(ClassMetaData meta)
Return a sequence that generates datastore identity values for the
given class.
|
Class<?> |
getDataStoreIdType(ClassMetaData meta)
Return the class used by this StoreManager for datastore identity
values.
|
DBDictionary |
getDBDictionary()
Return the dictionary in use.
|
JDBCFetchConfiguration |
getFetchConfiguration()
Return the current default fetch configuration.
|
JDBCLockManager |
getLockManager()
If the lock manager in use is a
JDBCLockManager, return it. |
Class<?> |
getManagedType(Object oid)
Return the persistent class for the given data store identity value.
|
Connection |
getNewConnection()
Return a new SQL connection to the database.
|
SQLFactory |
getSQLFactory()
Return the SQL factory for this runtime.
|
protected Class<?> |
getType(Result res,
ClassMapping mapping)
This method is to provide override for non-JDBC or JDBC-like
implementation of getting type from the result set.
|
Seq |
getValueSequence(FieldMetaData fmd)
Return a sequence that generates values for the given field.
|
protected void |
getVersion(ClassMapping mapping,
OpenJPAStateManager sm,
Result res)
This method is to provide override for non-JDBC or JDBC-like
implementation of getting version from the result set.
|
boolean |
initialize(OpenJPAStateManager sm,
PCState state,
FetchConfiguration fetch,
Object context)
Initialize the given state manager.
|
protected boolean |
initializeState(OpenJPAStateManager sm,
PCState state,
JDBCFetchConfiguration fetch,
ConnectionInfo info)
Initialize a newly-loaded instance.
|
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.
|
protected boolean |
isEmptyResult(Result res)
This method is to provide override for non-JDBC or JDBC-like
implementation of checking whether the result set is empty or not.
|
Object |
load(ClassMapping mapping,
JDBCFetchConfiguration fetch,
BitSet exclude,
Result result)
Load the object in the current row of the given result.
|
boolean |
load(OpenJPAStateManager sm,
BitSet fields,
FetchConfiguration fetch,
int lockLevel,
Object context)
Load the given state manager.
|
Collection |
loadAll(Collection sms,
PCState state,
int load,
FetchConfiguration fetch,
Object context)
Initialize, load, or validate the existance of all of the given
objects.
|
void |
loadSubclasses(ClassMapping mapping)
Makes sure all subclasses of the given type are loaded in the JVM.
|
Id |
newDataStoreId(long id,
ClassMapping mapping,
boolean subs)
Create a new datastore identity object from the given id value and
mapping.
|
Object |
newDataStoreId(Object val,
ClassMetaData meta)
Create a new unique datastore identity for the given type from
the given oid value (presumably pk, stringified oid, or oid instance).
|
FetchConfiguration |
newFetchConfiguration()
Return a fetch configuration suitable for this runtime.
|
StoreQuery |
newQuery(String language)
Return a query implementation suitable for this store.
|
void |
releaseConnection()
Instruct the store to release a retained connection.
|
void |
retainConnection()
Instruct the store to retain a connection for continued use.
|
void |
rollback()
Rollback the current data store transaction.
|
void |
rollbackOptimistic()
Notification that an optimistic transaction was rolled back before
a data store transaction ever began.
|
boolean |
select(Select sel,
ClassMapping mapping,
int subs,
OpenJPAStateManager sm,
BitSet fields,
JDBCFetchConfiguration fetch,
int eager,
boolean ident,
boolean outer)
For implementation use only.
|
void |
setContext(StoreContext ctx)
Set a reference to the corresponding context.
|
void |
setContext(StoreContext ctx,
JDBCConfiguration conf) |
protected void |
setMappedBy(OpenJPAStateManager sm,
FieldMapping mappedByFieldMapping,
Object mappedByObject) |
boolean |
syncVersion(OpenJPAStateManager sm,
Object context)
Update the version information in the given state manager to the
version stored in the data store.
|
public StoreContext getContext()
JDBCStoregetContext in interface JDBCStorepublic void setContext(StoreContext ctx)
StoreManagersetContext in interface StoreManagerpublic void setContext(StoreContext ctx, JDBCConfiguration conf)
public JDBCConfiguration getConfiguration()
JDBCStoregetConfiguration in interface JDBCStorepublic DBDictionary getDBDictionary()
JDBCStoregetDBDictionary in interface JDBCStorepublic SQLFactory getSQLFactory()
JDBCStoregetSQLFactory in interface JDBCStorepublic JDBCLockManager getLockManager()
JDBCStoreJDBCLockManager, return it.getLockManager in interface JDBCStorepublic JDBCFetchConfiguration getFetchConfiguration()
JDBCStoregetFetchConfiguration in interface JDBCStorepublic void beginOptimistic()
StoreManagerStoreManager.begin() method, which will still be called
when a true data store transaction should begin.beginOptimistic in interface StoreManagerpublic void rollbackOptimistic()
StoreManagerrollbackOptimistic in interface StoreManagerpublic void begin()
StoreManagerbegin in interface StoreManagerpublic void commit()
StoreManagercommit in interface StoreManagerpublic void rollback()
StoreManagerrollback in interface StoreManagerpublic void retainConnection()
StoreManagerretainConnection in interface StoreManagerpublic void releaseConnection()
StoreManagerreleaseConnection in interface StoreManagerpublic Object getClientConnection()
StoreManagergetClientConnection in interface StoreManagerpublic Connection getConnection()
JDBCStoreclose method should always be called on the connection
to free any resources it is using. When appropriate, the close
method is implemented as a no-op.getConnection in interface JDBCStoreprotected DataSource getDataSource()
public boolean exists(OpenJPAStateManager sm, Object context)
StoreManagerexists in interface StoreManagerpublic boolean isCached(List<Object> oids, BitSet edata)
StoreManagerisCached in interface StoreManagerpublic boolean syncVersion(OpenJPAStateManager sm, Object context)
StoreManagersyncVersion in interface StoreManagersm - the instance to checkcontext - the current execution data, or null if not
given to the calling method of the contextpublic int compareVersion(OpenJPAStateManager state, Object v1, Object v2)
StoreManagercompareVersion in interface StoreManagerstate - the state manager for the objectv1 - the first version object to comparev2 - the second version object to compareStoreManager.VERSION_LATER if v1
is later than v2StoreManager.VERSION_EARLIER if v1
is earlier than v2StoreManager.VERSION_SAME if v1
is the same as v2StoreManager.VERSION_DIFFERENT if v1
is different from v2, but the time
difference of the versions cannot be determinedpublic boolean initialize(OpenJPAStateManager sm, PCState state, FetchConfiguration fetch, Object context)
StoreManagerOpenJPAStateManager.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.initialize in interface StoreManagersm - the instance to initializestate - the lifecycle state to initialize the state manager withfetch - configuration for how to load the instancecontext - the current execution data, or null if not
given to the calling method of the brokerprotected boolean initializeState(OpenJPAStateManager sm, PCState state, JDBCFetchConfiguration fetch, ConnectionInfo info) throws ClassNotFoundException, SQLException
ClassNotFoundExceptionSQLExceptionprotected void setMappedBy(OpenJPAStateManager sm, FieldMapping mappedByFieldMapping, Object mappedByObject)
protected void getVersion(ClassMapping mapping, OpenJPAStateManager sm, Result res) throws SQLException
SQLExceptionprotected boolean isEmptyResult(Result res) throws SQLException
SQLExceptionprotected Class<?> getType(Result res, ClassMapping mapping)
public boolean load(OpenJPAStateManager sm, BitSet fields, FetchConfiguration fetch, int lockLevel, Object context)
StoreManagerOpenJPAStateManager.setVersion(java.lang.Object) method.load in interface StoreManagersm - the instance to loadfields - set of fields to load; all field indexes in this
set must be loaded; this set is mutablefetch - the fetch configuration to use when loading
related objectslockLevel - attempt to load simple fields at this lock level;
relations should be loaded at the read lock level
of the fetch configurationcontext - the current execution data, or null if not
given to the calling method of the brokerpublic Collection loadAll(Collection sms, PCState state, int load, FetchConfiguration fetch, Object context)
StoreManagerStoreContext.retrieveAll(java.util.Collection<java.lang.Object>, 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:
stateManager.getO () == null: An
uninitialized state manager. Perform the same actions as in
StoreManager.initialize(org.apache.openjpa.kernel.OpenJPAStateManager, org.apache.openjpa.kernel.PCState, org.apache.openjpa.kernel.FetchConfiguration, java.lang.Object).
load != FORCE_LOAD_NONE || stateManager.getPCState ()
== PCState.HOLLOW: A hollow state manager, or one whose
fields must be loaded because this is a refresh or retrieve action.
Peform the same actions as in StoreManager.load(org.apache.openjpa.kernel.OpenJPAStateManager, java.util.BitSet, org.apache.openjpa.kernel.FetchConfiguration, int, java.lang.Object), choosing the fields
to load based on the fetch configuration, or loading all fields
if load == FORCE_LOAD_ALL. Any required fields left
unloaded will cause a subsequent invocation of StoreManager.load(org.apache.openjpa.kernel.OpenJPAStateManager, java.util.BitSet, org.apache.openjpa.kernel.FetchConfiguration, int, java.lang.Object) on
the individual object in question.load == FORCE_LOAD_NONE &&
stateManager.getPCState () != PCState.HOLLOW: A non-hollow
state manager. Perform the same actions as in StoreManager.exists(org.apache.openjpa.kernel.OpenJPAStateManager, java.lang.Object),
and load additional state if desired. Non-hollow objects will only
be included outside of refresh invocations if a user calls
findAll with the validate
parameter set to true.loadAll in interface StoreManagersms - the state manager instances to loadstate - the lifecycle state to initialize uninitialized
state managers with; may be null if no uninitialized
instances are included in smsload - one of the FORCE_LOAD_* constants describing the
fields to force-load if this is a refresh or retrieve actionfetch - the current fetch configuration to use when loading
related objectscontext - the current execution data, or null if not
given to the calling method of the brokerImplHelper.loadAll(java.util.Collection, org.apache.openjpa.kernel.StoreManager, org.apache.openjpa.kernel.PCState, int, org.apache.openjpa.kernel.FetchConfiguration, java.lang.Object)public void beforeStateChange(OpenJPAStateManager sm, PCState fromState, PCState toState)
StoreManagerbeforeStateChange in interface StoreManagerpublic Collection flush(Collection<OpenJPAStateManager> sms)
StoreManagerOpenJPAStateManager.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.flush in interface StoreManagerorg.apache.openjpa.util.ApplicationIds#assign()public boolean cancelAll()
StoreManagercancelAll in interface StoreManagerpublic boolean assignObjectId(OpenJPAStateManager sm, boolean preFlush)
StoreManagerassignObjectId in interface StoreManagerpreFlush - whether this assignment is being requested by the
system as part of pre-flush activities, and can
be ignored if it is more efficient to assign within StoreManager.flush(java.util.Collection<org.apache.openjpa.kernel.OpenJPAStateManager>)ImplHelper.generateFieldValue(org.apache.openjpa.kernel.StoreContext, org.apache.openjpa.meta.FieldMetaData),
ImplHelper.generateIdentityValue(org.apache.openjpa.kernel.StoreContext, org.apache.openjpa.meta.ClassMetaData, int),
org.apache.openjpa.util.ApplicationIds#assign()public boolean assignField(OpenJPAStateManager sm, int field, boolean preFlush)
StoreManagerassignField in interface StoreManagerpreFlush - whether this assignment is being requested by the
system as part of pre-flush activities, and can
be ignored if it is more efficient to assign within StoreManager.flush(java.util.Collection<org.apache.openjpa.kernel.OpenJPAStateManager>)ImplHelper.generateFieldValue(org.apache.openjpa.kernel.StoreContext, org.apache.openjpa.meta.FieldMetaData)public Class<?> getManagedType(Object oid)
StoreManagergetManagedType in interface StoreManagerpublic Class<?> getDataStoreIdType(ClassMetaData meta)
StoreManagergetDataStoreIdType in interface StoreManagerpublic Object copyDataStoreId(Object oid, ClassMetaData meta)
StoreManagercopyDataStoreId in interface StoreManagerpublic Object newDataStoreId(Object val, ClassMetaData meta)
StoreManagernewDataStoreId in interface StoreManagerpublic Id newDataStoreId(long id, ClassMapping mapping, boolean subs)
JDBCStorenewDataStoreId in interface JDBCStorepublic ResultObjectProvider executeExtent(ClassMetaData meta, boolean subclasses, FetchConfiguration fetch)
StoreManagerexecuteExtent in interface StoreManagerpublic StoreQuery newQuery(String language)
StoreManagernewQuery in interface StoreManagerlanguage - the query languagepublic FetchConfiguration newFetchConfiguration()
StoreManagerFetchConfigurationImpl.newFetchConfiguration in interface StoreManagerpublic Seq getDataStoreIdSequence(ClassMetaData meta)
StoreManagergetDataStoreIdSequence in interface StoreManagerpublic Seq getValueSequence(FieldMetaData fmd)
StoreManagergetValueSequence in interface StoreManagerpublic void close()
StoreManagerclose in interface StoreManagerclose in interface Closeableprotected JDBCStoreManager.RefCountConnection connectInternal() throws SQLException
SQLExceptionpublic Connection getNewConnection()
JDBCStoreclose method should always be called on the connection
to free any resources it is using. When appropriate, the close
method is implemented as a no-op.getNewConnection in interface JDBCStorepublic Object find(Object oid, ValueMapping vm, JDBCFetchConfiguration fetch)
public Object load(ClassMapping mapping, JDBCFetchConfiguration fetch, BitSet exclude, Result result) throws SQLException
SQLExceptionpublic boolean select(Select sel, ClassMapping mapping, int subs, OpenJPAStateManager sm, BitSet fields, JDBCFetchConfiguration fetch, int eager, boolean ident, boolean outer)
sel - select to build onmapping - the mapping for the base type to select forsubs - whether the select might include subclasses of the
given mappingsm - state manager if an instance is being loaded or
initialized, else nullfields - if a state manager is being loaded, the set of
fields that must be loaded in order, else nullfetch - the fetch configuration; used if no specific fields
must be loaded, and used when selecting relationseager - eager fetch mode to useident - whether to select primary key columns as distinct
identifiersouter - whether we're outer-joining to this typepublic void loadSubclasses(ClassMapping mapping)
loadSubclasses in interface JDBCStoreCopyright © 2006–2022 Apache Software Foundation. All rights reserved.