stomp.jdo
Class JDOFactory

java.lang.Object
  |
  +--stomp.util.AbstractFactory
        |
        +--stomp.jdo.JDOFactory

public class JDOFactory
extends AbstractFactory

Gives static access to a properly configured PersistenceManagers. In general, there is a single PersistenceManager that handles the brunt of the calls, acting as the main cache for the application. Transaction management is completely abstracted away from developers by the objects in this factory. To start a transaction, use the getTransactionalPersistenceManager () method. After obtaining this new PM, any object which is going to be involved in the transaction must be relocated in the transactional PM. To commit the transaction, simply close () the PersistenceManager. Note that after closing the PM, any instances that were found in the transactional PM are considered out-of-date and should be discarded. However, any instances found through a read-only PM, even before the transaction, are still good, and will respond to reads correctly once the transaction is committed. Note that attempting to start a transaction through a PM will result in an exception being thrown. Transactions are started by calling "getTransactionalPM" and committed by calling "close ()" on the transactional PM. Also note that transactional PMs must be closed when they are no longer in use, so try {} finally {pm.close} blocks are strongly encouraged.

Author:
Eric Lindauer

Constructor Summary
JDOFactory()
           
 
Method Summary
 void deleteAll(java.lang.Class persistentClass)
           
 void deleteObject(java.lang.Object object)
           
 java.util.Collection executeQuery(java.lang.Class theClass, java.lang.String filter)
          convenience method for executing a String filter on all the instances of a particular class in the database, as well as all of its subclasses.
 java.util.Collection executeQuery(java.lang.Class theClass, java.lang.String filter, javax.jdo.PersistenceManager pm)
           
 java.lang.Object executeSingletonQuery(java.lang.Class theClass, java.lang.String filter)
          returns the first object in the Collection of matching results for the given query.
 java.lang.Object executeSingletonQuery(java.lang.Class theClass, java.lang.String filter, javax.jdo.PersistenceManager pm)
           
 java.lang.Object findInPm(java.lang.Object pc, javax.jdo.PersistenceManager pm)
          takes an instance associated with some other PM and refinds it through the given PM.
 java.lang.Object findReadOnly(java.lang.Object pc)
          takes an instance which has presumably been found through a transactional PM and refinds it through a read-only PM.
static java.lang.String getDBName()
          Deprecated.  
 javax.jdo.Extent getExtent(java.lang.Class theClass, boolean subClasses)
          Conveniencte metod for obtaining Extents of objects.
 javax.jdo.PersistenceManager getNewTransactionalPersistenceManager()
          returns a new transactional PM.
 javax.jdo.PersistenceManager getNewTransactionalPersistenceManager(java.lang.String schemaGroup)
           
 javax.jdo.PersistenceManager getNonTransactionalPersistenceManager()
          returns a PersistenceManager capable of returning all non-transactionally persistent objects.
 javax.jdo.PersistenceManager getNonTransactionalPersistenceManager(java.lang.String schemaGroup)
           
 java.lang.Object getObjectId(java.lang.Object pc)
          if the given object isPersistent ( pc ), returns the ObjectID associated with this object.
 javax.jdo.PersistenceManager getPersistenceManager(java.lang.Object pc)
           
 javax.jdo.PersistenceManager getReadOnlyPersistenceManager()
          returns a singleton PersistenceManager obtained from this config's singleton persistence manager factory.
 javax.jdo.PersistenceManager getReadOnlyPersistenceManager(java.lang.String schemaGroup)
           
 java.lang.String getSchemaGroup(java.lang.Class theClass)
          attempts to invoke 'getStaticSchemaGroup' on the given class.
 java.lang.String getSchemaGroup(java.lang.Object pc)
          If the object is persistent, returns the result of a call to 'getSchemaGroup'.
 javax.jdo.PersistenceManager getTransactionalPersistenceManager()
          returns a PM with a transaction already active.
 javax.jdo.PersistenceManager getTransactionalPersistenceManager(java.lang.String schemaGroup)
           
 void idsDeleted(java.util.Collection deletedIds)
          makes any necessary callbacks to listeners in this JVM, notifying them that the given Collection of objects was deleted.
 boolean isNonTransactional(java.lang.Object pc)
          returns true if the given object is PersistenceCapable, persistent, and was found through a "non-transactional" PM.
 boolean isPersistent(java.lang.Object pc)
          convenience method, returns true if the given object is already in the database, false otherwise.
 javax.jdo.Query newQuery(java.lang.Class theClass)
          Convenience method for obtaining Query objects.
 java.lang.Object persistNewObject(java.lang.Object pc)
          starts a new transaction, makes the pc persistent, and commits the transaction.
 java.lang.Object persistNewObject(java.lang.Object pc, javax.jdo.PersistenceManager pm)
          makes the pc persistent and managed by the given persistence manager.
 void refresh(java.lang.Object pc)
          Convenience method for refreshing an object
static JDOFactory singleton()
           
 
Methods inherited from class stomp.util.AbstractFactory
singletonFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDOFactory

public JDOFactory()
Method Detail

singleton

public static JDOFactory singleton()

persistNewObject

public java.lang.Object persistNewObject(java.lang.Object pc)
starts a new transaction, makes the pc persistent, and commits the transaction. Then refinds the object in a read-only PM and returns it. Note that if you call this method, you should not start any other transactions in the method. The EJB transaction setting for any method calling this method should be set to "RequiresNew". If pc is already persistent, this method does nothing.


