public abstract class BaseContext extends Object implements ObjectContext, DataChannel
| Modifier and Type | Field and Description |
|---|---|
protected DataChannel |
channel |
protected EntityResolver |
entityResolver |
protected ObjectContextGraphAction |
graphAction
Graph action that handles property changes
|
protected QueryCache |
queryCache |
protected static ThreadLocal<ObjectContext> |
threadObjectContext
A holder of a ObjectContext bound to the current thread.
|
protected Map<String,Object> |
userProperties
Stores user defined properties associated with this DataContext.
|
protected boolean |
validatingObjectsOnCommit |
FLUSH_CASCADE_SYNC, FLUSH_NOCASCADE_SYNC, GRAPH_CHANGED_SUBJECT, GRAPH_FLUSHED_SUBJECT, GRAPH_ROLLEDBACK_SUBJECT, ROLLBACK_CASCADE_SYNC| Modifier | Constructor and Description |
|---|---|
protected |
BaseContext() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
attachToChannel(DataChannel channel)
Attaches to a provided DataChannel.
|
protected void |
attachToRuntime(Injector injector)
Attaches this context to the CayenneRuntime whose Injector is passed as an argument
to this method.
|
protected boolean |
attachToRuntimeIfNeeded()
Checks whether this context is attached to Cayenne runtime stack and if not,
attempts to attach itself to the runtime using Injector returned from the call to
CayenneRuntime.getThreadInjector(). |
static void |
bindThreadObjectContext(ObjectContext context)
Binds a ObjectContext to the current thread.
|
abstract void |
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.
|
abstract void |
commitChangesToParent()
Flushes all changes to objects in this context to the parent DataChannel.
|
abstract Collection<?> |
deletedObjects()
Returns a collection of objects that are registered with this ObjectContext and
have a state PersistenceState.DELETED
|
void |
deleteObject(Object object)
Schedules an object for deletion on the next commit of this context.
|
void |
deleteObjects(Collection<?> objects)
Schedules deletion of a collection of persistent objects.
|
<T> void |
deleteObjects(T... objects)
Schedules deletion of one or more persistent objects.
|
protected void |
fireDataChannelChanged(Object postedBy,
GraphDiff changes) |
protected void |
fireDataChannelCommitted(Object postedBy,
GraphDiff changes) |
protected void |
fireDataChannelRolledback(Object postedBy,
GraphDiff changes) |
DataChannel |
getChannel()
Returns an DataChannel used by this context.
|
EntityResolver |
getEntityResolver()
Returns EntityResolver that stores all mapping information accessible by this
ObjectContext.
|
EventManager |
getEventManager()
Returns EventManager associated with the ObjectStore.
|
abstract GraphManager |
getGraphManager()
Returns GraphManager that manages object graph associated with this context.
|
QueryCache |
getQueryCache() |
static ObjectContext |
getThreadObjectContext()
Returns the ObjectContext bound to the current thread.
|
protected Map<String,Object> |
getUserProperties()
Returns a map of user-defined properties associated with this DataContext.
|
Object |
getUserProperty(String key)
Returns a user-defined property previously set via 'setUserProperty'.
|
protected void |
injectInitialValue(Object obj)
If ObjEntity qualifier is set, asks it to inject initial value to an object.
|
void |
invalidateObjects(Collection<?> objects)
Invalidates a Collection of persistent objects.
|
<T> void |
invalidateObjects(T... objects)
Invalidates one or more persistent objects.
|
boolean |
isValidatingObjectsOnCommit()
Returns whether this ObjectContext performs object validation before commit is
executed.
|
Persistent |
localObject(ObjectId id,
Object prototype)
Deprecated.
since 3.1 Cayenne users should use
localObject(Object); the
internal code has been refactored to avoid using this method all
together. |
<T> T |
localObject(T objectFromAnotherContext)
Returns a local copy of 'objectFromAnotherContext' object.
|
abstract Collection<?> |
modifiedObjects()
Returns a collection of objects that are registered with this ObjectContext and
have a state PersistenceState.MODIFIED
|
abstract <T> T |
newObject(Class<T> persistentClass)
Creates a new persistent object of a given class scheduled to be inserted to the
database on next commit.
|
abstract Collection<?> |
newObjects()
Returns a collection of objects that are registered with this ObjectContext and
have a state PersistenceState.NEW
|
protected abstract GraphDiff |
onContextFlush(ObjectContext originatingContext,
GraphDiff changes,
boolean cascade) |
GraphDiff |
onSync(ObjectContext originatingContext,
GraphDiff changes,
int syncType)
Processes synchronization request from a child ObjectContext, returning a GraphDiff
that describes changes to objects made on the receiving end as a result of
synchronization.
|
abstract QueryResponse |
performGenericQuery(Query query)
Executes any kind of query providing the result in a form of QueryResponse.
|
abstract List |
performQuery(Query query)
Executes a selecting query, returning a list of persistent objects or data rows.
|
void |
prepareForAccess(Persistent object,
String property,
boolean lazyFaulting)
A callback method that child Persistent objects are expected to call before
accessing property values.
|
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.
|
abstract void |
registerNewObject(Object object)
Registers a transient object with the context.
|
abstract void |
rollbackChanges()
Resets all uncommitted changes made to the objects in this ObjectContext, cascading
rollback operation all the way through the stack.
|
abstract void |
rollbackChangesLocally()
Resets all uncommitted changes made to the objects in this ObjectContext.
|
void |
setChannel(DataChannel channel)
Sets a new DataChannel for this context.
|
void |
setEntityResolver(EntityResolver entityResolver) |
void |
setQueryCache(QueryCache queryCache)
Sets a QueryCache to be used for storing cached query results.
|
void |
setUserProperty(String key,
Object value)
Sets a user-defined property.
|
void |
setValidatingObjectsOnCommit(boolean flag)
Sets the property defining whether this ObjectContext should perform object
validation before commit is executed.
|
abstract Collection<?> |
uncommittedObjects()
Returns a collection of MODIFIED, DELETED or NEW objects.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcreateChildContext, hasChangesonQueryprotected static final ThreadLocal<ObjectContext> threadObjectContext
protected transient DataChannel channel
protected transient QueryCache queryCache
protected transient EntityResolver entityResolver
protected boolean validatingObjectsOnCommit
protected ObjectContextGraphAction graphAction
public static ObjectContext getThreadObjectContext() throws IllegalStateException
IllegalStateException - if there is no ObjectContext bound to the current
thread.public static void bindThreadObjectContext(ObjectContext context)
getThreadObjectContext().
Using null parameter will unbind currently bound ObjectContext.protected boolean attachToRuntimeIfNeeded()
CayenneRuntime.getThreadInjector(). If thread Injector is not available and
the context is not attached, throws CayenneRuntimeException.
This method is called internally by the context before access to transient variables to allow the context to attach to the stack lazily following deserialization.
protected void attachToRuntime(Injector injector)
protected void attachToChannel(DataChannel channel)
public abstract void commitChanges()
ObjectContextcommitChanges in interface ObjectContextpublic abstract void commitChangesToParent()
ObjectContextObjectContext.commitChanges(), but no cascading flush occurs.commitChangesToParent in interface ObjectContextpublic abstract Collection<?> deletedObjects()
ObjectContextdeletedObjects in interface ObjectContextpublic DataChannel getChannel()
ObjectContextgetChannel in interface ObjectContextpublic void setChannel(DataChannel channel)
public EntityResolver getEntityResolver()
ObjectContextgetEntityResolver in interface DataChannelgetEntityResolver in interface ObjectContextpublic void setEntityResolver(EntityResolver entityResolver)
public boolean isValidatingObjectsOnCommit()
public void setValidatingObjectsOnCommit(boolean flag)
public <T> T localObject(T objectFromAnotherContext)
ObjectContextNote that passing an object with a non-existing id, may later result in FaultFailureException on attempt to read returned object properties.
localObject in interface ObjectContextpublic abstract GraphManager getGraphManager()
ObjectContextgetGraphManager in interface ObjectContext@Deprecated public Persistent localObject(ObjectId id, Object prototype)
localObject(Object); the
internal code has been refactored to avoid using this method all
together.ObjectContextprototype is not null, local object is refreshed with the prototype
values.
This method can do both "mapping" (i.e. finding an object with the same id in this context) and "synchronization" (i.e. updating the state of the found object with the state of the prototype object).
localObject in interface ObjectContextpublic abstract Collection<?> modifiedObjects()
ObjectContextmodifiedObjects in interface ObjectContextpublic abstract <T> T newObject(Class<T> persistentClass)
ObjectContextnewObject in interface ObjectContextpublic abstract void registerNewObject(Object object)
ObjectContextObjectContext.newObject(Class) is that a user creates an object herself, before
attaching it to the context, instead of relying on Cayenne to do that.registerNewObject in interface ObjectContextobject - new object that needs to be made persistent.public abstract Collection<?> newObjects()
ObjectContextnewObjects in interface ObjectContextpublic abstract QueryResponse performGenericQuery(Query query)
ObjectContextperformGenericQuery in interface ObjectContextpublic abstract List performQuery(Query query)
ObjectContextperformQuery in interface ObjectContextpublic void prepareForAccess(Persistent object, String property, boolean lazyFaulting)
ObjectContextprepareForAccess in interface ObjectContextpublic void propertyChanged(Persistent object, String property, Object oldValue, Object newValue)
ObjectContextpropertyChanged in interface ObjectContextpublic abstract void rollbackChanges()
ObjectContextrollbackChanges in interface ObjectContextpublic abstract void rollbackChangesLocally()
ObjectContextObjectContext.rollbackChanges()(), but rollback is local to this context and no
cascading changes undoing occurs.rollbackChangesLocally in interface ObjectContextpublic abstract Collection<?> uncommittedObjects()
ObjectContextuncommittedObjects in interface ObjectContextpublic QueryCache getQueryCache()
public void setQueryCache(QueryCache queryCache)
public EventManager getEventManager()
getEventManager in interface DataChannelpublic GraphDiff onSync(ObjectContext originatingContext, GraphDiff changes, int syncType)
DataChannelonSync in interface DataChanneloriginatingContext - an ObjectContext that initiated the sync. Can be null.changes - diff from the context that initiated the sync.syncType - One of DataChannel.FLUSH_NOCASCADE_SYNC, DataChannel.FLUSH_CASCADE_SYNC,
DataChannel.ROLLBACK_CASCADE_SYNC.protected abstract GraphDiff onContextFlush(ObjectContext originatingContext, GraphDiff changes, boolean cascade)
protected void fireDataChannelCommitted(Object postedBy, GraphDiff changes)
protected void fireDataChannelRolledback(Object postedBy, GraphDiff changes)
protected void fireDataChannelChanged(Object postedBy, GraphDiff changes)
public void invalidateObjects(Collection<?> objects)
ObjectContextinvalidateObjects in interface ObjectContextpublic <T> void invalidateObjects(T... objects)
ObjectContextObjectContext.invalidateObjects(Collection) only with a vararg argument list for easier
invalidation of individual objects. If no arguments are passed to this method, it
does nothing.invalidateObjects in interface ObjectContextprotected Map<String,Object> getUserProperties()
public Object getUserProperty(String key)
getUserProperty in interface ObjectContextpublic void setUserProperty(String key, Object value)
setUserProperty in interface ObjectContextprotected void injectInitialValue(Object obj)
public void deleteObject(Object object)
deleteObject in interface ObjectContextobject - a persistent object that we want to delete.DeleteDenyException - if a DENY delete rule is applicable for object
deletion.NullPointerException - if object is null.public <T> void deleteObjects(T... objects)
throws DeleteDenyException
ObjectContextObjectContext.deleteObjects(Collection) only with a vararg argument list for easier
deletion of individual objects.deleteObjects in interface ObjectContextDeleteDenyException - if a DeleteRule.DENY
delete rule is applicable for object deletion.public void deleteObjects(Collection<?> objects) throws DeleteDenyException
ObjectContextdeleteObjects in interface ObjectContextDeleteDenyException - if a DeleteRule.DENY
delete rule is applicable for object deletion.Copyright © 2001–2018 Apache Cayenne. All rights reserved.