org.apache.cayenne.util

## Class PersistentObjectHolder

- java.lang.Object
- - org.apache.cayenne.util.RelationshipFault
  - - org.apache.cayenne.util.PersistentObjectHolder

- All Implemented Interfaces:
    Serializable, ValueHolder

      public class PersistentObjectHolder
      extends RelationshipFault
      implements ValueHolder

  A ValueHolder implementation that holds a single Persistent object related to an object used to initialize PersistentObjectHolder. Value is resolved on first access.
  Since:
    1.2
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected boolean` | `fault`
    `protected Object` | `value`

    - ### Fields inherited from class org.apache.cayenne.util.RelationshipFault

      `relationshipName, relationshipOwner`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PersistentObjectHolder(Persistent relationshipOwner, String relationshipName)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected Object` | `connect(Persistent persistent)` Returns an object that should be stored as a value in this ValueHolder, ensuring that it is registered with the same context.
    `Object` | `getValue()` Returns a value resolving it via a query on the first call to this method.
    `Object` | `getValueDirectly()` Retrieves ValueHolder value without triggering fault resolution.
    `void` | `invalidate()` Turns a ValueHolder into a fault.
    `boolean` | `isFault()` Returns true if this holder is not resolved, meaning its object is not yet known.
    `protected void` | `mergeLocalChanges(List resolved)`
    `protected void` | `resolve()` Reads an object from the database.
    `Object` | `setValue(Object value)` Sets an object value, marking this ValueHolder as resolved.
    `Object` | `setValueDirectly(Object value)` Sets ValueHolder vaue without triggering fault resolution.

    - ### Methods inherited from class org.apache.cayenne.util.RelationshipFault

      `getRelationshipName, getRelationshipOwner, isTransientParent, isUncommittedParent, resolveFromDB, updateReverse`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### fault

          protected boolean fault

    - #### value

          protected Object value

  - ### Constructor Detail

    - #### PersistentObjectHolder

          public PersistentObjectHolder(Persistent relationshipOwner,
                                String relationshipName)

  - ### Method Detail

    - #### isFault

          public boolean isFault()

      Returns true if this holder is not resolved, meaning its object is not yet known.
      Specified by:
        `isFault` in interface `ValueHolder`

    - #### invalidate

          public void invalidate()

      Description copied from interface: `ValueHolder`
      Turns a ValueHolder into a fault.
      Specified by:
        `invalidate` in interface `ValueHolder`

    - #### getValue

          public Object getValue()
                          throws CayenneRuntimeException

      Returns a value resolving it via a query on the first call to this method.
      Specified by:
        `getValue` in interface `ValueHolder`
      Throws:
        `CayenneRuntimeException`

    - #### getValueDirectly

          public Object getValueDirectly()
                                  throws CayenneRuntimeException

      Description copied from interface: `ValueHolder`
      Retrieves ValueHolder value without triggering fault resolution.
      Specified by:
        `getValueDirectly` in interface `ValueHolder`
      Throws:
        `CayenneRuntimeException`

    - #### setValue

          public Object setValue(Object value)
                          throws CayenneRuntimeException

      Sets an object value, marking this ValueHolder as resolved.
      Specified by:
        `setValue` in interface `ValueHolder`
      Parameters:
        `value` - a new value of the ValueHolder.
      Returns:
        a previous value saved in the ValueHolder.
      Throws:
        `CayenneRuntimeException`

    - #### setValueDirectly

          public Object setValueDirectly(Object value)
                                  throws CayenneRuntimeException

      Description copied from interface: `ValueHolder`
      Sets ValueHolder vaue without triggering fault resolution.
      Specified by:
        `setValueDirectly` in interface `ValueHolder`
      Throws:
        `CayenneRuntimeException`

    - #### connect

          protected Object connect(Persistent persistent)

      Returns an object that should be stored as a value in this ValueHolder, ensuring that it is registered with the same context.

    - #### resolve

          protected void resolve()

      Reads an object from the database.

    - #### mergeLocalChanges

          protected void mergeLocalChanges(List resolved)

      Specified by:
        `mergeLocalChanges` in class `RelationshipFault`

Copyright © 2001–2014 Apache Cayenne. All rights reserved.