public static boolean canIncorporate(CanonicalPath entityPath) { SegmentType entityType = entityPath.getSegment().getElementType(); SegmentType parentType = entityPath.up().getSegment().getElementType(); return SegmentType.t.equals(parentType) && (SegmentType.rt.equals(entityType) || SegmentType.mt.equals(entityType)); }
public static boolean canIncorporate(CanonicalPath entityPath) { SegmentType entityType = entityPath.getSegment().getElementType(); SegmentType parentType = entityPath.up().getSegment().getElementType(); return SegmentType.t.equals(parentType) && (SegmentType.rt.equals(entityType) || SegmentType.mt.equals(entityType)); }
/** * Constructs a new entity * * @param name the human readable name of the entity, can be null * @param path the path of the entity, must not be null * @param properties the additional user-defined properties, can be null */ Entity(String name, CanonicalPath path, Map<String, Object> properties) { super(path, properties); this.name = name; if (!segmentTypeFromType(this.getClass()).equals(path.getSegment().getElementType())) { throw new IllegalArgumentException("Invalid path specified. Trying to create " + this.getClass().getSimpleName() + " but the path points to " + path.getSegment().getElementType().getSimpleName()); } }
/** * Constructs a new entity * * @param name the human readable name of the entity, can be null * @param path the path of the entity, must not be null * @param properties the additional user-defined properties, can be null */ Entity(String name, CanonicalPath path, Map<String, Object> properties) { super(path, properties); this.name = name; if (!segmentTypeFromType(this.getClass()).equals(path.getSegment().getElementType())) { throw new IllegalArgumentException("Invalid path specified. Trying to create " + this.getClass().getSimpleName() + " but the path points to " + path.getSegment().getElementType().getSimpleName()); } }
TraversalContext<BE, E> proceedTo(Path path) { if (!AbstractElement.segmentTypeFromType(entityClass).equals(path.getSegment().getElementType())) { throw new IllegalArgumentException("Path doesn't point to the type of element currently being accessed."); } return replacePath(Util.extendTo(this, path)); }
if (!SegmentType.r.equals(p.getSegment().getElementType())) { throw new IllegalArgumentException("Descend can only traverse child resources.");
private void convertToPipeline(RelativePath path, GraphTraversal<?, ?> pipeline) { for (Path.Segment s : path.getPath()) { if (SegmentType.up.equals(s.getElementType())) { pipeline.in(Relationships.WellKnown.contains.name()); } else { pipeline.out(Relationships.WellKnown.contains.name()) .hasLabel(Constants.Type.of(s.getElementType()).name()); apply(s, pipeline); } } }
@Override public Element find(CanonicalPath path) throws ElementNotFoundException { Iterator<? extends Element> it; if (SegmentType.rl.equals(path.getSegment().getElementType())) { //__eid is globally unique for relationships it = context.getGraph().traversal().E().has(__eid.name(), path.getSegment().getElementId()); } else { it = context.getGraph().traversal().V() .hasLabel(Constants.Type.of(path.getSegment().getElementType()).name()) .has(__cp.name(), path.toString()); } if (!it.hasNext()) { throw new ElementNotFoundException(); } return it.next(); }
@SuppressWarnings("unchecked") public void visit(GraphTraversal<?, ?> query, With.DataAt dataPos, QueryTranslationState state) { goBackFromEdges(query, state); query.out(hasData.name()); for (Path.Segment seg : dataPos.getDataPath().getPath()) { if (SegmentType.up.equals(seg.getElementType())) { query.in(contains.name()); } else { query.out(contains.name()); } query.has(__type.name(), Constants.Type.structuredData.name()); // map members have both index and key (so that the order of the elements is preserved) // list members have only the index Integer index = toInteger(seg.getElementId()); if (index == null) { query.has(Constants.Property.__structuredDataKey.name(), seg.getElementId()); } else { //well, the map could have a numeric key, so we cannot say it has to be a list index here. GraphTraversal<?, ?>[] indexOrKey = new GraphTraversal<?, ?>[2]; indexOrKey[0] = __.has(Constants.Property.__structuredDataIndex.name(), index) .hasNot(Constants.Property.__structuredDataKey.name()); indexOrKey[1] = __.has(Constants.Property.__structuredDataKey.name(), seg.getElementId()); query.or((Traversal[]) indexOrKey); } } }