Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.objectstyle.cayenne.access
Class ObjectStore

    java.lang.Object
      org.objectstyle.cayenne.access.ObjectStore

All Implemented Interfaces:
  java.io.Serializable, java.util.EventListener, SnapshotEventListener, GraphChangeHandler, GraphManager

    public class ObjectStore

extends java.lang.Object
implements java.io.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
Author:
  Andrus Adamchik
See Also:
  Serialized Form

Field Summary
`protected java.util.Map` | `changes`
`protected DataContext` | `context` The DataContext that owns this ObjectStore.
`protected DataRowStore` | `dataRowCache` Stores a reference to the DataRowStore.
`protected java.util.Map` | `newObjectsMap`
`protected java.util.Map` | `objectMap`
`protected java.util.Map` | `queryResultMap`

Constructor Summary
`ObjectStore()`
`ObjectStore(DataRowStore dataRowCache)`

Method Summary
`void` | `addObject(DataObject object)` Deprecated. since 1.2 as a different change tracking algorithm is used.
`void` | `arcCreated(java.lang.Object nodeId, java.lang.Object targetNodeId, java.lang.Object arcId)` Does nothing.
`void` | `arcDeleted(java.lang.Object nodeId, java.lang.Object targetNodeId, java.lang.Object arcId)` Does nothing.
`int` | `cachedQueriesCount()` Returns a number of query results cached by this object store.
`void` | `cacheQueryResult(java.lang.String name, java.util.List results)` Caches a list of query results.
`java.util.List` | `getCachedQueryResult(java.lang.String name)` Returns cached query results for a given query, or null if no results are cached.
`DataRow` | `getCachedSnapshot(ObjectId oid)` Returns a snapshot for ObjectId from the underlying snapshot cache.
`DataContext` | `getContext()`
`DataRowStore` | `getDataRowCache()` Returns a DataRowStore associated with this ObjectStore.
`java.lang.Object` | `getNode(java.lang.Object nodeId)` Returns a registered DataObject or null of no object exists for the ObjectId.
`DataObject` | `getObject(ObjectId id)` Deprecated. since 1.2 a GraphManager `getNode(Object)` method should be used.
`java.util.Iterator` | `getObjectIterator()` Returns an iterator over the registered objects.
`java.util.List` | `getObjects()` Deprecated. since 1.2 use GraphManager method `registeredNodes()`.
`DataRow` | `getSnapshot(ObjectId oid)` Returns a snapshot for ObjectId from the underlying snapshot cache.
`DataRow` | `getSnapshot(ObjectId oid, QueryEngine engine)` Deprecated. since 1.2. Use `getSnapshot(ObjectId)` instead.
`void` | `graphCommitAborted()` Does nothing.
`void` | `graphCommitStarted()` Does nothing.
`void` | `graphCommitted()` Does nothing.
`void` | `graphRolledback()` Does nothing.
`boolean` | `hasChanges()` Returns `true` if there are any modified, deleted or new objects registered with this ObjectStore, `false` otherwise.
`void` | `nodeCreated(java.lang.Object nodeId)` Does nothing.
`void` | `nodeIdChanged(java.lang.Object nodeId, java.lang.Object newId)` Does nothing.
`void` | `nodePropertyChanged(java.lang.Object nodeId, java.lang.String property, java.lang.Object oldValue, java.lang.Object newValue)` Does nothing.
`void` | `nodeRemoved(java.lang.Object nodeId)` Does nothing.
`void` | `objectRelationshipSet(DataObject source, DataObject target, ObjRelationship relationship, boolean processFlattened)` Deprecated. since 1.2 use `recordArcCreated(Persistent, ObjectId, String)`.
`void` | `objectRelationshipUnset(DataObject source, DataObject target, ObjRelationship relationship, boolean processFlattened)` Deprecated. since 1.2 use `recordArcDeleted(Persistent, ObjectId, String)`.
`void` | `objectsCommitted()` Deprecated. since 1.2 unused.
`java.util.List` | `objectsInState(int state)` Return a subset of registered objects that are in a certian persistence state.
`void` | `objectsInvalidated(java.util.Collection objects)` Invalidates a collection of DataObjects.
`void` | `objectsRolledBack()` Reverts changes to all stored uncomitted objects.
`void` | `objectsUnregistered(java.util.Collection objects)` Evicts a collection of DataObjects from the ObjectStore, invalidates the underlying cache snapshots.
`void` | `recordArcCreated(Persistent object, ObjectId targetId, java.lang.String relationshipName)` Performs tracking of object relationship changes.
`void` | `recordArcDeleted(Persistent object, ObjectId targetId, java.lang.String relationshipName)` Performs tracking of object relationship changes.
`java.util.Collection` | `registeredNodes()` Returns all registered DataObjects.
`int` | `registeredObjectsCount()` Returns a number of objects currently registered with this ObjectStore.
`void` | `registerNode(java.lang.Object nodeId, java.lang.Object nodeObject)` "Registers" a graph node, usually striong the node in some internal map using its id as a key.
`void` | `resolveHollow(DataObject object)` Initializes object with data from cache or from the database, if this object is not fully resolved.
`void` | `setContext(DataContext context)`
`void` | `setDataRowCache(DataRowStore dataRowCache)` Sets parent DataRowStore.
`void` | `snapshotsChanged(SnapshotEvent event)` SnapshotEventListener implementation that processes snapshot change event, updating DataObjects that have the changes.
`void` | `snapshotsUpdatedForObjects(java.util.List objects, java.util.List snapshots, boolean refresh)` Updates snapshots in the underlying DataRowStore.
`void` | `startTrackingNewObjects()` Starts tracking the registration of new objects from this ObjectStore.
`void` | `unregisterNewObjects()` Unregisters the newly registered DataObjects from this objectStore.
`java.lang.Object` | `unregisterNode(java.lang.Object nodeId)` "Unregisters" a graph node, forgetting any information associated with nodeId.
`void` | `validateUncommittedObjects()` Deprecated. since 1.2 - This method is no longer used in Cayenne internally.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### newObjectsMap

    protected transient java.util.Map newObjectsMap

