Class BaseDataObject

    • Field Detail

      • snapshotVersion

        protected long snapshotVersion
    • Constructor Detail

      • BaseDataObject

        public BaseDataObject()
    • Method Detail

      • readPropertyDirectly

        public Object readPropertyDirectly​(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
      • writePropertyDirectly

        public void writePropertyDirectly​(String propName,
                                          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
      • beforePropertyRead

        protected void beforePropertyRead​(String propName)
      • beforePropertyWrite

        protected void beforePropertyWrite​(String propName,
                                           Object oldValue,
                                           Object newValue)
      • readProperty

        public Object readProperty​(String propertyName)
        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
      • readNestedProperty

        public Object readNestedProperty​(String path)
        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 readPropertyDirectly(String), this method will resolve an object if it is HOLLOW.

        Examples:

        • Read this object property:
          String name = (String)artist.readNestedProperty("name");

        • Read an object related to this object:
          Gallery g = (Gallery)paintingInfo.readNestedProperty("toPainting.toGallery");

        • Read a property of an object related to this object:
          String name = (String)painting.readNestedProperty("toArtist.artistName");

        • Read to-many relationship list:
          List exhibits = (List)painting.readNestedProperty("toGallery.exhibitArray");

        • Read to-many relationship in the middle of the path:
          List<String> names = (List<String>)artist.readNestedProperty("paintingArray.paintingName");

        Specified by:
        readNestedProperty in interface DataObject
        Since:
        1.0.5
      • writeProperty

        public void writeProperty​(String propName,
                                  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.
      • setToOneTarget

        public void setToOneTarget​(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​(String relationshipName,
                                   Persistent object)
        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​(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​(String relName,
                                                DataObject val)
        Removes current object from reverse relationship of object val to this object.
      • getSnapshotVersion

        public long getSnapshotVersion()
        Description copied from interface: DataObject
        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
      • 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 Validating
        Since:
        1.1
      • toStringBuffer

        public StringBuffer toStringBuffer​(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​(StringBuffer buffer)