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

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

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

Transaction.rollback介绍

[英]Rolls back a transaction. This method may optionally throw TransactionException on error. Providers should consider wrapping their transaction exceptions in this TinkerPop exception as it will lead to better error handling with Gremlin Server and other parts of the stack.
[中]回滚事务。此方法可以选择在出错时抛出TransactionException。提供者应该考虑在TimeCurp异常中包装事务异常,因为这将导致GrimLin服务器和堆栈的其他部分更好的错误处理。

代码示例

代码示例来源:origin: JanusGraph/janusgraph

@Override
public void rollbackAll() {
  graphs.forEach((key, graph) -> {
    if (graph.tx().isOpen()) {
      graph.tx().rollback();
    }
  });
}

代码示例来源:origin: JanusGraph/janusgraph

public void closeTx(Graph graph, Boolean commit) {
  if (graph.tx().isOpen()) {
    if (commit) {
      graph.tx().commit();
    } else {
      graph.tx().rollback();
    }
  }
}

代码示例来源:origin: JanusGraph/janusgraph

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

代码示例来源:origin: thinkaurelius/titan

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

代码示例来源:origin: thinkaurelius/titan

mgmt.setTTL(likes, Duration.ofMillis(initialTTLMillis));
mgmt.commit();
graph.tx().rollback();
graph.tx().rollback();
graph.tx().rollback();

代码示例来源:origin: thinkaurelius/titan

@Test
public void testGettingUndefinedVertexLabelTTL() {
  if (!features.hasCellTTL()) {
    return;
  }
  // getTTL should return a null duration on an extant type without a TTL
  mgmt.makeVertexLabel("foo").make();
  mgmt.commit();
  graph.tx().rollback();
  // Check getTTL on vertex label
  mgmt = graph.openManagement();
  assertEquals(Duration.ZERO, mgmt.getTTL(mgmt.getVertexLabel("foo")));
  mgmt.rollback();
}

代码示例来源:origin: thinkaurelius/titan

@Test
public void testGettingUndefinedEdgeLabelTTL() {
  if (!features.hasCellTTL()) {
    return;
  }
  // getTTL should return a null duration on an extant type without a TTL
  mgmt.makeEdgeLabel("likes").make();
  mgmt.commit();
  graph.tx().rollback();
  // Check getTTL on edge label
  mgmt = graph.openManagement();
  assertEquals(Duration.ZERO, mgmt.getTTL(mgmt.getEdgeLabel("likes")));
  mgmt.rollback();
}

代码示例来源:origin: JanusGraph/janusgraph

@Test
public void testGettingUndefinedVertexLabelTTL() {
  if (!features.hasCellTTL()) {
    return;
  }
  // getTTL should return a null duration on an extant type without a TTL
  mgmt.makeVertexLabel("foo").make();
  mgmt.commit();
  graph.tx().rollback();
  // Check getTTL on vertex label
  mgmt = graph.openManagement();
  assertEquals(Duration.ZERO, mgmt.getTTL(mgmt.getVertexLabel("foo")));
  mgmt.rollback();
}

代码示例来源:origin: JanusGraph/janusgraph

@Test
public void testGettingUndefinedEdgeLabelTTL() {
  if (!features.hasCellTTL()) {
    return;
  }
  // getTTL should return a null duration on an extant type without a TTL
  mgmt.makeEdgeLabel("likes").make();
  mgmt.commit();
  graph.tx().rollback();
  // Check getTTL on edge label
  mgmt = graph.openManagement();
  assertEquals(Duration.ZERO, mgmt.getTTL(mgmt.getEdgeLabel("likes")));
  mgmt.rollback();
}

代码示例来源:origin: thinkaurelius/titan

@Test
public void testVLabelOnOrderedStorage() {
  final String label = "pl";
  mgmt.makeVertexLabel(label).partition().make();
  mgmt.commit();
  graph.tx().rollback();
  graph.addVertex(label);
  graph.tx().commit();
  mgmt = graph.openManagement();
  VertexLabel vl = mgmt.getVertexLabel(label);
  assertTrue(vl.isPartitioned());
  mgmt.rollback();
}

