I've added this to the latest draft of the specification dated 2007-09-28.

8.6 State Interrogation
public static ObjectState getObjectState(Object pc);
This method returns an enum representing the life cycle state of the parameter instance. The enum has an overloaded toString method that returns the life cycle state as discussed in section 5.5.
8.6.1 enum ObjectState
public enum ObjectState {
        TRANSIENT("transient"),
        TRANSIENT_CLEAN("transient-clean"),
        TRANSIENT_DIRTY("transient-dirty"),
        PERSISTENT_NEW("persistent-new"),
HOLLOW_PERSISTENT_NONTRANSACTIONAL("hollow/persistent- nontransactional"),
        PERSISTENT_NONTRANSACTIONAL_DIRTY("persistent-nontransactional-dirty"),
        PERSISTENT_CLEAN("persistent-clean"),
        PERSISTENT_DIRTY("persistent-dirty"),
        PERSISTENT_DELETED("persistent-deleted"),
        PERSISTENT_NEW_DELETED("persistent-new-deleted"),
        DETACHED_CLEAN("detached-clean"),
        DETACHED_DIRTY("detached-dirty");
}

Craig

On Aug 4, 2007, at 6:14 PM, cbeams wrote:


Craig, all,

This isn't so much a comment on the 2.1 spec changes, but rather a suggestion for an addition to the JDOHelper interface in the 2.1 timeline (I don't know if it's too late for this sort of thing)...

JPOX's JPOXJDOHelper implementation exposes a very useful method with the following signature:

        String getObjectState(Object pc)

I would love to see this method exposed by the standard JDOHelper interface. The spec currently provides status interrogation methods (per section 8.5), but they're primarily useful assuming one is testing for a particular state. For example, I might care to assert that a pc is 'detached-dirty':

        assert pc.isDetached() && pc.isDirty();

That's not so bad; it's even elegant. But if I'm debugging my way through an application, there's no standardized way (that I know of) to simply print out the state of the pc object. Using JPOX internals, I can do the following:

logger.debug(JPOXJDOHelper.getObjectState(pc)); // prints out 'detached-dirty', 'transient-clean', or whatever the state actually is.

or, just as easily:

        assert "detached-dirty".equals(JPOXJDOHelper.getObjectState(pc));

This method is most useful from a practical point of view: debugging. One might argue that such code need not be portable and thus standardized, but I'd counter with "why not"? State transitions in JDO are complex enough; if we can make the standard interface for interrogation of those states friendlier, all the better.

IMHO, the only problem with the current JPOX getObjectState() implementation is that it's string-based. If this method were to be considered for the 2.1 JDOHelper interface, I would suggest that the return type be an enumeration that contains identifiers for all the object states, optional and required:

        package javax.jdo;
        public interface JDOHelper {
                // ...
                ObjectState getObjectState(Object pc);
        }

Where ObjectState is defined as:

        package javax.jdo;
        public enum ObjectState {
                TRANSIENT,
                TRANSIENT_CLEAN,
                TRANSIENT_DIRTY,
                PERSISTENT_NEW,
                PERSISTENT_NONTRANSACTIONAL,
                PERSISTENT_NONTRANSACTIONAL_DIRTY,
                PERSISTENT_CLEAN,
                PERSISTENT_DIRTY,
                HOLLOW,
                PERSISTENT_DELETED,
                PERSISTENT_NEW_DELETED,
                DETACHED_CLEAN,
                DETACHED_DIRTY;
        }

With this addition in place, the user gets the best of both worlds. Asserting for a given state is trivially easy:

        assert JDOHelper.getObjectState(pc) == ObjectState.DETACHED_DIRTY;

And determining object state with no a priori knowledge is simple, too:

logger.debug(JDOHelper.getObjectState(pc)); // prints out "DETACHED_DIRTY"

The ObjectState enum could also override toString() such that it transforms the all-caps-and-underscores identifier to the lower- case-and-dashes format used within the spec, e.g.: DETACHED_DIRTY.toString() returns "detached-dirty"


Thanks for considering,

- Chris Beams




From: Craig L Russell <[EMAIL PROTECTED]>
Date: August 3, 2007 7:04:52 PM PDT
To: Apache JDO project <[email protected]>, JDO Expert Group <[EMAIL PROTECTED]>
Subject: JDO 2.1 specification draft can be reviewed...


at http://db.apache.org/jdo/documentation.html

Check it out, and send comments...

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/ jdo
408 276-5638 mailto:[EMAIL PROTECTED]
P.S. A good JDO? O, Gasp!




Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:[EMAIL PROTECTED]
P.S. A good JDO? O, Gasp!

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to