org.janusgraph.core.JanusGraph.tx()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(87)

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

JanusGraph.tx介绍

暂无

代码示例

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

public static void assertGraphOfTheGods(JanusGraph graphOfTheGods) {
  assertCount(12, graphOfTheGods.query().vertices());
  assertCount(3, graphOfTheGods.query().has(LABEL_NAME, "god").vertices());
  final JanusGraphVertex h = getOnlyVertex(graphOfTheGods.query().has("name", "hercules"));
  assertEquals(30, h.<Integer>value("age").intValue());
  assertEquals("demigod", h.label());
  assertCount(5, h.query().direction(Direction.BOTH).edges());
  graphOfTheGods.tx().commit();
}

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

@Test
public void testOrForceIndexPartialIndex() throws Exception {
  JanusGraph customGraph = null;
  try {
    customGraph = this.getForceIndexGraph();
    final JanusGraphManagement management = customGraph.openManagement();
    final PropertyKey stringProperty = management.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make();
    management.makePropertyKey("age").dataType(Integer.class).cardinality(Cardinality.SINGLE).make();
    management.buildIndex("oridx", Vertex.class).addKey(stringProperty, getStringMapping()).buildMixedIndex(INDEX);
    management.commit();
    customGraph.tx().commit();
    final GraphTraversalSource g = customGraph.traversal();
    g.addV().property("name", "Hiro").property("age", 2).next();
    g.addV().property("name", "Totoro").property("age", 1).next();
    customGraph.tx().commit();
    g.V().or(__.has("name", "Totoro"),__.has("age", 2)).hasNext();
    fail("should fail");
  } catch (final JanusGraphException e){
    assertTrue(e.getMessage().contains("Could not find a suitable index to answer graph query and graph scans are disabled"));
  } finally {
    if (customGraph != null) {
      JanusGraphFactory.close(customGraph);
    }
  }
}

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

@Test
  public void testOrForceIndexComposite() throws Exception {
    JanusGraph customGraph = null;
    try {
      customGraph = this.getForceIndexGraph();
      final JanusGraphManagement management = customGraph.openManagement();
      management.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make();
      final PropertyKey ageProperty = management.makePropertyKey("age").dataType(Integer.class).cardinality(Cardinality.SINGLE).make();
      management.buildIndex("ageridx", Vertex.class).addKey(ageProperty).buildCompositeIndex();
      management.commit();
      customGraph.tx().commit();
      final GraphTraversalSource g = customGraph.traversal();
      g.addV().property("name", "Hiro").property("age", 2).next();
      g.addV().property("name", "Totoro").property("age", 1).next();
      customGraph.tx().commit();
      g.V().has("age", P.gte(4).or(P.lt(2))).hasNext();
      fail("should fail");
    } catch (final JanusGraphException e){
      assertTrue(e.getMessage().contains("Could not find a suitable index to answer graph query and graph scans are disabled"));
    } finally {
      if (customGraph != null) {
        JanusGraphFactory.close(customGraph);
      }
    }
  }
}

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

@Test
public void testOrForceIndexUniqueMixedIndex() throws Exception {
  JanusGraph customGraph = null;
  try {
    customGraph = this.getForceIndexGraph();
    final JanusGraphManagement management = customGraph.openManagement();
    final PropertyKey nameProperty = management.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make();
    final PropertyKey ageProperty = management.makePropertyKey("age").dataType(Integer.class).cardinality(Cardinality.SINGLE).make();
    final PropertyKey lengthProperty = management.makePropertyKey("length").dataType(Integer.class).cardinality(Cardinality.SINGLE).make();
    management.buildIndex("oridx", Vertex.class).addKey(nameProperty, getStringMapping()).addKey(ageProperty).addKey(lengthProperty).buildMixedIndex(INDEX);
    management.commit();
    customGraph.tx().commit();
    testOr(customGraph);
  } finally {
    if (customGraph != null) {
      JanusGraphFactory.close(customGraph);
    }
  }
}

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

