@Override public Object id() { return this.baseVertexProperty.id(); }
@Override public void vertexPropertyPropertyRemoved(final VertexProperty element, final Property o) { vertexPropertyPropertyRemovedEvent.incrementAndGet(); order.add("vp-property-removed-" + element.id() + "-" + o); }
@Override public void vertexPropertyPropertyChanged(final VertexProperty element, final Property oldValue, final Object setValue) { vertexPropertyPropertyChangedEvent.incrementAndGet(); order.add("vp-property-changed-" + element.id()); }
@Override public void vertexPropertyRemoved(final VertexProperty vertexProperty) { vertexPropertyRemovedEvent.incrementAndGet(); order.add("vp-property-removed-" + vertexProperty.id()); }
@Override public boolean equals(Object obj) { if (!(obj instanceof VertexProperty)) { return false; } @SuppressWarnings("unchecked") VertexProperty<V> other = (VertexProperty<V>) obj; return this.id().equals(other.id()); }
private void addPropertiesToOriginalGraph() { TinkerHelper.dropGraphComputerView(this.graph); this.computeProperties.forEach((element, properties) -> { properties.forEach((key, vertexProperties) -> { vertexProperties.forEach(vertexProperty -> { final VertexProperty<?> newVertexProperty = ((Vertex) element).property(VertexProperty.Cardinality.list, vertexProperty.key(), vertexProperty.value(), T.id, vertexProperty.id()); vertexProperty.properties().forEachRemaining(property -> { newVertexProperty.property(property.key(), property.value()); }); }); }); }); this.computeProperties.clear(); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS, supported = false) @FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_NUMERIC_IDS, supported = false) public void shouldSupportNumericIdsIfNumericIdsAreGeneratedFromTheGraph() throws Exception { final Vertex v = graph.addVertex(); final VertexProperty p = v.property(VertexProperty.Cardinality.single, "name", "stephen"); if (p.id() instanceof Number) fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexPropertyFeatures.class.getSimpleName(), VertexPropertyFeatures.FEATURE_NUMERIC_IDS)); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS, supported = false) @FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_STRING_IDS, supported = false) public void shouldSupportStringIdsIfStringIdsAreGeneratedFromTheGraph() throws Exception { final Vertex v = graph.addVertex(); final VertexProperty p = v.property(VertexProperty.Cardinality.single, "name", "stephen"); if (p.id() instanceof String) fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexPropertyFeatures.class.getSimpleName(), VertexPropertyFeatures.FEATURE_STRING_IDS)); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS, supported = false) @FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_UUID_IDS, supported = false) public void shouldSupportUuidIdsIfUuidIdsAreGeneratedFromTheGraph() throws Exception { final Vertex v = graph.addVertex(); final VertexProperty p = v.property(VertexProperty.Cardinality.single, "name", "stephen"); if (p.id() instanceof UUID) fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexPropertyFeatures.class.getSimpleName(), VertexPropertyFeatures.FEATURE_UUID_IDS)); }
private static void serializerVertexProperty(final VertexProperty property, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider, final TypeSerializer typeSerializer, final boolean normalize, final boolean includeLabel) throws IOException { jsonGenerator.writeStartObject(); if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName()); GraphSONUtil.writeWithType(GraphSONTokens.ID, property.id(), jsonGenerator, serializerProvider, typeSerializer); GraphSONUtil.writeWithType(GraphSONTokens.VALUE, property.value(), jsonGenerator, serializerProvider, typeSerializer); if (includeLabel) jsonGenerator.writeStringField(GraphSONTokens.LABEL, property.label()); tryWriteMetaProperties(property, jsonGenerator, serializerProvider, typeSerializer, normalize); jsonGenerator.writeEndObject(); }
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"); }
@Override public void serialize(final VertexProperty property, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeStartObject(); jsonGenerator.writeObjectField(GraphSONTokens.ID, property.id()); jsonGenerator.writeObjectField(GraphSONTokens.VALUE, property.value()); if (includeLabel) jsonGenerator.writeStringField(GraphSONTokens.LABEL, property.label()); tryWriteMetaProperties(property, jsonGenerator, normalize); jsonGenerator.writeEndObject(); }
@Override public void serialize(final VertexProperty property, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeStartObject(); jsonGenerator.writeObjectField(GraphSONTokens.ID, property.id()); jsonGenerator.writeObjectField(GraphSONTokens.VALUE, property.value()); if (includeLabel) jsonGenerator.writeStringField(GraphSONTokens.LABEL, property.label()); tryWriteMetaProperties(property, jsonGenerator, normalize); jsonGenerator.writeEndObject(); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeVertexProperty() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().version(GraphSONVersion.V2_0).create().createMapper(); final VertexProperty vp = graph.vertices(convertToVertexId("marko")).next().property("name"); final String json = mapper.writeValueAsString(vp); final VertexProperty detached = mapper.readValue(json, VertexProperty.class); assertNotNull(detached); assertEquals(vp.label(), detached.label()); assertEquals(vp.id(), detached.id()); assertEquals(vp.value(), detached.value()); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeVertexProperty() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().version(GraphSONVersion.V3_0).create().createMapper(); final VertexProperty vp = graph.vertices(convertToVertexId("marko")).next().property("name"); final String json = mapper.writeValueAsString(vp); final VertexProperty detached = mapper.readValue(json, VertexProperty.class); assertNotNull(detached); assertEquals(vp.label(), detached.label()); assertEquals(vp.id(), detached.id()); assertEquals(vp.value(), detached.value()); }
public static VertexProperty createVertexProperty(final Attachable<VertexProperty> attachableVertexProperty, final Vertex hostVertex) { final VertexProperty<Object> baseVertexProperty = attachableVertexProperty.get(); final VertexProperty vertexProperty = hostVertex.graph().features().vertex().properties().willAllowId(baseVertexProperty.id()) ? hostVertex.property(hostVertex.graph().features().vertex().getCardinality(baseVertexProperty.key()), baseVertexProperty.key(), baseVertexProperty.value(), T.id, baseVertexProperty.id()) : hostVertex.property(hostVertex.graph().features().vertex().getCardinality(baseVertexProperty.key()), baseVertexProperty.key(), baseVertexProperty.value()); baseVertexProperty.properties().forEachRemaining(p -> vertexProperty.property(p.key(), p.value())); return vertexProperty; }
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; }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_MULTI_PROPERTIES) @FeatureRequirement(featureClass = Graph.Features.VertexPropertyFeatures.class, feature = Graph.Features.VertexPropertyFeatures.FEATURE_INTEGER_VALUES) @FeatureRequirement(featureClass = Graph.Features.VertexPropertyFeatures.class, feature = Graph.Features.VertexPropertyFeatures.FEATURE_USER_SUPPLIED_IDS) public void shouldAllowIdAssignment() { final Vertex v = graph.addVertex(); final Object id = graphProvider.convertId(123131231l, VertexProperty.class); v.property(VertexProperty.Cardinality.single, "name", "stephen", T.id, id); tryCommit(graph, g -> assertEquals(id, v.property("name").id())); }
@Override protected ByteBuf writeValue(final VertexProperty value, final ByteBufAllocator allocator, final GraphBinaryWriter context) throws SerializationException { final CompositeByteBuf result = allocator.compositeBuffer(5); result.addComponent(true, context.write(value.id(), allocator)); result.addComponent(true, context.writeValue(value.label(), allocator, false)); result.addComponent(true, context.write(value.value(), allocator)); // we don't serialize the parent vertex even as a "reference", but, let's hold a place for it result.addComponent(true, context.write(null, allocator)); // we don't serialize properties for graph elements. they are "references", but we leave a place holder // here as an option for the future as we've waffled this soooooooooo many times now result.addComponent(true, context.write(null, allocator)); return result; } }
@Override public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final O output, final VertexProperty vertexProperty) { kryo.writeClassAndObject(output, vertexProperty.id()); output.writeString(vertexProperty.label()); kryo.writeClassAndObject(output, vertexProperty.value()); kryo.writeClassAndObject(output, vertexProperty.element().id()); output.writeString(vertexProperty.element().label()); if (vertexProperty instanceof DetachedVertexProperty || (vertexProperty.graph().features().vertex().supportsMetaProperties())) { writeElementProperties(kryo, output, vertexProperty); } else { output.writeBoolean(false); } }