Search in sources :

Example 31 with ToManyProperty

use of org.apache.cayenne.reflect.ToManyProperty in project cayenne by apache.

the class CayenneContextQueryAction method invalidateLocally.

private void invalidateLocally(CayenneContextGraphManager graphManager, Iterator<?> it) {
    if (!it.hasNext()) {
        return;
    }
    EntityResolver resolver = actingContext.getEntityResolver();
    while (it.hasNext()) {
        final Persistent object = (Persistent) it.next();
        // present
        if (object.getPersistenceState() == PersistenceState.NEW) {
            continue;
        }
        ObjectId id = object.getObjectId();
        // per CAY-1082 ROP objects (unlike CayenneDataObject) require all
        // relationship faults invalidation.
        ClassDescriptor descriptor = resolver.getClassDescriptor(id.getEntityName());
        PropertyVisitor arcInvalidator = new PropertyVisitor() {

            public boolean visitAttribute(AttributeProperty property) {
                return true;
            }

            public boolean visitToMany(ToManyProperty property) {
                property.invalidate(object);
                return true;
            }

            public boolean visitToOne(ToOneProperty property) {
                property.invalidate(object);
                return true;
            }
        };
        descriptor.visitProperties(arcInvalidator);
        object.setPersistenceState(PersistenceState.HOLLOW);
        // remove cached changes
        graphManager.changeLog.unregisterNode(id);
        graphManager.stateLog.unregisterNode(id);
    }
}
Also used : ClassDescriptor(org.apache.cayenne.reflect.ClassDescriptor) ToManyProperty(org.apache.cayenne.reflect.ToManyProperty) EntityResolver(org.apache.cayenne.map.EntityResolver) AttributeProperty(org.apache.cayenne.reflect.AttributeProperty) PropertyVisitor(org.apache.cayenne.reflect.PropertyVisitor) ToOneProperty(org.apache.cayenne.reflect.ToOneProperty)

Aggregations

ToManyProperty (org.apache.cayenne.reflect.ToManyProperty)31 ToOneProperty (org.apache.cayenne.reflect.ToOneProperty)29 AttributeProperty (org.apache.cayenne.reflect.AttributeProperty)28 PropertyVisitor (org.apache.cayenne.reflect.PropertyVisitor)28 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)21 ArcProperty (org.apache.cayenne.reflect.ArcProperty)13 ObjRelationship (org.apache.cayenne.map.ObjRelationship)9 Persistent (org.apache.cayenne.Persistent)8 DbRelationship (org.apache.cayenne.map.DbRelationship)8 ObjAttribute (org.apache.cayenne.map.ObjAttribute)8 PropertyDescriptor (org.apache.cayenne.reflect.PropertyDescriptor)8 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)7 DbJoin (org.apache.cayenne.map.DbJoin)7 ObjEntity (org.apache.cayenne.map.ObjEntity)7 ObjectId (org.apache.cayenne.ObjectId)6 DbAttribute (org.apache.cayenne.map.DbAttribute)6 HashSet (java.util.HashSet)4 Map (java.util.Map)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3