FileDocCategorySizeDatePackage
JDOHelper.javaAPI DocGlassfish v2 API12357Fri May 04 22:34:56 BST 2007com.sun.jdo.api.persistence.support

JDOHelper

public class JDOHelper extends Object
An utility class for querying PersistenceCapable objects.

Fields Summary
private static final ResourceBundle
messages
I18N message handler
static final String
null_instance
Help string
Constructors Summary
Methods Summary
private static java.lang.ClassLoadergetArrayClassLoader(java.lang.Object[] arr)
Returns the first not null class loader for the elements of the object array. If element is itself an instance of the java.util.Collection or an Array it is recursively checked for its class loader.

param
arr array of objects to get the class loader for
return
the class loader that loaded the class or interface represented by its elements.

	ClassLoader cl = null;

	for (int i = 0; i < arr.length; i++) {
	    cl = getObjectClassLoader(arr[i]);
	    if (cl != null) {
		break;
	    }
	}
	return cl;
   
private static java.lang.ClassLoadergetCollectionClassLoader(java.util.Collection col)
Returns the class loader for the elements of the collection. If element is itself an instance of the java.util.Collection or an Array it is recursively checked for its class loader.

param
col collection of objects to get the class loader for
return
the class loader that loaded the class or interface represented by its elements.

	Object[] arr = col.toArray();
	return getArrayClassLoader(arr);
   
private static java.lang.ClassLoadergetObjectClassLoader(java.lang.Object obj)
Returns the class loader for the class of the object. If object is an instance of the java.util.Collection or an Array it is recursively checked for the class loader of its elements.

param
obj the object to get the class loader for
return
the class loader that loaded the class or interface represented by this object.

	Class clazz = obj.getClass();

	if (obj instanceof Collection) {
	    return getCollectionClassLoader((Collection)obj);
	} else if (clazz.isArray()) {
	    return getArrayClassLoader((Object[])obj);
	} else {
	    return clazz.getClassLoader();
	}
   
public static java.lang.ObjectgetObjectId(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.

param
obj an Object
return
a copy of the ObjectId of a persistent object; null if the object is transient
see
PersistenceCapable#jdoGetObjectId()
see
PersistenceManager#getObjectId(Object obj)
see
PersistenceManager#getObjectById(Object oid)

        if (obj instanceof PersistenceCapable)
            return ((PersistenceCapable)obj).jdoGetObjectId();
        return null;
    
public static PersistenceManagergetPersistenceManager(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.

param
obj an Object
return
the PersistenceManager associated with the object; null otherwise
see
PersistenceCapable#jdoGetPersistenceManager()

        if (obj instanceof PersistenceCapable)
            return ((PersistenceCapable)obj).jdoGetPersistenceManager();
        return null;
    
public static booleanisDeleted(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.

param
obj an Object
return
true if the object was deleted in the current transaction; false otherwise.
see
PersistenceCapable#jdoIsDeleted()
see
PersistenceManager#deletePersistent(Object obj)

        if (obj instanceof PersistenceCapable)
            return ((PersistenceCapable)obj).jdoIsDeleted();    
        return false;
    
public static booleanisDirty(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.

param
obj an Object
return
true if the object has been modified in the current transaction; false otherwise.
see
PersistenceCapable#jdoIsDirty()
see
PersistenceCapable#jdoMakeDirty(String fieldName)

        if (obj instanceof PersistenceCapable)
            return ((PersistenceCapable)obj).jdoIsDirty();
        return false;
    
public static booleanisNew(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.

param
obj an Object
return
true if the object was made persistent in the current transaction; false otherwise.
see
PersistenceCapable#jdoIsNew()
see
PersistenceManager#makePersistent(Object obj)

        if (obj instanceof PersistenceCapable)
            return ((PersistenceCapable)obj).jdoIsNew();
        return false;
    
public static booleanisPersistent(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.

param
obj an Object
return
true if the object is persistent; false otherwise.
see
PersistenceCapable#jdoIsPersistent()
see
PersistenceManager#makePersistent(Object obj)

        if (obj instanceof PersistenceCapable)
            return ((PersistenceCapable)obj).jdoIsPersistent();
        return false;
    
public static booleanisTransactional(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.

param
obj an Object
return
true if the object is transactional; false otherwise.
see
PersistenceCapable#jdoIsTransactional()

        if (obj instanceof PersistenceCapable)
            return ((PersistenceCapable)obj).jdoIsTransactional();
        return false;
    
public static voidmakeDirty(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.

param
obj an object
param
fieldName the name of the object's field to be marked dirty
see
PersistenceCapable#jdoMakeDirty(String fieldName)

        if (obj instanceof PersistenceCapable)
            ((PersistenceCapable)obj).jdoMakeDirty(fieldName);
    
public static java.lang.StringprintObject(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

 //NOI18N

                                     
         
        if (o==null)
                return null_instance;
        else if (isDeleted(o))
                return I18NHelper.getMessage(messages, "jdohelper.deleted_instance", //NOI18N
				o.getClass().getName());
        else
                return o.toString();