org.apache.tinkerpop.gremlin.structure.Transaction.onClose()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(86)

本文整理了Java中org.apache.tinkerpop.gremlin.structure.Transaction.onClose()方法的一些代码示例,展示了Transaction.onClose()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Transaction.onClose()方法的具体详情如下:
包路径:org.apache.tinkerpop.gremlin.structure.Transaction
类名称:Transaction
方法名:onClose

Transaction.onClose介绍

[英]Describes what happens to a transaction on a call to Graph#close(). This value can be set using standard behavior defined in CLOSE_BEHAVIOR or a mapper Consumer function.
[中]描述调用Graph#close()时事务发生的情况。可以使用CLOSE_behavior或mapper Consumer函数中定义的标准行为设置此值。

代码示例

代码示例来源:origin: apache/tinkerpop

graph.tx().onClose(Transaction.CLOSE_BEHAVIOR.COMMIT);
try {
  latch.await();

代码示例来源:origin: apache/tinkerpop

@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS)
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_PERSISTENCE)
public void shouldCommitOnCloseWhenConfigured() throws Exception {
  final AtomicReference<Object> oid = new AtomicReference<>();
  final Thread t = new Thread(() -> {
    final Vertex v1 = graph.addVertex("name", "marko");
    g.tx().onClose(Transaction.CLOSE_BEHAVIOR.COMMIT);
    oid.set(v1.id());
    graph.tx().close();
  });
  t.start();
  t.join();
  final Vertex v2 = graph.vertices(oid.get()).next();
  assertEquals("marko", v2.<String>value("name"));
}

代码示例来源:origin: apache/tinkerpop

@Test
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS)
public void shouldHaveExceptionConsistencyWhenOnCloseToNull() {
  try {
    g.tx().onClose(null);
    fail("An exception should be thrown when onClose behavior is set to null");
  } catch (Exception ex) {
    validateException(Transaction.Exceptions.onCloseBehaviorCannotBeNull(), ex);
  }
}

代码示例来源:origin: hugegraph/hugegraph

@Watched
@Override
public void clear(Graph graph, Configuration config) throws Exception {
  TestGraph testGraph = (TestGraph) graph;
  if (testGraph == null || !testGraph.initedBackend()) {
    return;
  }
  String graphName = config.getString(CoreOptions.STORE.name());
  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);
}

代码示例来源:origin: apache/tinkerpop

@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();
  }
}

代码示例来源:origin: io.mindmaps/mindmaps-titan-factory

private synchronized TitanGraph newTitanGraph(String name, String address, String pathToConfig){
  TitanGraph titanGraph = configureGraph(name, address, pathToConfig);
  buildTitanIndexes(titanGraph);
  titanGraph.tx().onClose(Transaction.CLOSE_BEHAVIOR.ROLLBACK);
  return titanGraph;
}

代码示例来源:origin: ai.grakn/grakn-titan-factory

private synchronized TitanGraph newTitanGraph(String name, String address, Properties properties, boolean batchLoading){
  TitanGraph titanGraph = configureGraph(name, address, properties, batchLoading);
  buildTitanIndexes(titanGraph);
  titanGraph.tx().onClose(Transaction.CLOSE_BEHAVIOR.ROLLBACK);
  return titanGraph;
}

代码示例来源:origin: org.apache.tinkerpop/gremlin-test

graph.tx().onClose(Transaction.CLOSE_BEHAVIOR.COMMIT);
try {
  latch.await();

代码示例来源:origin: org.apache.tinkerpop/gremlin-test

@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS)
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_PERSISTENCE)
public void shouldCommitOnCloseWhenConfigured() throws Exception {
  final AtomicReference<Object> oid = new AtomicReference<>();
  final Thread t = new Thread(() -> {
    final Vertex v1 = graph.addVertex("name", "marko");
    g.tx().onClose(Transaction.CLOSE_BEHAVIOR.COMMIT);
    oid.set(v1.id());
    graph.tx().close();
  });
  t.start();
  t.join();
  final Vertex v2 = graph.vertices(oid.get()).next();
  assertEquals("marko", v2.<String>value("name"));
}

代码示例来源:origin: org.apache.tinkerpop/gremlin-test

@Test
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS)
public void shouldHaveExceptionConsistencyWhenOnCloseToNull() {
  try {
    g.tx().onClose(null);
    fail("An exception should be thrown when onClose behavior is set to null");
  } catch (Exception ex) {
    validateException(Transaction.Exceptions.onCloseBehaviorCannotBeNull(), ex);
  }
}

代码示例来源:origin: ai.grakn/janus-factory

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;
}

代码示例来源:origin: org.apache.tinkerpop/gremlin-test

@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();
  }
}

相关文章