|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.cayenne.BaseContext
org.apache.cayenne.access.DataContext
public class DataContext
The most common implementation of ObjectContext. DataContext is an isolated
container of an object graph, in a sense that any uncommitted changes to persistent
objects that are registered with the context, are not visible to the users of other
contexts.
| Field Summary | |
|---|---|
protected org.apache.cayenne.access.DataContextMergeHandler |
mergeHandler
|
protected ObjectStore |
objectStore
|
protected boolean |
usingSharedSnaphsotCache
|
protected boolean |
validatingObjectsOnCommit
|
| Fields inherited from class org.apache.cayenne.BaseContext |
|---|
channel, entityResolver, graphAction, queryCache, threadObjectContext, userProperties |
| Fields inherited from interface org.apache.cayenne.DataChannel |
|---|
FLUSH_CASCADE_SYNC, FLUSH_NOCASCADE_SYNC, GRAPH_CHANGED_SUBJECT, GRAPH_FLUSHED_SUBJECT, GRAPH_ROLLEDBACK_SUBJECT, ROLLBACK_CASCADE_SYNC |
| Constructor Summary | |
|---|---|
DataContext()
Creates a new DataContext that is not attached to the Cayenne stack. |
|
DataContext(DataChannel channel,
ObjectStore objectStore)
Creates a new DataContext with parent DataChannel and ObjectStore. |
|
| Method Summary | ||
|---|---|---|
protected void |
attachToChannel(DataChannel channel)
Attaches to a provided DataChannel. |
|
void |
commitChanges()
Synchronizes object graph with the database. |
|
void |
commitChangesToParent()
"Flushes" the changes to the parent DataChannel. |
|
ObjectContext |
createChildContext()
Deprecated. Since 3.1 replaced by DataContextFactory.createContext(DataChannel) |
|
DataRow |
currentSnapshot(Persistent object)
Returns a DataRow reflecting current, possibly uncommitted, object state. |
|
java.util.Collection<?> |
deletedObjects()
Returns a list of objects that are registered with this DataContext and have a state PersistenceState.DELETED |
|
protected void |
fireDataChannelChanged(java.lang.Object postedBy,
GraphDiff changes)
|
|
DataContextDelegate |
getDelegate()
Returns a delegate currently associated with this DataContext. |
|
GraphManager |
getGraphManager()
Returns this context's ObjectStore. |
|
ObjectStore |
getObjectStore()
Returns ObjectStore associated with this DataContext. |
|
DataDomain |
getParentDataDomain()
Returns a DataDomain used by this DataContext. |
|
boolean |
hasChanges()
Returns true if there are any modified, deleted or new objects
registered with this DataContext, false otherwise. |
|
boolean |
isUsingSharedSnapshotCache()
Returns true if the ObjectStore uses shared cache of a parent
DataDomain. |
|
boolean |
isValidatingObjectsOnCommit()
Returns whether this DataContext performs object validation before commit is executed. |
|
Persistent |
localObject(ObjectId id,
java.lang.Object prototype)
Deprecated. since 3.1 Cayenne users should use BaseContext.localObject(Object); the
internal code has been refactored to avoid using this method all
together. |
|
java.util.Collection<?> |
modifiedObjects()
Returns a list of objects that are registered with this DataContext and have a state PersistenceState.MODIFIED |
|
|
newObject(java.lang.Class<T> persistentClass)
Creates and registers a new persistent object. |
|
Persistent |
newObject(java.lang.String entityName)
Instantiates a new object and registers it with this context. |
|
java.util.Collection<?> |
newObjects()
Returns a list of objects that are registered with this DataContext and have a state PersistenceState.NEW |
|
|
objectFromDataRow(java.lang.Class<T> objectClass,
DataRow dataRow)
Creates a DataObject from DataRow. |
|
|
objectFromDataRow(java.lang.Class<T> objectClass,
DataRow dataRow,
boolean refresh)
Deprecated. Use objectFromDataRow(Class |
|
DataObject |
objectFromDataRow(java.lang.String entityName,
DataRow dataRow)
Creates a DataObject from DataRow. |
|
DataObject |
objectFromDataRow(java.lang.String entityName,
DataRow dataRow,
boolean refresh)
Deprecated. Use objectFromDataRow(String entityName, DataRow dataRow) instead. |
|
java.util.List |
objectsFromDataRows(ClassDescriptor descriptor,
java.util.List<? extends DataRow> dataRows)
Converts a list of DataRows to a List of DataObject registered with this DataContext. |
|
protected GraphDiff |
onContextFlush(ObjectContext originatingContext,
GraphDiff changes,
boolean cascade)
|
|
QueryResponse |
onQuery(ObjectContext context,
Query query)
An implementation of a DataChannel method that is used by child contexts to
execute queries. |
|
QueryResponse |
performGenericQuery(Query query)
Executes a query returning a generic response. |
|
ResultIterator |
performIteratedQuery(Query query)
Performs a single database select query returning result as a ResultIterator. |
|
int[] |
performNonSelectingQuery(Query query)
Performs a single database query that does not select rows. |
|
int[] |
performNonSelectingQuery(java.lang.String queryName)
Performs a named mapped query that does not select rows. |
|
int[] |
performNonSelectingQuery(java.lang.String queryName,
java.util.Map<java.lang.String,?> parameters)
Performs a named mapped non-selecting query using a map of parameters. |
|
java.util.List |
performQuery(Query query)
Performs a single selecting query. |
|
java.util.List<?> |
performQuery(java.lang.String queryName,
boolean expireCachedLists)
Returns a list of objects or DataRows for a named query stored in one of the DataMaps. |
|
java.util.List<?> |
performQuery(java.lang.String queryName,
java.util.Map parameters,
boolean expireCachedLists)
Returns a list of objects or DataRows for a named query stored in one of the DataMaps. |
|
void |
registerNewObject(java.lang.Object object)
Registers a transient object with the context, recursively registering all transient persistent objects attached to this object via relationships. |
|
void |
rollbackChanges()
Reverts any changes that have occurred to objects registered with DataContext; also performs cascading rollback of all parent DataContexts. |
|
void |
rollbackChangesLocally()
If the parent channel is a DataContext, reverts local changes to make this context look like the parent, if the parent channel is a DataDomain, reverts all changes. |
|
void |
setDelegate(DataContextDelegate delegate)
Sets a DataContextDelegate for this context. |
|
void |
setUsingSharedSnapshotCache(boolean flag)
|
|
void |
setValidatingObjectsOnCommit(boolean flag)
Sets the property defining whether this DataContext should perform object validation before commit is executed. |
|
java.util.Collection<?> |
uncommittedObjects()
Returns a collection of all uncommitted registered objects. |
|
void |
unregisterObjects(java.util.Collection dataObjects)
Unregisters a Collection of DataObjects from the DataContext and the underlying ObjectStore. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.apache.cayenne.DataChannel |
|---|
getEntityResolver, getEventManager, onSync |
| Field Detail |
|---|
protected boolean usingSharedSnaphsotCache
protected boolean validatingObjectsOnCommit
protected ObjectStore objectStore
protected transient org.apache.cayenne.access.DataContextMergeHandler mergeHandler
| Constructor Detail |
|---|
public DataContext()
public DataContext(DataChannel channel,
ObjectStore objectStore)
| Method Detail |
|---|
@Deprecated public ObjectContext createChildContext()
DataContextFactory.createContext(DataChannel)
createChildContext in interface ObjectContextprotected void attachToChannel(DataChannel channel)
BaseContext
attachToChannel in class BaseContextpublic DataDomain getParentDataDomain()
public void setDelegate(DataContextDelegate delegate)
public DataContextDelegate getDelegate()
public ObjectStore getObjectStore()
public boolean hasChanges()
true if there are any modified, deleted or new objects
registered with this DataContext, false otherwise.
hasChanges in interface ObjectContextpublic java.util.Collection<?> newObjects()
newObjects in interface ObjectContextnewObjects in class BaseContextpublic java.util.Collection<?> deletedObjects()
deletedObjects in interface ObjectContextdeletedObjects in class BaseContextpublic java.util.Collection<?> modifiedObjects()
modifiedObjects in interface ObjectContextmodifiedObjects in class BaseContextpublic java.util.Collection<?> uncommittedObjects()
uncommittedObjects in interface ObjectContextuncommittedObjects in class BaseContextpublic DataRow currentSnapshot(Persistent object)
Warning: This method will return a partial snapshot if an object or one of its related objects that propagate their keys to this object have temporary ids. DO NOT USE this method if you expect a DataRow to represent a complete object state.
public java.util.List objectsFromDataRows(ClassDescriptor descriptor,
java.util.List<? extends DataRow> dataRows)
@Deprecated
public <T extends DataObject> T objectFromDataRow(java.lang.Class<T> objectClass,
DataRow dataRow,
boolean refresh)
DataRow
public <T extends DataObject> T objectFromDataRow(java.lang.Class<T> objectClass,
DataRow dataRow)
DataRow
@Deprecated
public DataObject objectFromDataRow(java.lang.String entityName,
DataRow dataRow,
boolean refresh)
DataRow
public DataObject objectFromDataRow(java.lang.String entityName,
DataRow dataRow)
DataRowpublic <T> T newObject(java.lang.Class<T> persistentClass)
newObject in interface ObjectContextnewObject in class BaseContextpublic Persistent newObject(java.lang.String entityName)
newObject(Class) method should be used, however
this method is helpful when generic persistent classes are used.
public void registerNewObject(java.lang.Object object)
DataObject.
registerNewObject in interface ObjectContextregisterNewObject in class BaseContextobject - new object that needs to be made persistent.public void unregisterObjects(java.util.Collection dataObjects)
BaseContext.invalidateObjects(Collection)public void rollbackChangesLocally()
rollbackChangesLocally in interface ObjectContextrollbackChangesLocally in class BaseContextpublic void rollbackChanges()
rollbackChanges in interface ObjectContextrollbackChanges in class BaseContextpublic void commitChangesToParent()
DataChannel. If the parent channel is a
DataContext, it updates its objects with this context's changes, without a database
update. If it is a DataDomain (the most common case), the changes are written to
the database. To cause cascading commit all the way to the database, one must use
commitChanges().
commitChangesToParent in interface ObjectContextcommitChangesToParent in class BaseContextcommitChanges()
public void commitChanges()
throws CayenneRuntimeException
commitChanges in interface ObjectContextcommitChanges in class BaseContextCayenneRuntimeException
protected GraphDiff onContextFlush(ObjectContext originatingContext,
GraphDiff changes,
boolean cascade)
onContextFlush in class BaseContext
public ResultIterator performIteratedQuery(Query query)
throws CayenneException
CayenneExceptionpublic QueryResponse performGenericQuery(Query query)
performGenericQuery in interface ObjectContextperformGenericQuery in class BaseContextpublic java.util.List performQuery(Query query)
Since 1.2 takes any Query parameter, not just GenericSelectQuery
performQuery in interface ObjectContextperformQuery in class BaseContextQueryMetadata.isFetchingDataRows().
public QueryResponse onQuery(ObjectContext context,
Query query)
DataChannel method that is used by child contexts to
execute queries. Not intended for direct use.
onQuery in interface DataChannelcontext - an ObjectContext that originated the query, used to
register result objects.
public int[] performNonSelectingQuery(Query query)
public int[] performNonSelectingQuery(java.lang.String queryName)
public int[] performNonSelectingQuery(java.lang.String queryName,
java.util.Map<java.lang.String,?> parameters)
public java.util.List<?> performQuery(java.lang.String queryName,
boolean expireCachedLists)
queryName - a name of a GenericSelectQuery defined in one of the DataMaps. If
no such query is defined, this method will throw a
CayenneRuntimeException.expireCachedLists - A flag that determines whether refresh of cached
lists is required in case a query uses caching.
public java.util.List<?> performQuery(java.lang.String queryName,
java.util.Map parameters,
boolean expireCachedLists)
queryName - a name of a GenericSelectQuery defined in one of the DataMaps. If
no such query is defined, this method will throw a
CayenneRuntimeException.parameters - A map of parameters to use with stored query.expireCachedLists - A flag that determines whether refresh of cached
lists is required in case a query uses caching.public boolean isUsingSharedSnapshotCache()
true if the ObjectStore uses shared cache of a parent
DataDomain.
public void setUsingSharedSnapshotCache(boolean flag)
public boolean isValidatingObjectsOnCommit()
public void setValidatingObjectsOnCommit(boolean flag)
public GraphManager getGraphManager()
getGraphManager in interface ObjectContextgetGraphManager in class BaseContext
public Persistent localObject(ObjectId id,
java.lang.Object prototype)
BaseContext.localObject(Object); the
internal code has been refactored to avoid using this method all
together.
prototype is not null, local object is refreshed with the prototype
values.
In case you pass a non-null second parameter, you are responsible for setting correct persistence state of the returned local object, as generally there is no way for Cayenne to determine the resulting local object state.
localObject in interface ObjectContextlocalObject in class BaseContext
protected void fireDataChannelChanged(java.lang.Object postedBy,
GraphDiff changes)
fireDataChannelChanged in class BaseContext
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||