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

x33g5p2x  于2022-01-20 转载在 其他  
字(12.7k)|赞(0)|评价(0)|浏览(138)

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

Graph.features介绍

[英]Gets the Features exposed by the underlying Graph implementation.
[中]获取基础图实现公开的功能。

代码示例

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

/**
 * This isn't really a test.  It just pretty prints the features for the graph for reference.  Of course,
 * if the implementing classes use anonymous inner classes it will
 */
@Test
public void shouldPrintTheFeatureList() {
  logger.info(String.format("Printing Features of %s for reference: ", g.getClass().getSimpleName()));
  logger.info(graph.features().toString());
  assertTrue(true);
}

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

@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_UUID_IDS)
public void shouldIterateVerticesWithUuidIdSupportUsingVertices() {
  // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
  final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, UUID.randomUUID()) : graph.addVertex();
  final Vertex v2 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, UUID.randomUUID()) : graph.addVertex();
  graph.addVertex();
  tryCommit(graph, graph -> {
    assertEquals(2, IteratorUtils.count(graph.vertices(v1, v2)));
  });
}

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

@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
public void shouldSetValueOnVertexOnAdd() throws Exception {
  assumeThat(graph.features().supports(VertexPropertyFeatures.class, featureName), is(true));
  final Vertex vertex = graph.addVertex("aKey", value);
  assertPropertyValue(vertex);
}

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

@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
public void shouldUseActualVertexWhenAdded() {
  final AtomicBoolean triggered = new AtomicBoolean(false);
  final AtomicReference<Vertex> eventedVertex = new AtomicReference<>();
  final MutationListener listener = new AbstractMutationListener() {
    @Override
    public void vertexAdded(final Vertex element) {
      eventedVertex.set(element);
      assertEquals("thing", element.label());
      assertThat(element.properties("here").hasNext(), is(false));
      triggered.set(true);
    }
  };
  final EventStrategy.Builder builder = EventStrategy.build().addListener(listener).detach(EventStrategy.Detachment.REFERENCE);
  if (graph.features().graph().supportsTransactions())
    builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph));
  final EventStrategy eventStrategy = builder.create();
  final GraphTraversalSource gts = create(eventStrategy);
  final Vertex v = gts.addV("thing").property("here", "there").next();
  tryCommit(graph);
  assertVertexEdgeCounts(graph, 1, 0);
  assertThat(triggered.get(), is(true));
  assertEquals(v, eventedVertex.get());
}

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

public Vertex vertexFromJson(final JsonNode json) throws IOException {
  final Map<String, Object> props = readProperties(json);
  final Object vertexId = getTypedValueFromJsonNode(json.get(GraphSONTokensTP2._ID));
  final Vertex v = vertexFeatures.willAllowId(vertexId) ? g.addVertex(T.id, vertexId) : g.addVertex();
  cache.put(vertexId, v);
  for (Map.Entry<String, Object> entry : props.entrySet()) {
    v.property(g.features().vertex().getCardinality(entry.getKey()), entry.getKey(), entry.getValue());
  }
  return v;
}

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

/**
 * Utility method that commits if the graph supports transactions and executes an assertion function before and
 * after the commit.  It assumes that the assertion should be true before and after the commit.
 */
public void tryCommit(final Graph graph, final Consumer<Graph> assertFunction) {
  assertFunction.accept(graph);
  if (graph.features().graph().supportsTransactions()) {
    graph.tx().commit();
    assertFunction.accept(graph);
  }
}

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

@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_NUMERIC_IDS)
public void shouldIterateVerticesWithNumericIdSupportUsingLongRepresentations() {
  // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
  final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, 1l) : graph.addVertex();
  final Vertex v2 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, 2l) : graph.addVertex();
  graph.addVertex();
  tryCommit(graph, graph -> {
    assertEquals(2, IteratorUtils.count(graph.vertices(Long.parseLong(v1.id().toString()), Long.parseLong(v2.id().toString()))));
  });
}

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

@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_PROPERTY)
public void shouldEnableFeatureOnVertexIfNotEnabled() throws Exception {
  assumeThat(graph.features().supports(VertexPropertyFeatures.class, featureName), is(false));
  try {
    graph.addVertex("aKey", value);
    fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexPropertyFeatures.class.getSimpleName(), featureName));
  } catch (Exception e) {
    validateException(Property.Exceptions.dataTypeOfPropertyValueNotSupported(value), e);
  }
}

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

@Test
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
public void shouldSetValueOnEdgeOnAdd() throws Exception {
  assumeThat(graph.features().supports(EdgePropertyFeatures.class, featureName), is(true));
  final Edge edge = createEdgeForPropertyFeatureTests("aKey", value);
  assertPropertyValue(edge);
}

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

