State Interrogation
The JDOHelper class provides
the following methods to interrogate the state of an instance:
static boolean isPersistent(Object obj); static boolean isTransactional(Object obj); static boolean isDirty(Object obj); static boolean isNew(Object obj); static boolean isDeleted(Object obj);
Each of these methods returns false if the instance is null, transient, or of a class that is not
persistent. Otherwise, these methods return the following:
isPersistent( )Returns
truefor an instance that represents a persistent object in the datastoreisTransactional( )Returns
truefor an instance whose state is associated with the current transactionisDirty( )Returns
truefor an instance whose state has changed in the current transactionisNew( )Returns
truefor an instance made persistent in the current transactionisDeleted( )Returns
trueif the instance has been deleted in the current transaction
Table 11-1
specifies the values these methods return for each required lifecycle
state. You could write a method that calls each of these methods and
returns a String denoting the
instance’s lifecycle state. This can be useful if you are debugging or
would like to know the lifecycle state of instances.
Table 11-1. State interrogation method return values
State of Instance | isPersistent( ) | isTransactional( ) | isDirty( ) | isNew( ) | isDeleted( ) |
|---|---|---|---|---|---|
Transient | false | false | false | false | false |
Hollow | true | false | false | false | false |
Persistent-new | true | true | true | true | false |
Persistent-clean | true | true | false | false | false |
Persistent-dirty ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access