org.apache.jdo.impl.fostore
Class FOStoreStoreManager

java.lang.Object
  extended byorg.apache.jdo.store.StoreManagerImpl
      extended byorg.apache.jdo.impl.fostore.FOStoreStoreManager
All Implemented Interfaces:
StoreManager

class FOStoreStoreManager
extends StoreManagerImpl

StoreManager represents the datastore to the rest of the JDO components. It provides the means to write and read instances, to get the extent of classes, and to get the object id for a persistence capable object.

Author:
Dave Bristor

Field Summary
private  FOStoreConnector connector
           
private static RuntimeJavaModelFactory javaModelFactory
          RuntimeJavaModelFactory.
private static javax.jdo.spi.JDOImplHelper jdoImplHelper
          JDOImplHelper instance.
(package private) static org.apache.commons.logging.Log logger
          Logger
private static I18NHelper msg
          I18N support.
private  FOStorePMF pmf
           
private  RequestFactory rf
           
 
Fields inherited from class org.apache.jdo.store.StoreManagerImpl
optimistic
 
Constructor Summary
(package private) FOStoreStoreManager(FOStorePMF pmf)
           
 
Method Summary
private  void activateClass(java.lang.Class cls, Message message)
          Writes a request to activate the given state manager's class
private  void activateClasses(java.lang.Class cls, Message message)
          Activates this class and all supeclasses.
 void copyKeyFieldsFromObjectId(StateManagerInternal sm, java.lang.Class pcClass)
          This method copies PK field values from internal Object Id into the Hollow instance.
 OID createInternalObjectId(StateManagerInternal sm, javax.jdo.spi.PersistenceCapable pc, java.lang.Object oid, java.lang.Class cls, PersistenceManagerInternal pm)
          Creates a new object id for the given class.
 java.lang.Object createObjectId(StateManagerInternal sm, PersistenceManagerInternal pm)
          Creates a new object id for the given sm.
 int delete(java.util.BitSet loadedFields, java.util.BitSet dirtyFields, StateManagerInternal sm)
          Causes the object managed by the given state manager to be deleted in the database.
 java.lang.String dump(DumpOption option, java.lang.String name)
          Dumps information about the store.
 void fetch(StateManagerInternal sm, int[] fieldNums)
          Causes values for fields required by the state manager's object to be retrieved from the store and supplied to the state manager.
 Connector getConnector()
          Returns a Connector suitable for committing or rolling back operations on this store.
 Connector getConnector(java.lang.String userid, java.lang.String password)
          Returns a Connector suitable for committing or rolling back operations on this store for a specific userid.
 javax.jdo.Extent getExtent(java.lang.Class pcClass, boolean subclasses, PersistenceManagerInternal pm)
          Provides the means to get all instances of a particular class, or of that class and its subclasses.
 java.lang.Object getExternalObjectId(java.lang.Object objectId, javax.jdo.spi.PersistenceCapable pc)
          Provides a datastore object id.
(package private)  java.util.ArrayList getInstances(java.util.ArrayList oids, int start, int numInstances, PersistenceManagerInternal pm, java.lang.Class cls)
          Get instances for oids
 java.lang.Object getInternalObjectId(java.lang.Object objectId, PersistenceManagerInternal pm)
          Returns an Object Id that can be used by the runtime code and which is a an internal representation of the given objectId.
 java.lang.Class getPCClassForOid(java.lang.Object objectId, PersistenceManagerInternal pm)
          Returns the Class of the PersistenceCapable instance identified by the given oid.
 boolean hasActualPCClass(java.lang.Object objectId)
          Returns true if actual Class for a PersistenceCapable instance can be resolved only in the database.
 int insert(java.util.BitSet loadedFields, java.util.BitSet dirtyFields, StateManagerInternal sm)
          Causes the object managed by the given state manager's object to be inserted into the database.
 java.lang.Object newObjectIdInstance(java.lang.Class pcClass, java.lang.String str)
          This method returns an object id instance corresponding to the Class and String arguments.
 QueryResult newQueryResult(QueryResultHelper qrh)
          Returns a QueryResult instance which is then returned as the result of Query.execute(...).
protected  void preFlush()
          Write a CommitRequest and flush the connector, to cause all CreateOid and ActivateClass requests to be committed in the database *before* any inserts, updates, or deletes.
 int update(java.util.BitSet loadedFields, java.util.BitSet dirtyFields, StateManagerInternal sm)
          Causes the object managed by the given state manager to be updated in the database.
