use of org.apache.cayenne.reflect.ArcProperty 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.ArcProperty in project cayenne by apache.
the class CayenneContextGraphManager method remapTargets.
/**
* Remaps keys in to-many map relationships that contain dirty objects with
* potentially modified properties.
*/
private void remapTargets() {
Iterator<Object> it = stateLog.dirtyIds().iterator();
EntityResolver resolver = context.getEntityResolver();
while (it.hasNext()) {
ObjectId id = (ObjectId) it.next();
ClassDescriptor descriptor = resolver.getClassDescriptor(id.getEntityName());
Collection<ArcProperty> mapArcProperties = descriptor.getMapArcProperties();
if (!mapArcProperties.isEmpty()) {
Object object = getNode(id);
for (ArcProperty arc : mapArcProperties) {
ToManyMapProperty reverseArc = (ToManyMapProperty) arc.getComplimentaryReverseArc();
Object source = arc.readPropertyDirectly(object);
if (source != null && !reverseArc.isFault(source)) {
remapTarget(reverseArc, source, object);
}
}
}
}
}
use of org.apache.cayenne.reflect.ArcProperty in project cayenne by apache.
the class CayenneContextMergeHandler method arcDeleted.
public void arcDeleted(Object nodeId, Object targetNodeId, Object arcId) {
// null source or target likely means the object is not faulted yet... Faults
// shouldn't get disturbed by adding/removing arcs
Object source = context.internalGraphManager().getNode(nodeId);
if (source == null) {
// no need to disconnect non-existent object
return;
}
// (see "TODO" in 'arcCreated')
ArcProperty p = (ArcProperty) propertyForId(nodeId, arcId.toString());
if (p.isFault(source)) {
return;
}
Object target = context.internalGraphManager().getNode(targetNodeId);
if (target == null) {
target = context.createFault((ObjectId) targetNodeId);
}
if (p instanceof ToManyProperty) {
((ToManyProperty) p).removeTargetDirectly(source, target);
} else {
p.writePropertyDirectly(source, target, null);
}
}
Aggregations