代码示例来源:origin: thinkaurelius/titan

graph.tx().rollback();

代码示例来源:origin: thinkaurelius/titan

@Test
public void testMemoryLeakage() {
  long memoryBaseline = 0;
  SummaryStatistics stats = new SummaryStatistics();
  int numRuns = 25;
  for (int r = 0; r < numRuns; r++) {
    if (r == 1 || r == (numRuns - 1)) {
      memoryBaseline = MemoryAssess.getMemoryUse();
      stats.addValue(memoryBaseline);
      //System.out.println("Memory before run "+(r+1)+": " + memoryBaseline / 1024 + " KB");
    }
    for (int t = 0; t < 1000; t++) {
      graph.addVertex();
      graph.tx().rollback();
      TitanTransaction tx = graph.newTransaction();
      tx.addVertex();
      tx.rollback();
    }
    if (r == 1 || r == (numRuns - 1)) {
      memoryBaseline = MemoryAssess.getMemoryUse();
      stats.addValue(memoryBaseline);
      //System.out.println("Memory after run " + (r + 1) + ": " + memoryBaseline / 1024 + " KB");
    }
    clopen();
  }
  System.out.println("Average: " + stats.getMean() + " Std. Dev: " + stats.getStandardDeviation());
  assertTrue(stats.getStandardDeviation() < stats.getMin());
}

代码示例来源:origin: JanusGraph/janusgraph

@Test
public void testVLabelOnOrderedStorage() {
  final String label = "pl";
  mgmt.makeVertexLabel(label).partition().make();
  mgmt.commit();
  graph.tx().rollback();
  graph.addVertex(label);
  graph.tx().commit();
  mgmt = graph.openManagement();
  VertexLabel vl = mgmt.getVertexLabel(label);
  assertTrue(vl.isPartitioned());
  mgmt.rollback();
}

代码示例来源:origin: thinkaurelius/titan

@Test
public void testEdgeTTLWithTransactions() throws Exception {
  if (!features.hasCellTTL()) {
    return;
  }
  EdgeLabel label1 = mgmt.makeEdgeLabel("likes").make();
  mgmt.setTTL(label1, Duration.ofSeconds(1));
  assertEquals(Duration.ofSeconds(1), mgmt.getTTL(label1));
  mgmt.commit();
  TitanVertex v1 = graph.addVertex(), v2 = graph.addVertex();
  v1.addEdge("likes", v2);
  // pre-commit state of the edge.  It is not yet subject to TTL
  assertNotEmpty(v1.query().direction(Direction.OUT).vertices());
  Thread.sleep(1001);
  // the edge should have expired by now, but only if it had been committed
  assertNotEmpty(v1.query().direction(Direction.OUT).vertices());
  graph.tx().commit();
  // still here, because we have just committed the edge.  Its countdown starts at the commit
  assertNotEmpty(v1.query().direction(Direction.OUT).vertices());
  Thread.sleep(1001);
  // the edge has expired in Cassandra, but still appears alive in this transaction
  assertNotEmpty(v1.query().direction(Direction.OUT).vertices());
  // syncing with the data store, we see that the edge has expired
  graph.tx().rollback();
  assertEmpty(v1.query().direction(Direction.OUT).vertices());
}

代码示例来源:origin: thinkaurelius/titan

graph.tx().rollback();
graph.tx().rollback();

代码示例来源:origin: thinkaurelius/titan

graph.tx().rollback();
graph.tx().rollback();

代码示例来源:origin: JanusGraph/janusgraph

