use of org.apache.cayenne.reflect.PropertyVisitor in project cayenne by apache.
the class ObjectStore method processIndirectlyModifiedIDs.
/**
* Requires external synchronization.
*
* @since 1.1
*/
void processIndirectlyModifiedIDs(Collection<ObjectId> indirectlyModifiedIDs) {
for (ObjectId oid : indirectlyModifiedIDs) {
// access object map directly - the method should be called in a synchronized context...
final DataObject object = (DataObject) objectMap.get(oid);
if (object == null || object.getPersistenceState() != PersistenceState.COMMITTED) {
continue;
}
// for now break all "independent" object relationships...
// in the future we may want to be more precise and go after modified
// relationships only, or even process updated lists without invalidating...
DataContextDelegate delegate = context.nonNullDelegate();
if (delegate.shouldMergeChanges(object, null)) {
ClassDescriptor descriptor = context.getEntityResolver().getClassDescriptor(oid.getEntityName());
descriptor.visitProperties(new PropertyVisitor() {
@Override
public boolean visitToMany(ToManyProperty property) {
property.invalidate(object);
return true;
}
@Override
public boolean visitToOne(ToOneProperty property) {
if (property.getRelationship().isSourceIndependentFromTargetChange()) {
property.invalidate(object);
}
return true;
}
@Override
public boolean visitAttribute(AttributeProperty property) {
return true;
}
});
delegate.finishedProcessDelete(object);
}
}
}
use of org.apache.cayenne.reflect.PropertyVisitor in project cayenne by apache.
the class CayenneContextChildDiffLoader method arcCreated.
@Override
public void arcCreated(Object nodeId, Object targetNodeId, Object arcId) {
final Persistent source = findObject(nodeId);
final Persistent target = findObject(targetNodeId);
// can result in NULL target here.
if (target == null) {
return;
}
ClassDescriptor descriptor = context.getEntityResolver().getClassDescriptor(((ObjectId) nodeId).getEntityName());
ArcProperty property = (ArcProperty) descriptor.getProperty(arcId.toString());
property.visit(new PropertyVisitor() {
public boolean visitAttribute(AttributeProperty property) {
return false;
}
public boolean visitToMany(ToManyProperty property) {
property.addTargetDirectly(source, target);
return false;
}
public boolean visitToOne(ToOneProperty property) {
property.setTarget(source, target, false);
return false;
}
});
context.propertyChanged(source, (String) arcId, null, target);
}
use of org.apache.cayenne.reflect.PropertyVisitor 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);
}
}
Aggregations