Class DataContextObjectStore

java.lang.Object
org.apache.cayenne.access.DataContextObjectStore
All Implemented Interfaces:
ObjectStore

public class DataContextObjectStore extends Object implements ObjectStore
The default ObjectStore implementation. Exposes a few locks for the callers to provide concurrency: per-object object lock and broader changes lock used by commits, etc. To prevent deadlocks, the changes lock is always taken before any object lock.
Since:
5.0
  • Field Details

  • Constructor Details

  • Method Details

    • withChangesLock

      public <T> T withChangesLock(Supplier<T> action)
      Runs the action under the lock guarding the uncommitted changes, returning its result. A commit holds the lock for its whole duration, so that no changes are recorded while the ones being committed are read. The lock is reentrant. It is always taken before an object lock, never while holding one.
    • withObjectLock

      public <T> T withObjectLock(ObjectId id, Supplier<T> action)
      Returns the monitor guarding writes to the state of the object with the id: attribute and relationship values, persistence state and snapshot version. Every writer of object state synchronizes on it for the duration of a write, so that concurrent writes do not interleave and other writers never see an object half-written. Readers do not synchronize. A monitor may be shared by several ids, so a writer must not hold more than one at a time, and must not perform blocking operations, such as queries, while holding it.
    • registeredObjectsCount

      public int registeredObjectsCount()
      Returns a number of objects currently registered with this ObjectStore.
    • getDataRowCache

      public DataRowStore getDataRowCache()
      Returns a DataRowStore associated with this ObjectStore.
    • objectsUnregistered

      public void objectsUnregistered(Collection<? extends Persistent> objects)
      Evicts a collection of Persistent objects from the ObjectStore, invalidates the underlying cache snapshots. Changes objects state to TRANSIENT. This method can be used for manual cleanup of Cayenne cache.
    • objectsRolledBack

      public void objectsRolledBack()
      Reverts changes to all stored uncomitted objects.
    • postprocessAfterCommit

      public void postprocessAfterCommit(GraphDiff parentChanges)
      Processes objects state after commit. Normally runs on the committing thread, that already holds the changes lock for the duration of the commit.
    • getCachedSnapshot

      public DataRow getCachedSnapshot(ObjectId oid)
      Returns a snapshot for ObjectId from the underlying snapshot cache, or null if the cache contains no snapshot. Snapshots are keyed by the concrete entity of an object, so an id of a superentity is matched against the ids of its subentities as well. A nested context has no snapshot cache of its own, so it takes the current state of the object in the parent context as the snapshot.
      Specified by:
      getCachedSnapshot in interface ObjectStore
    • getSnapshot

      public DataRow getSnapshot(ObjectId oid)
      Returns a snapshot for ObjectId from the underlying snapshot cache. If the cache contains no snapshot, it is fetched from the database. Returns null if no matching row exists.
      Specified by:
      getSnapshot in interface ObjectStore
      Since:
      1.2
    • getObjectIterator

      public Iterator<Persistent> getObjectIterator()
      Returns an iterator over the registered objects.
    • hasChanges

      public boolean hasChanges()
      Returns true if there are any modified, deleted or new objects registered with this ObjectStore, false otherwise. This method will treat "phantom" modifications are real ones. I.e. if you "change" an object property to an equivalent value, this method will still think such object is modified. Phantom modifications are only detected and discarded during commit.
      Specified by:
      hasChanges in interface ObjectStore
    • objectsInState

      public List<Persistent> objectsInState(int state)
      Return a subset of registered objects that are in a certain persistence state. Collection is returned by copy.
      Specified by:
      objectsInState in interface ObjectStore
    • getObject

      public Persistent getObject(ObjectId id)
      Description copied from interface: ObjectStore
      Returns a registered object for the id, or null if no such object is registered.
      Specified by:
      getObject in interface ObjectStore
    • registeredObjects

      public Collection<Persistent> registeredObjects()
      Description copied from interface: ObjectStore
      Returns a copy of the collection of all registered objects.
      Specified by:
      registeredObjects in interface ObjectStore
    • registerObject

      public void registerObject(ObjectId id, Persistent nodeObject)
      Description copied from interface: ObjectStore
      Registers an object under the id.
      Specified by:
      registerObject in interface ObjectStore
    • unregisterObject

      public Persistent unregisterObject(ObjectId id)
      Description copied from interface: ObjectStore
      Unregisters an object with the id, forgetting any information associated with it. Returns the unregistered object, or null if none was registered.
      Specified by:
      unregisterObject in interface ObjectStore
    • getFlattenedId

      public ObjectId getFlattenedId(ObjectId objectId, CayennePath path)
    • getFlattenedIds

      public Collection<ObjectId> getFlattenedIds(ObjectId objectId)
    • getFlattenedPathIdMap

      public Map<CayennePath, ObjectId> getFlattenedPathIdMap(ObjectId objectId)
    • markFlattenedPath

      public void markFlattenedPath(ObjectId objectId, CayennePath path, ObjectId id)
      Mark that flattened path for object has data row in DB.
      Since:
      4.1