javax.jdo
Class JDOHelper

java.lang.Object
  |
  +--javax.jdo.JDOHelper

public class JDOHelper
extends java.lang.Object

This class can be used by a JDO-aware application to call the JDO behavior of PersistenceCapable instances without declaring them to be PersistenceCapable.

Every class whose instances can be managed by a JDO PersistenceManager must implement the PersistenceCapable interface.

This helper class defines static methods that allow a JDO-aware application to examine the runtime state of instances. For example, an application can discover whether the instance is persistent, transactional, dirty, new, or deleted; and to get its associated PersistenceManager if it has one.


Constructor Summary
JDOHelper()
           
 
Method Summary
static java.lang.Object getObjectId(java.lang.Object pc)
          Return a copy of the JDO identity associated with this instance.
static PersistenceManager getPersistenceManager(java.lang.Object pc)
          Return the associated PersistenceManager if there is one.
static java.lang.Object getTransactionalObjectId(java.lang.Object pc)
          Return a copy of the JDO identity associated with this instance.
static boolean isDeleted(java.lang.Object pc)
          Tests whether this object has been deleted.
static boolean isDirty(java.lang.Object pc)
          Tests whether this object is dirty.
static boolean isNew(java.lang.Object pc)
          Tests whether this object has been newly made persistent.
static boolean isPersistent(java.lang.Object pc)
          Tests whether this object is persistent.
static boolean isTransactional(java.lang.Object pc)
          Tests whether this object is transactional.
static void makeDirty(java.lang.Object pc, java.lang.String fieldName)
          Explicitly mark this instance and this field dirty.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDOHelper

public JDOHelper()
Method Detail

getPersistenceManager

public static PersistenceManager getPersistenceManager(java.lang.Object pc)
Return the associated PersistenceManager if there is one. Transactional and persistent instances return the associated PersistenceManager.

Transient non-transactional instances and instances of classes that do not implement PersistenceCapable return null.

Parameters:
pc - the PersistenceCapable instance.
Returns:
the PersistenceManager associated with this instance.
See Also:
PersistenceCapable.jdoGetPersistenceManager()

makeDirty

public static void makeDirty(java.lang.Object pc,
                             java.lang.String fieldName)
Explicitly mark this instance and this field dirty. Normally, PersistenceCapable classes are able to detect changes made to their fields. However, if a reference to an array is given to a method outside the class, and the array is modified, then the persistent instance is not aware of the change. This API allows the application to notify the instance that a change was made to a field.

Transient instances and instances of classes that do not implement PersistenceCapable ignore this method.

Parameters:
pc - the PersistenceCapable instance.
fieldName - the name of the field to be marked dirty.
See Also:
PersistenceCapable.jdoMakeDirty(String fieldName)

getObjectId

public static java.lang.Object getObjectId(java.lang.Object pc)
Return a copy of the JDO identity associated with this instance.

Persistent instances of PersistenceCapable classes have a JDO identity managed by the PersistenceManager. This method returns a copy of the ObjectId that represents the JDO identity.

Transient instances and instances of classes that do not implement PersistenceCapable return null.

The ObjectId may be serialized and later restored, and used with a PersistenceManager from the same JDO implementation to locate a persistent instance with the same data store identity.

If the JDO identity is managed by the application, then the ObjectId may be used with a PersistenceManager from any JDO implementation that supports the PersistenceCapable class.

If the JDO identity is not managed by the application or the data store, then the ObjectId returned is only valid within the current transaction.

Parameters:
pc - the PersistenceCapable instance.
Returns:
a copy of the ObjectId of this instance as of the beginning of the transaction.
See Also:
PersistenceManager.getObjectId(Object pc), PersistenceCapable.jdoGetObjectId(), PersistenceManager.getObjectById(Object oid, boolean validate)

getTransactionalObjectId

public static java.lang.Object getTransactionalObjectId(java.lang.Object pc)
Return a copy of the JDO identity associated with this instance.

Parameters:
pc - the PersistenceCapable instance.
Returns:
a copy of the ObjectId of this instance as modified in this transaction.
See Also:
PersistenceCapable.jdoGetTransactionalObjectId(), PersistenceManager.getObjectById(Object oid, boolean validate)

isDirty

public static boolean isDirty(java.lang.Object pc)
Tests whether this object is dirty. Instances that have been modified, deleted, or newly made persistent in the current transaction return true.

Transient instances and instances of classes that do not implement PersistenceCapable return false.

Parameters:
pc - the PersistenceCapable instance.
Returns:
true if this instance has been modified in the current transaction.
See Also:
StateManager.makeDirty(Object pc, String fieldName), PersistenceCapable.jdoIsDirty()

isTransactional

public static boolean isTransactional(java.lang.Object pc)
Tests whether this object is transactional. Instances whose state is associated with the current transaction return true.

Transient instances and instances of classes that do not implement PersistenceCapable return false.

Parameters:
pc - the PersistenceCapable instance.
Returns:
true if this instance is transactional.
See Also:
PersistenceCapable.jdoIsTransactional()

isPersistent

public static boolean isPersistent(java.lang.Object pc)
Tests whether this object is persistent. Instances that represent persistent objects in the data store return true.

Transient instances and instances of classes that do not implement PersistenceCapable return false.

Parameters:
pc - the PersistenceCapable instance.
Returns:
true if this instance is persistent.
See Also:
PersistenceManager.makePersistent(Object pc), PersistenceCapable.jdoIsPersistent()

isNew

public static boolean isNew(java.lang.Object pc)
Tests whether this object has been newly made persistent. Instances that have been made persistent in the current transaction return true.

Transient instances and instances of classes that do not implement PersistenceCapable return false.

Parameters:
pc - the PersistenceCapable instance.
Returns:
true if this instance was made persistent in the current transaction.
See Also:
PersistenceManager.makePersistent(Object pc), PersistenceCapable.jdoIsNew()

isDeleted

public static boolean isDeleted(java.lang.Object pc)
Tests whether this object has been deleted. Instances that have been deleted in the current transaction return true.

Transient instances and instances of classes that do not implement PersistenceCapable return false.

Parameters:
pc - the PersistenceCapable instance.
Returns:
true if this instance was deleted in the current transaction.
See Also:
PersistenceManager.deletePersistent(Object pc), PersistenceCapable.jdoIsDeleted()


Authors: Thomas Mahler and others. (C) 2000, 2001.
All rights reserved. Published under the Gnu Public License.
http://objectbridge.sourceforge.net
Version: 0.8.375, 2002-04-04