org.apache.openjpa.jdbc.kernel
Class JDBCStoreManager

java.lang.Object
  extended by org.apache.openjpa.jdbc.kernel.JDBCStoreManager
All Implemented Interfaces:
JDBCStore, StoreManager, Closeable

public class JDBCStoreManager
extends Object
implements StoreManager, JDBCStore

StoreManager plugin that uses JDBC to store persistent data in a relational data store.

Author:
Abe White

Nested Class Summary
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.
 
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
JDBCStoreManager()
           
 
Method Summary
 boolean assignField(OpenJPAStateManager sm, int field, boolean preFlush)
           
 boolean assignObjectId(OpenJPAStateManager sm, boolean preFlush)
           
 void beforeStateChange(OpenJPAStateManager sm, PCState fromState, PCState toState)
           
 void begin()
           
 void beginOptimistic()
           
(package private)  boolean cacheFinder(ClassMapping mapping, SelectExecutor select, FetchConfiguration fetch)
           
 boolean cancelAll()
           
 void close()
           
 void commit()
           
 int compareVersion(OpenJPAStateManager state, Object v1, Object v2)
           
protected  JDBCStoreManager.RefCountConnection connectInternal()
          Connect to the database.
 Object copyDataStoreId(Object oid, ClassMetaData meta)
           
 ResultObjectProvider executeExtent(ClassMetaData meta, boolean subclasses, FetchConfiguration fetch)
           
 boolean exists(OpenJPAStateManager sm, Object context)
           
 Object find(Object oid, ValueMapping vm, JDBCFetchConfiguration fetch)
          Find the object with the given oid.
 Collection flush(Collection sms)
           
 Object getClientConnection()
           
 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)
           
 Class<?> getDataStoreIdType(ClassMetaData meta)
           
 DBDictionary getDBDictionary()
          Return the dictionary in use.
 JDBCFetchConfiguration getFetchConfiguration()
          Return the current default fetch configuration.
(package private)  FinderQueryImpl getFinder(ClassMapping mapping, FetchConfiguration fetch)
           
(package private)  FinderCache getFinderCache()
           
 JDBCLockManager getLockManager()
          If the lock manager in use is a JDBCLockManager, return it.
 Class<?> getManagedType(Object oid)
           
 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)
           
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)
           
protected  boolean initializeState(OpenJPAStateManager sm, PCState state, JDBCFetchConfiguration fetch, ConnectionInfo info)
          Initialize a newly-loaded instance.
 boolean isCached(List<Object> oids, BitSet edata)
           
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)
           
 Collection loadAll(Collection sms, PCState state, int load, FetchConfiguration fetch, Object context)
           
 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)
           
 FetchConfiguration newFetchConfiguration()
           
 StoreQuery newQuery(String language)
           
 void releaseConnection()
           
 void retainConnection()
           
 void rollback()
           
 void rollbackOptimistic()
           
 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)
           
 void setContext(StoreContext ctx, JDBCConfiguration conf)
           
protected  void setMappedBy(OpenJPAStateManager sm, FieldMapping mappedByFieldMapping, Object mappedByObject)
           
 boolean syncVersion(OpenJPAStateManager sm, Object context)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDBCStoreManager

public JDBCStoreManager()
Method Detail

getContext

public StoreContext getContext()
Description copied from interface: JDBCStore
Current persistence context.

Specified by:
getContext in interface JDBCStore

setContext

public void setContext(StoreContext ctx)
Specified by:
setContext in interface StoreManager

setContext

public void setContext(StoreContext ctx,
                       JDBCConfiguration conf)

getConfiguration

public JDBCConfiguration getConfiguration()
Description copied from interface: JDBCStore
Return the configuration for this runtime.

Specified by:
getConfiguration in interface JDBCStore

getDBDictionary

public DBDictionary getDBDictionary()
Description copied from interface: JDBCStore
Return the dictionary in use.

Specified by:
getDBDictionary in interface JDBCStore

getSQLFactory

public SQLFactory getSQLFactory()
Description copied from interface: JDBCStore
Return the SQL factory for this runtime.

