public void setToOneTarget(String relationshipName, DataObject value, boolean setReverse) { willConnect(relationshipName, value); Object oldTarget = readProperty(relationshipName); if (oldTarget == value) { return; } getObjectContext().propertyChanged(this, relationshipName, oldTarget, value); if (setReverse) { // unset old reverse relationship if (oldTarget instanceof DataObject) { unsetReverseRelationship(relationshipName, (DataObject) oldTarget); } // set new reverse relationship if (value != null) { setReverseRelationship(relationshipName, value); } } objectContext.prepareForAccess(this, relationshipName, false); writePropertyDirectly(relationshipName, value); }
public String toString() { return toStringBuffer(new StringBuffer(), true).toString(); }
/** * Calls {@link #validateForSave(ValidationResult)}. CayenneDataObject * subclasses may override it providing validation logic that should be * executed for the modified objects before saving them. * * @since 1.1 */ public void validateForUpdate(ValidationResult validationResult) { validateForSave(validationResult); }
public void removeToManyTarget(String relName, DataObject value, boolean setReverse) { // Now do the rest of the normal handling (regardless of whether it was // flattened or not) Object holder = readProperty(relName); // call 'propertyChanged' AFTER readProperty as readProperty ensures // that this // object fault is resolved getObjectContext().propertyChanged(this, relName, value, null); // TODO: andrus 8/20/2007 - can we optimize this somehow, avoiding type // checking?? if (holder instanceof Collection) { ((Collection<Object>) holder).remove(value); } else if (holder instanceof Map) { ((Map<Object, Object>) holder).remove(getMapKey(relName, value)); } if (value != null && setReverse) { unsetReverseRelationship(relName, value); } }
public void addToManyTarget(String relName, DataObject value, boolean setReverse) { if (value == null) { throw new NullPointerException("Attempt to add null target DataObject."); } willConnect(relName, value); // Now do the rest of the normal handling (regardless of whether it was // flattened or not) Object holder = readProperty(relName); // call 'propertyChanged' AFTER readProperty as readProperty ensures // that this // object fault is resolved getObjectContext().propertyChanged(this, relName, null, value); // TODO: andrus 8/20/2007 - can we optimize this somehow, avoiding type // checking?? if (holder instanceof Collection) { ((Collection<Object>) holder).add(value); } else if (holder instanceof Map) { ((Map<Object, Object>) holder).put(getMapKey(relName, value), value); } if (setReverse) { setReverseRelationship(relName, value); } }
public void setToOneTarget( String relationshipName, DataObject value, boolean setReverse) { willConnect(relationshipName, value); Object oldTarget = readProperty(relationshipName); if (oldTarget == value) { return; } getDataContext().getObjectStore().recordArcCreated( this, value != null ? value.getObjectId() : null, relationshipName); if (setReverse) { // unset old reverse relationship if (oldTarget instanceof DataObject) { unsetReverseRelationship(relationshipName, (DataObject) oldTarget); } // set new reverse relationship if (value != null) { setReverseRelationship(relationshipName, value); } } objectContext.prepareForAccess(this, relationshipName); writePropertyDirectly(relationshipName, value); }
public void addToManyTarget(String relName, DataObject value, boolean setReverse) { if (value == null) { throw new NullPointerException("Attempt to add null target DataObject."); } willConnect(relName, value); // Now do the rest of the normal handling (regardless of whether it was // flattened or not) List list = (List) readProperty(relName); // call 'recordArcCreated' AFTER readProperty as readProperty ensures that this // object fault is resolved getDataContext().getObjectStore().recordArcCreated( this, value.getObjectId(), relName); list.add(value); if (value != null && setReverse) { setReverseRelationship(relName, value); } }
public Object readProperty(String propName) { if (objectContext != null) { objectContext.prepareForAccess(this, propName); } Object object = readPropertyDirectly(propName); // must resolve faults immediately if (object instanceof Fault) { object = ((Fault) object).resolveFault(this, propName); writePropertyDirectly(propName, object); } return object; }
public void removeToManyTarget(String relName, DataObject value, boolean setReverse) { // Now do the rest of the normal handling (regardless of whether it was // flattened or not) List relList = (List) readProperty(relName); // call 'recordArcDeleted' AFTER readProperty as readProperty ensures that this // object fault is resolved getDataContext().getObjectStore().recordArcDeleted( this, value != null ? value.getObjectId() : null, relName); relList.remove(value); if (persistenceState == PersistenceState.COMMITTED) { persistenceState = PersistenceState.MODIFIED; } if (value != null && setReverse) { unsetReverseRelationship(relName, value); } }
Object property = readProperty(relName); if(property == null) { throw new IllegalArgumentException("unknown relName " + relName); if (!values.contains(obj)) { DataObject obj2 = (DataObject) obj; removeToManyTarget(relName, obj2, setReverse); addToManyTarget(relName, obj, setReverse);
ObjEntity objEntity = getObjectContext().getEntityResolver().getObjEntity(this); if (objEntity == null) { throw new CayenneRuntimeException("No ObjEntity mapping found for DataObject %s", getClass().getName()); Object value = this.readPropertyDirectly(next.getName()); if (dbAttribute.isMandatory()) { ValidationFailure failure = BeanValidationFailure.validateNotNull(this, next.getName(), value); Object value = this.readPropertyDirectly(relationship.getName()); ValidationFailure failure = BeanValidationFailure.validateNotNull(this, relationship.getName(), value);
public Object readNestedProperty(String path) { Object object = null; CayenneDataObject dataObject = this; String[] tokenized = tokenizePath(path); int length = tokenized.length; int pathIndex = 0; for (int i = 0; i < length; i++) { pathIndex += tokenized[i].length() + 1; object = dataObject.readSimpleProperty(tokenized[i]); if (object == null) { return null; } else if (object instanceof CayenneDataObject) { dataObject = (CayenneDataObject) object; } else if (i + 1 < length) { // read the rest of the path via introspection return PropertyUtils.getProperty(object, path.substring(pathIndex)); } } return 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 */ protected void willConnect(String relationshipName, DataObject dataObject) { // first handle most common case - both objects are in the same // DataContext or target is null if (dataObject == null || this.getObjectContext() == dataObject.getObjectContext()) { return; } else if (this.getObjectContext() == null && dataObject.getObjectContext() != null) { dataObject.getDataContext().registerNewObject(this); } else if (this.getObjectContext() != null && dataObject.getObjectContext() == null) { this.getDataContext().registerNewObject(dataObject); } else { throw new CayenneRuntimeException( "Cannot set object as destination of relationship " + relationshipName + " because it is in a different DataContext"); } }
ObjEntity objEntity = getDataContext().getEntityResolver().lookupObjEntity(this); if (objEntity == null) { throw new CayenneRuntimeException( DataNode node = getDataContext().getParentDataDomain().lookupDataNode( objEntity.getDataMap()); if (node == null) { DbAttribute dbAttribute = objAttribute.getDbAttribute(); Object value = this.readPropertyDirectly(objAttribute.getName()); if (dbAttribute.isMandatory()) { ValidationFailure failure = BeanValidationFailure.validateNotNull( Object value = this.readPropertyDirectly(relationship.getName()); ValidationFailure failure = BeanValidationFailure.validateNotNull( this,
private final Object readSimpleProperty(String property) { // side effect - resolves HOLLOW object Object object = readProperty(property); // if a null value is returned, there is still a chance to // find a non-persistent property via reflection if (object == null && !values.containsKey(property)) { object = PropertyUtils.getProperty(this, property); } return object; }
/** * 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. */ public StringBuffer toStringBuffer(StringBuffer buffer, boolean fullDesc) { String id = (objectId != null) ? objectId.toString() : "<no id>"; String state = PersistenceState.persistenceStateName(persistenceState); buffer.append('{').append(id).append("; ").append(state).append("; "); if (fullDesc) { appendProperties(buffer); } buffer.append("}"); return buffer; }
/** * Returns mapped ObjEntity for this object. If an object is transient or is not * mapped returns null. * * @since 1.2 */ public ObjEntity getObjEntity() { return (getObjectContext() != null) ? getObjectContext() .getEntityResolver() .lookupObjEntity(this) : null; }
return readSimpleProperty(path); Object property = readSimpleProperty(path0);
public void writeProperty(String propName, Object val) { if (objectContext != null) { objectContext.prepareForAccess(this, propName); // note how we notify DataContext of change BEFORE the object is actually // changed... this is needed to take a valid current snapshot Object oldValue = readPropertyDirectly(propName); objectContext.propertyChanged(this, propName, oldValue, val); } writePropertyDirectly(propName, val); }
private final Object readSimpleProperty(String property) { // side effect - resolves HOLLOW object Object object = readProperty(property); // if a null value is returned, there is still a chance to // find a non-persistent property via reflection if (object == null && !values.containsKey(property)) { object = PropertyUtils.getProperty(this, property); } return object; }