Java Code Examples for com.tinkerpop.blueprints.Graph#getVertex()
The following examples show how to use
com.tinkerpop.blueprints.Graph#getVertex() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FunctionExportPlugin.java From bjoern with GNU General Public License v3.0 | 6 votes |
private static void copyEdge(Graph graph, Edge edge) { Object id = edge.getId(); if (graph.getEdge(id) != null) { return; } Vertex src = graph.getVertex(edge.getVertex(Direction.OUT).getId()); Vertex dst = graph.getVertex(edge.getVertex(Direction.IN).getId()); if (src != null && dst != null) { Edge e = GraphHelper.addEdge(graph, id, src, dst, edge.getLabel()); if (e != null) { ElementHelper.copyProperties(edge, e); } } }
Example 2
Source File: ElementPropertyCachingTest.java From AccumuloGraph with Apache License 2.0 | 6 votes |
@Test public void testPreloadAllProperties() { AccumuloGraphConfiguration cfg = AccumuloGraphTestUtils.generateGraphConfig("preloadAllProperties"); cfg.setPropertyCacheTimeout(null, TIMEOUT); cfg.setPreloadAllProperties(true); Graph graph = open(cfg); AccumuloVertex v = (AccumuloVertex) graph.addVertex("V"); v.setProperty(NON_CACHED, true); v.setProperty(CACHED, true); v = (AccumuloVertex) graph.getVertex("V"); assertEquals(true, v.getPropertyInMemory(NON_CACHED)); assertEquals(true, v.getPropertyInMemory(CACHED)); graph.shutdown(); }
Example 3
Source File: ElementPropertyCachingTest.java From AccumuloGraph with Apache License 2.0 | 6 votes |
@Test public void testPreloadSomeProperties() { AccumuloGraphConfiguration cfg = AccumuloGraphTestUtils.generateGraphConfig("preloadSomeProperties"); cfg.setPropertyCacheTimeout(null, TIMEOUT); cfg.setPreloadedProperties(new String[]{CACHED}); Graph graph = open(cfg); AccumuloVertex v = (AccumuloVertex) graph.addVertex("V"); v.setProperty(NON_CACHED, true); v.setProperty(CACHED, true); v = (AccumuloVertex) graph.getVertex("V"); assertEquals(null, v.getPropertyInMemory(NON_CACHED)); assertEquals(true, v.getPropertyInMemory(CACHED)); graph.shutdown(); }
Example 4
Source File: NodeProcessor.java From bjoern with GNU General Public License v3.0 | 5 votes |
private void linkToPreviousNode(String baseId, int num) { String previousId = createCompleteId(baseId, num - 1); String thisId = createCompleteId(baseId, num); Graph graph = importer.getGraph(); Vertex fromNode = graph.getVertex(previousId); Vertex toNode = graph.getVertex(thisId); graph.addEdge(0, fromNode, toNode, "foo"); }
Example 5
Source File: FunctionExportPlugin.java From bjoern with GNU General Public License v3.0 | 5 votes |
private static void copyVertex(Graph graph, Vertex vertex) { Object id = vertex.getId(); if (graph.getVertex(id) != null) { return; } Vertex v = GraphHelper.addVertex(graph, id); if (v != null) { ElementHelper.copyProperties(vertex, v); } }
Example 6
Source File: ExtendedElementTest.java From AccumuloGraph with Apache License 2.0 | 5 votes |
@Test public void testSkipExistenceChecks() throws Exception { AccumuloGraphConfiguration cfg = AccumuloGraphTestUtils.generateGraphConfig("skipExistenceChecks"); cfg.setSkipExistenceChecks(true); Graph graph = makeGraph(cfg); String id; id = "doubleAdd"; assertNotNull(graph.addVertex(id)); assertNotNull(graph.addVertex(id)); Vertex vAdd = graph.getVertex(id); assertNotNull(vAdd); graph.removeVertex(vAdd); assertNotNull(graph.getVertex(id)); id = "doubleRemove"; Vertex vRemove = graph.addVertex(id); assertNotNull(vRemove); graph.removeVertex(vRemove); assertNotNull(graph.getVertex(id)); // MDL 24 Dec 2014: removeVertex still does checks. //graph.removeVertex(vRemove); //assertNotNull(graph.getVertex(id)); id = "notExist"; assertNotNull(graph.getVertex(id)); graph.shutdown(); }
Example 7
Source File: GraphHelper.java From org.openntf.domino with Apache License 2.0 | 5 votes |
/** * Copy the vertex/edges of one graph over to another graph. * The id of the elements in the from graph are attempted to be used in the to graph. * This method only works for graphs where the user can control the element ids. * * @param from the graph to copy from * @param to the graph to copy to */ public static void copyGraph(final Graph from, final Graph to) { for (final Vertex fromVertex : from.getVertices()) { final Vertex toVertex = to.addVertex(fromVertex.getId()); ElementHelper.copyProperties(fromVertex, toVertex); } for (final Edge fromEdge : from.getEdges()) { final Vertex outVertex = to.getVertex(fromEdge.getVertex(Direction.OUT).getId()); final Vertex inVertex = to.getVertex(fromEdge.getVertex(Direction.IN).getId()); final Edge toEdge = to.addEdge(fromEdge.getId(), outVertex, inVertex, fromEdge.getLabel()); ElementHelper.copyProperties(fromEdge, toEdge); } }
Example 8
Source File: EdgeProcessor.java From bjoern with GNU General Public License v3.0 | 4 votes |
protected Vertex lookupVertex(String id, Graph batchGraph) { return batchGraph.getVertex(id); }
Example 9
Source File: ElementPropertyCachingTest.java From AccumuloGraph with Apache License 2.0 | 4 votes |
@Test public void testCachingDisabled() { AccumuloGraphConfiguration cfg = AccumuloGraphTestUtils.generateGraphConfig("cachingDisabled"); assertTrue(cfg.getPropertyCacheTimeout(null) <= 0); assertTrue(cfg.getPropertyCacheTimeout(NON_CACHED) <= 0); assertTrue(cfg.getPropertyCacheTimeout(CACHED) <= 0); Graph graph = open(cfg); load(graph); AccumuloVertex a = (AccumuloVertex) graph.getVertex("A"); AccumuloVertex b = (AccumuloVertex) graph.getVertex("B"); AccumuloVertex c = (AccumuloVertex) graph.getVertex("C"); assertEquals(null, a.getProperty(NON_CACHED)); assertEquals(true, b.getProperty(NON_CACHED)); assertEquals(null, c.getProperty(NON_CACHED)); assertEquals(null, a.getProperty(CACHED)); assertEquals(null, b.getProperty(CACHED)); assertEquals(true, c.getProperty(CACHED)); assertEquals(null, a.getPropertyCache().get(NON_CACHED)); assertEquals(null, b.getPropertyCache().get(NON_CACHED)); assertEquals(null, c.getPropertyCache().get(NON_CACHED)); assertEquals(null, a.getPropertyCache().get(CACHED)); assertEquals(null, b.getPropertyCache().get(CACHED)); assertEquals(null, c.getPropertyCache().get(CACHED)); assertEquals(Sets.newHashSet(), a.getPropertyCache().keySet()); assertEquals(Sets.newHashSet(), b.getPropertyCache().keySet()); assertEquals(Sets.newHashSet(), c.getPropertyCache().keySet()); a.removeProperty(NON_CACHED); b.removeProperty(NON_CACHED); c.removeProperty(NON_CACHED); a.removeProperty(CACHED); b.removeProperty(CACHED); c.removeProperty(CACHED); assertEquals(null, a.getProperty(NON_CACHED)); assertEquals(null, b.getProperty(NON_CACHED)); assertEquals(null, c.getProperty(NON_CACHED)); assertEquals(null, a.getProperty(CACHED)); assertEquals(null, b.getProperty(CACHED)); assertEquals(null, c.getProperty(CACHED)); assertEquals(null, a.getPropertyCache().get(NON_CACHED)); assertEquals(null, b.getPropertyCache().get(NON_CACHED)); assertEquals(null, c.getPropertyCache().get(NON_CACHED)); assertEquals(null, a.getPropertyCache().get(CACHED)); assertEquals(null, b.getPropertyCache().get(CACHED)); assertEquals(null, c.getPropertyCache().get(CACHED)); assertEquals(Sets.newHashSet(), a.getPropertyCache().keySet()); assertEquals(Sets.newHashSet(), b.getPropertyCache().keySet()); assertEquals(Sets.newHashSet(), c.getPropertyCache().keySet()); graph.shutdown(); }
Example 10
Source File: ElementPropertyCachingTest.java From AccumuloGraph with Apache License 2.0 | 4 votes |
@Test public void testSpecificCaching() { AccumuloGraphConfiguration cfg = AccumuloGraphTestUtils.generateGraphConfig("getProperty"); cfg.setPropertyCacheTimeout(CACHED, TIMEOUT); assertTrue(cfg.getPropertyCacheTimeout(null) <= 0); assertTrue(cfg.getPropertyCacheTimeout(NON_CACHED) <= 0); assertEquals(TIMEOUT, cfg.getPropertyCacheTimeout(CACHED)); Graph graph = open(cfg); load(graph); AccumuloVertex a = (AccumuloVertex) graph.getVertex("A"); AccumuloVertex b = (AccumuloVertex) graph.getVertex("B"); AccumuloVertex c = (AccumuloVertex) graph.getVertex("C"); assertEquals(null, a.getProperty(NON_CACHED)); assertEquals(true, b.getProperty(NON_CACHED)); assertEquals(null, c.getProperty(NON_CACHED)); assertEquals(null, a.getProperty(CACHED)); assertEquals(null, b.getProperty(CACHED)); assertEquals(true, c.getProperty(CACHED)); assertEquals(null, a.getPropertyCache().get(NON_CACHED)); assertEquals(null, b.getPropertyCache().get(NON_CACHED)); assertEquals(null, c.getPropertyCache().get(NON_CACHED)); assertEquals(null, a.getPropertyCache().get(CACHED)); assertEquals(null, b.getPropertyCache().get(CACHED)); assertEquals(true, c.getPropertyCache().get(CACHED)); assertEquals(Sets.newHashSet(), a.getPropertyCache().keySet()); assertEquals(Sets.newHashSet(), b.getPropertyCache().keySet()); assertEquals(Sets.newHashSet(CACHED), c.getPropertyCache().keySet()); a.removeProperty(NON_CACHED); b.removeProperty(NON_CACHED); c.removeProperty(NON_CACHED); a.removeProperty(CACHED); b.removeProperty(CACHED); c.removeProperty(CACHED); assertEquals(null, a.getProperty(NON_CACHED)); assertEquals(null, b.getProperty(NON_CACHED)); assertEquals(null, c.getProperty(NON_CACHED)); assertEquals(null, a.getProperty(CACHED)); assertEquals(null, b.getProperty(CACHED)); assertEquals(null, c.getProperty(CACHED)); assertEquals(null, a.getPropertyCache().get(NON_CACHED)); assertEquals(null, b.getPropertyCache().get(NON_CACHED)); assertEquals(null, c.getPropertyCache().get(NON_CACHED)); assertEquals(null, a.getPropertyCache().get(CACHED)); assertEquals(null, b.getPropertyCache().get(CACHED)); assertEquals(null, c.getPropertyCache().get(CACHED)); assertEquals(Sets.newHashSet(), a.getPropertyCache().keySet()); assertEquals(Sets.newHashSet(), b.getPropertyCache().keySet()); assertEquals(Sets.newHashSet(), c.getPropertyCache().keySet()); graph.shutdown(); }
Example 11
Source File: ElementPropertyCachingTest.java From AccumuloGraph with Apache License 2.0 | 4 votes |
@Test public void testAllCaching() { AccumuloGraphConfiguration cfg = AccumuloGraphTestUtils.generateGraphConfig("setProperty"); cfg.setPropertyCacheTimeout(null, TIMEOUT); cfg.setPropertyCacheTimeout(CACHED, TIMEOUT); assertEquals(TIMEOUT, cfg.getPropertyCacheTimeout(null)); assertEquals(TIMEOUT, cfg.getPropertyCacheTimeout(NON_CACHED)); assertEquals(TIMEOUT, cfg.getPropertyCacheTimeout(CACHED)); Graph graph = open(cfg); load(graph); AccumuloVertex a = (AccumuloVertex) graph.getVertex("A"); AccumuloVertex b = (AccumuloVertex) graph.getVertex("B"); AccumuloVertex c = (AccumuloVertex) graph.getVertex("C"); assertEquals(null, a.getProperty(NON_CACHED)); assertEquals(true, b.getProperty(NON_CACHED)); assertEquals(null, c.getProperty(NON_CACHED)); assertEquals(null, a.getProperty(CACHED)); assertEquals(null, b.getProperty(CACHED)); assertEquals(true, c.getProperty(CACHED)); assertEquals(null, a.getPropertyCache().get(NON_CACHED)); assertEquals(true, b.getPropertyCache().get(NON_CACHED)); assertEquals(null, c.getPropertyCache().get(NON_CACHED)); assertEquals(null, a.getPropertyCache().get(CACHED)); assertEquals(null, b.getPropertyCache().get(CACHED)); assertEquals(true, c.getPropertyCache().get(CACHED)); assertEquals(Sets.newHashSet(), a.getPropertyCache().keySet()); assertEquals(Sets.newHashSet(NON_CACHED), b.getPropertyCache().keySet()); assertEquals(Sets.newHashSet(CACHED), c.getPropertyCache().keySet()); a.removeProperty(NON_CACHED); b.removeProperty(NON_CACHED); c.removeProperty(NON_CACHED); a.removeProperty(CACHED); b.removeProperty(CACHED); c.removeProperty(CACHED); assertEquals(null, a.getProperty(NON_CACHED)); assertEquals(null, b.getProperty(NON_CACHED)); assertEquals(null, c.getProperty(NON_CACHED)); assertEquals(null, a.getProperty(CACHED)); assertEquals(null, b.getProperty(CACHED)); assertEquals(null, c.getProperty(CACHED)); assertEquals(null, a.getPropertyCache().get(NON_CACHED)); assertEquals(null, b.getPropertyCache().get(NON_CACHED)); assertEquals(null, c.getPropertyCache().get(NON_CACHED)); assertEquals(null, a.getPropertyCache().get(CACHED)); assertEquals(null, b.getPropertyCache().get(CACHED)); assertEquals(null, c.getPropertyCache().get(CACHED)); assertEquals(Sets.newHashSet(), a.getPropertyCache().keySet()); assertEquals(Sets.newHashSet(), b.getPropertyCache().keySet()); assertEquals(Sets.newHashSet(), c.getPropertyCache().keySet()); graph.shutdown(); }