public static Vertex createVertex(final Attachable<Vertex> attachableVertex, final Graph hostGraph) {
  final Vertex baseVertex = attachableVertex.get();
  final Vertex vertex = hostGraph.features().vertex().willAllowId(baseVertex.id()) ?
      hostGraph.addVertex(T.id, baseVertex.id(), T.label, baseVertex.label()) :
      hostGraph.addVertex(T.label, baseVertex.label());
  baseVertex.properties().forEachRemaining(vp -> {
    final VertexProperty vertexProperty = hostGraph.features().vertex().properties().willAllowId(vp.id()) ?
        vertex.property(hostGraph.features().vertex().getCardinality(vp.key()), vp.key(), vp.value(), T.id, vp.id()) :
        vertex.property(hostGraph.features().vertex().getCardinality(vp.key()), vp.key(), vp.value());
    vp.properties().forEachRemaining(p -> vertexProperty.property(p.key(), p.value()));
  });
  return vertex;
}

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

public TransactionalEventQueue(final Graph graph) {
  if (!graph.features().graph().supportsTransactions())
    throw new IllegalStateException(String.format("%s requires the graph to support transactions", EventStrategy.class.getName()));
  // since this is a transactional graph events are enqueued so the events should be fired/reset only after
  // transaction is committed/rolled back as tied to a graph transaction
  graph.tx().addTransactionListener(status -> {
    if (status == Transaction.Status.COMMIT)
      fireEventQueue();
    else if (status == Transaction.Status.ROLLBACK)
      resetEventQueue();
    else
      throw new RuntimeException(String.format("The %s is not aware of this status: %s", EventQueue.class.getName(), status));
  });
}

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

@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_UUID_IDS)
public void shouldIterateVerticesWithUuidIdSupportUsingStringRepresentations() {
  // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
  final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, UUID.randomUUID()) : graph.addVertex();
  final Vertex v2 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, UUID.randomUUID()) : graph.addVertex();
  graph.addVertex();
  tryCommit(graph, graph -> {
    assertEquals(2, IteratorUtils.count(graph.vertices(v1.id().toString(), v2.id().toString())));
  });
}

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

@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_PROPERTY)
public void shouldSetValueOnVertex() throws Exception {
  assumeThat(graph.features().supports(VertexPropertyFeatures.class, featureName), is(true));
  final Vertex vertex = graph.addVertex();
  vertex.property(VertexProperty.Cardinality.single, "aKey", value);
  assertPropertyValue(vertex);
}

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

@Test
@FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS, supported = false)
public void shouldNotAllowAnyIdsIfUserSuppliedIdsIsFalse() throws Exception {
  assertFalse(graph.features().vertex().willAllowId(graphProvider.convertId(99999943835l, Vertex.class)));
}

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

/**
 * Commit transactions across all {@link Graph} objects.
 */
public final void commitAll() {
  graphs.entrySet().forEach(e -> {
    final Graph graph = e.getValue();
    if (graph.features().graph().supportsTransactions() && graph.tx().isOpen())
      graph.tx().commit();
  });
}

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

@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_STRING_IDS)
public void shouldIterateVerticesWithStringIdSupportUsingVertices() {
  // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
  final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, "1") : graph.addVertex();
  final Vertex v2 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, "2") : graph.addVertex();
  graph.addVertex();
  tryCommit(graph, graph -> {
    assertEquals(2, IteratorUtils.count(graph.vertices(v1, v2)));
  });
}

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

@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
public void shouldDetachVertexWhenRemoved() {
  final AtomicBoolean triggered = new AtomicBoolean(false);
  final Vertex v = graph.addVertex();
  final String label = v.label();
  final Object id = v.id();
  final MutationListener listener = new AbstractMutationListener() {
    @Override
    public void vertexRemoved(final Vertex element) {
      assertThat(element, instanceOf(DetachedVertex.class));
      assertEquals(id, element.id());
      assertEquals(label, element.label());
      triggered.set(true);
    }
  };
  final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
  if (graph.features().graph().supportsTransactions())
    builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph));
  final EventStrategy eventStrategy = builder.create();
  final GraphTraversalSource gts = create(eventStrategy);
  gts.V(v).drop().iterate();
  tryCommit(graph);
  assertVertexEdgeCounts(graph, 0, 0);
  assertThat(triggered.get(), is(true));
}

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

@Test
@FeatureRequirement(featureClass = EdgeFeatures.class, feature = EdgeFeatures.FEATURE_USER_SUPPLIED_IDS, supported = false)
public void shouldNotAllowAnyIdsIfUserSuppliedIdsIsFalse() throws Exception {
  assertFalse(graph.features().edge().willAllowId(graphProvider.convertId(99999943835l, Edge.class)));
}

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

/**
 * Rollback transactions across all {@link Graph} objects.
 */
public final void rollbackAll() {
  graphs.entrySet().forEach(e -> {
    final Graph graph = e.getValue();
    if (graph.features().graph().supportsTransactions() && graph.tx().isOpen())
      graph.tx().rollback();
  });
}

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

@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_NUMERIC_IDS)
public void shouldIterateVerticesWithNumericIdSupportUsingIntegerRepresentations() {
  // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
  final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, 1l) : graph.addVertex();
  final Vertex v2 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, 2l) : graph.addVertex();
  graph.addVertex();
  tryCommit(graph, graph -> {
    assertEquals(2, IteratorUtils.count(graph.vertices(Integer.parseInt(v1.id().toString()), Integer.parseInt(v2.id().toString()))));
  });
}

相关文章