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

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

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

Transaction.commit介绍

[英]Commits 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: thinkaurelius/titan

@Test
public void testArrayEqualityUsingImplicitKey() {
  TitanVertex v = graph.addVertex();
  byte singleDimension[] = new byte[]{127, 0, 0, 1};
  byte singleDimensionCopy[] = new byte[]{127, 0, 0, 1};
  final String singlePropName = "single";
  v.property(singlePropName, singleDimension);
  assertEquals(1, Iterables.size(graph.query().has(singlePropName, singleDimension).vertices()));
  assertEquals(1, Iterables.size(graph.query().has(singlePropName, singleDimensionCopy).vertices()));
  graph.tx().commit();
  assertEquals(1, Iterables.size(graph.query().has(singlePropName, singleDimension).vertices()));
  assertEquals(1, Iterables.size(graph.query().has(singlePropName, singleDimensionCopy).vertices()));
}

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

@Test
public void testStaleVertex() {
  PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
  PropertyKey age = mgmt.makePropertyKey("age").dataType(Integer.class).make();
  mgmt.buildIndex("byName", Vertex.class).addKey(name).unique().buildCompositeIndex();
  finishSchema();
  TitanVertex cartman = graph.addVertex("name", "cartman", "age", 10);
  TitanVertex stan = graph.addVertex("name", "stan", "age", 8);
  graph.tx().commit();
  cartman = getOnlyElement(graph.query().has("name", "cartman").vertices());
  graph.tx().commit();
  TitanVertexProperty p = (TitanVertexProperty) cartman.properties().next();
  assertTrue(((Long) p.longId()) > 0);
  graph.tx().commit();
}

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

@Test
public void testStaleVertex() {
  PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
  mgmt.makePropertyKey("age").dataType(Integer.class).make();
  mgmt.buildIndex("byName", Vertex.class).addKey(name).unique().buildCompositeIndex();
  finishSchema();
  JanusGraphVertex cartman = graph.addVertex("name", "cartman", "age", 10);
  graph.addVertex("name", "stan", "age", 8);
  graph.tx().commit();
  cartman = Iterables.getOnlyElement(graph.query().has("name", "cartman").vertices());
  graph.tx().commit();
  JanusGraphVertexProperty p = (JanusGraphVertexProperty) cartman.properties().next();
  assertTrue((p.longId()) > 0);
  graph.tx().commit();
}

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

@Test
public void testArrayEqualityUsingImplicitKey() {
  JanusGraphVertex v = graph.addVertex();
  byte singleDimension[] = new byte[]{127, 0, 0, 1};
  byte singleDimensionCopy[] = new byte[]{127, 0, 0, 1};
  final String singlePropName = "single";
  v.property(singlePropName, singleDimension);
  assertEquals(1, Iterables.size(graph.query().has(singlePropName, singleDimension).vertices()));
  assertEquals(1, Iterables.size(graph.query().has(singlePropName, singleDimensionCopy).vertices()));
  graph.tx().commit();
  assertEquals(1, Iterables.size(graph.query().has(singlePropName, singleDimension).vertices()));
  assertEquals(1, Iterables.size(graph.query().has(singlePropName, singleDimensionCopy).vertices()));
}

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

@Test
public void testNestedTransactions() {
  Vertex v1 = graph.addVertex();
  newTx();
  Vertex v2 = tx.addVertex();
  v2.property("name", "foo");
  tx.commit();
  v1.addEdge("related", graph.traversal().V(v2).next());
  graph.tx().commit();
  assertCount(1, v1.edges(OUT));
}

代码示例来源: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: JanusGraph/janusgraph

@Test
public void testNestedTransactions() {
  Vertex v1 = graph.addVertex();
  newTx();
  Vertex v2 = tx.addVertex();
  v2.property("name", "foo");
  tx.commit();
  v1.addEdge("related", graph.traversal().V(v2).next());
  graph.tx().commit();
  assertCount(1, v1.edges(OUT));
}

