Search in sources :

Example 86 with Persistent

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;
}
Also used : ValidationException(org.apache.cayenne.validation.ValidationException) Validating(org.apache.cayenne.Validating) Persistent(org.apache.cayenne.Persistent) ValidationResult(org.apache.cayenne.validation.ValidationResult)

Example 87 with Persistent

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;
}
Also used : Persistent(org.apache.cayenne.Persistent)

Example 88 with Persistent

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);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Persistent(org.apache.cayenne.Persistent) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

Persistent (org.apache.cayenne.Persistent)88 ObjectId (org.apache.cayenne.ObjectId)38 Test (org.junit.Test)32 ArrayList (java.util.ArrayList)17 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)17 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)17 DataObject (org.apache.cayenne.DataObject)13 Map (java.util.Map)12 ObjEntity (org.apache.cayenne.map.ObjEntity)10 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)10 AttributeProperty (org.apache.cayenne.reflect.AttributeProperty)10 DataRow (org.apache.cayenne.DataRow)8 PropertyVisitor (org.apache.cayenne.reflect.PropertyVisitor)8 ToManyProperty (org.apache.cayenne.reflect.ToManyProperty)8 ToOneProperty (org.apache.cayenne.reflect.ToOneProperty)8 Collection (java.util.Collection)7 HashMap (java.util.HashMap)7 ObjectContext (org.apache.cayenne.ObjectContext)6 DbEntity (org.apache.cayenne.map.DbEntity)6 List (java.util.List)5