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:
- Serialized Form
- 
Field SummaryFields Modifier and Type Field Description protected Map<Object,org.apache.cayenne.access.ObjectDiff>changesprotected DataContextcontextThe DataContext that owns this ObjectStore.protected DataRowStoredataRowCacheStores a reference to the DataRowStore.protected booleandataRowCacheSetprotected Map<Object,Persistent>objectMapprotected Map<Object,Set<String>>trackedFlattenedPathsMap that tracks flattened paths for given object Id that is present in db.
- 
Constructor SummaryConstructors Constructor Description ObjectStore(DataRowStore dataRowCache, Map<Object,Persistent> objectMap)Creates an ObjectStore withDataRowStoreand a map to use for storing registered objects.
- 
Method SummaryModifier and Type Method Description voidarcCreated(Object nodeId, Object targetNodeId, Object arcId)Notifies implementing object that a new arc was created between two nodes.voidarcDeleted(Object nodeId, Object targetNodeId, Object arcId)Notifies implementing object that an arc between two nodes was deleted.DataRowgetCachedSnapshot(ObjectId oid)Returns a snapshot for ObjectId from the underlying snapshot cache.DataContextgetContext()DataRowStoregetDataRowCache()Returns a DataRowStore associated with this ObjectStore.ObjectgetNode(Object nodeId)Returns a registered DataObject or null of no object exists for the ObjectId.Iterator<Persistent>getObjectIterator()Returns an iterator over the registered objects.DataRowgetSnapshot(ObjectId oid)Returns a snapshot for ObjectId from the underlying snapshot cache.booleanhasChanges()Returnstrueif there are any modified, deleted or new objects registered with this ObjectStore,falseotherwise.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.List<Persistent>objectsInState(int state)Return a subset of registered objects that are in a certain persistence state.voidobjectsRolledBack()Reverts changes to all stored uncomitted objects.voidobjectsUnregistered(Collection objects)Evicts a collection of DataObjects from the ObjectStore, invalidates the underlying cache snapshots.Collection<Object>registeredNodes()Returns all registered DataObjects.intregisteredObjectsCount()Returns 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.ObjectunregisterNode(Object nodeId)"Unregisters" a graph node, forgetting any information associated with nodeId.
- 
Field Details- 
objectMap
- 
changes
- 
trackedFlattenedPathsMap 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
 
- 
dataRowCacheStores 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. 
- 
dataRowCacheSetprotected boolean dataRowCacheSet
- 
contextThe DataContext that owns this ObjectStore.
 
- 
- 
Constructor Details- 
ObjectStoreCreates 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- 
registeredObjectsCountpublic int registeredObjectsCount()Returns a number of objects currently registered with this ObjectStore.- Since:
- 1.2
 
- 
getDataRowCacheReturns a DataRowStore associated with this ObjectStore.
- 
setDataRowCacheSets parent DataRowStore. Registers to receive SnapshotEvents if the cache is configured to allow ObjectStores to receive such events.
- 
objectsUnregisteredEvicts 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.
- 
objectsRolledBackpublic void objectsRolledBack()Reverts changes to all stored uncomitted objects.- Since:
- 1.1
 
- 
getCachedSnapshotReturns a snapshot for ObjectId from the underlying snapshot cache. If cache contains no snapshot, a null is returned.- Since:
- 1.1
 
- 
getSnapshotReturns 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
 
- 
getObjectIteratorReturns an iterator over the registered objects.
- 
hasChangespublic 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.
- 
objectsInStateReturn a subset of registered objects that are in a certain persistence state. Collection is returned by copy.
- 
snapshotsChangedSnapshotEventListener 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 interface- SnapshotEventListener
- Since:
- 1.1
 
- 
getContext- Since:
- 1.2
 
- 
setContext- Since:
- 1.2
 
- 
getNodeReturns a registered DataObject or null of no object exists for the ObjectId.- Specified by:
- getNodein interface- GraphManager
- Since:
- 1.2
 
- 
registeredNodesReturns all registered DataObjects. List is returned by copy and can be modified by the caller.- Specified by:
- registeredNodesin interface- GraphManager
- Since:
- 1.2
 
- 
registerNodeDescription 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 interface- GraphManager
- Since:
- 1.2
 
- 
unregisterNodeDescription copied from interface:GraphManager"Unregisters" a graph node, forgetting any information associated with nodeId.- Specified by:
- unregisterNodein interface- GraphManager
- Since:
- 1.2
 
- 
nodeIdChangedDoes nothing.- Specified by:
- nodeIdChangedin interface- GraphChangeHandler
- Since:
- 1.2
 
- 
nodeCreatedDescription copied from interface:GraphChangeHandlerNotifies implementing object that a new node was created in the graph.- Specified by:
- nodeCreatedin interface- GraphChangeHandler
- Since:
- 1.2
 
- 
nodeRemovedDescription copied from interface:GraphChangeHandlerNotifies implementing object that a node was removed from the graph.- Specified by:
- nodeRemovedin interface- GraphChangeHandler
- Since:
- 1.2
 
- 
nodePropertyChangedRecords dirty object snapshot.- Specified by:
- nodePropertyChangedin interface- GraphChangeHandler
- Since:
- 1.2
 
- 
arcCreatedDescription copied from interface:GraphChangeHandlerNotifies implementing object that a new arc was created between two nodes.- Specified by:
- arcCreatedin interface- GraphChangeHandler
- Since:
- 1.2
 
- 
arcDeletedDescription copied from interface:GraphChangeHandlerNotifies implementing object that an arc between two nodes was deleted.- Specified by:
- arcDeletedin interface- GraphChangeHandler
- Since:
- 1.2
 
 
-