Interface PersistenceCapable

  • All Known Subinterfaces:
    PersistenceCapable

    public interface PersistenceCapable
    A class that can be managed by a JDO implementation.

    Every class whose instances can be managed by a JDO PersistenceManager must implement the PersistenceCapable interface.

    This interface defines methods that allow the implementation to manage the instances. It also defines methods that allow a JDO aware application to examine the runtime state of instances. For example, an application can discover whether the instance is persistent, transactional, dirty, new, or deleted; and to get its associated PersistenceManager if it has one.

    In the Reference Implementation, the JDO Enhancer modifies the class to implement PersistenceCapable prior to loading the class into the runtime environment. The Reference Enhancer also adds code to implement the methods defined by PersistenceCapable.

    The PersistenceCapable interface is designed to avoid name conflicts in the scope of user-defined classes. All of its declared method names are prefixed with 'jdo'.

    • Method Detail

      • jdoGetPersistenceManager

        PersistenceManager jdoGetPersistenceManager()
        Return the associated PersistenceManager if there is one. Transactional and persistent instances return the associated PersistenceManager.

        Transient non-transactional instances return null.

        Returns:
        the PersistenceManager associated with this instance.
      • jdoMakeDirty

        void jdoMakeDirty​(String fieldName)
        Explicitly mark this instance and this field dirty. 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 instance is not aware of the change. This API allows the application to notify the instance that a change was made to a field.

        Transient instances ignore this method.

        Parameters:
        fieldName - the name of the field to be marked dirty.
      • jdoGetObjectId

        Object jdoGetObjectId()
        Return a copy of the JDO identity associated with this instance.

        Persistent instances of PersistenceCapable classes have a JDO identity managed by the PersistenceManager. This method returns a copy of the ObjectId that represents the JDO identity.

        Transient instances return null.

        The ObjectId may be serialized and later restored, and used with a PersistenceManager from the same JDO implementation to locate a persistent instance 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.

        Returns:
        a copy of the ObjectId of this instance.
        See Also:
        PersistenceManager.getObjectId(Object pc), PersistenceManager.getObjectById(Object oid)
      • jdoIsDirty

        boolean jdoIsDirty()
        Tests whether this object is dirty. Instances that have been modified, deleted, or newly made persistent in the current transaction return true.

        Transient instances return false.

        Returns:
        true if this instance has been modified in the current transaction.
        See Also:
        jdoMakeDirty(String fieldName)
      • jdoIsTransactional

        boolean jdoIsTransactional()
        Tests whether this object is transactional. Instances that respect transaction boundaries return true. These instances include transient instances made transactional as a result of being the target of a makeTransactional method call; newly made persistent or deleted persistent instances; persistent instances read in data store transactions; and persistent instances modified in optimistic transactions.

        Transient instances return false.

        Returns:
        true if this instance is transactional.
      • jdoIsPersistent

        boolean jdoIsPersistent()
        Tests whether this object is persistent. Instances whose state is stored in the data store return true.

        Transient instances return false.

        Returns:
        true if this instance is persistent.
        See Also:
        PersistenceManager.makePersistent(Object pc)
      • jdoIsNew

        boolean jdoIsNew()
        Tests whether this object has been newly made persistent. Instances that have been made persistent in the current transaction return true.

        Transient instances return false.

        Returns:
        true if this instance was made persistent in the current transaction.
        See Also:
        PersistenceManager.makePersistent(Object pc)
      • jdoIsDeleted

        boolean jdoIsDeleted()
        Tests whether this object has been deleted. Instances that have been deleted in the current transaction return true.

        Transient instances return false.

        Returns:
        true if this instance was deleted in the current transaction.
        See Also:
        PersistenceManager.deletePersistent(Object pc)