org.apache.tinkerpop.gremlin.structure.Transaction Java Examples
The following examples show how to use
org.apache.tinkerpop.gremlin.structure.Transaction.
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: MoveIndicesToIsLatestVertexMigration.java From timbuctoo with GNU General Public License v3.0 | 6 votes |
@Override public void execute(TinkerPopGraphManager graphWrapper) throws IOException { GraphDatabaseService service = graphWrapper.getGraphDatabase(); IndexManager indexManager = service.index(); try (Transaction tx = graphWrapper.getGraph().tx()) { clearIndices(indexManager); tx.commit(); } try (Transaction tx = graphWrapper.getGraph().tx()) { if (!tx.isOpen()) { tx.open(); } constructIndices(indexManager); fillVertexIndices(graphWrapper, indexManager); fillEdgeIndex(service, indexManager); tx.commit(); } }
Example #2
Source File: RemoveSearchResultsMigration.java From timbuctoo with GNU General Public License v3.0 | 6 votes |
@Override public void execute(TinkerPopGraphManager graphWrapper) throws IOException { Graph graph = graphWrapper.getGraph(); try (Transaction tx = graph.tx()) { graph.traversal().V() .forEachRemaining(v -> { if (!v.property("types").isPresent()) { return; } Object types = v.value("types"); if (!(types instanceof String)) { LOG.error("Types property that is not a string at " + v.id()); return; } if (!((String) types).contains("\"searchresult\"")) { return; } LOG.info("Removing vertex with id " + v.id() + ". types=" + v.value("types")); v.remove(); }); tx.commit(); } }
Example #3
Source File: TestAllVertices.java From sqlg with MIT License | 6 votes |
@Test public void testVertexIteratorWithIncorrectId() throws Exception { Graph g = this.sqlgGraph; final Vertex v1 = g.addVertex("name", "marko"); final Object oid = v1.id(); g.tx().onClose(Transaction.CLOSE_BEHAVIOR.ROLLBACK); g.close(); try (SqlgGraph graph = SqlgGraph.open(configuration)) { try { graph.vertices(oid).next(); Assert.fail("Vertex should not be found as close behavior was set to rollback"); } catch (Exception ex) { validateException(new NoSuchElementException(), ex); } } }
Example #4
Source File: AddPidsToWomenWritersEntities.java From timbuctoo with GNU General Public License v3.0 | 6 votes |
@Override public void execute(ImmutableMultimap<String, String> parameters, PrintWriter output) throws Exception { final Graph graph = graphWrapper.getGraph(); final Transaction tx = graph.tx(); try { tx.open(); addMissingPidsToEntities(graph, "wwpersons", "wwperson"); addMissingPidsToEntities(graph, "wwdocuments", "wwdocument"); tx.commit(); } catch (Exception e) { LOG.error("Redirection uri creation failed", e); tx.rollback(); } finally { tx.close(); } }
Example #5
Source File: CoreTraversalTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@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(); }
Example #6
Source File: DefaultGraphManager.java From tinkerpop with Apache License 2.0 | 6 votes |
/** * Selectively close transactions on the specified graphs or the graphs of traversal sources. */ private void closeTx(final Set<String> graphSourceNamesToCloseTxOn, final Transaction.Status tx) { final Set<Graph> graphsToCloseTxOn = new HashSet<>(); // by the time this method has been called, it should be validated that the source/graph is present. // might be possible that it could have been removed dynamically, but that i'm not sure how one would do // that as of right now unless they were embedded in which case they'd need to know what they were doing // anyway graphSourceNamesToCloseTxOn.forEach(r -> { if (graphs.containsKey(r)) graphsToCloseTxOn.add(graphs.get(r)); else graphsToCloseTxOn.add(traversalSources.get(r).getGraph()); }); graphsToCloseTxOn.forEach(graph -> { if (graph.features().graph().supportsTransactions() && graph.tx().isOpen()) { if (tx == Transaction.Status.COMMIT) graph.tx().commit(); else graph.tx().rollback(); } }); }
Example #7
Source File: TxFactoryTest.java From Ferma with Apache License 2.0 | 6 votes |
@Test public void testAbstractTxSucceeding() { DummyTransaction tx = Mockito.mock(DummyTransaction.class, Mockito.CALLS_REAL_METHODS); Transaction rawTx = Mockito.mock(Transaction.class); Mockito.when(tx.getDelegate()).thenReturn(rawTx); DummyGraph graphMock = Mockito.mock(DummyGraph.class, Mockito.CALLS_REAL_METHODS); Mockito.when(graphMock.createTx()).thenReturn(tx); Mockito.when(graphMock.tx()).thenReturn(tx); try (Tx tx2 = graphMock.tx()) { assertNotNull(Tx.getActive()); tx2.success(); } assertNull(Tx.getActive()); verify(tx).commit(); verify(tx).close(); verify(tx, Mockito.never()).rollback(); }
Example #8
Source File: GraphManager.java From hugegraph with Apache License 2.0 | 6 votes |
private void closeTx(final Set<String> graphSourceNamesToCloseTxOn, final Transaction.Status tx) { final Set<Graph> graphsToCloseTxOn = new HashSet<>(); graphSourceNamesToCloseTxOn.forEach(name -> { if (this.graphs.containsKey(name)) { graphsToCloseTxOn.add(this.graphs.get(name)); } }); graphsToCloseTxOn.forEach(graph -> { if (graph.features().graph().supportsTransactions() && graph.tx().isOpen()) { if (tx == Transaction.Status.COMMIT) { graph.tx().commit(); } else { graph.tx().rollback(); } } }); }
Example #9
Source File: TxFactoryTest.java From Ferma with Apache License 2.0 | 6 votes |
@Test public void testAbstractTxDefault() { DummyTransaction tx = Mockito.mock(DummyTransaction.class, Mockito.CALLS_REAL_METHODS); Transaction rawTx = Mockito.mock(Transaction.class); Mockito.when(tx.getDelegate()).thenReturn(rawTx); DummyGraph graphMock = Mockito.mock(DummyGraph.class, Mockito.CALLS_REAL_METHODS); Mockito.when(graphMock.tx()).thenReturn(tx); try (Tx tx2 = tx) { assertNotNull(Tx.getActive()); // Don't call tx2.success() or tx2.failure() } assertNull(Tx.getActive()); verify(tx).close(); verify(graphMock.tx()).rollback(); verify(graphMock.tx()).close(); verify(graphMock.tx(), Mockito.never()).commit(); }
Example #10
Source File: TxFactoryTest.java From Ferma with Apache License 2.0 | 6 votes |
@Test public void testAbstractTxFailing() { DummyTransaction tx = Mockito.mock(DummyTransaction.class, Mockito.CALLS_REAL_METHODS); Transaction rawTx = Mockito.mock(Transaction.class); Mockito.when(tx.getDelegate()).thenReturn(rawTx); DummyGraph graphMock = Mockito.mock(DummyGraph.class, Mockito.CALLS_REAL_METHODS); Mockito.when(graphMock.tx()).thenReturn(tx); try (Tx tx2 = tx) { assertNotNull(Tx.getActive()); tx2.failure(); } assertNull(Tx.getActive()); verify(tx).close(); verify(graphMock.tx()).rollback(); verify(graphMock.tx()).close(); verify(graphMock.tx(), Mockito.never()).commit(); }
Example #11
Source File: MakePidsAbsoluteUrls.java From timbuctoo with GNU General Public License v3.0 | 6 votes |
@Override public void execute(TinkerPopGraphManager graphWrapper) throws IOException { Transaction tx = graphWrapper.getGraph().tx(); if (!tx.isOpen()) { tx.open(); } graphWrapper.getGraph().traversal() .V() .has("pid") .filter(x -> !((String) x.get().value("pid")).startsWith("http://")) .forEachRemaining(it -> { String orig = it.value("pid"); String replacement = "http://hdl.handle.net/11240/" + orig; if (Math.random() < 0.1) { LOG.info(Logmarkers.migration, "Replacing " + orig + " with " + replacement); } it.property("pid", replacement); }); tx.commit(); }
Example #12
Source File: HugeGraphAuthProxy.java From hugegraph with Apache License 2.0 | 5 votes |
@Override public Transaction tx() { /* * Can't verifyPermission() here, will be called by rollbackAll(). */ return this.hugegraph.tx(); }
Example #13
Source File: TestRollback.java From sqlg with MIT License | 5 votes |
@Test public void shouldHaveExceptionConsistencyWhenUsingManualTransactionOnRollback() { this.sqlgGraph.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.MANUAL); try { this.sqlgGraph.tx().rollback(); fail("An exception should be thrown when read/write behavior is manual and no transaction is opened"); } catch (Exception ex) { } }
Example #14
Source File: BitsyTransactionContext.java From bitsy with Apache License 2.0 | 5 votes |
public BitsyTransactionContext(IGraphStore store) { this.unmodifiedVertices = new HashMap<UUID, BitsyVertex>(); this.unmodifiedEdges = new HashMap<UUID, BitsyEdge>(); this.changedVertices = new HashMap<UUID, BitsyVertex>(); this.changedEdges = new HashMap<UUID, BitsyEdge>(); this.store = store; this.transactionListeners = new ArrayList<Consumer<Transaction.Status>>(); this.adjMap = new AdjacencyMap(false, new IEdgeRemover() { @Override public IEdge removeEdge(UUID id) { return removeEdgeOnVertexDelete(id); } }); }
Example #15
Source File: TestGraphProvider.java From hugegraph with Apache License 2.0 | 5 votes |
@Watched @Override public void clear(Graph graph, Configuration config) throws Exception { TestGraph testGraph = (TestGraph) graph; if (testGraph == null) { return; } String graphName = config.getString(CoreOptions.STORE.name()); if (!testGraph.initedBackend()) { testGraph.close(); } if (testGraph.closed()) { if (this.graphs.get(graphName) == testGraph) { this.graphs.remove(graphName); } return; } // Reset consumers graph.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.AUTO); graph.tx().onClose(Transaction.CLOSE_BEHAVIOR.ROLLBACK); // Ensure tx clean graph.tx().rollback(); // Clear all data Class<?> testClass = (Class<?>) config.getProperty(TEST_CLASS); testGraph.clearAll(testClass.getCanonicalName()); LOG.debug("Clear graph '{}'", graphName); }
Example #16
Source File: DelegatingTransactionTest.java From Ferma with Apache License 2.0 | 5 votes |
@Before public void setUp() { gremlinTx = Mockito.mock(Transaction.class); framedGraph = Mockito.mock(WrappedFramedGraph.class, Mockito.RETURNS_MOCKS); baseGraph = Mockito.mock(Graph.class, Mockito.RETURNS_MOCKS); when(gremlinTx.createThreadedTx()).thenReturn(baseGraph); delegatingTx = new DelegatingTransaction(gremlinTx, framedGraph); }
Example #17
Source File: RelationTypeRdfUriMigration.java From timbuctoo with GNU General Public License v3.0 | 5 votes |
@Override public void execute(TinkerPopGraphManager graphWrapper) throws IOException { final Graph graph = graphWrapper.getGraph(); final Transaction transaction = graph.tx(); if (!transaction.isOpen()) { transaction.open(); } final GraphDatabaseService graphDatabase = graphWrapper.getGraphDatabase(); final Index<Node> rdfIndex = graphDatabase.index().forNodes(RDFINDEX_NAME); final String regularNameProp = "relationtype_regularName"; final String inverseNameProp = "relationtype_inverseName"; graph.traversal().V().has(regularNameProp).forEachRemaining(vertex -> { final String regularName = vertex.property(regularNameProp).isPresent() ? vertex.<String>property(regularNameProp).value() : ""; final String inverseName = vertex.property(inverseNameProp).isPresent() ? vertex.<String>property(inverseNameProp).value() : ""; final String rdfUri = TIMBUCTOO_NAMESPACE + regularName; final String[] rdfAlternatives = new String[]{ TIMBUCTOO_NAMESPACE + inverseName }; LOG.info("setting rdfUri: \"{}\" and rdfAlternatives [{}] for relationType", rdfUri, rdfAlternatives); vertex.property(RDF_URI_PROP, rdfUri); vertex.property(RDF_SYNONYM_PROP, rdfAlternatives); LOG.info("indexing rdfUri: \"{}\" and rdfAlternatives [{}] for relationType", rdfUri, rdfAlternatives); org.neo4j.graphdb.Node neo4jNode = graphDatabase.getNodeById((Long) vertex.id()); rdfIndex.add(neo4jNode, RelationTypeService.RELATIONTYPE_INDEX_NAME, rdfUri); rdfIndex.add(neo4jNode, RelationTypeService.RELATIONTYPE_INDEX_NAME, rdfAlternatives[0]); }); transaction.commit(); transaction.close(); }
Example #18
Source File: DelegatingTransactionTest.java From Ferma with Apache License 2.0 | 5 votes |
private void assertDelegatingIsOpenUsage(boolean expectedValue) { Transaction tx = Mockito.mock(Transaction.class); WrappedFramedGraph<?> graph = Mockito.mock(WrappedFramedGraph.class); when(tx.isOpen()).thenReturn(expectedValue); DelegatingTransaction delTx = new DelegatingTransaction(tx, graph); Assert.assertEquals(expectedValue, delTx.isOpen()); Mockito.verify(tx, Mockito.times(1)).isOpen(); Mockito.verifyNoMoreInteractions(tx, graph); }
Example #19
Source File: Neo4JSession.java From neo4j-gremlin-bolt with Apache License 2.0 | 5 votes |
public org.neo4j.driver.Transaction beginTransaction() { // check we have a transaction already in progress if (transaction != null && transaction.isOpen()) throw Transaction.Exceptions.transactionAlreadyOpen(); // begin transaction transaction = session.beginTransaction(); // log information if (logger.isDebugEnabled()) logger.debug("Beginning transaction on session [{}]-[{}]", session.hashCode(), transaction.hashCode()); // return transaction instance return transaction; }
Example #20
Source File: DelegatingTransactionTest.java From Ferma with Apache License 2.0 | 5 votes |
@Test public void testAddTxListener() { Consumer<Transaction.Status> txListener = Mockito.mock(Consumer.class, "Foo"); delegatingTx.addTransactionListener(txListener); // Only delegating so the same listener should be passed Mockito.verify(gremlinTx, Mockito.times(1)).addTransactionListener(txListener); Mockito.verifyZeroInteractions(framedGraph); Mockito.verifyZeroInteractions(txListener); Mockito.verifyNoMoreInteractions(gremlinTx); }
Example #21
Source File: Neo4JSessionWhileAddVertexTest.java From neo4j-gremlin-bolt with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("unchecked") public void givenNewVertexWithoutIdShouldBeAvailableOnAllIdsQueries() { // arrange Mockito.when(graph.tx()).thenAnswer(invocation -> transaction); Mockito.when(graph.getPartition()).thenAnswer(invocation -> partition); Mockito.when(session.beginTransaction()).then(invocation -> neo4jTransaction); Mockito.when(neo4jTransaction.run(Mockito.any(String.class), Mockito.anyMap())).then(invocation -> statementResult); Mockito.when(statementResult.hasNext()).then(invocation -> false); Mockito.when(statementResult.consume()).then(invocation -> resultSummary); Mockito.when(provider.fieldName()).thenAnswer(invocation -> "id"); Mockito.when(provider.generate()).thenAnswer(invocation -> null); ArgumentCaptor<Long> argument = ArgumentCaptor.forClass(Long.class); Mockito.when(provider.processIdentifier(argument.capture())).thenAnswer(invocation -> argument.getValue()); try (Neo4JSession session = new Neo4JSession(graph, this.session, provider, provider, false)) { // transaction try (org.neo4j.driver.Transaction tx = session.beginTransaction()) { // add vertex session.addVertex(); // act Iterator<Vertex> vertices = session.vertices(new Object[0]); // assert Assert.assertTrue("Failed to find vertex", vertices.hasNext()); Vertex vertex = vertices.next(); Assert.assertNotNull("Failed to create vertex", vertex); Assert.assertEquals("Failed to assign vertex label", Vertex.DEFAULT_LABEL, vertex.label()); // commit tx.commit(); } } }
Example #22
Source File: Neo4JSessionWhileAddEdgeTest.java From neo4j-gremlin-bolt with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("unchecked") public void givenNewEdgeWithIdShouldBeAvailableOnAllIdsQueries() { // arrange Mockito.when(graph.tx()).thenAnswer(invocation -> transaction); Mockito.when(graph.getPartition()).thenAnswer(invocation -> partition); Mockito.when(session.beginTransaction()).then(invocation -> neo4jTransaction); Mockito.when(neo4jTransaction.run(Mockito.any(String.class), Mockito.anyMap())).then(invocation -> statementResult); Mockito.when(statementResult.hasNext()).then(invocation -> false); Mockito.when(statementResult.consume()).then(invocation -> resultSummary); Mockito.when(provider.fieldName()).thenAnswer(invocation -> "id"); Mockito.when(provider.generate()).thenAnswer(invocation -> 1L); ArgumentCaptor<Long> argument = ArgumentCaptor.forClass(Long.class); Mockito.when(provider.processIdentifier(argument.capture())).thenAnswer(invocation -> argument.getValue()); try (Neo4JSession session = new Neo4JSession(graph, this.session, provider, provider, false)) { // transaction try (org.neo4j.driver.Transaction tx = session.beginTransaction()) { // add edge session.addEdge("label1", outVertex, inVertex); // act Iterator<Edge> edges = session.edges(new Object[0]); // assert Assert.assertTrue("Failed to create edge", edges.hasNext()); Edge edge = edges.next(); Assert.assertNotNull("Failed to create edge", edge); Assert.assertEquals("Failed to assign edge label", "label1", edge.label()); // commit tx.commit(); } } }
Example #23
Source File: Neo4JSessionWhileAddEdgeTest.java From neo4j-gremlin-bolt with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("unchecked") public void givenNewEdgeWithoutIdShouldBeAvailableOnAllIdsQueries() { // arrange Mockito.when(graph.tx()).thenAnswer(invocation -> transaction); Mockito.when(graph.getPartition()).thenAnswer(invocation -> partition); Mockito.when(session.beginTransaction()).then(invocation -> neo4jTransaction); Mockito.when(neo4jTransaction.run(Mockito.any(String.class), Mockito.anyMap())).then(invocation -> statementResult); Mockito.when(statementResult.hasNext()).then(invocation -> false); Mockito.when(statementResult.consume()).then(invocation -> resultSummary); Mockito.when(provider.fieldName()).thenAnswer(invocation -> "id"); Mockito.when(provider.generate()).thenAnswer(invocation -> null); ArgumentCaptor<Long> argument = ArgumentCaptor.forClass(Long.class); Mockito.when(provider.processIdentifier(argument.capture())).thenAnswer(invocation -> argument.getValue()); try (Neo4JSession session = new Neo4JSession(graph, this.session, provider, provider, false)) { // transaction try (org.neo4j.driver.Transaction tx = session.beginTransaction()) { // add edge session.addEdge("label1", outVertex, inVertex); // act Iterator<Edge> edges = session.edges(new Object[0]); // assert Assert.assertTrue("Failed to create edge", edges.hasNext()); Edge edge = edges.next(); Assert.assertNotNull("Failed to create edge", edge); Assert.assertEquals("Failed to assign edge label", "label1", edge.label()); // commit tx.commit(); } } }
Example #24
Source File: TinkerpopSaver.java From timbuctoo with GNU General Public License v3.0 | 5 votes |
public void setUploadFinished(String vreName, Vre.PublishState publishState) { try (Transaction tx = graphWrapper.getGraph().tx()) { final GraphTraversal<Vertex, Vertex> vreT = vreIniter.getVreTraversal(vreName); if (vreT.hasNext()) { vreT.next().property(Vre.PUBLISH_STATE_PROPERTY_NAME, publishState.toString()); } tx.commit(); } }
Example #25
Source File: CoreTraversalTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @LoadGraphWith(MODERN) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) public void shouldTraverseIfAutoTxEnabledAndOriginalTxIsClosed() { // this should be the default, but manually set in just in case the implementation has other ideas g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.AUTO); // close down the current transaction final Traversal t = g.V().has("name", "marko"); g.tx().rollback(); // the traversal should still work since there are auto transactions assertEquals(1, IteratorUtils.count(t)); }
Example #26
Source File: VreIniter.java From timbuctoo with GNU General Public License v3.0 | 5 votes |
public Vertex upsertVre(String vreName, String vreLabel, String fileName) { final Vertex result; try (Transaction tx = wrapper.getGraph().tx()) { final GraphTraversal<Vertex, Vertex> vre = getVreTraversal(vreName); if (vre.hasNext()) { result = vre.next(); if (result.property(TinkerpopSaver.SAVED_MAPPING_STATE).isPresent()) { result.property(TinkerpopSaver.SAVED_MAPPING_STATE).remove(); } wrapper.getGraph().traversal().V(result.id()) .out(TinkerpopSaver.RAW_COLLECTION_EDGE_NAME) .union( __.out(TinkerpopSaver.RAW_ITEM_EDGE_NAME), __.out(TinkerpopSaver.RAW_PROPERTY_EDGE_NAME), __.identity() //the collection ) .drop() .toList();//force traversal and thus side-effects } else { result = wrapper.getGraph() .addVertex(T.label, Vre.DATABASE_LABEL, Vre.VRE_NAME_PROPERTY_NAME, vreName); } result.property(Vre.VRE_LABEL_PROPERTY_NAME, vreLabel); result.property(Vre.UPLOADED_FILE_NAME, fileName); result.property(Vre.PUBLISH_STATE_PROPERTY_NAME, Vre.PublishState.UPLOADING.toString()); tx.commit(); } vres.reload(); return result; }
Example #27
Source File: DelegatingTransactionTest.java From Ferma with Apache License 2.0 | 5 votes |
@Test public void testRemoveTxListener() { Consumer<Transaction.Status> txListener = Mockito.mock(Consumer.class, "Foo"); delegatingTx.removeTransactionListener(txListener); Mockito.verify(gremlinTx, Mockito.times(1)).removeTransactionListener(txListener); Mockito.verifyZeroInteractions(framedGraph, txListener); Mockito.verifyNoMoreInteractions(gremlinTx); }
Example #28
Source File: FixDcarKeywordDisplayNameMigration.java From timbuctoo with GNU General Public License v3.0 | 5 votes |
@Override public void execute(TinkerPopGraphManager graphWrapper) throws IOException { final Graph graph = graphWrapper.getGraph(); final GraphTraversal<Vertex, Vertex> dcarDisplayNameT = graph.traversal().V() .has(T.label, LabelP.of(Vre.DATABASE_LABEL)) .has("name", "DutchCaribbean") .out("hasCollection") .has("collectionName", "dcarkeywords") .out("hasDisplayName"); // Only apply this config change if this config actually exists in the current database if (dcarDisplayNameT.hasNext()) { LOG.info("Changing displayName configuration for dcarkeywords to dcarkeyword_value"); final Vertex dcarDisplayName = dcarDisplayNameT.next(); final Transaction transaction = graph.tx(); if (!transaction.isOpen()) { transaction.open(); } dcarDisplayName.property(LocalProperty.DATABASE_PROPERTY_NAME, "dcarkeyword_value"); transaction.commit(); transaction.close(); } else { LOG.info("Skipping change for displayName configuration of dcarkeywords " + "as this collection does not exist in this database"); } }
Example #29
Source File: AbstractTransaction.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void open() { if (isOpen()) throw Transaction.Exceptions.transactionAlreadyOpen(); else doOpen(); }
Example #30
Source File: EventStrategy.java From tinkerpop with Apache License 2.0 | 5 votes |
public TransactionalEventQueue(final Graph graph) { if (!graph.features().graph().supportsTransactions()) throw new IllegalStateException(String.format("%s requires the graph to support transactions", EventStrategy.class.getName())); // since this is a transactional graph events are enqueued so the events should be fired/reset only after // transaction is committed/rolled back as tied to a graph transaction graph.tx().addTransactionListener(status -> { if (status == Transaction.Status.COMMIT) fireEventQueue(); else if (status == Transaction.Status.ROLLBACK) resetEventQueue(); else throw new RuntimeException(String.format("The %s is not aware of this status: %s", EventQueue.class.getName(), status)); }); }