|
||||||||||
| 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 EntityResolver |
entityResolver
|
protected String |
lazyInitParentDomainName
Stores the name of parent DataDomain. |
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, 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 | ||
|---|---|---|
static void |
bindThreadDataContext(DataContext context)
Deprecated. since 3.0, replaced by BaseContex#getThreadObjectContext(). |
|
void |
commitChanges()
Synchronizes object graph with the database. |
|
void |
commitChangesToParent()
"Flushes" the changes to the parent DataChannel. |
|
DataObject |
createAndRegisterNewObject(Class objectClass)
Deprecated. since 3.0, use newObject(Class) instead. |
|
DataObject |
createAndRegisterNewObject(String objEntityName)
Deprecated. since 3.0, use newObject(String) instead. |
|
ObjectContext |
createChildContext()
Creates and returns a new child ObjectContext. |
|
DataContext |
createChildDataContext()
Deprecated. since 3.0 use createChildContext(). |
|
static DataContext |
createDataContext()
Factory method that creates and returns a new instance of DataContext based on default domain. |
|
static DataContext |
createDataContext(boolean useSharedCache)
Factory method that creates and returns a new instance of DataContext based on default domain. |
|
static DataContext |
createDataContext(String domainName)
Factory method that creates and returns a new instance of DataContext using named domain as its parent. |
|
static DataContext |
createDataContext(String domainName,
boolean useSharedCache)
Creates and returns new DataContext that will use a named DataDomain as its parent. |
|
DataRow |
currentSnapshot(Persistent object)
Returns a DataRow reflecting current, possibly uncommitted, object state. |
|
Collection<?> |
deletedObjects()
Returns a list of objects that are registered with this DataContext and have a state PersistenceState.DELETED |
|
void |
deleteObject(Object object)
Schedules an object for deletion on the next commit of this DataContext. |
|
void |
deleteObjects(Collection objects)
Schedules all objects in the collection for deletion on the next commit of this DataContext. |
|
protected void |
fireDataChannelChanged(Object postedBy,
GraphDiff changes)
|
|
DataChannel |
getChannel()
Returns an DataChannel used by this context. |
|
DataContextDelegate |
getDelegate()
Returns a delegate currently associated with this DataContext. |
|
EntityResolver |
getEntityResolver()
Returns EntityResolver. |
|
GraphManager |
getGraphManager()
Returns this context's ObjectStore. |
|
ObjectStore |
getObjectStore()
Returns ObjectStore associated with this DataContext. |
|
DataDomain |
getParentDataDomain()
Returns a DataDomain used by this DataContext. |
|
QueryCache |
getQueryCache()
Returns QueryCache used by this DataContext, creating it on the fly if
needed. |
|
static DataContext |
getThreadDataContext()
Deprecated. since 3.0, replaced by BaseContex#getThreadObjectContext(). |
|
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,
Object prototype)
Returns an object local to this DataContext and matching the ObjectId. |
|
Collection<?> |
modifiedObjects()
Returns a list of objects that are registered with this DataContext and have a state PersistenceState.MODIFIED |
|
|
newObject(Class<T> persistentClass)
Creates and registers a new persistent object. |
|
Persistent |
newObject(String entityName)
Instantiates a new object and registers it with this context. |
|
Collection<?> |
newObjects()
Returns a list of objects that are registered with this DataContext and have a state PersistenceState.NEW |
|
|
objectFromDataRow(Class<T> objectClass,
DataRow dataRow,
boolean refresh)
Creates a DataObject from DataRow. |
|
DataObject |
objectFromDataRow(String entityName,
DataRow dataRow,
boolean refresh)
Creates a DataObject from DataRow. |
|
List |
objectsFromDataRows(Class<?> objectClass,
List<? extends DataRow> dataRows,
boolean refresh,
boolean resolveInheritanceHierarchy)
Deprecated. since 3.0 as refresh and resolveInheritanceHierarchy flags are deprecated. Use objectsFromDataRows(ClassDescriptor, List)
instead. |
|
List |
objectsFromDataRows(ClassDescriptor descriptor,
List<? extends DataRow> dataRows)
Converts a list of DataRows to a List of DataObject registered with this DataContext. |
|
List |
objectsFromDataRows(ObjEntity entity,
List dataRows,
boolean refresh,
boolean resolveInheritanceHierarchy)
Deprecated. since 3.0 as refreshing and resolvingInheritanceHierarchy flags are deprecated. Use objectsFromDataRows(ClassDescriptor, List)
instead. |
|
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(String queryName)
Performs a named mapped query that does not select rows. |
|
int[] |
performNonSelectingQuery(String queryName,
Map<String,?> parameters)
Performs a named mapped non-selecting query using a map of parameters. |
|
List |
performQuery(Query query)
Performs a single selecting query. |
|
List<?> |
performQuery(String queryName,
boolean expireCachedLists)
Returns a list of objects or DataRows for a named query stored in one of the DataMaps. |
|
List<?> |
performQuery(String queryName,
Map parameters,
boolean expireCachedLists)
Returns a list of objects or DataRows for a named query stored in one of the DataMaps. |
|
void |
propertyChanged(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. |
|
DataObject |
refetchObject(ObjectId oid)
Deprecated. since 3.0 use ObjectIdQuery with appropriate refresh settings. |
|
void |
registerNewObject(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 |
setChannel(DataChannel channel)
|
|
void |
setDelegate(DataContextDelegate delegate)
Sets a DataContextDelegate for this context. |
|
void |
setValidatingObjectsOnCommit(boolean flag)
Sets the property defining whether this DataContext should perform object validation before commit is executed. |
|
Collection<?> |
uncommittedObjects()
Returns a collection of all uncommitted registered objects. |
|
void |
unregisterObjects(Collection dataObjects)
Unregisters a Collection of DataObjects from the DataContext and the underlying ObjectStore. |
|
| Methods inherited from class org.apache.cayenne.BaseContext |
|---|
bindThreadObjectContext, fireDataChannelCommitted, fireDataChannelRolledback, getEventManager, getThreadObjectContext, getUserProperties, getUserProperty, invalidateObjects, onSync, prepareForAccess, prepareForAccess, setQueryCache, setUserProperty |
| 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 |
|---|
getEventManager, onSync |
| Field Detail |
|---|
protected boolean usingSharedSnaphsotCache
protected boolean validatingObjectsOnCommit
protected ObjectStore objectStore
protected transient EntityResolver entityResolver
protected transient org.apache.cayenne.access.DataContextMergeHandler mergeHandler
protected transient String lazyInitParentDomainName
| Constructor Detail |
|---|
public DataContext()
public DataContext(DataChannel channel,
ObjectStore objectStore)
| Method Detail |
|---|
@Deprecated
public static DataContext getThreadDataContext()
throws IllegalStateException
IllegalStateException - if there is no DataContext bound to the current
thread.WebApplicationContextFilter@Deprecated public static void bindThreadDataContext(DataContext context)
getThreadDataContext(). Using
null parameter will unbind currently bound DataContext.
public static DataContext createDataContext()
createDataContext(String) must be used instead. ObjectStore
associated with created DataContext will have a cache stack configured using parent
domain settings.
public static DataContext createDataContext(boolean useSharedCache)
createDataContext(String, boolean) must be used instead.
ObjectStore associated with newly created DataContext will have a cache stack
configured according to the specified policy, overriding a parent domain setting.
public static DataContext createDataContext(String domainName)
public static DataContext createDataContext(String domainName,
boolean useSharedCache)
public QueryCache getQueryCache()
QueryCache used by this DataContext, creating it on the fly if
needed. Uses parent DataDomain QueryCacheFactory to initialize the cache
for the first time, passing parent DataDomain's properties.
getQueryCache in class BaseContextpublic ObjectContext createChildContext()
createChildContext in interface ObjectContext@Deprecated public DataContext createChildDataContext()
createChildContext().
public void setChannel(DataChannel channel)
public DataChannel getChannel()
ObjectContext
getChannel in interface ObjectContextgetChannel 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 Collection<?> newObjects()
newObjects in interface ObjectContextnewObjects in class BaseContextpublic Collection<?> deletedObjects()
deletedObjects in interface ObjectContextdeletedObjects in class BaseContextpublic Collection<?> modifiedObjects()
modifiedObjects in interface ObjectContextmodifiedObjects in class BaseContextpublic 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.
@Deprecated
public List objectsFromDataRows(ObjEntity entity,
List dataRows,
boolean refresh,
boolean resolveInheritanceHierarchy)
objectsFromDataRows(ClassDescriptor, List)
instead.
public List objectsFromDataRows(ClassDescriptor descriptor,
List<? extends DataRow> dataRows)
@Deprecated
public List objectsFromDataRows(Class<?> objectClass,
List<? extends DataRow> dataRows,
boolean refresh,
boolean resolveInheritanceHierarchy)
objectsFromDataRows(ClassDescriptor, List)
instead.
DataRow
public <T extends DataObject> T objectFromDataRow(Class<T> objectClass,
DataRow dataRow,
boolean refresh)
DataRow
public DataObject objectFromDataRow(String entityName,
DataRow dataRow,
boolean refresh)
DataRow@Deprecated public DataObject createAndRegisterNewObject(String objEntityName)
newObject(String) instead.
public <T> T newObject(Class<T> persistentClass)
newObject in interface ObjectContextnewObject in class BaseContextpublic Persistent newObject(String entityName)
newObject(Class) method should be used, however
this method is helpful when generic persistent classes are used.
@Deprecated public DataObject createAndRegisterNewObject(Class objectClass)
newObject(Class) instead.
public void registerNewObject(Object object)
DataObject.
registerNewObject in interface ObjectContextregisterNewObject in class BaseContextobject - new object that needs to be made persistent.public void unregisterObjects(Collection dataObjects)
BaseContext.invalidateObjects(Collection)public void deleteObjects(Collection objects)
"Nullify" delete rule side effect: passing a collection representing to-many relationship with nullify delete rule may result in objects being removed from collection.
public void deleteObject(Object object)
throws DeleteDenyException
deleteObject in interface ObjectContextdeleteObject in class BaseContextobject - a persistent object that we want to delete.
DeleteDenyException - if a DENY delete rule is applicable for object
deletion.
NullPointerException - if object is null.@Deprecated public DataObject refetchObject(ObjectId oid)
ObjectIdQuery with appropriate refresh settings.
PersistenceState.HOLLOW. It can also be used
to refresh certain objects.
CayenneRuntimeException - if object id doesn't match any records, or if there
is more than one object is fetched.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 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(String queryName)
public int[] performNonSelectingQuery(String queryName,
Map<String,?> parameters)
public List<?> performQuery(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 List<?> performQuery(String queryName,
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 EntityResolver getEntityResolver()
getEntityResolver in interface DataChannelgetEntityResolver in interface ObjectContextgetEntityResolver in class BaseContextpublic boolean isUsingSharedSnapshotCache()
true if the ObjectStore uses shared cache of a parent
DataDomain.
public boolean isValidatingObjectsOnCommit()
public void setValidatingObjectsOnCommit(boolean flag)
public void propertyChanged(Persistent object,
String property,
Object oldValue,
Object newValue)
ObjectContext
propertyChanged in interface ObjectContextpropertyChanged in class BaseContextpublic GraphManager getGraphManager()
getGraphManager in interface ObjectContextgetGraphManager in class BaseContext
public Persistent localObject(ObjectId id,
Object prototype)
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(Object postedBy,
GraphDiff changes)
fireDataChannelChanged in class BaseContext
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||