public abstract class BaseDataObject extends PersistentObject implements DataObject, Validating
DataObject,
have no assumption about how data is actually stored.
Three variants are currently supported:
Map based storage, e.g. values will be stored in general Map (CayenneDataObject)
HybridDataObject)
This class can be used directly as superclass for field-based data objects.
To create own implementation of DataObject with custom field storage logic it is enough
to implement readPropertyDirectly(String) and writePropertyDirectly(String, Object) methods
and serialization support if needed (helper methods writeState(ObjectOutputStream)
and readState(ObjectInputStream) are provided).
CayenneDataObject,
HybridDataObject,
Serialized Form| Modifier and Type | Field and Description |
|---|---|
protected long |
snapshotVersion |
objectContext, objectId, persistenceStateDEFAULT_VERSION| Constructor and Description |
|---|
BaseDataObject() |
| Modifier and Type | Method and Description |
|---|---|
void |
addToManyTarget(String relName,
DataObject value,
boolean setReverse)
Adds an object to a to-many relationship.
|
protected void |
appendProperties(StringBuffer buffer) |
protected void |
beforePropertyRead(String propName) |
protected void |
beforePropertyWrite(String propName,
Object oldValue,
Object newValue) |
long |
getSnapshotVersion()
Returns a version of a DataRow snapshot that was used to create this object.
|
Object |
readNestedProperty(String path)
Returns a value of the property identified by a property path.
|
Object |
readProperty(String propertyName)
Returns a value of the property identified by propName.
|
Object |
readPropertyDirectly(String propName)
Returns mapped property value as curently stored in the DataObject.
|
protected void |
readSerialized(ObjectInputStream in) |
protected void |
readState(ObjectInputStream in) |
void |
removeToManyTarget(String relName,
DataObject value,
boolean setReverse)
Removes an object from a to-many relationship.
|
void |
setObjectContext(ObjectContext objectContext) |
void |
setPersistenceState(int persistenceState) |
protected void |
setReverseRelationship(String relName,
DataObject val)
Initializes reverse relationship from object
val to this
object. |
void |
setSnapshotVersion(long snapshotVersion) |
List<? extends DataObject> |
setToManyTarget(String relName,
Collection<? extends DataObject> values,
boolean setReverse)
Sets the relationships to the specified
DataObject objects. |
void |
setToOneTarget(String relationshipName,
DataObject value,
boolean setReverse)
Sets to-one relationship to a new value.
|
String |
toString() |
StringBuffer |
toStringBuffer(StringBuffer buffer,
boolean fullDesc)
A variation of "toString" method, that may be more efficient in some
cases.
|
protected void |
unsetReverseRelationship(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)
|
protected void |
validateForSave(ValidationResult validationResult)
Performs property validation of the object, appending any validation
failures to the provided validationResult object.
|
void |
validateForUpdate(ValidationResult validationResult)
|
protected void |
willConnect(String relationshipName,
Persistent object)
Called before establishing a relationship with another object.
|
void |
writeProperty(String propName,
Object val)
Sets the property to the new value.
|
void |
writePropertyDirectly(String propName,
Object val)
Modifies a value of a named property without altering the object state in any way,
and without triggering any database operations.
|
protected void |
writeSerialized(ObjectOutputStream out) |
protected void |
writeState(ObjectOutputStream out) |
getMapKey, getObjectContext, getObjectId, getPersistenceState, setObjectIdclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetObjectContext, getObjectId, getPersistenceState, setObjectIdpublic Object readPropertyDirectly(String propName)
DataObjectreadPropertyDirectly in interface DataObjectpublic void writePropertyDirectly(String propName, Object val)
DataObjectwritePropertyDirectly in interface DataObjectprotected void beforePropertyRead(String propName)
protected void beforePropertyWrite(String propName, Object oldValue, Object newValue)
public Object readProperty(String propertyName)
DataObjectreadProperty in interface DataObjectpublic Object readNestedProperty(String path)
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 readPropertyDirectly(String), this method will resolve an
object if it is HOLLOW.
Examples:
String name = (String)artist.readNestedProperty("name");Gallery g = (Gallery)paintingInfo.readNestedProperty("toPainting.toGallery");
String name = (String)painting.readNestedProperty("toArtist.artistName");
List exhibits = (List)painting.readNestedProperty("toGallery.exhibitArray");
List<String> names = (List<String>)artist.readNestedProperty("paintingArray.paintingName");
readNestedProperty in interface DataObjectpublic void writeProperty(String propName, Object val)
DataObjectDataObject.setToOneTarget(String, DataObject, boolean).writeProperty in interface DataObjectpropName - a name of the bean property being modified.val - a new value of the property.public void removeToManyTarget(String relName, DataObject value, boolean setReverse)
DataObjectremoveToManyTarget in interface DataObjectpublic void addToManyTarget(String relName, DataObject value, boolean setReverse)
DataObjectaddToManyTarget in interface DataObjectpublic List<? extends DataObject> setToManyTarget(String relName, Collection<? extends DataObject> values, boolean setReverse)
DataObject objects.
New relationships will be created with
addToManyTarget(String, org.apache.cayenne.DataObject, boolean),
already established relationships stay untouched. Missing relationships
will be removed with
removeToManyTarget(String, org.apache.cayenne.DataObject, boolean)
and returnd as List. You may delete them manually.
Notice: Moving an object relationship to another object, is still needing
an manually "unregister" from the first object by
removeToManyTarget(String, org.apache.cayenne.DataObject, boolean)
relName - name of the relationvalues - DataObject objects of this
Collection are set to the object. No changes will
be made to the the Collection, a copy is used. It
is safe to pass a persisted Collection of another
object.setReverse - update reverse relationshipsList<? extends DataObject> of unrelated
DataObjects. If no relationship was removed an empty List is
returned.IllegalArgumentException - if no relationship could be read by relName, or if the passed
Collection is null. To clear all relationships
use an empty CollectionUnsupportedOperationException - if the relation Collection Type is neither
java.util.Collection nor
java.util.Mappublic void setToOneTarget(String relationshipName, DataObject value, boolean setReverse)
DataObjectsetToOneTarget in interface DataObjectrelationshipName - 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.protected void willConnect(String relationshipName, Persistent object)
protected void setReverseRelationship(String relName, DataObject val)
val to this
object.relName - name of relationship from this object to val.protected void unsetReverseRelationship(String relName, DataObject val)
val to this object.public void setPersistenceState(int persistenceState)
setPersistenceState in interface PersistentsetPersistenceState in class PersistentObjectpublic long getSnapshotVersion()
DataObjectgetSnapshotVersion in interface DataObjectpublic void setSnapshotVersion(long snapshotVersion)
setSnapshotVersion in interface DataObjectprotected void validateForSave(ValidationResult validationResult)
public void validateForInsert(ValidationResult validationResult)
validateForSave(ValidationResult). CayenneDataObject
subclasses may override it providing validation logic that should be
executed for the newly created objects before saving them.validateForInsert in interface Validatingpublic void validateForUpdate(ValidationResult validationResult)
validateForSave(ValidationResult). CayenneDataObject
subclasses may override it providing validation logic that should be
executed for the modified objects before saving them.validateForUpdate in interface Validatingpublic void validateForDelete(ValidationResult validationResult)
validateForDelete in interface Validatingpublic void setObjectContext(ObjectContext objectContext)
setObjectContext in interface PersistentsetObjectContext in class PersistentObjectprotected void writeSerialized(ObjectOutputStream out) throws IOException
IOExceptionprotected void readSerialized(ObjectInputStream in) throws IOException, ClassNotFoundException
IOExceptionClassNotFoundExceptionprotected void writeState(ObjectOutputStream out) throws IOException
IOExceptionprotected void readState(ObjectInputStream in) throws IOException, ClassNotFoundException
IOExceptionClassNotFoundExceptionpublic StringBuffer toStringBuffer(StringBuffer buffer, boolean fullDesc)
protected void appendProperties(StringBuffer buffer)
public String toString()
toString in class PersistentObjectCopyright © 2001–2021 Apache Cayenne. All rights reserved.