org.apache.cayenne
Class CayenneDataObject

java.lang.Object
  extended by org.apache.cayenne.CayenneDataObject
All Implemented Interfaces:
java.io.Serializable, DataObject, Persistent, XMLSerializable

public class CayenneDataObject
extends java.lang.Object
implements DataObject, XMLSerializable

A default implementation of DataObject interface. It is normally used as a superclass of Cayenne persistent objects.

Author:
Andrei Adamchik
See Also:
Serialized Form

Field Summary
protected  ObjectContext objectContext
           
protected  ObjectId objectId
           
protected  int persistenceState
           
protected  long snapshotVersion
           
protected  java.util.Map values
           
 
Fields inherited from interface org.apache.cayenne.DataObject
DEFAULT_VERSION
 
Constructor Summary
CayenneDataObject()
           
 
Method Summary
 void addToManyTarget(java.lang.String relName, DataObject value, boolean setReverse)
           
protected  void appendProperties(java.lang.StringBuffer buffer)
           
 void decodeFromXML(XMLDecoder decoder)
          Decodes itself from XML using the provided XMLDecoder.
 void encodeAsXML(XMLEncoder encoder)
          Encodes object to XML using provided encoder.
 void fetchFinished()
          Default implementation does nothing.
 DataContext getDataContext()
          Returns a DataContext that holds this object.
 ObjectContext getObjectContext()
          Returns this object's DataContext.
 ObjectId getObjectId()
           
 ObjEntity getObjEntity()
          Returns mapped ObjEntity for this object.
 int getPersistenceState()
           
 long getSnapshotVersion()
          Returns a version of a DataRow snapshot that was used to create this object.
 java.lang.Object readNestedProperty(java.lang.String path)
          Returns a value of the property identified by a property path.
 java.lang.Object readProperty(java.lang.String propName)
          Returns a value of the property identified by propName.
 java.lang.Object readPropertyDirectly(java.lang.String propName)
          Returns mapped property value as curently stored in the DataObject.
 void removeToManyTarget(java.lang.String relName, DataObject value, boolean setReverse)
           
 void resolveFault()
          Deprecated. since 1.2 use 'getObjectContext().prepareForAccess(object)'
 void setDataContext(DataContext dataContext)
          Initializes DataObject's persistence context.
 void setObjectContext(ObjectContext objectContext)
           
 void setObjectId(ObjectId objectId)
           
 void setPersistenceState(int persistenceState)
           
protected  void setReverseRelationship(java.lang.String relName, DataObject val)
          Initializes reverse relationship from object val to this object.
 void setSnapshotVersion(long snapshotVersion)
           
 void setToOneTarget(java.lang.String relationshipName, DataObject value, boolean setReverse)
          Sets to-one relationship to a new value.
 java.lang.String toString()
           
 java.lang.StringBuffer toStringBuffer(java.lang.StringBuffer buffer, boolean fullDesc)
          A variation of "toString" method, that may be more efficient in some cases.
protected  void unsetReverseRelationship(java.lang.String relName, DataObject val)
          Removes current object from reverse relationship of object val to this object.
 void validateForDelete(ValidationResult validationResult)
          This implementation does nothing.
 void validateForInsert(ValidationResult validationResult)
          Calls validateForSave(ValidationResult).
protected  void validateForSave(ValidationResult validationResult)
          Performs property validation of the object, appending any validation failures to the provided validationResult object.
 void validateForUpdate(ValidationResult validationResult)
          Calls validateForSave(ValidationResult).
protected  void willConnect(java.lang.String relationshipName, DataObject dataObject)
          Called before establishing a relationship with another object.
 void writeProperty(java.lang.String propName, java.lang.Object val)
          Sets the property to the new value.
 void writePropertyDirectly(java.lang.String propName, java.lang.Object val)
          Modifies a value of a named property without altering the object state in any way, and without triggering any database operations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

snapshotVersion

protected long snapshotVersion

objectId

protected ObjectId objectId

persistenceState

protected transient int persistenceState

objectContext

