Package org.apache.cayenne
Interface ObjectContext
- All Superinterfaces:
- DataChannel,- Serializable
- All Known Implementing Classes:
- BaseContext,- DataContext
public interface ObjectContext extends DataChannel, Serializable
A Cayenne object facade to a persistent store. Instances of ObjectContext are
 used in the application code to access Cayenne persistence features.
- Since:
- 1.2
- 
Field SummaryFields inherited from interface org.apache.cayenne.DataChannelFLUSH_CASCADE_SYNC, FLUSH_NOCASCADE_SYNC, GRAPH_CHANGED_SUBJECT, GRAPH_FLUSHED_SUBJECT, GRAPH_ROLLEDBACK_SUBJECT, ROLLBACK_CASCADE_SYNC
- 
Method SummaryModifier and Type Method Description <T> ResultBatchIterator<T>batchIterator(Select<T> query, int size)Creates a ResultBatchIterator based on the provided query and batch size.voidcommitChanges()Flushes all changes to objects in this context to the parent DataChannel, cascading flush operation all the way through the stack, ultimately saving data in the database.voidcommitChangesToParent()Flushes all changes to objects in this context to the parent DataChannel.Collection<?>deletedObjects()Returns a collection of objects that are registered with this ObjectContext and have a state PersistenceState.DELETEDvoiddeleteObject(Object object)Schedules deletion of a persistent object.voiddeleteObjects(Collection<?> objects)Schedules deletion of a collection of persistent objects.<T> voiddeleteObjects(T... objects)Schedules deletion of one or more persistent objects.DataChannelgetChannel()Returns an DataChannel used by this context.EntityResolvergetEntityResolver()Returns EntityResolver that stores all mapping information accessible by this ObjectContext.GraphManagergetGraphManager()Returns GraphManager that manages object graph associated with this context.ObjectgetUserProperty(String key)Returns a user-defined property previously set via 'setUserProperty'.booleanhasChanges()Returnstrueif there are any modified, deleted or new objects registered with this ObjectContext,falseotherwise.voidinvalidateObjects(Collection<?> objects)Invalidates a Collection of persistent objects.<T> voidinvalidateObjects(T... objects)Invalidates one or more persistent objects.<T> voiditerate(Select<T> query, ResultIteratorCallback<T> callback)Creates a ResultIterator based on the provided query and passes it to a callback for processing.<T> ResultIterator<T>iterator(Select<T> query)Creates a ResultIterator based on the provided query.<T extends Persistent>
 TlocalObject(T objectFromAnotherContext)Returns a local copy of 'objectFromAnotherContext' object.Collection<?>modifiedObjects()Returns a collection of objects that are registered with this ObjectContext and have a state PersistenceState.MODIFIED<T> TnewObject(Class<T> persistentClass)Creates a new persistent object of a given class scheduled to be inserted to the database on next commit.Collection<?>newObjects()Returns a collection of objects that are registered with this ObjectContext and have a state PersistenceState.NEWQueryResponseperformGenericQuery(Query query)Executes any kind of query providing the result in a form of QueryResponse.ListperformQuery(Query query)Executes a selecting query, returning a list of persistent objects or data rows.voidprepareForAccess(Persistent object, String property, boolean lazyFaulting)A callback method that child Persistent objects are expected to call before accessing property values.voidpropertyChanged(Persistent object, String property, Object oldValue, Object newValue)A callback method that child Persistent objects are expected to call from inside the setter after modifying a value of a persistent property, including "simple" and "arc" properties.voidregisterNewObject(Object object)Registers a transient object with the context.voidrollbackChanges()Resets all uncommitted changes made to the objects in this ObjectContext, cascading rollback operation all the way through the stack.voidrollbackChangesLocally()Resets all uncommitted changes made to the objects in this ObjectContext.<T> List<T>select(Select<T> query)Executes a selecting query, returning a list of persistent objects or data rows.<T> TselectFirst(Select<T> query)Selects a single object using provided query.<T> TselectOne(Select<T> query)Executes a selecting query, returning either NULL if query matched no objects, or a single object.voidsetUserProperty(String key, Object value)Sets a user-defined property.Collection<?>uncommittedObjects()Returns a collection of MODIFIED, DELETED or NEW objects.Methods inherited from interface org.apache.cayenne.DataChannelgetEventManager, onQuery, onSync
- 
Method Details- 
getEntityResolverEntityResolver getEntityResolver()Returns EntityResolver that stores all mapping information accessible by this ObjectContext.- Specified by:
- getEntityResolverin interface- DataChannel
 
- 
newObjectsCollection<?> newObjects()Returns a collection of objects that are registered with this ObjectContext and have a state PersistenceState.NEW
- 
deletedObjectsCollection<?> deletedObjects()Returns a collection of objects that are registered with this ObjectContext and have a state PersistenceState.DELETED
- 
modifiedObjectsCollection<?> modifiedObjects()Returns a collection of objects that are registered with this ObjectContext and have a state PersistenceState.MODIFIED
- 
uncommittedObjectsCollection<?> uncommittedObjects()Returns a collection of MODIFIED, DELETED or NEW objects.
- 
localObjectReturns a local copy of 'objectFromAnotherContext' object. "Local" means that the returned object is registered in this context. If the local object hasn't been previously cached in this context, a hollow object is created and returned to the caller. No DB query is performed to resolve an object.Note that passing an object with a non-existing id, may later result in FaultFailureException on attempt to read returned object properties. - Since:
- 3.1
 
