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; }
@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())))); }); }
@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 shouldIterateVerticesWithNumericIdSupportUsingDoubleRepresentation() { // 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(); graph.addVertex(); tryCommit(graph, graph -> { final Vertex v = graph.vertices(Double.parseDouble(v1.id().toString())).next(); assertEquals(v1.id(), v.id()); }); }
@Test @FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS, supported = false) public void shouldNotAllowAnyIdsIfUserSuppliedIdsIsFalse() throws Exception { assertFalse(graph.features().vertex().properties().willAllowId(graphProvider.convertId(99999943835l, VertexProperty.class))); }
@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 shouldIterateVerticesWithStringIdSupportUsingVertexId() { // 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(); graph.addVertex(); tryCommit(graph, graph -> { final Vertex v = graph.vertices(v1.id()).next(); assertEquals(v1.id(), v.id()); }); }
@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 shouldIterateVerticesWithNumericIdSupportUsingStringRepresentations() { // 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(v1.id().toString(), v2.id().toString()))); }); }
@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 shouldIterateVerticesWithNumericIdSupportUsingDoubleRepresentations() { // 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(Double.parseDouble(v1.id().toString()), Double.parseDouble(v2.id().toString())))); }); }
@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 shouldIterateVerticesWithNumericIdSupportUsingVertexIds() { // 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(v1.id(), v2.id()))); }); }
@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 shouldIterateVerticesWithNumericIdSupportUsingVertices() { // 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(v1, v2))); }); }
@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 shouldIterateVerticesWithNumericIdSupportUsingStringRepresentation() { // 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(); graph.addVertex(); tryCommit(graph, graph -> { final Vertex v = graph.vertices(v1.id().toString()).next(); assertEquals(v1.id(), v.id()); }); }
@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 shouldIterateVerticesWithUuidIdSupportUsingStringRepresentation() { // 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(); graph.addVertex(); tryCommit(graph, graph -> { final Vertex v = graph.vertices(v1.id().toString()).next(); assertEquals(v1.id(), v.id()); }); }
@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 shouldIterateVerticesWithUuidIdSupportUsingVertex() { // 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(); graph.addVertex(); tryCommit(graph, graph -> { final Vertex v = graph.vertices(v1).next(); assertEquals(v1.id(), v.id()); }); }
@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()))); }); }
@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 shouldIterateVerticesWithUuidIdSupportUsingVertexId() { // 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(); graph.addVertex(); tryCommit(graph, graph -> { final Vertex v = graph.vertices(v1.id()).next(); assertEquals(v1.id(), v.id()); }); }
public static VertexProperty createVertexProperty(final Attachable<VertexProperty> attachableVertexProperty, final Graph hostGraph) { final VertexProperty<Object> baseVertexProperty = attachableVertexProperty.get(); final Iterator<Vertex> vertexIterator = hostGraph.vertices(baseVertexProperty.element().id()); if (vertexIterator.hasNext()) { final VertexProperty vertexProperty = hostGraph.features().vertex().properties().willAllowId(baseVertexProperty.id()) ? vertexIterator.next().property(hostGraph.features().vertex().getCardinality(baseVertexProperty.key()), baseVertexProperty.key(), baseVertexProperty.value(), T.id, baseVertexProperty.id()) : vertexIterator.next().property(hostGraph.features().vertex().getCardinality(baseVertexProperty.key()), baseVertexProperty.key(), baseVertexProperty.value()); baseVertexProperty.properties().forEachRemaining(p -> vertexProperty.property(p.key(), p.value())); return vertexProperty; } throw new IllegalStateException("Could not find vertex to create the attachable vertex property on"); }
@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))); }
@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 shouldIterateVerticesWithStringIdSupportUsingVertexIds() { // 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.id(), v2.id()))); }); }
@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))); }); }
@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 shouldIterateVerticesWithUuidIdSupportUsingVertexIds() { // 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(), v2.id()))); }); }
@Before public void innerSetup() { final Graph.Features f = graph.features(); edgeFeatures = f.edge(); edgePropertyFeatures = edgeFeatures.properties(); graphFeatures = f.graph(); variablesFeatures = graphFeatures.variables(); vertexFeatures = f.vertex(); vertexPropertyFeatures = vertexFeatures.properties(); }