### objectMap

    protected java.util.Map objectMap

### queryResultMap

    protected java.util.Map queryResultMap

### changes

    protected java.util.Map changes

### 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.

### context

    protected DataContext context

  The DataContext that owns this ObjectStore.

Constructor Detail

### ObjectStore

    public ObjectStore()

### ObjectStore

    public ObjectStore(DataRowStore dataRowCache)

Method Detail

### recordArcCreated

    public void recordArcCreated(Persistent object,
                                 ObjectId targetId,
                                 java.lang.String relationshipName)

  Performs tracking of object relationship changes.

  Since:
    1.2

### recordArcDeleted

    public void recordArcDeleted(Persistent object,
                                 ObjectId targetId,
                                 java.lang.String relationshipName)

  Performs tracking of object relationship changes.

  Since:
    1.2

### registeredObjectsCount

    public int registeredObjectsCount()

  Returns a number of objects currently registered with this ObjectStore.

  Since:
    1.2

### cachedQueriesCount

    public int cachedQueriesCount()

  Returns a number of query results cached by this object store. Note that each result is a list and can possibly contain a large number of entries.

  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.

### objectsInvalidated

    public void objectsInvalidated(java.util.Collection objects)

  Invalidates a collection of DataObjects. Changes objects state to HOLLOW.

  See Also:
    `objectsUnregistered(Collection)`

