private void fillReverseRelationship(Object destinationTarget, ArcProperty property) { ArcProperty clientProperty = (ArcProperty) targetDescriptor.getProperty(property.getName()); if (clientProperty != null) { ArcProperty clientReverse = clientProperty.getComplimentaryReverseArc(); if (clientReverse instanceof ToOneProperty) { clientReverse.writeProperty(destinationTarget, null, target); } } }
private void connect(Persistent object, List<Persistent> related) { if (incoming.getRelationship().isToMany()) { ValueHolder toManyList = (ValueHolder) incoming.readProperty(object); // TODO, Andrus 11/15/2005 - if list is modified, shouldn't we attempt to // merge the changes instead of overwriting? toManyList.setValueDirectly(related != null ? related : new ArrayList(1)); } else { // this should've been handled elsewhere throw new CayenneRuntimeException("To-one relationship wasn't handled properly: %s", incoming.getName()); } }
@Override public boolean visitIdentificationVariable(EJBQLExpression expression) { PropertyDescriptor property = descriptor.getProperty(expression.getText()); if (property instanceof ArcProperty) { incoming = ((ArcProperty) property).getRelationship(); descriptor = ((ArcProperty) property).getTargetDescriptor(); } else { throw new EJBQLException("Incorrect relationship path: " + expression.getText()); } return true; }
private void clearNullRelationships(List<Persistent> parentObjects) { for (Persistent object : parentObjects) { if (incoming.readPropertyDirectly(object) instanceof Fault) { incoming.writePropertyDirectly(object, null, null); } } }
static void unsetReverse(final Persistent sourceObject, String propertyName, final Persistent targetObject) { ArcProperty property = (ArcProperty) Cayenne.getClassDescriptor(sourceObject).getProperty(propertyName); ArcProperty reverseArc = property.getComplimentaryReverseArc(); if (reverseArc != null) { reverseArc.visit(new PropertyVisitor() { public boolean visitToMany(ToManyProperty property) { property.removeTargetDirectly(targetObject, sourceObject); return false; } public boolean visitToOne(ToOneProperty property) { property.setTarget(targetObject, null, false); return false; } public boolean visitAttribute(AttributeProperty property) { return false; } }); sourceObject.getObjectContext().getGraphManager() .arcDeleted(targetObject.getObjectId(), sourceObject.getObjectId(), reverseArc.getName()); markAsDirty(targetObject); } }
/** * Returns a non-null relationship object for this query. */ public ObjRelationship getRelationship(EntityResolver resolver) { updateMetadata(resolver); return arc.getRelationship(); }
/** * Checks if an object has its to-one relationship target modified in memory. */ static boolean isToOneTargetModified( ArcProperty property, Persistent object, ObjectDiff diff) { if (object.getPersistenceState() != PersistenceState.MODIFIED || diff == null) { return false; } if (property.isFault(object)) { return false; } Persistent toOneTarget = (Persistent) property.readPropertyDirectly(object); ObjectId currentId = (toOneTarget != null) ? toOneTarget.getObjectId() : null; // if ObjectId is temporary, target is definitely modified... // this would cover NEW objects (what are the other cases of temp id??) if (currentId != null && currentId.isTemporary()) { return true; } if (!diff.containsArcSnapshot(property.getName())) { return false; } ObjectId targetId = diff.getArcSnapshotValue(property.getName()); return !Util.nullSafeEquals(currentId, targetId); }
ObjRelationship relationship = property.getRelationship(); if (relationship.isFlattened()) { } else if (property.getComplimentaryReverseArc() == null) { String arc = ASTDbPath.DB_PREFIX + property.getComplimentaryReverseDbRelationshipPath(); ArcOperation complimentartyOp = new ArcOperation(targetId, arcDiff.getNodeId(), arc, arcDiff.isDelete());
final Collection<Persistent> relatedObjects = toCollection(property.readProperty(object)); break; case DeleteRule.NULLIFY: ArcProperty reverseArc = property.getComplimentaryReverseArc(); reverseArc.visit(new PropertyVisitor() {
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); } try { if (p instanceof ToManyProperty) { ((ToManyProperty) p).removeTargetDirectly(source, target); } else { p.writePropertyDirectly(source, target, null); } } finally { } }
/** * 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); } } } } }
.getProperty(relationshipQuery.getRelationshipName()); if (!property.isFault(object)) { Object related = property.readPropertyDirectly(object);
ToManyMapProperty reverseArc = (ToManyMapProperty) arc.getComplimentaryReverseArc(); Object source = arc.readProperty(object); if (source != null && !reverseArc.isFault(source)) { remapTarget(reverseArc, source, object);
@Override public ClassDescriptor getClassDescriptor() { return arc.getTargetDescriptor(); }
@Override public String toString() { String label = incoming != null ? incoming.getName() : "<root>"; return new ToStringBuilder(this).append("incoming", label).append( "phantom", phantom).toString(); }
static void setReverse(final Persistent sourceObject, String propertyName, final Persistent targetObject) { ArcProperty property = (ArcProperty) Cayenne.getClassDescriptor(sourceObject).getProperty(propertyName); ArcProperty reverseArc = property.getComplimentaryReverseArc(); if (reverseArc != null) { reverseArc.visit(new PropertyVisitor() { public boolean visitToMany(ToManyProperty property) { property.addTargetDirectly(targetObject, sourceObject); return false; } public boolean visitToOne(ToOneProperty property) { property.setTarget(targetObject, sourceObject, false); return false; } public boolean visitAttribute(AttributeProperty property) { return false; } }); sourceObject.getObjectContext().getGraphManager() .arcCreated(targetObject.getObjectId(), sourceObject.getObjectId(), reverseArc.getName()); markAsDirty(targetObject); } }
private boolean visitRelationship(ArcProperty arc) { DbRelationship dbRel = arc.getRelationship().getDbRelationships().get(0); for (DbAttribute attribute : dbRel.getSourceAttributes()) { String target = attribute.getName(); appendColumn(targetSource, target, prefix + target); } return true; } });
public void arcCreated(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 connect non-existent object return; } // TODO (Andrus, 10/17/2005) - check for local modifications to avoid // overwriting... 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); } try { if (p instanceof ToManyProperty) { ((ToManyProperty) p).addTargetDirectly(source, target); } else { p.writePropertyDirectly(source, null, target); } } finally { } }
@Override public void arcCreated(Object nodeId, Object targetNodeId, Object arcId) { final Persistent source = findObject(nodeId); final Persistent target = findObject(targetNodeId); // if a target was later deleted, the diff for arcCreated is still preserved and // 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); }