Index: /home/andy/work/jdo/trunk/api2/src/java/javax/jdo/JDOHelper.java =================================================================== --- /home/andy/work/jdo/trunk/api2/src/java/javax/jdo/JDOHelper.java (revision 576057) +++ /home/andy/work/jdo/trunk/api2/src/java/javax/jdo/JDOHelper.java (working copy) @@ -1737,4 +1737,68 @@ } ); } + + /** Accessor for the state of the passed object. + * @param pc The object + * @return The object state + * @since 2.1 + */ + public static ObjectState getObjectState(Object pc) { + if (pc == null) { + return null; + } + + if (isDetached(pc)) { + // Detached + if (isDirty(pc)) { + return ObjectState.DETACHED_DIRTY; + } + else { + return ObjectState.DETACHED_CLEAN; + } + } + else { + if (isPersistent(pc)) { + // Persistent + if (isTransactional(pc)) { + // Transactional + if (isDirty(pc) && !isNew(pc) && !isDeleted(pc)) { + return ObjectState.PERSISTENT_DIRTY; + } + else if (!isNew(pc) && !isDirty(pc) && !isDeleted(pc)) { + return ObjectState.PERSISTENT_CLEAN; + } + else if (isNew(pc) && isDirty(pc) && !isDeleted(pc)) { + return ObjectState.PERSISTENT_NEW; + } + else if (isNew(pc) && isDirty(pc) && isDeleted(pc)) { + return ObjectState.PERSISTENT_NEW_DELETED; + } + else if (!isNew(pc) && isDirty(pc) && isDeleted(pc)) { + return ObjectState.PERSISTENT_DELETED; + } + } + else { + // Nontransactional + if (isDirty(pc)) { + return ObjectState.PERSISTENT_NONTRANSACTIONAL_DIRTY; + } + else { + return ObjectState.HOLLOW_PERSISTENT_NONTRANSACTIONAL; + } + } + } + else { + // Transient + if (isDirty(pc) && isTransactional(pc)) { + return ObjectState.TRANSIENT_DIRTY; + } + else if (!isDirty(pc) && isTransactional(pc)) { + return ObjectState.TRANSIENT_CLEAN; + } + } + } + + return ObjectState.TRANSIENT; + } }