Specified by:
getSQLFactory in interface JDBCStore

getLockManager

public JDBCLockManager getLockManager()
Description copied from interface: JDBCStore
If the lock manager in use is a JDBCLockManager, return it.

Specified by:
getLockManager in interface JDBCStore

getFetchConfiguration

public JDBCFetchConfiguration getFetchConfiguration()
Description copied from interface: JDBCStore
Return the current default fetch configuration.

Specified by:
getFetchConfiguration in interface JDBCStore

beginOptimistic

public void beginOptimistic()
Specified by:
beginOptimistic in interface StoreManager

rollbackOptimistic

public void rollbackOptimistic()
Specified by:
rollbackOptimistic in interface StoreManager

begin

public void begin()
Specified by:
begin in interface StoreManager

commit

public void commit()
Specified by:
commit in interface StoreManager

rollback

public void rollback()
Specified by:
rollback in interface StoreManager

retainConnection

public void retainConnection()
Specified by:
retainConnection in interface StoreManager

releaseConnection

public void releaseConnection()
Specified by:
releaseConnection in interface StoreManager

getClientConnection

public Object getClientConnection()
Specified by:
getClientConnection in interface StoreManager

getConnection

public Connection getConnection()
Description copied from interface: JDBCStore
Return a SQL connection to the database. The close 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.

Specified by:
getConnection in interface JDBCStore

getDataSource

protected DataSource getDataSource()

exists

public boolean exists(OpenJPAStateManager sm,
                      Object context)
Specified by:
exists in interface StoreManager

isCached

public boolean isCached(List<Object> oids,
                        BitSet edata)
Specified by:
isCached in interface StoreManager

syncVersion

public boolean syncVersion(OpenJPAStateManager sm,
                           Object context)
Specified by:
syncVersion in interface StoreManager

compareVersion

public int compareVersion(OpenJPAStateManager state,
                          Object v1,
                          Object v2)
Specified by:
compareVersion in interface StoreManager

initialize

public boolean initialize(OpenJPAStateManager sm,
                          PCState state,
                          FetchConfiguration fetch,
                          Object context)
Specified by:
initialize in interface StoreManager

initializeState

protected boolean initializeState(OpenJPAStateManager sm,
                                  PCState state,
                                  JDBCFetchConfiguration fetch,
                                  ConnectionInfo info)
                           throws ClassNotFoundException,
                                  SQLException
Initialize a newly-loaded instance.

Throws:
ClassNotFoundException
SQLException

setMappedBy

protected void setMappedBy(OpenJPAStateManager sm,
                           FieldMapping mappedByFieldMapping,
                           Object mappedByObject)

getVersion

protected void getVersion(ClassMapping mapping,
                          OpenJPAStateManager sm,
                          Result res)
                   throws SQLException
This method is to provide override for non-JDBC or JDBC-like implementation of getting version from the result set.

Throws:
SQLException

isEmptyResult

protected boolean isEmptyResult(Result res)
                         throws SQLException
This method is to provide override for non-JDBC or JDBC-like implementation of checking whether the result set is empty or not.

Throws:
SQLException

getType

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.


load

public boolean load(OpenJPAStateManager sm,
                    BitSet fields,
                    FetchConfiguration fetch,
                    int lockLevel,
                    Object context)
Specified by:
load in interface StoreManager

loadAll

public Collection loadAll(Collection sms,
                          PCState state,
                          int load,
                          FetchConfiguration fetch,
                          Object context)
Specified by:
loadAll in interface StoreManager

beforeStateChange

public void beforeStateChange(OpenJPAStateManager sm,
                              PCState fromState,
                              PCState toState)
Specified by:
beforeStateChange in interface StoreManager

flush

public Collection flush(Collection sms)
Specified by:
flush in interface StoreManager

cancelAll

public boolean cancelAll()
Specified by:
cancelAll in interface StoreManager

assignObjectId

public boolean assignObjectId(OpenJPAStateManager sm,
                              boolean preFlush)
Specified by:
assignObjectId in interface StoreManager

assignField

