Package org.apache.cayenne.access
Class ObjectStore
java.lang.Object
org.apache.cayenne.access.ObjectStore
- All Implemented Interfaces:
Serializable,EventListener,SnapshotEventListener,GraphChangeHandler,GraphManager
- Direct Known Subclasses:
NoSyncObjectStore
public class ObjectStore
extends Object
implements Serializable, SnapshotEventListener, GraphManager
ObjectStore stores objects using their ObjectId as a key. It works as a dedicated
object cache for a DataContext. Users rarely need to access ObjectStore directly, as
DataContext serves as a facade, providing cover methods for most ObjectStore
operations.
- Since:
- 1.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Map<Object, ObjectDiff> protected DataContextThe DataContext that owns this ObjectStore.protected DataRowStoreStores a reference to the DataRowStore.protected booleanprotected Map<Object, Persistent> Map that tracks flattened paths for given object Id that is present in db. -
Constructor Summary
ConstructorsConstructorDescriptionObjectStore(DataRowStore dataRowCache, Map<Object, Persistent> objectMap) Creates an ObjectStore withDataRowStoreand a map to use for storing registered objects. -
Method Summary
Modifier and TypeMethodDescriptionvoidarcCreated(Object nodeId, Object targetNodeId, ArcId arcId) Notifies implementing object that a new arc was created between two nodes.voidarcDeleted(Object nodeId, Object targetNodeId, ArcId arcId) Notifies implementing object that an arc between two nodes was deleted.Returns a snapshot for ObjectId from the underlying snapshot cache.Returns a DataRowStore associated with this ObjectStore.getFlattenedId(ObjectId objectId, String path) getFlattenedIds(ObjectId objectId) getFlattenedPathIdMap(ObjectId objectId) Returns a registered DataObject or null of no object exists for the ObjectId.Returns an iterator over the registered objects.getSnapshot(ObjectId oid) Returns a snapshot for ObjectId from the underlying snapshot cache.booleanReturnstrueif there are any modified, deleted or new objects registered with this ObjectStore,falseotherwise.voidmarkFlattenedPath(ObjectId objectId, String path, ObjectId id) Mark that flattened path for object has data row in DB.voidnodeCreated(Object nodeId) Notifies implementing object that a new node was created in the graph.voidnodeIdChanged(Object nodeId, Object newId) Does nothing.voidnodePropertyChanged(Object nodeId, String property, Object oldValue, Object newValue) Records dirty object snapshot.voidnodeRemoved(Object nodeId) Notifies implementing object that a node was removed from the graph.objectsInState(int state) Return a subset of registered objects that are in a certain persistence state.voidReverts changes to all stored uncomitted objects.voidobjectsUnregistered(Collection objects) Evicts a collection of DataObjects from the ObjectStore, invalidates the underlying cache snapshots.voidpostprocessAfterCommit(GraphDiff parentChanges) Internal unsynchronized method to process objects state after commit.Returns all registered DataObjects.intReturns a number of objects currently registered with this ObjectStore.voidregisterNode(Object nodeId, Object nodeObject) "Registers" a graph node, usually storing the node in some internal map using its id as a key.voidsetContext(DataContext context) voidsetDataRowCache(DataRowStore dataRowCache) Sets parent DataRowStore.voidsnapshotsChanged(SnapshotEvent event) SnapshotEventListener implementation that processes snapshot change event, updating DataObjects that have the changes.unregisterNode(Object nodeId) "Unregisters" a graph node, forgetting any information associated with nodeId.
-
Field Details
-
objectMap
-
changes
-
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
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
The DataContext that owns this ObjectStore.
-
-
Constructor Details
-
ObjectStore
Creates an ObjectStore withDataRowStoreand 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 Details
-
registeredObjectsCount
public int registeredObjectsCount()Returns a number of objects currently registered with this ObjectStore.- Since:
- 1.2
-
getDataRowCache
Returns a DataRowStore associated with this ObjectStore. -
setDataRowCache
Sets parent DataRowStore. Registers to receive SnapshotEvents if the cache is configured to allow ObjectStores to receive such events. -
objectsUnregistered
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
Internal unsynchronized method to process objects state after commit.- Since:
- 1.2
-
getCachedSnapshot
Returns a snapshot for ObjectId from the underlying snapshot cache. If cache contains no snapshot, a null is returned.- Since:
- 1.1
-
getSnapshot
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
Returns an iterator over the registered objects. -
hasChanges
public boolean hasChanges()Returnstrueif there are any modified, deleted or new objects registered with this ObjectStore,falseotherwise. 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
Return a subset of registered objects that are in a certain persistence state. Collection is returned by copy. -
snapshotsChanged
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:
snapshotsChangedin interfaceSnapshotEventListener- Since:
- 1.1
-
getContext
- Since:
- 1.2
-
setContext
- Since:
- 1.2
-
getNode
Returns a registered DataObject or null of no object exists for the ObjectId.- Specified by:
getNodein interfaceGraphManager- Since:
- 1.2
-
registeredNodes
Returns all registered DataObjects. List is returned by copy and can be modified by the caller.- Specified by:
registeredNodesin interfaceGraphManager- Since:
- 1.2
-
registerNode
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:
registerNodein interfaceGraphManager- Since:
- 1.2
-
unregisterNode
Description copied from interface:GraphManager"Unregisters" a graph node, forgetting any information associated with nodeId.- Specified by:
unregisterNodein interfaceGraphManager- Since:
- 1.2
-
nodeIdChanged
Does nothing.- Specified by:
nodeIdChangedin interfaceGraphChangeHandler- Since:
- 1.2
-
nodeCreated
Description copied from interface:GraphChangeHandlerNotifies implementing object that a new node was created in the graph.- Specified by:
nodeCreatedin interfaceGraphChangeHandler- Since:
- 1.2
-
nodeRemoved
Description copied from interface:GraphChangeHandlerNotifies implementing object that a node was removed from the graph.- Specified by:
nodeRemovedin interfaceGraphChangeHandler- Since:
- 1.2
-
nodePropertyChanged
Records dirty object snapshot.- Specified by:
nodePropertyChangedin interfaceGraphChangeHandler- Since:
- 1.2
-
arcCreated
Description copied from interface:GraphChangeHandlerNotifies implementing object that a new arc was created between two nodes.- Specified by:
arcCreatedin interfaceGraphChangeHandler- Since:
- 1.2
-
arcDeleted
Description copied from interface:GraphChangeHandlerNotifies implementing object that an arc between two nodes was deleted.- Specified by:
arcDeletedin interfaceGraphChangeHandler- Since:
- 1.2
-
getFlattenedId
- Since:
- 4.2
-
getFlattenedIds
- Since:
- 4.2
-
getFlattenedPathIdMap
- Since:
- 4.2.1
-
markFlattenedPath
Mark that flattened path for object has data row in DB.- Since:
- 4.1
-