protected transient ObjectContext objectContext

values

protected java.util.Map values
Constructor Detail

CayenneDataObject

public CayenneDataObject()
Method Detail

getDataContext

public DataContext getDataContext()
Returns a DataContext that holds this object. Object becomes assocaiated with a DataContext either when the object is fetched using a query, or when a new object is registered explicitly with a DataContext.

Specified by:
getDataContext in interface DataObject

setDataContext

public void setDataContext(DataContext dataContext)
Initializes DataObject's persistence context.

Specified by:
setDataContext in interface DataObject

getObjEntity

public ObjEntity getObjEntity()
Returns mapped ObjEntity for this object. If an object is transient or is not mapped returns null.

Since:
1.2

getObjectId

public ObjectId getObjectId()
Specified by:
getObjectId in interface Persistent

setObjectId

public void setObjectId(ObjectId objectId)
Specified by:
setObjectId in interface Persistent

getPersistenceState

public int getPersistenceState()
Specified by:
getPersistenceState in interface Persistent

setPersistenceState

public void setPersistenceState(int persistenceState)
Specified by:
setPersistenceState in interface Persistent

readNestedProperty

public java.lang.Object readNestedProperty(java.lang.String path)
Description copied from interface: DataObject
Returns a value of the property identified by a property path. Supports reading both mapped and unmapped properties. Unmapped properties are accessed in a manner consistent with JavaBeans specification.

Property path (or nested property) is a dot-separated path used to traverse object relationships until the final object is found. If a null object found while traversing path, null is returned. If a list is encountered in the middle of the path, CayenneRuntimeException is thrown. Unlike DataObject.readPropertyDirectly(String), this method will resolve an object if it is HOLLOW.

Examples:

Specified by:
readNestedProperty in interface DataObject

resolveFault

public void resolveFault()
Deprecated. since 1.2 use 'getObjectContext().prepareForAccess(object)'

Description copied from interface: DataObject
Initializes object with data from cache or from the database, if this object is not fully resolved.

Specified by:
resolveFault in interface DataObject
Since:
1.1

readProperty

public java.lang.Object readProperty(java.lang.String propName)
Description copied from interface: DataObject
Returns a value of the property identified by propName. Resolves faults if needed. This method can safely be used instead of or in addition to the auto-generated property accessors in subclasses of CayenneDataObject.

Specified by:
readProperty in interface DataObject

readPropertyDirectly

public java.lang.Object readPropertyDirectly(java.lang.String propName)
Description copied from interface: DataObject
Returns mapped property value as curently stored in the DataObject. Returned value maybe a fault or a real value. This method will not attempt to resolve faults, or to read unmapped properties.

Specified by:
readPropertyDirectly in interface DataObject

writeProperty

public void writeProperty(java.lang.String propName,
                          java.lang.Object val)
Description copied from interface: DataObject
Sets the property to the new value. Resolves faults if needed. This method can be safely used instead of or in addition to the auto-generated property modifiers to set simple properties. Note that to set to-one relationships use DataObject.setToOneTarget(String, DataObject, boolean).

Specified by:
writeProperty in interface DataObject
Parameters:
propName - a name of the bean property being modified.
val - a new value of the property.

writePropertyDirectly

public void writePropertyDirectly(java.lang.String propName,
                                  java.lang.Object val)
Description copied from interface: DataObject
Modifies a value of a named property without altering the object state in any way, and without triggering any database operations. This method is intended mostly for internal use by Cayenne framework, and shouldn't be called from the application code.

Specified by:
writePropertyDirectly in interface DataObject

removeToManyTarget

public void removeToManyTarget(java.lang.String relName,
                               DataObject value,
                               boolean setReverse)
Specified by:
removeToManyTarget in interface DataObject

addToManyTarget

public void addToManyTarget(java.lang.String relName,
                            DataObject value,
                            boolean setReverse)
Specified by:
addToManyTarget in interface DataObject

setToOneTarget

public void setToOneTarget(java.lang.String relationshipName,
                           DataObject value,
                           boolean setReverse)
