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

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

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

JanusGraph.traversal介绍

暂无

代码示例

代码示例来源: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 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: 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: 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: org.jboss.windup.web.addons/windup-web-support-impl

@Override
public Response getByType(Long executionID, String vertexType, Integer depth, Boolean dedup, String inEdges, String outEdges, Boolean includeInVertices, String blacklistProperties)
{
  List<String> inEdges_ = inEdges == null ? Collections.emptyList() : Arrays.asList(StringUtils.split(inEdges, ','));
  List<String> outEdges_ = outEdges == null ? Collections.emptyList() : Arrays.asList(StringUtils.split(outEdges, ','));
  List<String> blacklistProperties_ = blacklistProperties == null ? Collections.emptyList() : Arrays.asList(StringUtils.split(blacklistProperties, ','));
  GraphContext graphContext = getGraph(executionID);
  List<Map<String, Object>> vertices = new ArrayList<>();
  for (Vertex v : graphContext.getGraph().traversal().V().has(WindupVertexFrame.TYPE_PROP, vertexType).toSet())
  {
    vertices.add(convertToMap(new GraphMarshallingContext(executionID, v, depth, dedup, outEdges_, inEdges_, blacklistProperties_, includeInVertices), v));
  }
  return Response.status(Response.Status.OK).entity(vertices).build();
}

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

@Override
public Object executeGremlinScript(ScriptEngine scriptEngine, Map<? extends String, ? extends Object> userBindings,
                  String query, boolean isPath) throws ScriptException {
  Bindings bindings = scriptEngine.createBindings();
  bindings.putAll(userBindings);
  bindings.put("g", getGraph().traversal());
  Object result = scriptEngine.eval(query, bindings);
  return convertGremlinValue(result);
}

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

private Object executeGremlinScript(String gremlinQuery) throws AtlasBaseException {
  GremlinGroovyScriptEngine scriptEngine = getGremlinScriptEngine();
  try {
    Bindings bindings = scriptEngine.createBindings();
    bindings.put("graph", getGraph());
    bindings.put("g", getGraph().traversal());
    Object result = scriptEngine.eval(gremlinQuery, bindings);
    return result;
  } catch (ScriptException e) {
    throw new AtlasBaseException(AtlasErrorCode.GREMLIN_SCRIPT_EXECUTION_FAILED, e, gremlinQuery);
  } finally {
    releaseGremlinScriptEngine(scriptEngine);
  }
}

代码示例来源:origin: org.jboss.windup.web.addons/windup-web-support-impl

@Override
public List<Map<String, Object>> getByType(Long executionID, String vertexType, String propertyName, String propertyValue, Integer depth, Boolean dedup, Boolean includeInVertices)
{
  GraphContext graphContext = getGraph(executionID);
  List<Map<String, Object>> vertices = new ArrayList<>();
  Traversal<Vertex, Vertex> query = graphContext.getGraph().traversal().V().has(WindupVertexFrame.TYPE_PROP, vertexType).has(propertyName, propertyValue);
  for (Vertex vertex : query.toSet())
  {
    vertices.add(convertToMap(new GraphMarshallingContext(executionID, vertex, depth, dedup, null, null, null, includeInVertices), vertex));
  }
  return vertices;
}

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

@SuppressWarnings("unchecked")
public <T> List<T> findByClass(GraphContext graphContext, String edgeLabel, JavaClassModel javaClassModel, Class<T> typeClass)
{
  List<T> result = new ArrayList<>();
  graphContext.getGraph().traversal().V()
      .has(JavaClassModel.QUALIFIED_NAME, javaClassModel.getQualifiedName())
      .has(WindupFrame.TYPE_PROP, JavaClassModel.TYPE)
      .in(edgeLabel)
      .toList()
      .forEach(v -> {
        T frame = graphContext.getFramed().frameElement(v, typeClass);
        result.add(frame);
      });
  return result;
}

代码示例来源:origin: org.jboss.windup.rules.apps/windup-rules-java-ee

@SuppressWarnings("unchecked")
public <T> List<T> findByClass(GraphContext graphContext, String edgeLabel, JavaClassModel javaClassModel, Class<T> typeClass)
{
  List<T> result = new ArrayList<>();
  graphContext.getGraph().traversal().V()
      .has(JavaClassModel.QUALIFIED_NAME, javaClassModel.getQualifiedName())
      .has(WindupFrame.TYPE_PROP, JavaClassModel.TYPE)
      .in(edgeLabel)
      .toList()
      .forEach(v -> {
        T frame = graphContext.getFramed().frameElement(v, typeClass);
        result.add(frame);
      });
  return result;
}

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

