@Override public Element relate(Element sourceEntity, Element targetEntity, String name, Map<String, Object> properties) { if (name == null) { throw new IllegalArgumentException("name == null"); } if (!(sourceEntity instanceof Vertex)) { throw new IllegalArgumentException("Source not a vertex."); } if (!(targetEntity instanceof Vertex)) { throw new IllegalArgumentException("Target not a vertex."); } Map<String, Object> props = properties == null ? Collections.emptyMap() : properties; Object[] keyValues = asKeyValues(props, __sourceType.name(), sourceEntity.property(__type.name()).value(), __targetType.name(), targetEntity.property(__type.name()).orElse(null), __sourceCp.name(), sourceEntity.property(__cp.name()).orElse(null), __targetCp.name(), targetEntity.property(__cp.name()).orElse(null), __sourceEid.name(), sourceEntity.property(__eid.name()).orElse(null), __targetEid.name(), targetEntity.property(__eid.name()).orElse(null)); Edge e = ((Vertex) sourceEntity).addEdge(name, (Vertex) targetEntity, keyValues); //these need the ID of the edge, so we need to set the props after the edge has been created e.property(__eid.name(), e.id().toString()); e.property(__cp.name(), CanonicalPath.of().relationship(e.id().toString()).get().toString()); return e; }
@Override public void delete(String id) throws RelationNotFoundException { //TODO this doesn't respect the current position in the graph inTx((tx) -> { try { BE relationshipObject = tx.find(CanonicalPath.of().relationship(id).get()); BE source = tx.getRelationshipSource(relationshipObject); BE target = tx.getRelationshipTarget(relationshipObject); String relationshipName = tx.extractRelationshipName(relationshipObject); RelationshipRules.checkDelete(tx, source, Relationships.Direction.outgoing, relationshipName, target); Relationship r = tx.convert(relationshipObject, Relationship.class); tx.delete(relationshipObject); tx.getPreCommit().addNotifications( new EntityAndPendingNotifications<>(relationshipObject, r, deleted())); return null; } catch (ElementNotFoundException e) { throw new RelationNotFoundException(id, Query.filters(context.select().with(RelationWith.id(id)).get())); } }); } }
@Override public void update(String id, Relationship.Update update) throws RelationNotFoundException { //TODO this doesn't respect the current position in the graph inTx(tx -> { try { BE relationshipObject = tx.find(CanonicalPath.of().relationship(id) .get()); tx.update(relationshipObject, update); Relationship r = tx.convert(relationshipObject, Relationship.class); tx.getPreCommit().addNotifications(new EntityAndPendingNotifications<>(relationshipObject, r, new Notification<>(new Action.Update<>(r, update), r, updated()))); return null; } catch (ElementNotFoundException e) { throw new RelationNotFoundException(id, Query.filters(context.select().with(RelationWith.id(id)).get())); } }); }
public Relationship(String id, String name, CanonicalPath source, CanonicalPath target, Map<String, Object> properties) { super(CanonicalPath.of().relationship(id).get(), properties); this.id = id; this.name = name; this.source = source; this.target = target; }
public Relationship(String id, String name, CanonicalPath source, CanonicalPath target, Map<String, Object> properties) { super(CanonicalPath.of().relationship(id).get(), properties); this.id = id; this.name = name; this.source = source; this.target = target; }