public boolean assignField(OpenJPAStateManager sm,
                           int field,
                           boolean preFlush)
Specified by:
assignField in interface StoreManager

getManagedType

public Class<?> getManagedType(Object oid)
Specified by:
getManagedType in interface StoreManager

getDataStoreIdType

public Class<?> getDataStoreIdType(ClassMetaData meta)
Specified by:
getDataStoreIdType in interface StoreManager

copyDataStoreId

public Object copyDataStoreId(Object oid,
                              ClassMetaData meta)
Specified by:
copyDataStoreId in interface StoreManager

newDataStoreId

public Object newDataStoreId(Object val,
                             ClassMetaData meta)
Specified by:
newDataStoreId in interface StoreManager

newDataStoreId

public Id newDataStoreId(long id,
                         ClassMapping mapping,
                         boolean subs)
Description copied from interface: JDBCStore
Create a new datastore identity object from the given id value and mapping.

Specified by:
newDataStoreId in interface JDBCStore

executeExtent

public ResultObjectProvider executeExtent(ClassMetaData meta,
                                          boolean subclasses,
                                          FetchConfiguration fetch)
Specified by:
executeExtent in interface StoreManager

newQuery

public StoreQuery newQuery(String language)
Specified by:
newQuery in interface StoreManager

newFetchConfiguration

public FetchConfiguration newFetchConfiguration()
Specified by:
newFetchConfiguration in interface StoreManager

getDataStoreIdSequence

public Seq getDataStoreIdSequence(ClassMetaData meta)
Specified by:
getDataStoreIdSequence in interface StoreManager

getValueSequence

public Seq getValueSequence(FieldMetaData fmd)
Specified by:
getValueSequence in interface StoreManager

close

public void close()
Specified by:
close in interface StoreManager
Specified by:
close in interface Closeable

connectInternal

protected JDBCStoreManager.RefCountConnection connectInternal()
                                                       throws SQLException
Connect to the database. This method is separated out so that it can be overridden.

Throws:
SQLException

getNewConnection

public Connection getNewConnection()
Description copied from interface: JDBCStore
Return a new SQL connection to the database. This is used when the current connection still has a open result set and a new database operation needs to be done. The close 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.

Specified by:
getNewConnection in interface JDBCStore

find

public Object find(Object oid,
                   ValueMapping vm,
                   JDBCFetchConfiguration fetch)
Find the object with the given oid.

Specified by:
find in interface JDBCStore
vm - the mapping holding this oid, or null if not applicable

load

public Object load(ClassMapping mapping,
                   JDBCFetchConfiguration fetch,
                   BitSet exclude,
                   Result result)
            throws SQLException
Load the object in the current row of the given result.

Throws:
SQLException

select

public boolean select(Select sel,
                      ClassMapping mapping,
                      int subs,
                      OpenJPAStateManager sm,
                      BitSet fields,
                      JDBCFetchConfiguration fetch,
                      int eager,
                      boolean ident,
                      boolean outer)
For implementation use only. Return a select for the proper mappings. Return null if no select is needed. The method is designed to be complementary to the load methods.

Parameters:
sel - select to build on
mapping - the mapping for the base type to select for
subs - whether the select might include subclasses of the given mapping
sm - state manager if an instance is being loaded or initialized, else null
fields - if a state manager is being loaded, the set of fields that must be loaded in order, else null
fetch - the fetch configuration; used if no specific fields must be loaded, and used when selecting relations
eager - eager fetch mode to use
ident - whether to select primary key columns as distinct identifiers
outer - whether we're outer-joining to this type
Returns:
true if the select is required, false otherwise

loadSubclasses

public void loadSubclasses(ClassMapping mapping)
Makes sure all subclasses of the given type are loaded in the JVM. This is usually done automatically.

Specified by:
loadSubclasses in interface JDBCStore

getFinder

FinderQueryImpl getFinder(ClassMapping mapping,
                          FetchConfiguration fetch)

cacheFinder

boolean cacheFinder(ClassMapping mapping,
                    SelectExecutor select,
                    FetchConfiguration fetch)

getFinderCache

FinderCache getFinderCache()


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