@Override
public AtlasGraphTraversal<AtlasVertex, AtlasEdge> E(final Object... edgeIds) {
  AtlasGraphTraversal traversal = new AtlasJanusGraphTraversal(this, getGraph().traversal());
  traversal.getBytecode().addStep(GraphTraversal.Symbols.E, edgeIds);
  traversal.addStep(new GraphStep<>(traversal, Vertex.class, true, edgeIds));
  return traversal;
}

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

@Override
public AtlasGraphTraversal<AtlasVertex, AtlasEdge> V(final Object... vertexIds) {
  AtlasGraphTraversal traversal = new AtlasJanusGraphTraversal(this, getGraph().traversal());
  traversal.getBytecode().addStep(GraphTraversal.Symbols.V, vertexIds);
  traversal.addStep(new GraphStep<>(traversal, Vertex.class, true, vertexIds));
  return traversal;
}

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

@SuppressWarnings("unchecked")
public static <T extends WindupVertexFrame> T refresh(GraphContext context, T frame)
{
  Vertex v = context.getGraph().traversal().V((Long)frame.getId()).next();
  return (T) context.getFramed().frameElement(v, WindupVertexFrame.class);
}

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

@SuppressWarnings("unchecked")
public static <T extends WindupVertexFrame> T refresh(GraphContext context, T frame)
{
  Vertex v = context.getGraph().traversal().V((Long)frame.getId()).next();
  return (T) context.getFramed().frameElement(v, WindupVertexFrame.class);
}

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

/**
 * Return a global application index (not associated with a specific {@link ProjectModel}).
 */
public ApplicationReportIndexModel getOrCreateGlobalApplicationIndex()
{
  GraphTraversal<Vertex, Vertex> pipeline = getGraphContext().getGraph().traversal().V();
  pipeline.has(WindupVertexFrame.TYPE_PROP, ApplicationReportModel.TYPE);
  pipeline.filter(it -> !it.get().edges(Direction.OUT, ApplicationReportIndexModel.APPLICATION_REPORT_INDEX_TO_PROJECT_MODEL).hasNext());
  final ApplicationReportIndexModel result = pipeline.hasNext() ? frame(pipeline.next()) : create();
  return result;
}

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

/**
 * Return a global application index (not associated with a specific {@link ProjectModel}).
 */
public ApplicationReportIndexModel getOrCreateGlobalApplicationIndex()
{
  GraphTraversal<Vertex, Vertex> pipeline = getGraphContext().getGraph().traversal().V();
  pipeline.has(WindupVertexFrame.TYPE_PROP, ApplicationReportModel.TYPE);
  pipeline.filter(it -> !it.get().edges(Direction.OUT, ApplicationReportIndexModel.APPLICATION_REPORT_INDEX_TO_PROJECT_MODEL).hasNext());
  final ApplicationReportIndexModel result = pipeline.hasNext() ? frame(pipeline.next()) : create();
  return result;
}

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

public Iterable<FileModel> findByFilenameRegex(String filenameRegex)
{
  filenameRegex = TitanUtil.titanifyRegex(filenameRegex);
  Iterable<Vertex> vertices = getGraphContext().getGraph()
      .traversal()
      .V()
      .has(FileModel.FILE_NAME, Text.textRegex(filenameRegex))
      // I'm not sure why this is necessary, but for some reason ".has(WindupFrame.TYPE_PROP, FileModel.TYPE)"
      // seems to be unreliable with this query. Doing it with this filter seems to fix it.
      .filter(traversal -> {
        Iterator<VertexProperty<String>> typeIterator = traversal.get().properties(WindupFrame.TYPE_PROP);
        while (typeIterator.hasNext()) {
          if (FileModel.TYPE.equals(typeIterator.next().value())) {
            return true;
          }
        }
        return false;
      })
      .toList();
  return new FramedVertexIterable<>(getGraphContext().getFramed(), vertices, FileModel.class);
}

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

/**
 * Finds all {@link ArchiveModel}s with the given sha1 hash.
 */
public Iterable<ArchiveModel> findBySHA1(String sha1)
{
  List<Vertex> query = getGraphContext().getGraph().traversal()
    .V()
    .property(FileModel.SHA1_HASH, sha1)
    .property(WindupVertexFrame.TYPE_PROP, Text.CONTAINS, ArchiveModel.TYPE)
    .toList();
  return new FramedVertexIterable<>(getGraphContext().getFramed(), query, ArchiveModel.class);
}

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

/**
 * Finds all {@link ArchiveModel}s with the given sha1 hash.
 */
public Iterable<ArchiveModel> findBySHA1(String sha1)
{
  List<Vertex> query = getGraphContext().getGraph().traversal()
    .V()
    .property(FileModel.SHA1_HASH, sha1)
    .property(WindupVertexFrame.TYPE_PROP, Text.CONTAINS, ArchiveModel.TYPE)
    .toList();
  return new FramedVertexIterable<>(getGraphContext().getFramed(), query, ArchiveModel.class);
}

相关文章