You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2015/05/26 15:35:15 UTC
[2/2] incubator-tinkerpop git commit: Add some versioning to GraphSON.
Add some versioning to GraphSON.
In this way, we can change the format of GraphSON and allow users to choose which version they want.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/61137ebd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/61137ebd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/61137ebd
Branch: refs/heads/master
Commit: 61137ebd97bd6691a67a62d31356d61348712515
Parents: 2f8a972
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue May 26 09:19:26 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 26 09:19:26 2015 -0400
----------------------------------------------------------------------
.../structure/io/graphson/GraphSONMapper.java | 32 +++++++++-
.../structure/io/graphson/GraphSONModule.java | 67 ++++++++++++++++----
.../structure/io/graphson/GraphSONVersion.java | 38 +++++++++++
3 files changed, 120 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/61137ebd/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapper.java
index 0bbcfef..ea1ea2b 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapper.java
@@ -59,13 +59,15 @@ public class GraphSONMapper implements Mapper<ObjectMapper> {
private final boolean loadCustomSerializers;
private final boolean normalize;
private final boolean embedTypes;
+ private final GraphSONVersion version;
private GraphSONMapper(final List<SimpleModule> customModules, final boolean loadCustomSerializers,
- final boolean normalize, final boolean embedTypes) {
+ final boolean normalize, final boolean embedTypes, final GraphSONVersion version) {
this.customModules = customModules;
this.loadCustomSerializers = loadCustomSerializers;
this.normalize = normalize;
this.embedTypes = embedTypes;
+ this.version = version;
}
@Override
@@ -89,7 +91,7 @@ public class GraphSONMapper implements Mapper<ObjectMapper> {
provider.setDefaultKeySerializer(new GraphSONSerializers.GraphSONKeySerializer());
om.setSerializerProvider(provider);
- om.registerModule(new GraphSONModule(normalize));
+ om.registerModule(version.getBuilder().create(normalize));
customModules.forEach(om::registerModule);
// plugin external serialization modules
@@ -102,6 +104,10 @@ public class GraphSONMapper implements Mapper<ObjectMapper> {
return om;
}
+ public GraphSONVersion getVersion() {
+ return this.version;
+ }
+
public static Builder build() {
return new Builder();
}
@@ -112,10 +118,14 @@ public class GraphSONMapper implements Mapper<ObjectMapper> {
private boolean normalize = false;
private boolean embedTypes = false;
private IoRegistry registry = null;
+ private GraphSONVersion version = GraphSONVersion.V1_0;
private Builder() {
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public Builder addRegistry(final IoRegistry registry) {
this.registry = registry;
@@ -123,6 +133,22 @@ public class GraphSONMapper implements Mapper<ObjectMapper> {
}
/**
+ * Set the version of GraphSON to use.
+ */
+ public Builder version(final GraphSONVersion version) {
+ this.version = version;
+ return this;
+ }
+
+ /**
+ * Set the version of GraphSON to use.
+ */
+ public Builder version(final String version) {
+ this.version = GraphSONVersion.valueOf(version);
+ return this;
+ }
+
+ /**
* Supply a mapper module for serialization/deserialization.
*/
public Builder addCustomModule(final SimpleModule custom) {
@@ -161,7 +187,7 @@ public class GraphSONMapper implements Mapper<ObjectMapper> {
simpleModules.stream().map(Pair::getValue1).forEach(this.customModules::add);
}
- return new GraphSONMapper(customModules, loadCustomModules, normalize, embedTypes);
+ return new GraphSONMapper(customModules, loadCustomModules, normalize, embedTypes, version);
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/61137ebd/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
index 3a66390..4161faf 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
@@ -31,25 +31,64 @@ import org.apache.tinkerpop.gremlin.structure.util.star.StarGraphGraphSONSeriali
* The set of serializers that handle the core graph interfaces. These serializers support normalization which
* ensures that generated GraphSON will be compatible with line-based versioning tools. This setting comes with
* some overhead, with respect to key sorting and other in-memory operations.
+ * <p/>
+ * This is a base class for grouping these core serializers. Concrete extensions of this class represent a "version"
+ * that should be registered with the {@link GraphSONVersion} enum.
*
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
-class GraphSONModule extends SimpleModule {
+abstract class GraphSONModule extends SimpleModule {
+
+ GraphSONModule(final String name) {
+ super(name);
+ }
+
+ /**
+ * Version 1.0 of GraphSON.
+ */
+ static final class GraphSONModuleV1d0 extends GraphSONModule {
+
+ /**
+ * Constructs a new object.
+ */
+ GraphSONModuleV1d0(final boolean normalize) {
+ super("graphson-1.0");
+ addSerializer(Edge.class, new GraphSONSerializers.EdgeJacksonSerializer(normalize));
+ addSerializer(Vertex.class, new GraphSONSerializers.VertexJacksonSerializer(normalize));
+ addSerializer(VertexProperty.class, new GraphSONSerializers.VertexPropertyJacksonSerializer(normalize));
+ addSerializer(Property.class, new GraphSONSerializers.PropertyJacksonSerializer());
+ addSerializer(TraversalMetrics.class, new GraphSONSerializers.TraversalMetricsJacksonSerializer());
+ addSerializer(Path.class, new GraphSONSerializers.PathJacksonSerializer());
+ addSerializer(StarGraphGraphSONSerializer.DirectionalStarGraph.class, new StarGraphGraphSONSerializer(normalize));
+ }
+
+ public static Builder build() {
+ return new Builder();
+ }
+
+ static final class Builder implements GraphSONModuleBuilder {
+
+ private Builder() {}
+
+ @Override
+ public GraphSONModule create(final boolean normalize) {
+ return new GraphSONModuleV1d0(normalize);
+ }
+ }
+ }
/**
- * Constructs a new object.
- *
- * @param normalize when set to true, keys and objects are ordered to ensure that they are the occur in
- * the same order
+ * A "builder" used to create {@link GraphSONModule} instances. Each "version" should have an associated
+ * {@code GraphSONModuleBuilder} so that it can be registered with the {@link GraphSONVersion} enum.
*/
- public GraphSONModule(final boolean normalize) {
- super("graphson");
- addSerializer(Edge.class, new GraphSONSerializers.EdgeJacksonSerializer(normalize));
- addSerializer(Vertex.class, new GraphSONSerializers.VertexJacksonSerializer(normalize));
- addSerializer(VertexProperty.class, new GraphSONSerializers.VertexPropertyJacksonSerializer(normalize));
- addSerializer(Property.class, new GraphSONSerializers.PropertyJacksonSerializer());
- addSerializer(TraversalMetrics.class, new GraphSONSerializers.TraversalMetricsJacksonSerializer());
- addSerializer(Path.class, new GraphSONSerializers.PathJacksonSerializer());
- addSerializer(StarGraphGraphSONSerializer.DirectionalStarGraph.class, new StarGraphGraphSONSerializer(normalize));
+ static interface GraphSONModuleBuilder {
+
+ /**
+ * Creates a new {@link GraphSONModule} object.
+ *
+ * @param normalize when set to true, keys and objects are ordered to ensure that they are the occur in
+ * the same order.
+ */
+ GraphSONModule create(final boolean normalize);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/61137ebd/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONVersion.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONVersion.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONVersion.java
new file mode 100644
index 0000000..aa5cd29
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONVersion.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.structure.io.graphson;
+
+/**
+ * The set of available GraphSON versions.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public enum GraphSONVersion {
+ V1_0(GraphSONModule.GraphSONModuleV1d0.build());
+
+ private final GraphSONModule.GraphSONModuleBuilder builder;
+
+ private GraphSONVersion(final GraphSONModule.GraphSONModuleBuilder builder) {
+ this.builder = builder;
+ }
+
+ public GraphSONModule.GraphSONModuleBuilder getBuilder() {
+ return builder;
+ }
+}