- 
newObjectCreates a new persistent object of a given class scheduled to be inserted to the database on next commit.
- 
registerNewObjectRegisters a transient object with the context. The difference withnewObject(Class)is that a user creates an object herself, before attaching it to the context, instead of relying on Cayenne to do that.- Parameters:
- object- new object that needs to be made persistent.
- Since:
- 3.0
 
- 
deleteObjectSchedules deletion of a persistent object.- Throws:
- DeleteDenyException- if a- DeleteRule.DENYdelete rule is applicable for object deletion.
 
- 
deleteObjectsSchedules deletion of a collection of persistent objects.- Throws:
- DeleteDenyException- if a- DeleteRule.DENYdelete rule is applicable for object deletion.
 
- 
deleteObjectsSchedules deletion of one or more persistent objects. Same asdeleteObjects(Collection)only with a vararg argument list for easier deletion of individual objects.- Throws:
- DeleteDenyException- if a- DeleteRule.DENYdelete rule is applicable for object deletion.
- Since:
- 3.1
 
- 
prepareForAccessA callback method that child Persistent objects are expected to call before accessing property values. This callback allows ObjectContext to "inflate" unresolved objects on demand and also resolve properties that rely on lazy faulting.- Since:
- 3.0
 
- 
propertyChangedA callback method that child Persistent objects are expected to call from inside the setter after modifying a value of a persistent property, including "simple" and "arc" properties.
- 
commitChangesvoid commitChanges()Flushes all changes to objects in this context to the parent DataChannel, cascading flush operation all the way through the stack, ultimately saving data in the database.
- 
commitChangesToParentvoid commitChangesToParent()Flushes all changes to objects in this context to the parent DataChannel. Same ascommitChanges(), but no cascading flush occurs.
- 
rollbackChangesvoid rollbackChanges()Resets all uncommitted changes made to the objects in this ObjectContext, cascading rollback operation all the way through the stack.
- 
rollbackChangesLocallyvoid rollbackChangesLocally()Resets all uncommitted changes made to the objects in this ObjectContext. Same asrollbackChanges(), but rollback is local to this context and no cascading changes undoing occurs.
- 
performQueryExecutes a selecting query, returning a list of persistent objects or data rows.
- 
selectExecutes a selecting query, returning a list of persistent objects or data rows.- Since:
- 4.0
 
- 
selectOneExecutes a selecting query, returning either NULL if query matched no objects, or a single object. If query matches more than one object,CayenneRuntimeExceptionis thrown.- Since:
- 4.0
 
- 
selectFirstSelects a single object using provided query. The query itself can match any number of objects, but will return only the first one. It returns null if no objects were matched.If it matched more than one object, the first object from the list is returned. This makes 'selectFirst' different from selectOne(Select), which would throw in this situation. 'selectFirst' is useful e.g. when the query is ordered and we only want to see the first object (e.g. "most recent news article"), etc.Selecting the first object via "Select.selectFirst(ObjectContext)" is more comprehensible than selecting via "ObjectContext.selectFirst(Select)", because implementations of "Select" set fetch size limit to one. - Since:
- 4.0
 
- 
iterateCreates a ResultIterator based on the provided query and passes it to a callback for processing. The caller does not need to worry about closing the iterator. This method takes care of it.- Since:
- 4.0
 
- 
iteratorCreates a ResultIterator based on the provided query. It is usually backed by an open result set and is useful for processing of large data sets, preserving a constant memory footprint. The caller must wrap iteration in try/finally (or try-with-resources for Java 1.7 and higher) and close the ResultIterator explicitly. Or useiterate(Select, ResultIteratorCallback)as an alternative.- Since:
- 4.0
 
- 
batchIteratorCreates a ResultBatchIterator based on the provided query and batch size. It is usually backed by an open result set and is useful for processing of large data sets, preserving a constant memory footprint. The caller must wrap iteration in try/finally (or try-with-resources for Java 1.7 and higher) and close the ResultBatchIterator explicitly.- Since:
- 4.0
 
- 
performGenericQueryExecutes any kind of query providing the result in a form of QueryResponse.
- 
getGraphManagerGraphManager getGraphManager()Returns GraphManager that manages object graph associated with this context.
- 
getChannelDataChannel getChannel()Returns an DataChannel used by this context.
- 
hasChangesboolean hasChanges()Returnstrueif there are any modified, deleted or new objects registered with this ObjectContext,falseotherwise.- Since:
- 3.0
 
- 
invalidateObjectsInvalidates a Collection of persistent objects. This operation only applies to the objects already committed to the database and does nothing to the NEW objects. It would remove each object's snapshot from caches and change object's state to HOLLOW. On the next access to this object, the object will be refetched.
- 
invalidateObjects<T> void invalidateObjects(T... objects)Invalidates one or more persistent objects. Same asinvalidateObjects(Collection)only with a vararg argument list for easier invalidation of individual objects. If no arguments are passed to this method, it does nothing.- Since:
- 3.1
 
- 
getUserPropertyReturns a user-defined property previously set via 'setUserProperty'. Concurrent access to properties does not require any special synchronization- Since:
- 3.0
 
- 
setUserPropertySets a user-defined property. Concurrent access to properties does not require any special synchronization- Since:
- 3.0
 
 
-