void close(Transaction tx) { closeConsumer.accept(tx); Preconditions.checkState(!tx.isOpen(),"Invalid close behavior configured: Should close transaction. [%s]",closeConsumer); }
void close(Transaction tx) { closeConsumerInternal.get().accept(tx); Preconditions.checkState(!tx.isOpen(),"Invalid close behavior configured: Should close transaction. [%s]", closeConsumerInternal); }
@Override public void commitAll() { graphs.forEach((key, graph) -> { if (graph.tx().isOpen()) graph.tx().commit(); }); }
@Override public void rollbackAll() { graphs.forEach((key, graph) -> { if (graph.tx().isOpen()) { graph.tx().rollback(); } }); }
public void closeTx(Graph graph, Boolean commit) { if (graph.tx().isOpen()) { if (commit) { graph.tx().commit(); } else { graph.tx().rollback(); } } }
public void clopen(Object... settings) { config = getConfiguration(); if (mgmt!=null && mgmt.isOpen()) mgmt.rollback(); if (null != tx && tx.isOpen()) tx.commit(); if (settings!=null && settings.length>0) { final Map<TestConfigOption,Object> options = validateConfigOptions(settings); JanusGraphManagement janusGraphManagement = null; final ModifiableConfiguration modifiableConfiguration = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS,config, BasicConfiguration.Restriction.LOCAL); for (final Map.Entry<TestConfigOption,Object> option : options.entrySet()) { if (option.getKey().option.isLocal()) { modifiableConfiguration.set(option.getKey().option,option.getValue(),option.getKey().umbrella); } else { if (janusGraphManagement==null) janusGraphManagement = graph.openManagement(); janusGraphManagement.set(ConfigElement.getPath(option.getKey().option,option.getKey().umbrella),option.getValue()); } } if (janusGraphManagement!=null) janusGraphManagement.commit(); modifiableConfiguration.close(); } if (null != graph && null != graph.tx() && graph.tx().isOpen()) graph.tx().commit(); if (null != graph && graph.isOpen()) graph.close(); Preconditions.checkNotNull(config); open(config); }
@Override public void clear(Graph g, final Configuration configuration) throws Exception { if (null != g) { while (g instanceof WrappedGraph) g = ((WrappedGraph<? extends Graph>) g).getBaseGraph(); JanusGraph graph = (JanusGraph) g; if (graph.isOpen()) { if (g.tx().isOpen()) g.tx().rollback(); try { g.close(); } catch (IOException | IllegalStateException e) { logger.warn("Titan graph may not have closed cleanly", e); } } } WriteConfiguration config = new CommonsConfiguration(configuration); BasicConfiguration readConfig = new BasicConfiguration(GraphDatabaseConfiguration.ROOT_NS, config, BasicConfiguration.Restriction.NONE); if (readConfig.has(GraphDatabaseConfiguration.STORAGE_BACKEND)) { JanusGraphBaseTest.clearGraph(config); } }
@Override public void clear(Graph g, final Configuration configuration) throws Exception { if (null != g) { while (g instanceof WrappedGraph) g = ((WrappedGraph<? extends Graph>) g).getBaseGraph(); TitanGraph graph = (TitanGraph) g; if (graph.isOpen()) { if (g.tx().isOpen()) g.tx().rollback(); g.close(); } } WriteConfiguration config = new CommonsConfiguration(configuration); BasicConfiguration readConfig = new BasicConfiguration(GraphDatabaseConfiguration.ROOT_NS, config, BasicConfiguration.Restriction.NONE); if (readConfig.has(GraphDatabaseConfiguration.STORAGE_BACKEND)) { TitanGraphBaseTest.clearGraph(config); } }
@Override public void accept(final Transaction transaction) { if (!transaction.isOpen()) throw Exceptions.transactionMustBeOpenToReadWrite(); } }
@Override public void accept(final Transaction transaction) { if (transaction.isOpen()) throw Exceptions.openTransactionsOnClose(); } }
@Override public void accept(final Transaction transaction) { if (transaction.isOpen()) transaction.commit(); } },
@Override public void accept(final Transaction transaction) { if (transaction.isOpen()) transaction.rollback(); } },
@Override public void accept(final Transaction transaction) { if (!transaction.isOpen()) transaction.open(); } },
/** * Rollback transactions across all {@link Graph} objects. */ public final void rollbackAll() { graphs.entrySet().forEach(e -> { final Graph graph = e.getValue(); if (graph.features().graph().supportsTransactions() && graph.tx().isOpen()) graph.tx().rollback(); }); }
/** * Commit transactions across all {@link Graph} objects. */ public final void commitAll() { graphs.entrySet().forEach(e -> { final Graph graph = e.getValue(); if (graph.features().graph().supportsTransactions() && graph.tx().isOpen()) graph.tx().commit(); }); }
@Test @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS) public void shouldAllowAutoTransactionToWorkWithoutMutationByDefault() { // expecting no exceptions to be thrown here g.tx().commit(); assertThat(g.tx().isOpen(), is(false)); g.tx().rollback(); assertThat(g.tx().isOpen(), is(false)); g.tx().commit(); assertThat(g.tx().isOpen(), is(false)); }
public void rollbackAll() { this.graphs.values().forEach(graph -> { if (graph.features().graph().supportsTransactions() && graph.tx().isOpen()) { graph.tx().rollback(); } }); }
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_THREADED_TRANSACTIONS) public void shouldOpenTxWhenThreadedTransactionIsCreated() throws Exception { // threaded transactions should be immediately open on creation final Graph threadedG = g.tx().createThreadedTx(); assertThat(threadedG.tx().isOpen(), is(true)); threadedG.tx().rollback(); assertThat(threadedG.tx().isOpen(), is(false)); }
protected void onSideEffectSuccess(final Graph graph, final Context ctx) { // there was no "writing" here, just side-effect retrieval, so if a transaction was opened then // just close with rollback if (graph.features().graph().supportsTransactions() && graph.tx().isOpen()) graph.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); } }