final Set<List<Vertex>> set = ReferenceFactory.detach(g.V().hasLabel("software").fold().toSet()); for (final Vertex v : set.iterator().next()) { assertTrue(v instanceof ReferenceVertex);
final Set<List<Vertex>> set = DetachedFactory.detach(g.V().hasLabel("software").fold().toSet(), true); for (final Vertex v : set.iterator().next()) { assertTrue(v instanceof DetachedVertex);
@Override public Set<E> toSet() { return QueryUtils.prepareTerminalOperation(this, true).toSet(); }
@Override public Response getByType(Long executionID, String vertexType, Integer depth, Boolean dedup, String inEdges, String outEdges, Boolean includeInVertices, String blacklistProperties) { List<String> inEdges_ = inEdges == null ? Collections.emptyList() : Arrays.asList(StringUtils.split(inEdges, ',')); List<String> outEdges_ = outEdges == null ? Collections.emptyList() : Arrays.asList(StringUtils.split(outEdges, ',')); List<String> blacklistProperties_ = blacklistProperties == null ? Collections.emptyList() : Arrays.asList(StringUtils.split(blacklistProperties, ',')); GraphContext graphContext = getGraph(executionID); List<Map<String, Object>> vertices = new ArrayList<>(); for (Vertex v : graphContext.getGraph().traversal().V().has(WindupVertexFrame.TYPE_PROP, vertexType).toSet()) { vertices.add(convertToMap(new GraphMarshallingContext(executionID, v, depth, dedup, outEdges_, inEdges_, blacklistProperties_, includeInVertices), v)); } return Response.status(Response.Status.OK).entity(vertices).build(); }
@Override public Set<EObject> toSet() { QueryStepBuilderInternal<S, EObject> finalStep = this.reifyEObjects(); GraphTraversal<S, EObject> traversal = QueryUtils.prepareTerminalOperation(finalStep, true); return traversal.toSet(); }
public Set<Entity> findEntitiesByCollection(Collection collection) { CollectionDescription description = collection.getDescription(); String typeName = description.getEntityTypeName(); String vreName = description.getVreName(); return graphWrapper.getGraph().traversal().V().has(T.label, LabelP.of(DATABASE_LABEL)) .has(ENTITY_TYPE_NAME_PROPERTY_NAME, typeName) .out(HAS_ENTITY_NODE_RELATION_NAME).out(HAS_ENTITY_RELATION_NAME) .toSet().stream().map(v -> new Entity(v, getCollections(v, vreName))) .collect(Collectors.toSet()); }
@Test public void transientVertexDeletionsAreReflectedInGremlinQueries() { ChronoGraph g = this.getGraph(); g.addVertex("name", "martin"); g.addVertex("name", "john"); g.tx().commit(); Vertex me = g.traversal().V().has("name", "martin").toSet().iterator().next(); assertNotNull(me); me.remove(); // assert that the query no longer returns "me", even before committing the operation assertTrue("Transient vertex deletions are ignored by gremlin query!", g.traversal().V().has("name", "martin").toSet().isEmpty()); }
private Set<Collection> getCollections(Vertex foundVertex, String vreName) { return traversal() .V(foundVertex.id()) .in(HAS_ENTITY_RELATION_NAME) .in(HAS_ENTITY_NODE_RELATION_NAME) .where( __.in(Vre.HAS_COLLECTION_RELATION_NAME) .has(Vre.VRE_NAME_PROPERTY_NAME, vreName) ).map(collectionT -> { return new Collection(vreName, collectionT.get(), graphWrapper); }).toSet(); }
@Test public void transientEdgeDeletionsAreReflectedInGremlinQueries() { ChronoGraph g = this.getGraph(); Vertex me = g.addVertex("name", "martin"); Vertex john = g.addVertex("name", "john"); me.addEdge("friend", john, "since", "forever"); g.tx().commit(); Edge e = g.traversal().E().has("since", "forever").toSet().iterator().next(); assertNotNull(e); e.remove(); // assert that the query no longer returns the edge, even before committing the operation assertTrue("Transient edge deletions are ignored by gremlin query!", g.traversal().E().has("since", "forever").toSet().isEmpty()); }
@Test public void removingVertexPropertiesWorks() { Graph g = this.getGraph(); g.addVertex("kind", "person", "name", "martin"); g.tx().commit(); Vertex me = g.traversal().V().has("name", "martin").toSet().iterator().next(); assertNotNull(me); me.property("kind").remove(); g.tx().commit(); Vertex me2 = g.traversal().V().has("name", "martin").toSet().iterator().next(); assertNotNull(me2); assertFalse(me2.property("kind").isPresent()); }
@Test public void multipleHasClausesWorksOnNonIndexedVertexProperty() { ChronoGraph graph = this.getGraph(); Vertex vExpected = graph.addVertex("kind", "person", "name", "Martin"); graph.addVertex("kind", "person", "name", "Thomas"); graph.addVertex("kind", "project", "name", "Chronos"); graph.addVertex("kind", "project", "name", "Martin"); // multiple HAS clauses need to be AND-connected. Set<Vertex> result = graph.traversal().V().has("name", "Martin").has("kind", "person").toSet(); assertEquals(1, result.size()); assertTrue(result.contains(vExpected)); graph.tx().commit(); result = graph.traversal().V().has("name", "Martin").has("kind", "person").toSet(); assertEquals(1, result.size()); assertTrue(result.contains(vExpected)); }
@Test public void queryToGremlinSyntaxTest() { ChronoGraph g = this.getGraph(); Set<Edge> set = g.find().vertices().where("name").containsIgnoreCase("EVA").toTraversal().outE().toSet(); assertNotNull(set); assertTrue(set.isEmpty()); }
private static void assertFirstNameCountEquals(final ChronoGraph graph, final String firstName, final int count) { assertEquals(count, graph.find().vertices().where(P_FIRST_NAME).isEqualTo(firstName).count()); assertEquals(count, graph.traversal().V().has(P_FIRST_NAME, firstName).toSet().size()); }
private static void assertLastNameCountEquals(final ChronoGraph graph, final String lastName, final int count) { assertEquals(count, graph.find().vertices().where(P_LAST_NAME).isEqualTo(lastName).count()); assertEquals(count, graph.traversal().V().has(P_LAST_NAME, lastName).toSet().size()); }
@Test public void basicVertexRetrievalWorks() { ChronoGraph graph = this.getGraph(); graph.addVertex("name", "Martin", "age", 26); graph.addVertex("name", "Martin", "age", 10); graph.addVertex("name", "John", "age", 26); graph.tx().commit(); Set<Vertex> vertices = graph.traversal().V().has("name", "Martin").has("age", 26).toSet(); assertEquals(1, vertices.size()); Vertex vertex = Iterables.getOnlyElement(vertices); assertEquals("Martin", vertex.value("name")); assertEquals(26, (int) vertex.value("age")); }
@Test public void basicEgdeRetrievalWorks() { ChronoGraph graph = this.getGraph(); Vertex me = graph.addVertex("kind", "person", "name", "Martin"); Vertex chronos = graph.addVertex("kind", "project", "name", "Chronos"); Vertex otherProject = graph.addVertex("kind", "project", "name", "Other Project"); me.addEdge("worksOn", chronos, "since", "2015-07-30"); me.addEdge("worksOn", otherProject, "since", "2000-01-01"); graph.tx().commit(); Set<Edge> edges = graph.traversal().E().has("since", "2015-07-30").toSet(); assertEquals(1, edges.size()); }
@Test public void canQueryNonStandardObjectTypeInHasClause() { ChronoGraph graph = this.getGraph(); graph.addVertex("name", new FullName("John", "Doe")); graph.addVertex("name", new FullName("Jane", "Doe")); graph.tx().commit(); assertEquals(1, graph.traversal().V().has("name", new FullName("John", "Doe")).toSet().size()); }
@Test public void canFindStringWithLeadingWhitespace() { ChronoGraph graph = this.getGraph(); graph.getIndexManager().create().stringIndex().onVertexProperty("name").build(); graph.addVertex("name", " John"); graph.addVertex("name", "John"); graph.tx().commit(); assertEquals(" John", Iterables.getOnlyElement(graph.traversal().V().has("name", " John").toSet()).value("name")); }
@Test public void canFindStringWithTrailingWhitespace() { ChronoGraph graph = this.getGraph(); graph.getIndexManager().create().stringIndex().onVertexProperty("name").build(); graph.addVertex("name", "John "); graph.addVertex("name", "John"); graph.tx().commit(); assertEquals("John ", Iterables.getOnlyElement(graph.traversal().V().has("name", "John ").toSet()).value("name")); }
@Test public void indexCreationWorks() { ChronoGraph g = this.getGraph(); ChronoGraphIndex index = g.getIndexManager().create().stringIndex().onVertexProperty("name").build(); assertNotNull(index); g.tx().commit(); Vertex v = g.addVertex("name", "Martin"); g.addVertex("name", "John"); g.addVertex("name", "Martina"); g.tx().commit(); // find by case-insensitive search assertEquals(v, Iterables.getOnlyElement(g.traversal().V().has("name", "Martin").toSet())); }