/** * @see GraphTraversal#hasId(Object, Object...) */ public static <A> GraphTraversal<A, A> hasId(final Object id, Object... otherIds) { return __.<A>start().hasId(id, otherIds); }
/** * @see GraphTraversal#hasId(P) */ public static <A> GraphTraversal<A, A> hasId(final P<Object> predicate) { return __.<A>start().hasId(predicate); }
@Override public Traversal<Vertex, Long> get_g_V_hasIdXemptyX_count() { return g.V().hasId(Collections.emptyList()).count(); }
/** * Gets a vertex by its ID from the given graph. * * @param id The vertex ID. * @param graph The graph that holds the vertex with the given ID. * @param g A standard traversal source for the given graph. * @return The vertex with the given ID. */ public default Vertex getVertexById(final Object id, final Graph graph, final GraphTraversalSource g) { return g.V().hasId(id).next(); }
@Override public Traversal<Vertex, Vertex> get_g_VX1X_out_hasIdX2X(final Object v1Id, final Object v2Id) { return g.V(v1Id).out().hasId(v2Id); }
@Override public Traversal<Vertex, Vertex> get_g_VX1X_out_hasIdX2_3X(final Object v1Id, final Object v2Id, final Object v3Id) { return g.V(v1Id).out().hasId(v2Id, v3Id); }
@Override public Traversal<Vertex, Long> get_g_V_hasIdXwithoutXemptyXX_count() { return g.V().hasId(P.without(Collections.emptyList())).count(); }
@Override public Traversal<Vertex, Long> get_g_V_hasIdXwithinXemptyXX_count() { return g.V().hasId(P.within(Collections.emptyList())).count(); }
@Override public Traversal<Vertex, Vertex> get_g_V_in_hasIdXneqX1XX(final Object v1Id) { return g.V().in().hasId(P.neq(v1Id)); }
private Edge getEdge(final Object id1, final Object id2) { return g.V(id1) .bothE().filter(__.otherV().hasId(id2)) .next(); } }
return this.hasId((P) id);
@Test public void testQueryVerticesByIdsWithHasIdFilterAndNumberId() { HugeGraph graph = graph(); SchemaManager schema = graph.schema(); schema.vertexLabel("user").useCustomizeNumberId().create(); graph.addVertex(T.label, "user", T.id, 123); graph.addVertex(T.label, "user", T.id, 456); graph.addVertex(T.label, "user", T.id, 789); graph.tx().commit(); GraphTraversalSource g = graph.traversal(); List<Vertex> vertices; vertices = g.V().hasId(P.within(123)).toList(); Assert.assertEquals(1, vertices.size()); vertices = g.V(123, 456).hasId(P.within(123)).toList(); Assert.assertEquals(1, vertices.size()); vertices = g.V(123, 456).hasId(123).toList(); Assert.assertEquals(1, vertices.size()); vertices = g.V(123, 456, 789).hasId(P.within(123, 456)).toList(); Assert.assertEquals(2, vertices.size()); vertices = g.V(123, 456, 789).hasId(456, 789).toList(); Assert.assertEquals(2, vertices.size()); vertices = g.V(123, 456, 789).hasId(P.within(123, 456, 789)).toList(); Assert.assertEquals(3, vertices.size()); }
/** * {@inheritDoc} */ @Override public Vertex getOrCreateVertex(final Vertex vertex, final Graph graph, final GraphTraversalSource g) { final Iterator<Vertex> iterator = useUserSuppliedIds() ? g.V().hasId(vertex.id()) : g.V().has(vertex.label(), bulkLoaderVertexId, vertex.id().toString()); return iterator.hasNext() ? iterator.next() : useUserSuppliedIds() ? g.addV(vertex.label()).property(T.id, vertex.id()).next() : g.addV(vertex.label()).property(bulkLoaderVertexId, vertex.id().toString()).next(); }
public static List<Path> shortestPath(final HugeGraph graph, Object from, Object to, int maxDepth) { GraphTraversal<Vertex, Path> t = graph.traversal() .V(from) .repeat(__.out().simplePath()) .until(__.hasId(to).or().loops().is(P.gt(maxDepth))) .hasId(to) .path().by("name") .limit(1); return t.toList(); }
/** * @see GraphTraversal#hasId(Object, Object...) */ public static <A> GraphTraversal<A, A> hasId(final Object id, Object... otherIds) { return __.<A>start().hasId(id, otherIds); }
/** * @see GraphTraversal#hasId(P) */ public static <A> GraphTraversal<A, A> hasId(final P<Object> predicate) { return __.<A>start().hasId(predicate); }
private static GraphTraversal<?, ?> matchProperty(final GraphTraversal<?, ?> traversal, final String propertyName, final PropertyType type, final Node object) { switch (propertyName) { case "id": return object.isConcrete() ? traversal.hasId(object.getLiteralValue()) : traversal.id().as(object.getName()); case "label": return object.isConcrete() ? traversal.hasLabel(object.getLiteralValue().toString()) : traversal.label().as(object.getName()); case "key": return object.isConcrete() ? traversal.hasKey(object.getLiteralValue().toString()) : traversal.key().as(object.getName()); case "value": return object.isConcrete() ? traversal.hasValue(object.getLiteralValue().toString()) : traversal.value().as(object.getName()); default: if (type.equals(PropertyType.PROPERTY)) { return traversal.properties(propertyName).as(object.getName()); } else { return object.isConcrete() ? traversal.values(propertyName).is(object.getLiteralValue()) : traversal.values(propertyName).as(object.getName()); } } } }
/** * Gets a vertex by its ID from the given graph. * * @param id The vertex ID. * @param graph The graph that holds the vertex with the given ID. * @param g A standard traversal source for the given graph. * @return The vertex with the given ID. */ public default Vertex getVertexById(final Object id, final Graph graph, final GraphTraversalSource g) { return g.V().hasId(id).next(); }