Class JDOHelper
- java.lang.Object
-
- com.sun.jdo.api.persistence.support.JDOHelper
-
public class JDOHelper extends Object
An utility class for queryingPersistenceCapable
objects.
-
-
Constructor Summary
Constructors Constructor Description JDOHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Object
getObjectId(Object obj)
Returns a copy of the JDO identity associated with an object.static PersistenceManager
getPersistenceManager(Object obj)
Returns the associated PersistenceManager of an object if there is one.static boolean
isDeleted(Object obj)
Tests whether the object has been deleted.static boolean
isDirty(Object obj)
Tests whether an object is dirty.static boolean
isNew(Object obj)
Tests whether the object has been newly made persistent.static boolean
isPersistent(Object obj)
Tests whether an object is persistent.static boolean
isTransactional(Object obj)
Tests whether an object is transactional.static void
makeDirty(Object obj, String fieldName)
Explicitly marks a field of an object as dirty if the object is persistent and transactional.static String
printObject(Object o)
Prints the object.
-
-
-
Method Detail
-
getPersistenceManager
public static PersistenceManager getPersistenceManager(Object obj)
Returns the associated PersistenceManager of an object if there is one. For transactional and persistent objects, their associatedPersistenceManager
is returned. For transient objects,null
is returned.- Parameters:
obj
- anObject
- Returns:
- the PersistenceManager associated with the object;
null
otherwise - See Also:
PersistenceCapable.jdoGetPersistenceManager()
-
makeDirty
public static void makeDirty(Object obj, 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 objectfieldName
- the name of the object's field to be marked dirty- See Also:
PersistenceCapable.jdoMakeDirty(String fieldName)
-
getObjectId
public static Object getObjectId(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
- anObject
- 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(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
- anObject
- 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(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
- anObject
- Returns:
true
if the object is transactional;false
otherwise.- See Also:
PersistenceCapable.jdoIsTransactional()
-
isPersistent
public static boolean isPersistent(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
- anObject
- Returns:
true
if the object is persistent;false
otherwise.- See Also:
PersistenceCapable.jdoIsPersistent()
,PersistenceManager.makePersistent(Object obj)
-
isNew
public static boolean isNew(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
- anObject
- 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(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
- anObject
- Returns:
true
if the object was deleted in the current transaction;false
otherwise.- See Also:
PersistenceCapable.jdoIsDeleted()
,PersistenceManager.deletePersistent(Object obj)
-
-