public static void assertGraphOfTheGods(JanusGraph graphOfTheGods) { assertCount(12, graphOfTheGods.query().vertices()); assertCount(3, graphOfTheGods.query().has(LABEL_NAME, "god").vertices()); final JanusGraphVertex h = getOnlyVertex(graphOfTheGods.query().has("name", "hercules")); assertEquals(30, h.<Integer>value("age").intValue()); assertEquals("demigod", h.label()); assertCount(5, h.query().direction(Direction.BOTH).edges()); graphOfTheGods.tx().commit(); }
@Test public void testOrForceIndexPartialIndex() throws Exception { JanusGraph customGraph = null; try { customGraph = this.getForceIndexGraph(); final JanusGraphManagement management = customGraph.openManagement(); final PropertyKey stringProperty = management.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make(); management.makePropertyKey("age").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); management.buildIndex("oridx", Vertex.class).addKey(stringProperty, getStringMapping()).buildMixedIndex(INDEX); management.commit(); customGraph.tx().commit(); final GraphTraversalSource g = customGraph.traversal(); g.addV().property("name", "Hiro").property("age", 2).next(); g.addV().property("name", "Totoro").property("age", 1).next(); customGraph.tx().commit(); g.V().or(__.has("name", "Totoro"),__.has("age", 2)).hasNext(); fail("should fail"); } catch (final JanusGraphException e){ assertTrue(e.getMessage().contains("Could not find a suitable index to answer graph query and graph scans are disabled")); } finally { if (customGraph != null) { JanusGraphFactory.close(customGraph); } } }
@Test public void testOrForceIndexComposite() throws Exception { JanusGraph customGraph = null; try { customGraph = this.getForceIndexGraph(); final JanusGraphManagement management = customGraph.openManagement(); management.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make(); final PropertyKey ageProperty = management.makePropertyKey("age").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); management.buildIndex("ageridx", Vertex.class).addKey(ageProperty).buildCompositeIndex(); management.commit(); customGraph.tx().commit(); final GraphTraversalSource g = customGraph.traversal(); g.addV().property("name", "Hiro").property("age", 2).next(); g.addV().property("name", "Totoro").property("age", 1).next(); customGraph.tx().commit(); g.V().has("age", P.gte(4).or(P.lt(2))).hasNext(); fail("should fail"); } catch (final JanusGraphException e){ assertTrue(e.getMessage().contains("Could not find a suitable index to answer graph query and graph scans are disabled")); } finally { if (customGraph != null) { JanusGraphFactory.close(customGraph); } } } }
@Test public void testOrForceIndexUniqueMixedIndex() throws Exception { JanusGraph customGraph = null; try { customGraph = this.getForceIndexGraph(); final JanusGraphManagement management = customGraph.openManagement(); final PropertyKey nameProperty = management.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make(); final PropertyKey ageProperty = management.makePropertyKey("age").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); final PropertyKey lengthProperty = management.makePropertyKey("length").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); management.buildIndex("oridx", Vertex.class).addKey(nameProperty, getStringMapping()).addKey(ageProperty).addKey(lengthProperty).buildMixedIndex(INDEX); management.commit(); customGraph.tx().commit(); testOr(customGraph); } finally { if (customGraph != null) { JanusGraphFactory.close(customGraph); } } }
@Test public void testAndForceIndex() throws Exception { JanusGraph customGraph = null; try { customGraph = this.getForceIndexGraph(); final JanusGraphManagement management = customGraph.openManagement(); final PropertyKey nameProperty = management.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make(); final PropertyKey ageProperty = management.makePropertyKey("age").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); management.buildIndex("oridx", Vertex.class).addKey(nameProperty, getStringMapping()).addKey(ageProperty).buildMixedIndex(INDEX); management.commit(); customGraph.tx().commit(); final GraphTraversalSource g = customGraph.traversal(); g.addV().property("name", "Hiro").property("age", 2).next(); g.addV().property("name", "Totoro").property("age", 1).next(); customGraph.tx().commit(); assertCount(1, g.V().has("name", "Totoro")); assertCount(1, g.V().has("age", 2)); assertCount(1, g.V().and(__.has("name", "Hiro"),__.has("age", 2))); assertCount(0, g.V().and(__.has("name", "Totoro"),__.has("age", 2))); } finally { if (customGraph != null) { JanusGraphFactory.close(customGraph); } } }
@Test public void testOrForceIndexMixedAndCompositeIndex() throws Exception { JanusGraph customGraph = null; try { customGraph = this.getForceIndexGraph(); final JanusGraphManagement management = customGraph.openManagement(); final PropertyKey nameProperty = management.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make(); final PropertyKey ageProperty = management.makePropertyKey("age").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); final PropertyKey lengthProperty = management.makePropertyKey("length").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); management.buildIndex("nameidx", Vertex.class).addKey(nameProperty, getStringMapping()).buildMixedIndex(INDEX); management.buildIndex("ageridx", Vertex.class).addKey(ageProperty).buildCompositeIndex(); management.buildIndex("lengthidx", Vertex.class).addKey(lengthProperty).buildMixedIndex(INDEX); management.commit(); customGraph.tx().commit(); testOr(customGraph); } finally { if (customGraph != null) { JanusGraphFactory.close(customGraph); } } }
@Override public Transaction newTransaction() { return context.getGraph().tx(); }
@Override public Transaction newTransaction() { return context.getGraph().tx(); }
public static void unload() { synchronized (AtlasJanusGraphDatabase.class) { if (graphInstance == null) { return; } graphInstance.tx().commit(); graphInstance.close(); graphInstance = null; } }
@Override public void commit() { getGraph().tx().commit(); }
@Override public void rollback() { getGraph().tx().rollback(); }
@Override public void commit() { getGraph().tx().commit(); }
@Override public void commit() { getGraph().tx().commit(); }
/** * Commit the current transaction and close the graph. */ private void close(){ // we need to commit the Management changes or else they are not applied. mgt.commit(); graph.tx().commit(); graph.close(); }
@Override public void commit() { ExecutionStatistics.performBenchmarked("GraphService.commit", () -> { getGraphContext().getGraph().tx().commit(); return null; }); }
@Override public void commit() { ExecutionStatistics.performBenchmarked("GraphService.commit", () -> { getGraphContext().getGraph().tx().commit(); return null; }); }
private synchronized JanusGraph newJanusGraph(boolean batchLoading){ JanusGraph JanusGraph = configureGraph(batchLoading); buildJanusIndexes(JanusGraph); JanusGraph.tx().onClose(Transaction.CLOSE_BEHAVIOR.ROLLBACK); if (!strategiesApplied.getAndSet(true)) { TraversalStrategies strategies = TraversalStrategies.GlobalCache.getStrategies(StandardJanusGraph.class); strategies = strategies.clone().addStrategies(new JanusPreviousPropertyStepStrategy()); //TODO: find out why Tinkerpop added these strategies. They result in many NoOpBarrier steps which slowed down our queries so we had to remove them. strategies.removeStrategies(PathRetractionStrategy.class, LazyBarrierStrategy.class); TraversalStrategies.GlobalCache.registerStrategies(StandardJanusGraph.class, strategies); TraversalStrategies.GlobalCache.registerStrategies(StandardJanusGraphTx.class, strategies); } return JanusGraph; }
@Override public String writeSingle(String key) throws Exception { if (useJanusgraphTransaction) { graph.addVertex(T.label, VERTEX_LABEL_LEVEL_1, PROP_CUSTOM_ID_KEY, key, PROP_METADATA_KEY, dataGenerator.getRandomValue()); //Automatically opens a new transaction graph.tx().commit(); } else { traversalSource.getGraph().addVertex(T.label, VERTEX_LABEL_LEVEL_1, PROP_CUSTOM_ID_KEY, key, PROP_METADATA_KEY, dataGenerator.getRandomValue()); traversalSource.getGraph().tx().commit(); } return OK; }