org.janusgraph.core.JanusGraph类的使用及代码示例

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

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

JanusGraph介绍

[英]JanusGraph graph database implementation of the Blueprint's interface. Use JanusGraphFactory to open and configure JanusGraph instances.
[中]JanusGraph图形数据库实现了蓝图的接口。使用JanusGraphFactory打开和配置JanusGraph实例。

代码示例

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

/**
   * Calls {@link JanusGraphFactory#open(String)}, passing the JanusGraph configuration file path
   * which must be the sole element in the {@code args} array, then calls
   * {@link #load(org.janusgraph.core.JanusGraph)} on the opened graph,
   * then calls {@link org.janusgraph.core.JanusGraph#close()}
   * and returns.
   * <p>
   * This method may call {@link System#exit(int)} if it encounters an error, such as
   * failure to parse its arguments.  Only use this method when executing main from
   * a command line.  Use one of the other methods on this class ({@link #create(String)}
   * or {@link #load(org.janusgraph.core.JanusGraph)}) when calling from
   * an enclosing application.
   *
   * @param args a singleton array containing a path to a JanusGraph config properties file
   */
  public static void main(String args[]) {
    if (null == args || 1 != args.length) {
      System.err.println("Usage: GraphOfTheGodsFactory <janusgraph-config-file>");
      System.exit(1);
    }

    JanusGraph g = JanusGraphFactory.open(args[0]);
    load(g);
    g.close();
  }
}

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

/**
 * Drop graph database, deleting all data in storage and indexing backends. Graph can be open or closed (will be
 * closed as part of the drop operation). The graph is also removed from the {@link JanusGraphManager}
 * graph reference tracker, if there.
 *
 * <p><b>WARNING: This is an irreversible operation that will delete all graph and index data.</b></p>
 * @param graph JanusGraph graph database. Can be open or closed.
 * @throws BackendException If an error occurs during deletion
 */
public static void drop(JanusGraph graph) throws BackendException {
  Preconditions.checkNotNull(graph);
  Preconditions.checkArgument(graph instanceof StandardJanusGraph,"Invalid graph instance detected: %s",graph.getClass());
  final StandardJanusGraph g = (StandardJanusGraph) graph;
  final JanusGraphManager jgm = JanusGraphManagerUtility.getInstance();
  if (jgm != null) {
    jgm.removeGraph(g.getGraphName());
  }
  if (graph.isOpen()) {
    graph.close();
  }
  final GraphDatabaseConfiguration config = g.getConfiguration();
  final Backend backend = config.getBackend();
  try {
    backend.clearStorage();
  } finally {
    IOUtils.closeQuietly(backend);
  }
}

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

JanusGraphManagement m2 = g2.openManagement();
assertEquals(secondValue.toString(), m2.get(path));
g2.close();

代码示例来源:origin: awslabs/dynamodb-janusgraph-storage-backend

private static Vertex get(final JanusGraph graph, final String key, final String value) {
    final GraphTraversalSource g = graph.traversal();
    final Iterator<Vertex> it = g.V().has(key, value);
    if (it.hasNext()) {
      return it.next();
    }
    return null;
  }
}

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

JanusGraphManagement management = null;
try {
  management = g.openManagement();
  idx = management.getGraphIndex(graphIndexName);
  for (PropertyKey pk : idx.getFieldKeys()) {

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

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

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

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

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

public void setGraph(JanusGraph graph) {
  Preconditions.checkArgument(graph!=null && graph.isOpen(),"Need to provide open graph");
  this.graph = (StandardJanusGraph)graph;
  provided = true;
}

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

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

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

JanusGraphManagement management = graph.openManagement();
final PropertyKey name = management.makePropertyKey("name").dataType(String.class).make();
JanusGraphManagement.IndexBuilder nameIndexBuilder = management.buildIndex("name", Vertex.class).addKey(name);
JanusGraphTransaction tx = graph.newTransaction();

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

代码示例来源:origin: awslabs/dynamodb-janusgraph-storage-backend

@Override
  public void run() {
    final long start = System.currentTimeMillis();
    final Vertex vertex = graph.addVertex();
    vertex.property(COMIC_BOOK, comicBook);
    REGISTRY.counter(COUNTER_GET + COMIC_BOOK).inc();
    final long end = System.currentTimeMillis();
    final long time = end - start;
    REGISTRY.timer(TIMER_CREATE + COMIC_BOOK).update(time, TimeUnit.MILLISECONDS);
  }
}

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

JanusGraphTransaction tx1 = graph.newTransaction();
JanusGraphTransaction tx2 = graph.newTransaction();
job.run(tx1);
job.run(tx2);

代码示例来源: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 Iterable<AtlasVertex<AtlasJanusVertex, AtlasJanusEdge>> getVertices() {
  Iterator<Vertex> vertices = getGraph().vertices();
  return wrapVertices(vertices);
}

代码示例来源:origin: Netflix/ndbench

@Override
public void init(DataGenerator dataGenerator) throws Exception {
  this.graph = graphBuilder.open();
  this.traversalSource = graph.traversal();
  this.dataGenerator = dataGenerator;
  createSchema(graph);
  logger.info("Initing JanusGraph Plugin CQL");
}

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

private static void removeGraphFromCache(final JanusGraph graph) {
  final JanusGraphManager jgm = JanusGraphManagerUtility.getInstance();
  Preconditions.checkState(jgm != null, JANUS_GRAPH_MANAGER_EXPECTED_STATE_MSG);
  jgm.removeGraph(((StandardJanusGraph) graph).getGraphName());
  final ManagementSystem mgmt = (ManagementSystem) graph.openManagement();
  mgmt.evictGraphFromCache();
  mgmt.commit();
}

相关文章