代码示例来源: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 testPartitionedVertexScan() throws Exception {
  tearDown();
  clearGraph(getConfiguration());
  WriteConfiguration partConf = getConfiguration();
  open(partConf);
  mgmt.makeVertexLabel("part").partition().make();
  finishSchema();
  TitanVertex supernode = graph.addVertex("part");
  for (int i = 0; i < 128; i++) {
    TitanVertex v = graph.addVertex("part");
    v.addEdge("default", supernode);
    if (0 < i && 0 == i % 4)
      graph.tx().commit();
  }
  graph.tx().commit();
  org.apache.hadoop.conf.Configuration c = new org.apache.hadoop.conf.Configuration();
  c.set(ConfigElement.getPath(TitanHadoopConfiguration.GRAPH_CONFIG_KEYS, true) + "." + "storage.cassandra.keyspace", getClass().getSimpleName());
  c.set(ConfigElement.getPath(TitanHadoopConfiguration.GRAPH_CONFIG_KEYS, true) + "." + "storage.backend", "cassandrathrift");
  c.set("cassandra.input.partitioner.class", "org.apache.cassandra.dht.Murmur3Partitioner");
  Job job = getVertexJobWithDefaultMapper(c);
  // Should throw an exception since filter-partitioned-vertices wasn't enabled
  assertFalse(job.waitForCompletion(true));
}

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

@Test
public void testPartitionedVertexFilteredScan() throws Exception {
  tearDown();
  clearGraph(getConfiguration());
  WriteConfiguration partConf = getConfiguration();
  open(partConf);
  mgmt.makeVertexLabel("part").partition().make();
  finishSchema();
  TitanVertex supernode = graph.addVertex("part");
  for (int i = 0; i < 128; i++) {
    TitanVertex v = graph.addVertex("part");
    v.addEdge("default", supernode);
    if (0 < i && 0 == i % 4)
      graph.tx().commit();
  }
  graph.tx().commit();
  org.apache.hadoop.conf.Configuration c = new org.apache.hadoop.conf.Configuration();
  c.set(ConfigElement.getPath(TitanHadoopConfiguration.GRAPH_CONFIG_KEYS, true) + "." + "storage.cassandra.keyspace", getClass().getSimpleName());
  c.set(ConfigElement.getPath(TitanHadoopConfiguration.GRAPH_CONFIG_KEYS, true) + "." + "storage.backend", "cassandrathrift");
  c.set(ConfigElement.getPath(TitanHadoopConfiguration.FILTER_PARTITIONED_VERTICES), "true");
  c.set("cassandra.input.partitioner.class", "org.apache.cassandra.dht.Murmur3Partitioner");
  Job job = getVertexJobWithDefaultMapper(c);
  // Should succeed
  assertTrue(job.waitForCompletion(true));
}

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

@Test
public void testEdgesExceedCacheSize() {
  // Add a vertex with as many edges as the tx-cache-size. (20000 by default)
  int numEdges = graph.getConfiguration().getTxVertexCacheSize();
  TitanVertex parentVertex = graph.addVertex();
  for (int i = 0; i < numEdges; i++) {
    TitanVertex childVertex = graph.addVertex();
    parentVertex.addEdge("friend", childVertex);
  }
  graph.tx().commit();
  assertCount(numEdges, parentVertex.query().direction(Direction.OUT).edges());
  // Remove an edge.
  parentVertex.query().direction(OUT).edges().iterator().next().remove();
  // Check that getEdges returns one fewer.
  assertCount(numEdges - 1, parentVertex.query().direction(Direction.OUT).edges());
  // Run the same check one more time.
  // This fails! (Expected: 19999. Actual: 20000.)
  assertCount(numEdges - 1, parentVertex.query().direction(Direction.OUT).edges());
}

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