Description copied from interface: DataObject
Sets to-one relationship to a new value. Resolves faults if needed. This method can safely be used instead of or in addition to the auto-generated property modifiers to set properties that are to-one relationships.

Specified by:
setToOneTarget in interface DataObject
Parameters:
relationshipName - a name of the bean property being modified - same as the name of ObjRelationship.
value - a new value of the property.
setReverse - whether to update the reverse relationship pointing from the old and new values of the property to this object.

willConnect

protected void willConnect(java.lang.String relationshipName,
                           DataObject dataObject)
Called before establishing a relationship with another object. Applies "persistence by reachability" logic, pulling one of the two objects to a DataConext of another object in case one of the objects is transient. If both objects are persistent, and they don't have the same DataContext, CayenneRuntimeException is thrown.

Since:
1.2

setReverseRelationship

protected void setReverseRelationship(java.lang.String relName,
                                      DataObject val)
Initializes reverse relationship from object val to this object.

Parameters:
relName - name of relationship from this object to val.

unsetReverseRelationship

protected void unsetReverseRelationship(java.lang.String relName,
                                        DataObject val)
Removes current object from reverse relationship of object val to this object.


toStringBuffer

public java.lang.StringBuffer toStringBuffer(java.lang.StringBuffer buffer,
                                             boolean fullDesc)
A variation of "toString" method, that may be more efficient in some cases. For example when printing a list of objects into the same String.


appendProperties

protected void appendProperties(java.lang.StringBuffer buffer)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

fetchFinished

public void fetchFinished()
Default implementation does nothing.

Specified by:
fetchFinished in interface DataObject
See Also:
DataObject.fetchFinished()

getSnapshotVersion

public long getSnapshotVersion()
Returns a version of a DataRow snapshot that was used to create this object.

Specified by:
getSnapshotVersion in interface DataObject
Since:
1.1

setSnapshotVersion

public void setSnapshotVersion(long snapshotVersion)
Specified by:
setSnapshotVersion in interface DataObject
Since:
1.1

validateForSave

protected void validateForSave(ValidationResult validationResult)
Performs property validation of the object, appending any validation failures to the provided validationResult object. This method is invoked from "validateFor.." before committing a NEW or MODIFIED object to the database. Validation includes checking for null values and value sizes. CayenneDataObject subclasses may override this method, calling super.

Since:
1.1

validateForInsert

public void validateForInsert(ValidationResult validationResult)
Calls validateForSave(ValidationResult). CayenneDataObject subclasses may override it providing validation logic that should be executed for the newly created objects before saving them.

Specified by:
validateForInsert in interface DataObject
Since:
1.1

validateForUpdate

public void validateForUpdate(ValidationResult validationResult)
Calls validateForSave(ValidationResult). CayenneDataObject subclasses may override it providing validation logic that should be executed for the modified objects before saving them.

Specified by:
validateForUpdate in interface DataObject
Since:
1.1

validateForDelete

public void validateForDelete(ValidationResult validationResult)
This implementation does nothing. CayenneDataObject subclasses may override it providing validation logic that should be executed for the deleted objects before committing them.

Specified by:
validateForDelete in interface DataObject
Since:
1.1

encodeAsXML

public void encodeAsXML(XMLEncoder encoder)
Encodes object to XML using provided encoder.

Specified by:
encodeAsXML in interface XMLSerializable
Parameters:
encoder - The encoder object.
Since:
1.2

decodeFromXML

public void decodeFromXML(XMLDecoder decoder)
Description copied from interface: XMLSerializable
Decodes itself from XML using the provided XMLDecoder.

Specified by:
decodeFromXML in interface XMLSerializable
Parameters:
decoder - The decoder object.

getObjectContext

public ObjectContext getObjectContext()
Returns this object's DataContext.

Specified by:
getObjectContext in interface Persistent
Since:
1.2

setObjectContext

public void setObjectContext(ObjectContext objectContext)
Specified by:
setObjectContext in interface Persistent
Since:
1.2


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