@Test
public void testAndForceIndex() throws Exception {
  JanusGraph customGraph = null;
  try {
    customGraph = this.getForceIndexGraph();
    final JanusGraphManagement management = customGraph.openManagement();
    final PropertyKey nameProperty = management.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make();
    final PropertyKey ageProperty = management.makePropertyKey("age").dataType(Integer.class).cardinality(Cardinality.SINGLE).make();
    management.buildIndex("oridx", Vertex.class).addKey(nameProperty, getStringMapping()).addKey(ageProperty).buildMixedIndex(INDEX);
    management.commit();
    customGraph.tx().commit();
    final GraphTraversalSource g = customGraph.traversal();
    g.addV().property("name", "Hiro").property("age", 2).next();
    g.addV().property("name", "Totoro").property("age", 1).next();
    customGraph.tx().commit();
    assertCount(1, g.V().has("name", "Totoro"));
    assertCount(1, g.V().has("age", 2));
    assertCount(1, g.V().and(__.has("name", "Hiro"),__.has("age", 2)));
    assertCount(0, g.V().and(__.has("name", "Totoro"),__.has("age", 2)));
  } finally {
    if (customGraph != null) {
      JanusGraphFactory.close(customGraph);
    }
  }
}

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

@Test
public void testOrForceIndexMixedAndCompositeIndex() throws Exception {
  JanusGraph customGraph = null;
  try {
    customGraph = this.getForceIndexGraph();
    final JanusGraphManagement management = customGraph.openManagement();
    final PropertyKey nameProperty = management.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make();
    final PropertyKey ageProperty = management.makePropertyKey("age").dataType(Integer.class).cardinality(Cardinality.SINGLE).make();
    final PropertyKey lengthProperty = management.makePropertyKey("length").dataType(Integer.class).cardinality(Cardinality.SINGLE).make();
    management.buildIndex("nameidx", Vertex.class).addKey(nameProperty, getStringMapping()).buildMixedIndex(INDEX);
    management.buildIndex("ageridx", Vertex.class).addKey(ageProperty).buildCompositeIndex();
    management.buildIndex("lengthidx", Vertex.class).addKey(lengthProperty).buildMixedIndex(INDEX);
    management.commit();
    customGraph.tx().commit();
    testOr(customGraph);
  } finally {
    if (customGraph != null) {
      JanusGraphFactory.close(customGraph);
    }
  }
}

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

@Override
public Transaction newTransaction()
{
  return context.getGraph().tx();
}

代码示例来源:origin: org.jboss.windup.graph/windup-graph-api

@Override
public Transaction newTransaction()
{
  return context.getGraph().tx();
}

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

public static void unload() {
  synchronized (AtlasJanusGraphDatabase.class) {
    if (graphInstance == null) {
      return;
    }
    graphInstance.tx().commit();
    graphInstance.close();
    graphInstance = null;
  }
}

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

@Override
public JanusGraph getGraphWithNewTransaction(JanusGraph graph, boolean batchloading){
  if(graph.isClosed()) graph = buildTinkerPopGraph(batchloading);
  if(!graph.tx().isOpen()){
    graph.tx().open();
  }
  return graph;
}

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

@Override
public void commit() {
  getGraph().tx().commit();
}

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

@Override
public void rollback() {
  getGraph().tx().rollback();
}

代码示例来源:origin: org.jboss.windup.graph/windup-graph-impl

@Override
public void commit()
{
  getGraph().tx().commit();
}

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

@Override
public void commit()
{
  getGraph().tx().commit();
}

代码示例来源:origin: marcelocf/janusgraph_tutorial

/**
 * Commit the current transaction and close the graph.
 */
private void close(){
 // we need to commit the Management changes or else they are not applied.
 mgt.commit();
 graph.tx().commit();
 graph.close();
}

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

@Override
public void openTransaction(GraknTxType txType){
  super.openTransaction(txType);
  if(getTinkerPopGraph().isOpen() && !getTinkerPopGraph().tx().isOpen()) getTinkerPopGraph().tx().open();
}

代码示例来源:origin: org.jboss.windup.graph/windup-graph-api

@Override
public void commit()
{
  ExecutionStatistics.performBenchmarked("GraphService.commit", () ->
  {
    getGraphContext().getGraph().tx().commit();
    return null;
  });
}

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

@Override
public void commit()
{
  ExecutionStatistics.performBenchmarked("GraphService.commit", () ->
  {
    getGraphContext().getGraph().tx().commit();
    return null;
  });
}

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

@Override
public String writeSingle(String key) throws Exception {
  if (useJanusgraphTransaction) {
      graph.addVertex(T.label, VERTEX_LABEL_LEVEL_1, PROP_CUSTOM_ID_KEY, key, PROP_METADATA_KEY,
          dataGenerator.getRandomValue()); //Automatically opens a new transaction
      graph.tx().commit();
  } else {
    traversalSource.getGraph().addVertex(T.label, VERTEX_LABEL_LEVEL_1, PROP_CUSTOM_ID_KEY, key,
        PROP_METADATA_KEY, dataGenerator.getRandomValue());
    traversalSource.getGraph().tx().commit();
  }
  return OK;
}

相关文章