com.sun.jdo.api.persistence.support
Class JDOHelper

java.lang.Object
  extended by com.sun.jdo.api.persistence.support.JDOHelper

public class JDOHelper
extends java.lang.Object

An utility class for querying PersistenceCapable objects.


Constructor Summary
JDOHelper()
           
 
Method Summary
static java.lang.Object getObjectId(java.lang.Object obj)
          Returns a copy of the JDO identity associated with an object.
static PersistenceManager getPersistenceManager(java.lang.Object obj)
          Returns the associated PersistenceManager of an object if there is one.
static boolean isDeleted(java.lang.Object obj)
          Tests whether the object has been deleted.
static boolean isDirty(java.lang.Object obj)
          Tests whether an object is dirty.
static boolean isNew(java.lang.Object obj)
          Tests whether the object has been newly made persistent.
static boolean isPersistent(java.lang.Object obj)
          Tests whether an object is persistent.
static boolean isTransactional(java.lang.Object obj)
          Tests whether an object is transactional.
static void makeDirty(java.lang.Object obj, java.lang.String fieldName)
          Explicitly marks a field of an object as dirty if the object is persistent and transactional.
static java.lang.String printObject(java.lang.Object o)
          Prints the object.
 
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 obj)
Returns the associated PersistenceManager of an object if there is one. For transactional and persistent objects, their associated PersistenceManager is returned. For transient objects, null is returned.

Parameters:
obj - an Object
Returns:
the PersistenceManager associated with the object; null otherwise
See Also:
PersistenceCapable.jdoGetPersistenceManager()

makeDirty

public static void makeDirty(java.lang.Object obj,
                             java.lang.String fieldName)
Explicitly marks a field of an object as dirty if the object is persistent and transactional. 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 object is not aware of the change. This method allows the application to notify the object that a change was made to a field. For transient objects, this method does nothing.

Parameters:
obj - an object
fieldName - the name of the object's field to be marked dirty
See Also:
PersistenceCapable.jdoMakeDirty(String fieldName)

getObjectId

public static java.lang.Object getObjectId(java.lang.Object obj)
Returns a copy of the JDO identity associated with an object. Persistent objects of PersistenceCapable classes have a JDO identity managed by the PersistenceManager. This method returns a copy of the ObjectId that represents the JDO identity of a persistent object. For transient objects, null is returned.

The ObjectId may be serialized and later restored, and used with a PersistenceManager from the same JDO implementation to locate a persistent object 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:
obj - an Object
Returns:
a copy of the ObjectId of a persistent object; null if the object is transient
See Also:
PersistenceCapable.jdoGetObjectId(), PersistenceManager.getObjectId(Object obj), PersistenceManager.getObjectById(Object oid)

isDirty

public static boolean isDirty(java.lang.Object obj)
Tests whether an object is dirty. If the object have been modified, deleted, or newly made persistent in the current transaction, true is returned. For transient objects, false is returned.

Parameters:
obj - an Object
Returns:
true if the object has been modified in the current transaction; false otherwise.
See Also:
PersistenceCapable.jdoIsDirty(), PersistenceCapable.jdoMakeDirty(String fieldName)

isTransactional

public static boolean isTransactional(java.lang.Object obj)
Tests whether an object is transactional. For objects that respect transaction boundaries, true is returned. These objects include transient objects made transactional as a result of being the target of a makeTransactional method call; newly made persistent or deleted persistent objects; persistent objects read in data store transactions; and persistent objects modified in optimistic transactions. For non-transactional objects, false is returned.

Parameters:
obj - an Object
Returns:
true if the object is transactional; false otherwise.
See Also:
PersistenceCapable.jdoIsTransactional()

isPersistent

public static boolean isPersistent(java.lang.Object obj)
Tests whether an object is persistent. For objects whose state is stored in the data store, true is returned. For transient objects, false is returned.

Parameters:
obj - an Object
Returns:
true if the object is persistent; false otherwise.
See Also:
PersistenceCapable.jdoIsPersistent(), PersistenceManager.makePersistent(Object obj)

isNew

public static boolean isNew(java.lang.Object obj)
Tests whether the object has been newly made persistent. For objects that have been made persistent in the current transaction, true is returned. For transient or objects, false is returned.

Parameters:
obj - an Object
Returns:
true if the object was made persistent in the current transaction; false otherwise.
See Also:
PersistenceCapable.jdoIsNew(), PersistenceManager.makePersistent(Object obj)

isDeleted

public static boolean isDeleted(java.lang.Object obj)
Tests whether the object has been deleted. For objects that have been deleted in the current transaction, true is returned. For transient objects, false is returned.

Parameters:
obj - an Object
Returns:
true if the object was deleted in the current transaction; false otherwise.
See Also:
PersistenceCapable.jdoIsDeleted(), PersistenceManager.deletePersistent(Object obj)

printObject

public static java.lang.String printObject(java.lang.Object o)
Prints the object. If object is not NULL and is not deleted, calls toString() method on the object. Does not allow to access fields of the deleted object



Copyright © 2012 GlassFish Community. All Rights Reserved.