PersistentObjectHolder (cayenne-doc: Cayenne Documentation 5.0-M2 API)
Description: declaration: package: org.apache.cayenne.util, class: PersistentObjectHolder

# Class PersistentObjectHolder<E>

java.lang.Object
org.apache.cayenne.util.RelationshipFault<E>
org.apache.cayenne.util.PersistentObjectHolder<E>

All Implemented Interfaces:
  `Serializable, ValueHolder<E>`

public class PersistentObjectHolder<E> extends RelationshipFault<E> implements ValueHolder<E>
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
  Description
  `protected boolean`
  `fault`
  `protected E`
  `value`

  ### Fields inherited from class RelationshipFault

  `relationshipName, relationshipOwner`
  Modifier and Type
  Field
  Description
  `protected String`
  `relationshipName`
  `protected Persistent`
  `relationshipOwner`

- ## Constructor Summary

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

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected void`
  `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.
  `E`
  `getValue()`
  Returns a value resolving it via a query on the first call to this method.
  `E`
  `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.
  `E`
  `setValue(E value)`
  Sets an object value, marking this ValueHolder as resolved.
  `E`
  `setValueDirectly(E value)`
  Sets ValueHolder vaue without triggering fault resolution.

  ### Methods inherited from class RelationshipFault

  `getRelationshipName, getRelationshipOwner, isTransientParent, isUncommittedParent, resolveFromDB, updateReverse`
  Modifier and Type
  Method
  Description
  `String`
  `getRelationshipName()`
  `Persistent`
  `getRelationshipOwner()`
  `protected boolean`
  `isTransientParent()`
  `protected boolean`
  `isUncommittedParent()`
  `protected List<E>`
  `resolveFromDB()`
  Executes a query that returns related objects.
  `protected void`
  `updateReverse(List<E> resolved)`

  ### Methods inherited from class Object

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

- ## Field Details

  - ### fault

    protected boolean fault

  - ### value

    protected E value

- ## Constructor Details

  - ### PersistentObjectHolder

    public PersistentObjectHolder(Persistent relationshipOwner, String relationshipName)

- ## Method Details

  - ### 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<E>`

  - ### invalidate

    public void invalidate()
    Description copied from interface: `ValueHolder`
    Turns a ValueHolder into a fault.
    Specified by:
      `invalidate` in interface `ValueHolder<E>`

  - ### getValue

    public E getValue() throws CayenneRuntimeException
    Returns a value resolving it via a query on the first call to this method.
    Specified by:
      `getValue` in interface `ValueHolder<E>`
    Throws:
      `CayenneRuntimeException`

  - ### getValueDirectly

    public E getValueDirectly() throws CayenneRuntimeException
    Description copied from interface: `ValueHolder`
    Retrieves ValueHolder value without triggering fault resolution.
    Specified by:
      `getValueDirectly` in interface `ValueHolder<E>`
    Throws:
      `CayenneRuntimeException`

  - ### setValue

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

  - ### setValueDirectly

    public E setValueDirectly(E value) throws CayenneRuntimeException
    Description copied from interface: `ValueHolder`
    Sets ValueHolder vaue without triggering fault resolution.
    Specified by:
      `setValueDirectly` in interface `ValueHolder<E>`
    Throws:
      `CayenneRuntimeException`

  - ### connect

    protected void 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<E>`