private  boolean verify(StateManagerInternal sm, boolean verifyFields, java.util.BitSet fieldsToVerify)
          Verifies existence or values of a state manager's object in the database.
 int verifyFields(java.util.BitSet ignoredFields, java.util.BitSet fieldsToVerify, StateManagerInternal sm)
          Causes the object managed by the given state manager to be verified in the database.
 
Methods inherited from class org.apache.jdo.store.StoreManagerImpl
flush
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pmf

private final FOStorePMF pmf

connector

private final FOStoreConnector connector

rf

private final RequestFactory rf

msg

private static final I18NHelper msg
I18N support.


logger

static final org.apache.commons.logging.Log logger
Logger


jdoImplHelper

private static final javax.jdo.spi.JDOImplHelper jdoImplHelper
JDOImplHelper instance.


javaModelFactory

private static final RuntimeJavaModelFactory javaModelFactory
RuntimeJavaModelFactory.

Constructor Detail

FOStoreStoreManager

FOStoreStoreManager(FOStorePMF pmf)
Method Detail

getConnector

public Connector getConnector()
Description copied from interface: StoreManager
Returns a Connector suitable for committing or rolling back operations on this store.

See Also:
StoreManager.getConnector()

getConnector

public Connector getConnector(java.lang.String userid,
                              java.lang.String password)
Description copied from interface: StoreManager
Returns a Connector suitable for committing or rolling back operations on this store for a specific userid.

Parameters:
userid - the userid for the connection
password - the password for the connection
See Also:
StoreManager.getConnector(String userid, String password)

insert

public int insert(java.util.BitSet loadedFields,
                  java.util.BitSet dirtyFields,
                  StateManagerInternal sm)
Description copied from interface: StoreManager
Causes the object managed by the given state manager's object to be inserted into the database.

Parameters:
loadedFields - BitSet of fields to be inserted in the database (may be ignored).
dirtyFields - BitSet of all fields as all fields are marked as dirty for insert. After return, bits will remain as set for fields that were not inserted. If any bits are set, the return will be FLUSHED_PARTIAL.
sm - The state manager whose object is to be inserted.
Returns:
one of StateManagerInternal.FLUSHED_{COMPLETE, PARTIAL, NONE}, depending on the success of the operation in inserting specified fields into the database.
See Also:
StoreManager.insert(BitSet, BitSet, StateManagerInternal)

update

public int update(java.util.BitSet loadedFields,
                  java.util.BitSet dirtyFields,
                  StateManagerInternal sm)
Description copied from interface: StoreManager
Causes the object managed by the given state manager to be updated in the database.

Parameters:
loadedFields - BitSet of fields loaded from the database.
dirtyFields - BitSet of changed fields that are to be flushed to the database. It is the StoreManager policy which fields are to be verified against those in the database, if this update is within the context of an optimistic transaction. After return, bits will remain set for fields that were not flushed, and in such case the return will be FLUSHED_PARTIAL.
sm - The state manager whose object is to be updated.
Returns:
one of StateManagerInternal.FLUSHED_{COMPLETE, PARTIAL, NONE}, depending on the success of the operation in updating specified fields into the database.
See Also:
StoreManager.update(BitSet, BitSet, StateManagerInternal)

verifyFields

public int verifyFields(java.util.BitSet ignoredFields,
                        java.util.BitSet fieldsToVerify,
                        StateManagerInternal sm)
Description copied from interface: StoreManager
Causes the object managed by the given state manager to be verified in the database.

Parameters:
ignoredFields - BitSet of fields to be verified against those in the database.
fieldsToVerify - Unused as there are no changed fields in this transaction.
sm - The state manager whose object is to be verified.
Returns:
StateManagerInternal.FLUSHED_COMPLETE.
See Also:
StoreManager.verifyFields(BitSet, BitSet, StateManagerInternal)

delete

public int delete(java.util.BitSet loadedFields,
                  java.util.BitSet dirtyFields,
                  StateManagerInternal sm)
Description copied from interface: StoreManager
Causes the object managed by the given state manager to be deleted in the database.