### objectsUnregistered

    public void objectsUnregistered(java.util.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.

  See Also:
    `objectsInvalidated(Collection)`

### objectsRolledBack

    public void objectsRolledBack()

  Reverts changes to all stored uncomitted objects.

  Since:
    1.1

### objectRelationshipUnset

    public void objectRelationshipUnset(DataObject source,
                                        DataObject target,
                                        ObjRelationship relationship,
                                        boolean processFlattened)

  Deprecated. since 1.2 use `recordArcDeleted(Persistent, ObjectId, String)`.

  Performs tracking of object relationship changes.

  Since:
    1.1

### objectRelationshipSet

    public void objectRelationshipSet(DataObject source,
                                      DataObject target,
                                      ObjRelationship relationship,
                                      boolean processFlattened)

  Deprecated. since 1.2 use `recordArcCreated(Persistent, ObjectId, String)`.

  Performs tracking of object relationship changes.

  Since:
    1.1

### snapshotsUpdatedForObjects

    public void snapshotsUpdatedForObjects(java.util.List objects,
                                           java.util.List snapshots,
                                           boolean refresh)

  Updates snapshots in the underlying DataRowStore. If `refresh` is true, all snapshots in `snapshots` will be loaded into DataRowStore, regardless of the existing cache state. If `refresh` is false, only missing snapshots are loaded. This method is normally called internally by the DataContext owning the ObjectStore to update the caches after a select query.

  Parameters:
    `objects` - a list of object whose snapshots need to be updated.
    `snapshots` - a list of snapshots. Must be of the same length and use the same order as `objects` list.
    `refresh` - controls whether existing cached snapshots should be replaced with the new ones.
  Since:
    1.1

### objectsCommitted

    public void objectsCommitted()

  Deprecated. since 1.2 unused.

  Processes internal objects after the parent DataContext was committed. Changes object persistence state and handles snapshot updates.

  Since:
    1.1

### addObject

    public void addObject(DataObject object)

  Deprecated. since 1.2 as a different change tracking algorithm is used.

  Adds a new object to the ObjectStore.

### startTrackingNewObjects

    public void startTrackingNewObjects()

  Starts tracking the registration of new objects from this ObjectStore. Used in conjunction with unregisterNewObjects() to control garbage collection when an instance of ObjectStore is used over a longer time for batch processing.

  See Also:
    `unregisterNewObjects()`

### unregisterNewObjects

    public void unregisterNewObjects()

  Unregisters the newly registered DataObjects from this objectStore. Used in conjunction with startTrackingNewObjects() to control garbage collection when an instance of ObjectStore is used over a longer time for batch processing.

  See Also:
    `startTrackingNewObjects()`

### getObject

    public DataObject getObject(ObjectId id)

  Deprecated. since 1.2 a GraphManager `getNode(Object)` method should be used.

  Returns a DataObject registered for a given ObjectId, or null if no such object exists. This method does not do a database fetch.

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

### getCachedQueryResult

    public java.util.List getCachedQueryResult(java.lang.String name)

  Returns cached query results for a given query, or null if no results are cached. Note that ObjectStore will only lookup results in its local cache, and not the shared cache associated with the underlying DataRowStore.

  Since:
    1.1

### cacheQueryResult

    public void cacheQueryResult(java.lang.String name,
                                 java.util.List results)

  Caches a list of query results.

  Since:
    1.1

### getSnapshot

    public DataRow getSnapshot(ObjectId oid,
                               QueryEngine engine)

  Deprecated. since 1.2. Use `getSnapshot(ObjectId)` instead.

  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.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

### getObjects

    public java.util.List getObjects()

  Deprecated. since 1.2 use GraphManager method `registeredNodes()`.

  Returns a list of objects that are registered with this DataContext, regardless of their persistence state. List is returned by copy and can be modified by the caller.

### getObjectIterator

    public java.util.Iterator 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 java.util.List objectsInState(int state)

  Return a subset of registered objects that are in a certian 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

### validateUncommittedObjects

    public void validateUncommittedObjects()
                                    throws ValidationException

  Deprecated. since 1.2 - This method is no longer used in Cayenne internally.

  Performs validation of all uncommitted objects in the ObjectStore. If validation fails, a ValidationException is thrown, listing all encountered failures. This is a utility method for the users to call. Cayenne itself uses a different mechanism to validate objects on commit.

  Throws:
    `ValidationException`
  Since:
    1.1

### resolveHollow

    public void resolveHollow(DataObject object)

  Initializes object with data from cache or from the database, if this object is not fully resolved.

  Since:
    1.1

### getContext

    public DataContext getContext()

  Since:
    1.2

### setContext

    public void setContext(DataContext context)

  Since:
    1.2

### getNode

    public java.lang.Object getNode(java.lang.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 java.util.Collection 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(java.lang.Object nodeId,
                             java.lang.Object nodeObject)

  Description copied from interface: `GraphManager`
  "Registers" a graph node, usually striong the node in some internal map using its id as a key.

  Specified by:
    `registerNode` in interface `GraphManager`
  Since:
    1.2

### unregisterNode

    public java.lang.Object unregisterNode(java.lang.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

### graphCommitAborted

    public void graphCommitAborted()

  Does nothing.

  Since:
    1.2

### graphCommitStarted

    public void graphCommitStarted()

  Does nothing.

  Since:
    1.2

### graphCommitted

    public void graphCommitted()

  Does nothing.

  Since:
    1.2

### graphRolledback

    public void graphRolledback()

  Does nothing.

  Since:
    1.2

### nodeIdChanged

    public void nodeIdChanged(java.lang.Object nodeId,
                              java.lang.Object newId)

  Does nothing.

  Specified by:
    `nodeIdChanged` in interface `GraphChangeHandler`
  Since:
    1.2

### nodeCreated

    public void nodeCreated(java.lang.Object nodeId)

  Does nothing.

  Specified by:
    `nodeCreated` in interface `GraphChangeHandler`
  Since:
    1.2

### nodeRemoved

    public void nodeRemoved(java.lang.Object nodeId)

  Does nothing.

  Specified by:
    `nodeRemoved` in interface `GraphChangeHandler`
  Since:
    1.2

### nodePropertyChanged

    public void nodePropertyChanged(java.lang.Object nodeId,
                                    java.lang.String property,
                                    java.lang.Object oldValue,
                                    java.lang.Object newValue)

  Does nothing.

  Specified by:
    `nodePropertyChanged` in interface `GraphChangeHandler`
  Since:
    1.2

### arcCreated

    public void arcCreated(java.lang.Object nodeId,
                           java.lang.Object targetNodeId,
                           java.lang.Object arcId)

  Does nothing.

  Specified by:
    `arcCreated` in interface `GraphChangeHandler`
  Since:
    1.2

### arcDeleted

    public void arcDeleted(java.lang.Object nodeId,
                           java.lang.Object targetNodeId,
                           java.lang.Object arcId)

  Does nothing.

  Specified by:
    `arcDeleted` in interface `GraphChangeHandler`
  Since:
    1.2

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2006 ObjectStyle.org All Rights Reserved.