org.apache.cayenne
Class CayenneContext

java.lang.Object
  extended by org.apache.cayenne.CayenneContext
All Implemented Interfaces:
java.io.Serializable, ObjectContext

public class CayenneContext
extends java.lang.Object
implements ObjectContext

A default generic implementation of ObjectContext suitable for accessing Cayenne from either an ORM or a client tiers. Communicates with Cayenne via a DataChannel.

Since:
1.2
Author:
Andrus Adamchik
See Also:
Serialized Form

Field Summary
protected  DataChannel channel
           
protected  EntityResolver entityResolver
           
 
Constructor Summary
CayenneContext()
          Creates a new CayenneContext with no channel and disabled graph events.
CayenneContext(DataChannel channel)
          Creates a new CayenneContext, initializaing it with a channel instance.
CayenneContext(DataChannel channel, boolean changeEventsEnabled, boolean syncEventsEnabled)
          Creates a new CayenneContext, initializaing it with a channel.
 
Method Summary
 void commitChanges()
          Commits changes to uncommitted objects.
 void commitChangesToParent()
          Flushes all changes to objects in this context to the parent DataChannel.
 java.util.Collection deletedObjects()
          Returns a collection of objects that are registered with this ObjectContext and have a state PersistenceState.DELETED
 void deleteObject(Persistent object)
          Deletes an object locally, scheduling it for future deletion from the external data store.
 DataChannel getChannel()
          Returns an DataChannel used by this context.
 EntityResolver getEntityResolver()
          Returns an EntityResolver that provides mapping information needed for CayenneContext operation.
 GraphManager getGraphManager()
          Returns GraphManager that manages object graph associated with this context.
 boolean isChangeEventsEnabled()
          Returns true if this context posts individual object modification events.
 boolean isLifecycleEventsEnabled()
          Returns true if this context posts lifecycle events.
 Persistent localObject(ObjectId id, Persistent prototype)
          Converts a list of Persistent objects registered in some other ObjectContext to a list of objects local to this ObjectContext.
 java.util.Collection modifiedObjects()
          Returns a collection of objects that are registered with this ObjectContext and have a state PersistenceState.MODIFIED
 Persistent newObject(java.lang.Class persistentClass)
          Creates and registers a new Persistent object instance.
 java.util.Collection newObjects()
          Returns a collection of objects that are registered with this ObjectContext and have a state PersistenceState.NEW
 QueryResponse performGenericQuery(Query query)
          Executes any kind of query providing the result in a form of QueryResponse.
 java.util.List performQuery(Query query)
          Runs a query, returning result as list.
 void prepareForAccess(Persistent object, java.lang.String property)
          Resolves an object if it is HOLLOW.
 void propertyChanged(Persistent object, java.lang.String property, java.lang.Object oldValue, java.lang.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.
 void rollbackChanges()
          Resets all uncommitted changes made to the objects in this ObjectContext, cascading rollback operation all the way through the stack.
 void rollbackChangesLocally()
          Resets all uncommitted changes made to the objects in this ObjectContext.
 void setChannel(DataChannel channel)
          Sets the context channel, setting up a listener for channel events.
 void setEntityResolver(EntityResolver entityResolver)
           
 java.util.Collection uncommittedObjects()
          Returns a collection of MODIFIED, DELETED or NEW objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

channel

protected transient DataChannel channel

entityResolver

protected EntityResolver entityResolver
Constructor Detail

CayenneContext

public CayenneContext()
Creates a new CayenneContext with no channel and disabled graph events.


CayenneContext

public CayenneContext(DataChannel channel)
Creates a new CayenneContext, initializaing it with a channel instance. CayenneContext created using this constructor WILL NOT broadcast graph change events.


CayenneContext

public CayenneContext(DataChannel channel,
                      boolean changeEventsEnabled,
                      boolean syncEventsEnabled)
Creates a new CayenneContext, initializaing it with a channel. If graphEventsEnabled is true, this context will broadcast GraphEvents using ObjectContext.GRAPH_CHANGE_SUBJECT.

Method Detail

getChannel

public DataChannel getChannel()
Description copied from interface: ObjectContext
Returns an DataChannel used by this context.

Specified by:
getChannel in interface ObjectContext

setChannel

public void setChannel(DataChannel channel)
Sets the context channel, setting up a listener for channel events.


isChangeEventsEnabled

public boolean isChangeEventsEnabled()
Returns true if this context posts individual object modification events. Subject used for these events is ObjectContext.GRAPH_CHANGED_SUBJECT.


isLifecycleEventsEnabled

public boolean isLifecycleEventsEnabled()
Returns true if this context posts lifecycle events. Subjects used for these events are ObjectContext.GRAPH_COMMIT_STARTED_SUBJECT, ObjectContext.GRAPH_COMMITTED_SUBJECT, ObjectContext.GRAPH_COMMIT_ABORTED_SUBJECT, ObjectContext.GRAPH_ROLLEDBACK_SUBJECT..


getEntityResolver

public EntityResolver getEntityResolver()
Returns an EntityResolver that provides mapping information needed for CayenneContext operation. If EntityResolver is not set, this method would obtain and cache one from the underlying DataChannel.

Specified by:
getEntityResolver in interface ObjectContext

setEntityResolver

public void setEntityResolver(EntityResolver entityResolver)

getGraphManager

public GraphManager getGraphManager()
Description copied from interface: ObjectContext
Returns GraphManager that manages object graph associated with this context.

Specified by:
getGraphManager in interface ObjectContext

commitChanges

public void commitChanges()
Commits changes to uncommitted objects. First checks if there are changes in this context and if any changes are detected, sends a commit message to remote Cayenne service via an internal instance of CayenneConnector.

Specified by:
commitChanges in interface ObjectContext

rollbackChanges

public void rollbackChanges()
Description copied from interface: ObjectContext
Resets all uncommitted changes made to the objects in this ObjectContext, cascading rollback operation all the way through the stack.

Specified by:
rollbackChanges in interface ObjectContext

commitChangesToParent

public void commitChangesToParent()
Description copied from interface: ObjectContext
Flushes all changes to objects in this context to the parent DataChannel. Same as ObjectContext.commitChanges(), but no cascading flush occurs.

Specified by:
commitChangesToParent in interface ObjectContext

rollbackChangesLocally

public void rollbackChangesLocally()
Description copied from interface: ObjectContext
Resets all uncommitted changes made to the objects in this ObjectContext. Same as ObjectContext.rollbackChanges()(), but rollback is local to this context and no cascading changes undoing occurs.

Specified by:
rollbackChangesLocally in interface ObjectContext

deleteObject

public void deleteObject(Persistent object)
Deletes an object locally, scheduling it for future deletion from the external data store.

Specified by:
deleteObject in interface ObjectContext

newObject

public Persistent newObject(java.lang.Class persistentClass)
Creates and registers a new Persistent object instance.

Specified by:
newObject in interface ObjectContext

performQuery

public java.util.List performQuery(Query query)
Runs a query, returning result as list.

Specified by:
performQuery in interface ObjectContext

performGenericQuery

public QueryResponse performGenericQuery(Query query)
Description copied from interface: ObjectContext
Executes any kind of query providing the result in a form of QueryResponse.

Specified by:
performGenericQuery in interface ObjectContext

localObject

public Persistent localObject(ObjectId id,
                              Persistent prototype)
Converts a list of Persistent objects registered in some other ObjectContext to a list of objects local to this ObjectContext.

Current limitation: all objects in the source list must be either in COMMITTED or in HOLLOW state.

Specified by:
localObject in interface ObjectContext

prepareForAccess

public void prepareForAccess(Persistent object,
                             java.lang.String property)
Resolves an object if it is HOLLOW.

Specified by:
prepareForAccess in interface ObjectContext

propertyChanged

public void propertyChanged(Persistent object,
                            java.lang.String property,
                            java.lang.Object oldValue,
                            java.lang.Object newValue)
Description copied from interface: ObjectContext
A callback method that child Persistent objects are expected to call from inside the setter after modifying a value of a persistent property.

Specified by:
propertyChanged in interface ObjectContext

uncommittedObjects

public java.util.Collection uncommittedObjects()
Description copied from interface: ObjectContext
Returns a collection of MODIFIED, DELETED or NEW objects.

Specified by:
uncommittedObjects in interface ObjectContext

deletedObjects

public java.util.Collection deletedObjects()
Description copied from interface: ObjectContext
Returns a collection of objects that are registered with this ObjectContext and have a state PersistenceState.DELETED

Specified by:
deletedObjects in interface ObjectContext

modifiedObjects

public java.util.Collection modifiedObjects()
Description copied from interface: ObjectContext
Returns a collection of objects that are registered with this ObjectContext and have a state PersistenceState.MODIFIED

Specified by:
modifiedObjects in interface ObjectContext

newObjects

public java.util.Collection newObjects()
Description copied from interface: ObjectContext
Returns a collection of objects that are registered with this ObjectContext and have a state PersistenceState.NEW

Specified by:
newObjects in interface ObjectContext


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