Parameters:
loadedFields - BitSet of fields loaded from the database.
dirtyFields - BitSet of changed fields. It is the StoreManager policy which fields are to be verified against those in the database, if this delete is within the context of an optimistic transaction. After return, bits will remain set for the fields that were not flushed, if the update was performed to resolve dependencies. In such case the return will be StateManagerInternal.FLUSHED_PARTIAL.
sm - The state manager whose object is to be deleted.
Returns:
one of StateManagerInternal.FLUSHED_{COMPLETE, NONE}, depending on the success of the delete operation.
See Also:
StoreManager.delete(BitSet, BitSet, StateManagerInternal)

fetch

public void fetch(StateManagerInternal sm,
                  int[] fieldNums)
Description copied from interface: StoreManager
Causes values for fields required by the state manager's object to be retrieved from the store and supplied to the state manager.

Parameters:
sm - The state manager whose fields are to be read.
fieldNums - The fields which are to be read.
See Also:
StoreManager.fetch(org.apache.jdo.state.StateManagerInternal, int[])

getExtent

public javax.jdo.Extent getExtent(java.lang.Class pcClass,
                                  boolean subclasses,
                                  PersistenceManagerInternal pm)
Description copied from interface: StoreManager
Provides the means to get all instances of a particular class, or of that class and its subclasses. If there are no instances of the given class (nor its subclass) in the store, returns null.

Parameters:
pcClass - Indicates the class of the instances that are in the returned Extent.
subclasses - If true, then instances subclasses of pcClass are included in the resulting Extent. If false, then only instances of pcClass are included.
pm - PersistenceManagerInternal making the request.
Returns:
An Extent from which instances of pcClass (and subclasses if appropriate) can be obtained. Does not return null if there are no instances; in that case it returns an empty Extent.
See Also:
StoreManager.getExtent(java.lang.Class, boolean, org.apache.jdo.pm.PersistenceManagerInternal)

createObjectId

public java.lang.Object createObjectId(StateManagerInternal sm,
                                       PersistenceManagerInternal pm)
Creates a new object id for the given sm. Delegates implementation to #createInternalObjectId(StateManagerInternal sm,Class cls, PersistenceManagerInternal pm)

Parameters:
sm - StateManagerInternal for which an Object Id is needed.
pm - PersistenceManagerInternal in which the sm's object is created.
Returns:
Object Id corresponding to the given StateManagerInternal
See Also:
StoreManager.createObjectId(org.apache.jdo.state.StateManagerInternal, org.apache.jdo.pm.PersistenceManagerInternal)

createInternalObjectId

public OID createInternalObjectId(StateManagerInternal sm,
                                  javax.jdo.spi.PersistenceCapable pc,
                                  java.lang.Object oid,
                                  java.lang.Class cls,
                                  PersistenceManagerInternal pm)
Creates a new object id for the given class. Binds metadata for the sm (i.e., ensures that there is a CLID for instances of the sm's object's class). Creates a request in the message that will provide a datastore oid for the provisional oid which is returned, but does not interact with the store.

See Also:
StoreManager.createObjectId(org.apache.jdo.state.StateManagerInternal, org.apache.jdo.pm.PersistenceManagerInternal)

getExternalObjectId

public java.lang.Object getExternalObjectId(java.lang.Object objectId,
                                            javax.jdo.spi.PersistenceCapable pc)
Provides a datastore object id. If objectId is not provisional, return it. Otherwise, see if we have a corresponding datastore objectId and return that if so. If neither of those works out, flush the current message which (we hope) will have a corresponding CreateObjectIdRequest in it. Then look as before for a corresponding datastore objectId in our mapping and return that. If we still don't have a correspondance, throw an exception.

Parameters:
objectId - Object Id for which an external Object Id is needed.
pc - PersistenceCapable instance associated with this Object Id.
Returns:
An Object Id that can be given to user/client code.
See Also:
StoreManager.getExternalObjectId(Object oid, PersistenceCapable pc)

copyKeyFieldsFromObjectId

public void copyKeyFieldsFromObjectId(StateManagerInternal sm,
                                      java.lang.Class pcClass)
Description copied from interface: StoreManager
This method copies PK field values from internal Object Id into the Hollow instance.

Parameters:
sm - StateManagerInternal for which an operation is needed.
pcClass - the Class of the persistence-capable instance
See Also:
StoreManager.copyKeyFieldsFromObjectId(org.apache.jdo.state.StateManagerInternal, java.lang.Class)