@Test
public void testEdgeTTLWithTransactions() throws Exception {
  if (!features.hasCellTTL()) {
    return;
  }
  EdgeLabel label1 = mgmt.makeEdgeLabel("likes").make();
  mgmt.setTTL(label1, Duration.ofSeconds(1));
  assertEquals(Duration.ofSeconds(1), mgmt.getTTL(label1));
  mgmt.commit();
  JanusGraphVertex v1 = graph.addVertex(), v2 = graph.addVertex();
  v1.addEdge("likes", v2);
  // pre-commit state of the edge.  It is not yet subject to TTL
  assertNotEmpty(v1.query().direction(Direction.OUT).vertices());
  Thread.sleep(1001);
  // the edge should have expired by now, but only if it had been committed
  assertNotEmpty(v1.query().direction(Direction.OUT).vertices());
  graph.tx().commit();
  // still here, because we have just committed the edge.  Its countdown starts at the commit
  assertNotEmpty(v1.query().direction(Direction.OUT).vertices());
  Thread.sleep(1001);
  // the edge has expired in Cassandra, but still appears alive in this transaction
  assertNotEmpty(v1.query().direction(Direction.OUT).vertices());
  // syncing with the data store, we see that the edge has expired
  graph.tx().rollback();
  assertEmpty(v1.query().direction(Direction.OUT).vertices());
}

代码示例来源:origin: thinkaurelius/titan

@Test
public void testVertexTTLWithCompositeIndex() throws Exception {
  if (!features.hasCellTTL()) {
    return;
  }
  PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
  PropertyKey time = mgmt.makePropertyKey("time").dataType(Long.class).make();
  TitanGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name).buildCompositeIndex();
  TitanGraphIndex index2 = mgmt.buildIndex("index2", Vertex.class).addKey(name).addKey(time).buildCompositeIndex();
  VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make();
  mgmt.setTTL(label1, Duration.ofSeconds(1));
  assertEquals(Duration.ZERO, mgmt.getTTL(name));
  assertEquals(Duration.ZERO, mgmt.getTTL(time));
  assertEquals(Duration.ofSeconds(1), mgmt.getTTL(label1));
  mgmt.commit();
  TitanVertex v1 = tx.addVertex(T.label, "event", "name", "some event", "time", System.currentTimeMillis());
  tx.commit();
  Object id = v1.id();
  v1 = getV(graph, id);
  assertNotNull(v1);
  assertNotEmpty(graph.query().has("name", "some event").vertices());
  Thread.sleep(1001);
  graph.tx().rollback();
  v1 = getV(graph, id);
  assertNull(v1);
  assertEmpty(graph.query().has("name", "some event").vertices());
}

代码示例来源:origin: JanusGraph/janusgraph

@Test
public void testVertexTTLWithCompositeIndex() throws Exception {
  if (!features.hasCellTTL()) {
    return;
  }
  PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
  PropertyKey time = mgmt.makePropertyKey("time").dataType(Long.class).make();
  final JanusGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name)
      .buildCompositeIndex();
  final JanusGraphIndex index2 = mgmt.buildIndex("index2", Vertex.class).addKey(name).addKey(time)
      .buildCompositeIndex();
  VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make();
  mgmt.setTTL(label1, Duration.ofSeconds(1));
  assertEquals(Duration.ZERO, mgmt.getTTL(name));
  assertEquals(Duration.ZERO, mgmt.getTTL(time));
  assertEquals(Duration.ofSeconds(1), mgmt.getTTL(label1));
  mgmt.commit();
  JanusGraphVertex v1 = tx.addVertex(T.label, "event", "name", "some event", "time", System.currentTimeMillis());
  tx.commit();
  Object id = v1.id();
  v1 = getV(graph, id);
  assertNotNull(v1);
  assertNotEmpty(graph.query().has("name", "some event").vertices());
  Thread.sleep(1001);
  graph.tx().rollback();
  v1 = getV(graph, id);
  assertNull(v1);
  assertEmpty(graph.query().has("name", "some event").vertices());
}

代码示例来源:origin: thinkaurelius/titan

graph.tx().rollback();
e1 = getOnlyElement(v1.query().direction(Direction.OUT).labels("likes").edges());
d = e1.value("~ttl");

相关文章