/** * Get a list of all Configurations, excluding the template configuration; if none exist, * return an empty list * * @return List<Map<String, Object>> */ public List<Map<String, Object>> getConfigurations() { final List<Map<String, Object>> graphConfigurations = graph.traversal().V().has(PROPERTY_TEMPLATE, false).valueMap().toList(); return graphConfigurations.stream().map(this::deserializeVertexProperties).collect(Collectors.toList()); }
/** * Get template configuration if exists, else return null. * * @return Map<String, Object> */ public Map<String, Object> getTemplateConfiguration() { final List<Map<String, Object>> templateConfigurations = graph.traversal().V().has(PROPERTY_TEMPLATE, true).valueMap().toList(); if (templateConfigurations.size() == 0) return null; if (templateConfigurations.size() > 1) { log.warn("Your configuration management graph is an a bad state. Please " + "ensure you have just one template configuration. The behavior " + "of the class' APIs are henceforth unpredictable until this is fixed."); } templateConfigurations.get(0).remove(PROPERTY_TEMPLATE); return deserializeVertexProperties(templateConfigurations.get(0)); }
private void assertGeoshape(Function<Geoshape,Geoshape> makeGeoshape) { graph.traversal().E().has("place").toList().forEach(e-> { assertTrue(e.property("shape").isPresent()); Geoshape place = (Geoshape) e.property("place").value(); Geoshape expected = makeGeoshape.apply(place); Geoshape actual = (Geoshape) e.property("shape").value(); assertEquals(expected, actual); }); }
assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices())); assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices())); assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices())); assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices())); g.V().drop().iterate(); assertEquals(2, g.V().has(property, value1).toList().size()); g.V().properties().drop().iterate();
@Test @LoadGraphWith(MODERN) public void shouldLoadVerticesViaVertices() { final List<Vertex> vertices = g.V().toList(); final List<Vertex> verticesReloaded = g.V(vertices.toArray()).toList(); assertEquals(vertices.size(), verticesReloaded.size()); assertEquals(new HashSet<>(vertices), new HashSet<>(verticesReloaded)); }
/** * Get Configuration according to supplied graphName mapped to a specific * {@link Graph}; if does not exist, return null. * * @return Map<String, Object> */ public Map<String, Object> getConfiguration(final String configName) { final List<Map<String, Object>> graphConfiguration = graph.traversal().V().has(PROPERTY_GRAPH_NAME, configName).valueMap().toList(); if (graphConfiguration.isEmpty()) return null; else if (graphConfiguration.size() > 1) { // this case shouldn't happen because our index has a unique constraint log.warn("Your configuration management graph is an a bad state. Please " + "ensure you have just one configuration per graph. The behavior " + "of the class' APIs are henceforth unpredictable until this is fixed."); } return deserializeVertexProperties(graphConfiguration.get(0)); }
@Test @LoadGraphWith(MODERN) public void shouldLoadVerticesViaIds() { final List<Vertex> vertices = g.V().toList(); final List<Object> ids = vertices.stream().map(Vertex::id).collect(Collectors.toList()); final List<Vertex> verticesReloaded = g.V(ids.toArray()).toList(); assertEquals(vertices.size(), verticesReloaded.size()); assertEquals(new HashSet<>(vertices), new HashSet<>(verticesReloaded)); }
@Test @LoadGraphWith(MODERN) public void shouldLoadEdgesViaIds() { final List<Edge> edges = g.E().toList(); final List<Object> ids = edges.stream().map(Edge::id).collect(Collectors.toList()); final List<Edge> edgesReloaded = g.E(ids.toArray()).toList(); assertEquals(edges.size(), edgesReloaded.size()); assertEquals(new HashSet<>(edges), new HashSet<>(edgesReloaded)); }
@Test @LoadGraphWith(MODERN) public void shouldLoadEdgesViaEdges() { final List<Edge> edges = g.E().toList(); final List<Edge> edgesReloaded = g.E(edges.toArray()).toList(); assertEquals(edges.size(), edgesReloaded.size()); assertEquals(new HashSet<>(edges), new HashSet<>(edgesReloaded)); }
public static void query(HugeGraph graph) { // query all vertices System.out.println(">>>> query all vertices"); GraphTraversal<Vertex, Vertex> vertex = graph.traversal().V(); System.out.println(">>>> query all vertices: size=" + vertex.toList().size()); // query all edges GraphTraversal<Edge, Edge> edges = graph.traversal().E(); System.out.println(">>>> query all edges: size=" + edges.toList().size()); // query edges by condition List<Edge> tomhanksMovies = graph.traversal().V() .hasLabel("person") .has("name", "Tom Hanks") .outE("ACTED_IN").toList(); System.out.println(">>>> Tom Hanks ACTED_IN: " + tomhanksMovies); }
@Test public void testRemoveVertexOneByOne() { HugeGraph graph = graph(); init10Vertices(); List<Vertex> vertexes = graph.traversal().V().toList(); Assert.assertEquals(10, vertexes.size()); for (int i = 0; i < vertexes.size(); i++) { vertexes.get(i).remove(); graph.tx().commit(); Assert.assertEquals(9 - i, graph.traversal().V().toList().size()); } }
@Test public void testQueryComplexIndexedPropertyByNotEqualOnePrefix() { HugeGraph graph = graph(); init5Computers(); List<Vertex> vertexes = graph.traversal().V() .has("cpu", "2.8GHz").toList(); Assert.assertEquals(0, vertexes.size()); vertexes = graph.traversal().V().has("cpu", "4.8GHz").toList(); Assert.assertEquals(0, vertexes.size()); }
@Test public void testQuerySingleIndexedPropertyByEqual() { HugeGraph graph = graph(); init5Computers(); List<Vertex> vertexes = graph.traversal().V() .has("band", "lenovo").toList(); Assert.assertEquals(2, vertexes.size()); vertexes = graph.traversal().V().has("band", "apple").toList(); Assert.assertEquals(1, vertexes.size()); }
@Test public void testQueryComplexIndexedPropertyByEqualOnePrefix() { HugeGraph graph = graph(); init5Computers(); List<Vertex> vertexes = graph.traversal().V() .has("cpu", "3.2GHz").toList(); Assert.assertEquals(3, vertexes.size()); vertexes = graph.traversal().V().has("cpu", "4.6GHz").toList(); Assert.assertEquals(1, vertexes.size()); }
@Test public void testQuerySingleIndexedPropertyByNotEqual() { HugeGraph graph = graph(); init5Computers(); List<Vertex> vertexes = graph.traversal().V() .has("band", "acer").toList(); Assert.assertEquals(0, vertexes.size()); vertexes = graph.traversal().V().has("band", "Hp").toList(); Assert.assertEquals(0, vertexes.size()); }