hasActualPCClass

public boolean hasActualPCClass(java.lang.Object objectId)
Description copied from interface: StoreManager
Returns true if actual Class for a PersistenceCapable instance can be resolved only in the database.

Parameters:
objectId - Object Id whose java.lang.Class needs to be resolved.
Returns:
true if the request needs to be resolved in the back end.
See Also:
StoreManager.hasActualPCClass(java.lang.Object)

getInternalObjectId

public java.lang.Object getInternalObjectId(java.lang.Object objectId,
                                            PersistenceManagerInternal pm)
Description copied from interface: StoreManager
Returns an Object Id that can be used by the runtime code and which is a an internal representation of the given objectId.

Parameters:
objectId - Object Id for which an internal Object Id is needed.
pm - PersistenceManagerInternal which requested the Object Id.
Returns:
An Object Id that can be given to user/client code.
See Also:
StoreManager.getInternalObjectId(java.lang.Object, org.apache.jdo.pm.PersistenceManagerInternal)

getPCClassForOid

public java.lang.Class getPCClassForOid(java.lang.Object objectId,
                                        PersistenceManagerInternal pm)
Description copied from interface: StoreManager
Returns the Class of the PersistenceCapable instance identified by the given oid.

Parameters:
objectId - object id whose java.lang.Class is wanted.
pm - PersistenceManagerInternal to use in loading the oid's Class.
Returns:
java.lang.Class of the PersistenceCapable instance identified with this oid.
See Also:
StoreManager.getPCClassForOid(java.lang.Object, org.apache.jdo.pm.PersistenceManagerInternal)

newObjectIdInstance

public java.lang.Object newObjectIdInstance(java.lang.Class pcClass,
                                            java.lang.String str)
This method returns an object id instance corresponding to the Class and String arguments. The String argument might have been the result of executing toString on an object id instance.

Parameters:
pcClass - the Class of the persistence-capable instance
str - the String form of the object id
Returns:
an instance of the object identity class

newQueryResult

public QueryResult newQueryResult(QueryResultHelper qrh)
Returns a QueryResult instance which is then returned as the result of Query.execute(...). This method allows support for datastore specific query execution strategies, since each StoreManager can have its own implementation of the QueryResult interface. For now fostore uses the non optimized BasicQueryResult as QueryResult implemenatation.

Specified by:
newQueryResult in interface StoreManager
Overrides:
newQueryResult in class StoreManagerImpl
Parameters:
qrh - the helper providing the query tree, the candidates and the actual parameters.
Returns:
a datastore specific query result instance

activateClasses

private void activateClasses(java.lang.Class cls,
                             Message message)
Activates this class and all supeclasses.


activateClass

private void activateClass(java.lang.Class cls,
                           Message message)
Writes a request to activate the given state manager's class


dump

public java.lang.String dump(DumpOption option,
                             java.lang.String name)
Dumps information about the store. The provided information depends on the option parameter. Currently, there are the following options supported:

Parameters:
option - Dump option, specifies the kind of information.
name - Optional fully qualified classname.
See Also:
DumpOption

getInstances

java.util.ArrayList getInstances(java.util.ArrayList oids,
                                 int start,
                                 int numInstances,
                                 PersistenceManagerInternal pm,
                                 java.lang.Class cls)
Get instances for oids

Parameters:
oids - List of oids
start - Starting index within oids of oids whose instances are to be returned.
numInstances - Number of instances to return.
pm - PersistenceManagerInternal on whose behalf the instances are being obtained.
cls - Candidate Class for which instances are being obtained.
Returns:
ArrayList of instances corresponding to numInstances of oids in the oids parameter, starting at start.

verify

private boolean verify(StateManagerInternal sm,
                       boolean verifyFields,
                       java.util.BitSet fieldsToVerify)
Verifies existence or values of a state manager's object in the database.

Parameters:
sm - The state manager whose object is to be verified.
verifyFields - If true, verify values of object, otherwise verify only existence (and ignore remaining parameters).
fieldsToVerify - Set of fields to be verified against those in the database.
Returns:
true if verify was successful (either by existence of value matching as per verifyFields).

preFlush

protected void preFlush()
Write a CommitRequest and flush the connector, to cause all CreateOid and ActivateClass requests to be committed in the database *before* any inserts, updates, or deletes.

Specified by:
preFlush in class StoreManagerImpl