use of org.apache.cayenne.Persistent in project cayenne by apache.
the class ObjectStoreGraphDiff method validateAndCheckNoop.
/**
* Requires external synchronization on ObjectStore.
*/
boolean validateAndCheckNoop() {
if (getChangesByObjectId().isEmpty()) {
return true;
}
boolean noop = true;
// build a new collection for validation as validation methods may
// result in
// ObjectStore modifications
Collection<Validating> objectsToValidate = null;
for (final ObjectDiff diff : getChangesByObjectId().values()) {
if (!diff.isNoop()) {
noop = false;
if (diff.getObject() instanceof Validating) {
if (objectsToValidate == null) {
objectsToValidate = new ArrayList<>();
}
objectsToValidate.add((Validating) diff.getObject());
}
}
}
if (objectsToValidate != null) {
ValidationResult result = new ValidationResult();
for (Validating object : objectsToValidate) {
switch(((Persistent) object).getPersistenceState()) {
case PersistenceState.NEW:
object.validateForInsert(result);
break;
case PersistenceState.MODIFIED:
object.validateForUpdate(result);
break;
case PersistenceState.DELETED:
object.validateForDelete(result);
break;
}
}
if (result.hasFailures()) {
throw new ValidationException(result);
}
}
return noop;
}
use of org.apache.cayenne.Persistent in project cayenne by apache.
the class PrefetchObjectResolver method objectFromDataRow.
@Override
Persistent objectFromDataRow(DataRow row, ObjectId anId, ClassDescriptor classDescriptor) {
// skip processing of objects that were already processed in this
// transaction, either by this node or by some other node...
// added per CAY-1695 ..
Persistent object = seen.get(anId);
if (object == null) {
object = super.objectFromDataRow(row, anId, classDescriptor);
seen.put(anId, object);
}
return object;
}
use of org.apache.cayenne.Persistent in project cayenne by apache.
the class ResultScanParentAttachmentStrategy method linkToParent.
public void linkToParent(DataRow row, Persistent object) {
if (partitionByChild == null) {
indexParents();
}
Object key;
if (joins.length > 1) {
List<Object> values = new ArrayList<>(joins.length);
for (int j = 0; j < joins.length; j++) {
values.add(row.get(joins[j].getTargetName()));
}
key = values;
} else {
key = row.get(joins[0].getTargetName());
}
List<Persistent> parents = (List<Persistent>) partitionByChild.get(key);
if (parents != null) {
for (Persistent parent : parents) {
node.linkToParent(object, parent);
}
}
}
Aggregations