@Test
public void testUnsettingTTL() throws InterruptedException {
  if (!features.hasCellTTL()) {
  TitanVertex v2 = graph.addVertex();
  v1.addEdge("likes", v2);
  graph.tx().commit();
  v2 = graph.addVertex();
  v1.addEdge("likes", v2);
  graph.tx().commit();

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

@Test
public void testCacheSpeedup() {
  Object[] newConfig = {option(GraphDatabaseConfiguration.DB_CACHE),true,
    previous = v;
  graph.tx().commit();
  long vertexId = getId(previous);
  assertCount(numV, graph.query().vertices());
    double timehot = 0;
    for (int i = 0;i<innerRepeat;i++) {
      graph.tx().commit();
      timewarm += testAllVertices(vertexId,numV);
      for (int j=0;j<innerRepeat;j++) {

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

@Test
public void testEdgesExceedCacheSize() {
  // Add a vertex with as many edges as the tx-cache-size. (20000 by default)
  int numEdges = graph.getConfiguration().getTxVertexCacheSize();
  JanusGraphVertex parentVertex = graph.addVertex();
  for (int i = 0; i < numEdges; i++) {
    JanusGraphVertex childVertex = graph.addVertex();
    parentVertex.addEdge("friend", childVertex);
  }
  graph.tx().commit();
  assertCount(numEdges, parentVertex.query().direction(Direction.OUT).edges());
  // Remove an edge.
  parentVertex.query().direction(OUT).edges().iterator().next().remove();
  // Check that getEdges returns one fewer.
  assertCount(numEdges - 1, parentVertex.query().direction(Direction.OUT).edges());
  // Run the same check one more time.
  // This fails! (Expected: 19999. Actual: 20000.)
  assertCount(numEdges - 1, parentVertex.query().direction(Direction.OUT).edges());
}

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

@Test
public void testIndexQueryWithLabelsAndContainsIN() {
  // This test is based on the steps to reproduce #882
  String labelName = "labelName";
  VertexLabel label = mgmt.makeVertexLabel(labelName).make();
  PropertyKey uid = mgmt.makePropertyKey("uid").dataType(String.class).make();
  TitanGraphIndex uidCompositeIndex = mgmt.buildIndex("uidIndex", Vertex.class).indexOnly(label).addKey(uid).unique().buildCompositeIndex();
  mgmt.setConsistency(uidCompositeIndex, ConsistencyModifier.LOCK);
  finishSchema();
  TitanVertex foo = graph.addVertex(labelName);
  TitanVertex bar = graph.addVertex(labelName);
  foo.property("uid", "foo");
  bar.property("uid", "bar");
  graph.tx().commit();
  Iterable<TitanVertex> vertexes = graph.query()
      .has("uid", Contain.IN, ImmutableList.of("foo", "bar"))
      .has(LABEL_NAME, labelName)
      .vertices();
  assertEquals(2, Iterables.size(vertexes));
  for (TitanVertex v : vertexes) {
    assertEquals(labelName, v.vertexLabel().name());
  }
}

代码示例来源: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

@Category({BrittleTests.class})
@Test
public void testEdgeTTLWithIndex() throws Exception {
  if (!features.hasCellTTL()) {
  assertNotEmpty(graph.query().has("time", 42).edges());
  graph.tx().commit();
  long commitTime = System.currentTimeMillis();

代码示例来源: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: JanusGraph/janusgraph

@Test
public void testIndexQueryWithLabelsAndContainsIN() {
  // This test is based on the steps to reproduce #882
  String labelName = "labelName";
  VertexLabel label = mgmt.makeVertexLabel(labelName).make();
  PropertyKey uid = mgmt.makePropertyKey("uid").dataType(String.class).make();
  JanusGraphIndex uidCompositeIndex = mgmt.buildIndex("uidIndex", Vertex.class)
      .indexOnly(label).addKey(uid).unique().buildCompositeIndex();
  mgmt.setConsistency(uidCompositeIndex, ConsistencyModifier.LOCK);
  finishSchema();
  JanusGraphVertex foo = graph.addVertex(labelName);
  JanusGraphVertex bar = graph.addVertex(labelName);
  foo.property("uid", "foo");
  bar.property("uid", "bar");
  graph.tx().commit();
  Iterable<JanusGraphVertex> vertexes = graph.query()
      .has("uid", Contain.IN, ImmutableList.of("foo", "bar"))
      .has(LABEL_NAME, labelName)
      .vertices();
  assertEquals(2, Iterables.size(vertexes));
  for (JanusGraphVertex v : vertexes) {
    assertEquals(labelName, v.vertexLabel().name());
  }
}

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

@Test
public void testCreateDelete() {
  makeKey("weight", Double.class);
  Edge e2 = v1.addEdge("friend", v3);
  assertEquals(111, e.<Integer>value("uid").intValue());
  graph.tx().commit();

相关文章