Class ObjectStore

    • Field Detail

      • trackedFlattenedPaths

        protected Map<Object,​Map<String,​ObjectId>> trackedFlattenedPaths
        Map that tracks flattened paths for given object Id that is present in db. Presence of path in this map is used to separate insert from update case of flattened records.
        Since:
        4.1
      • dataRowCache

        protected transient DataRowStore dataRowCache
        Stores a reference to the DataRowStore.

        Serialization note: It is up to the owner of this ObjectStore to initialize DataRowStore after deserialization of this object. ObjectStore will not know how to restore the DataRowStore by itself.

      • dataRowCacheSet

        protected boolean dataRowCacheSet
      • context

        protected DataContext context
        The DataContext that owns this ObjectStore.
    • Constructor Detail

      • ObjectStore

        public ObjectStore​(DataRowStore dataRowCache,
                           Map<Object,​Persistent> objectMap)
        Creates an ObjectStore with DataRowStore and a map to use for storing registered objects. Passed map doesn't require any special synchronization behavior, as ObjectStore is synchronized itself.
        Since:
        3.0
    • Method Detail

      • registeredObjectsCount

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

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

        public void setDataRowCache​(DataRowStore dataRowCache)
        Sets parent DataRowStore. Registers to receive SnapshotEvents if the cache is configured to allow ObjectStores to receive such events.
      • objectsUnregistered

        public void objectsUnregistered​(Collection objects)
        Evicts a collection of DataObjects 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.
        Since:
        1.1
      • postprocessAfterCommit

        public void postprocessAfterCommit​(GraphDiff parentChanges)
        Internal unsynchronized method to process objects state after commit.
        Since:
        1.2
      • getCachedSnapshot

        public DataRow getCachedSnapshot​(ObjectId oid)
        Returns a snapshot for ObjectId from the underlying snapshot cache. If cache contains no snapshot, a null is returned.
        Since:
        1.1
      • getSnapshot

        public DataRow getSnapshot​(ObjectId oid)
        Returns a snapshot for ObjectId from the underlying snapshot cache. If cache contains no snapshot, it will attempt fetching it using provided QueryEngine. If fetch attempt fails or inconsistent data is returned, underlying cache will throw a CayenneRuntimeException.
        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.
      • 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.
      • snapshotsChanged

        public void snapshotsChanged​(SnapshotEvent event)
        SnapshotEventListener implementation that processes snapshot change event, updating DataObjects that have the changes.

        Implementation note: This method should not attempt to alter the underlying DataRowStore, since it is normally invoked *AFTER* the DataRowStore was modified as a result of some external interaction.

        Specified by:
        snapshotsChanged in interface SnapshotEventListener
        Since:
        1.1
      • getContext

        public DataContext getContext()
        Since:
        1.2
      • setContext

        public void setContext​(DataContext context)
        Since:
        1.2
      • getNode

        public Object getNode​(Object nodeId)
        Returns a registered DataObject or null of no object exists for the ObjectId.
        Specified by:
        getNode in interface GraphManager
        Since:
        1.2
      • registeredNodes

        public Collection<Object> registeredNodes()
        Returns all registered DataObjects. List is returned by copy and can be modified by the caller.
        Specified by:
        registeredNodes in interface GraphManager
        Since:
        1.2
      • registerNode

        public void registerNode​(Object nodeId,
                                 Object nodeObject)
        Description copied from interface: GraphManager
        "Registers" a graph node, usually storing the node in some internal map using its id as a key.
        Specified by:
        registerNode in interface GraphManager
        Since:
        1.2
      • unregisterNode

        public Object unregisterNode​(Object nodeId)
        Description copied from interface: GraphManager
        "Unregisters" a graph node, forgetting any information associated with nodeId.
        Specified by:
        unregisterNode in interface GraphManager
        Since:
        1.2
      • markFlattenedPath

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