persistNewObject

public java.lang.Object persistNewObject(java.lang.Object pc,
                                         javax.jdo.PersistenceManager pm)
makes the pc persistent and managed by the given persistence manager. Does not close the persistnce manager. If pc is already persistent, this method does nothing.


isPersistent

public boolean isPersistent(java.lang.Object pc)
convenience method, returns true if the given object is already in the database, false otherwise.


findReadOnly

public java.lang.Object findReadOnly(java.lang.Object pc)
takes an instance which has presumably been found through a transactional PM and refinds it through a read-only PM. This ensures that the fields will be kept up-to-date as other transactions are committed, besides allowing reading of the fields, etc. note that any newly created objects will not be findable until the transaction in which they were created is committed! ( use persistNewObject ( pc ) to be sure ).


isNonTransactional

public boolean isNonTransactional(java.lang.Object pc)
returns true if the given object is PersistenceCapable, persistent, and was found through a "non-transactional" PM. Otherwise returns false.


getPersistenceManager

public javax.jdo.PersistenceManager getPersistenceManager(java.lang.Object pc)

findInPm

public java.lang.Object findInPm(java.lang.Object pc,
                                 javax.jdo.PersistenceManager pm)
takes an instance associated with some other PM and refinds it through the given PM. Convenience method. If the object is not associated with a PM or is not persistence-capable, the object is returned directly.


getObjectId

public java.lang.Object getObjectId(java.lang.Object pc)
if the given object isPersistent ( pc ), returns the ObjectID associated with this object. otherwise returns null.


executeQuery

public java.util.Collection executeQuery(java.lang.Class theClass,
                                         java.lang.String filter)
convenience method for executing a String filter on all the instances of a particular class in the database, as well as all of its subclasses.


executeQuery

public java.util.Collection executeQuery(java.lang.Class theClass,
                                         java.lang.String filter,
                                         javax.jdo.PersistenceManager pm)

executeSingletonQuery

public java.lang.Object executeSingletonQuery(java.lang.Class theClass,
                                              java.lang.String filter)
returns the first object in the Collection of matching results for the given query. If no results are found, this method returns null.


executeSingletonQuery

public java.lang.Object executeSingletonQuery(java.lang.Class theClass,
                                              java.lang.String filter,
                                              javax.jdo.PersistenceManager pm)

getTransactionalPersistenceManager

public javax.jdo.PersistenceManager getTransactionalPersistenceManager()
returns a PM with a transaction already active.


getTransactionalPersistenceManager

public javax.jdo.PersistenceManager getTransactionalPersistenceManager(java.lang.String schemaGroup)

getNewTransactionalPersistenceManager

public javax.jdo.PersistenceManager getNewTransactionalPersistenceManager()
returns a new transactional PM. when this pm is "closed", the transaction will commit.


getNewTransactionalPersistenceManager

public javax.jdo.PersistenceManager getNewTransactionalPersistenceManager(java.lang.String schemaGroup)

getReadOnlyPersistenceManager

public javax.jdo.PersistenceManager getReadOnlyPersistenceManager()
returns a singleton PersistenceManager obtained from this config's singleton persistence manager factory. This PM is *read-only*. Any attempts to start a transaction with this PM will result in an exception. To do anything that requires a transaction, use teh getTransactionalPersistenceManager method.


getReadOnlyPersistenceManager

public javax.jdo.PersistenceManager getReadOnlyPersistenceManager(java.lang.String schemaGroup)

getNonTransactionalPersistenceManager

public javax.jdo.PersistenceManager getNonTransactionalPersistenceManager()
returns a PersistenceManager capable of returning all non-transactionally persistent objects. In particular, it is guaranteed that PMs from this method have the non-transactional write set to true. Objects found in this pm are completely independent of other transactions, whether in the current JVM or elsewhere. They are never updated to reflect changes, never committed etc, and function as basically a transient version of a persistent object.


getNonTransactionalPersistenceManager

public javax.jdo.PersistenceManager getNonTransactionalPersistenceManager(java.lang.String schemaGroup)

idsDeleted

public void idsDeleted(java.util.Collection deletedIds)
makes any necessary callbacks to listeners in this JVM, notifying them that the given Collection of objects was deleted. requires: Collection is a collection of ObjectIds


deleteObject

public void deleteObject(java.lang.Object object)

deleteAll

public void deleteAll(java.lang.Class persistentClass)

getDBName

public static java.lang.String getDBName()
Deprecated.  

This should be removed.


newQuery

public javax.jdo.Query newQuery(java.lang.Class theClass)
Convenience method for obtaining Query objects. This uses the read-only PM associated with the schemaGroup for the given class to produce a query object.


getExtent

public javax.jdo.Extent getExtent(java.lang.Class theClass,
                                  boolean subClasses)
Conveniencte metod for obtaining Extents of objects.


refresh

public void refresh(java.lang.Object pc)
Convenience method for refreshing an object


getSchemaGroup

public java.lang.String getSchemaGroup(java.lang.Object pc)
If the object is persistent, returns the result of a call to 'getSchemaGroup'. Otherwise, attempts to find the answer via relection by using pc.getClass ().


getSchemaGroup

public java.lang.String getSchemaGroup(java.lang.Class theClass)
attempts to invoke 'getStaticSchemaGroup' on the given class. returns the result if the method exists, otherwise, throws IllegalArgumentException.