@Override public void accept(final Transaction transaction) { if (!transaction.isOpen()) transaction.open(); } },
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS) public void shouldAllowReferenceOfVertexIdOutsideOfOriginalThreadManual() throws Exception { g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.MANUAL); g.tx().open(); final Vertex v1 = graph.addVertex("name", "stephen"); final AtomicReference<Object> id = new AtomicReference<>(); final Thread t = new Thread(() -> { g.tx().open(); id.set(v1.id()); }); t.start(); t.join(); assertEquals(v1.id(), id.get()); g.tx().rollback(); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS) public void shouldAllowReferenceOfEdgeIdOutsideOfOriginalThreadManual() throws Exception { g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.MANUAL); g.tx().open(); final Vertex v1 = graph.addVertex(); final Edge e = v1.addEdge("self", v1, "weight", 0.5d); final AtomicReference<Object> id = new AtomicReference<>(); final Thread t = new Thread(() -> { g.tx().open(); id.set(e.id()); }); t.start(); t.join(); assertEquals(e.id(), id.get()); g.tx().rollback(); }
@Test @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) public void shouldHaveExceptionConsistencyWhenTransactionAlreadyOpen() { if (!g.tx().isOpen()) g.tx().open(); try { g.tx().open(); fail("An exception should be thrown when a transaction is opened twice"); } catch (Exception ex) { validateException(Transaction.Exceptions.transactionAlreadyOpen(), ex); } }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS) public void shouldAllowReferenceOfVertexOutsideOfOriginalTransactionalContextManual() { g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.MANUAL); g.tx().open(); final Vertex v1 = graph.addVertex("name", "stephen"); g.tx().commit(); g.tx().open(); assertEquals("stephen", v1.value("name")); g.tx().rollback(); g.tx().open(); assertEquals("stephen", v1.value("name")); g.tx().close(); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS) public void shouldAllowReferenceOfEdgeOutsideOfOriginalTransactionalContextManual() { g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.MANUAL); g.tx().open(); final Vertex v1 = graph.addVertex(); final Edge e = v1.addEdge("self", v1, "weight", 0.5d); g.tx().commit(); g.tx().open(); assertEquals(0.5d, e.value("weight"), 0.00001d); g.tx().rollback(); g.tx().open(); assertEquals(0.5d, e.value("weight"), 0.00001d); g.tx().close(); }
@Test @LoadGraphWith(MODERN) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) public void shouldTraverseIfManualTxEnabledAndOriginalTxIsClosed() { // auto should be the default, so force manual g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.MANUAL); // close down the current transaction and fire up a fresh one g.tx().open(); final Traversal t = g.V().has("name", "marko"); g.tx().rollback(); // the traversal should still work since there are auto transactions g.tx().open(); assertEquals(1, IteratorUtils.count(t)); g.tx().rollback(); }
@Test @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) public void shouldHaveExceptionConsistencyWhenTransactionOpenOnClose() { g.tx().onClose(Transaction.CLOSE_BEHAVIOR.MANUAL); if (!g.tx().isOpen()) g.tx().open(); try { graph.tx().close(); fail("An exception should be thrown when close behavior is manual and the graph is close with an open transaction"); } catch (Exception ex) { validateException(Transaction.Exceptions.openTransactionsOnClose(), ex); } finally { // rollback manually to keep the test clean g.tx().rollback(); } }
@Override public void accept(final Transaction transaction) { if (!transaction.isOpen()) transaction.open(); } },
@Override public void open() { this.getDelegate().open(); }
graph.tx().open(); graph.addVertex(T.label, "book", "name", "java-3"); graph.addVertex(T.label, "book", "name", "java-4");
private void commit() { if (++numberOfEntriesWithoutCommit >= 5000) { numberOfEntriesWithoutCommit = 0; tx.commit(); tx.close(); tx.open(); } }
@Override public TitanGraph getGraphWithNewTransaction(TitanGraph graph){ if(!graph.tx().isOpen()){ graph.tx().open(); } return graph; }
@Override public void prepareToWrite() { LOG.info("Prepare to write"); tx = graphWrapper.getGraph().tx(); if (!tx.isOpen()) { tx.open(); } currentVertex = graphWrapper.getGraph().addVertex("history"); commit(); }
@Test @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) public void shouldHaveExceptionConsistencyWhenTransactionAlreadyOpen() { if (!g.tx().isOpen()) g.tx().open(); try { g.tx().open(); fail("An exception should be thrown when a transaction is opened twice"); } catch (Exception ex) { validateException(Transaction.Exceptions.transactionAlreadyOpen(), ex); } }
@Override public JanusGraph getGraphWithNewTransaction(JanusGraph graph, boolean batchloading){ if(graph.isClosed()) graph = buildTinkerPopGraph(batchloading); if(!graph.tx().isOpen()){ graph.tx().open(); } return graph; }
@Override public void commitTx(){ try { super.commitTx(); } catch (TitanException e){ throw new GraknBackendException(e); } if(!getTinkerPopGraph().tx().isOpen()){ getTinkerPopGraph().tx().open(); //Until we sort out the transaction handling properly commits have to result in transactions being auto opened } }
@Override public void openTransaction(GraknTxType txType){ super.openTransaction(txType); if(getTinkerPopGraph().isOpen() && !getTinkerPopGraph().tx().isOpen()) getTinkerPopGraph().tx().open(); }
.create(); graph.tx().open();
.range().create(); graph.tx().open();