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/04/09 16:12:12 UTC
[15/15] incubator-tinkerpop git commit: Still trying to get all tests
to run after enforcing id types in TinkerGraph.
Still trying to get all tests to run after enforcing id types in TinkerGraph.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/59028c8a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/59028c8a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/59028c8a
Branch: refs/heads/TINKERPOP3-581
Commit: 59028c8ad18f23609e31220a59717a2bc05b78af
Parents: 53a06b7
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Apr 9 10:10:59 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Apr 9 10:10:59 2015 -0400
----------------------------------------------------------------------
.../traversal/step/sideEffect/GraphStep.java | 18 +--
.../apache/tinkerpop/gremlin/LoadGraphWith.java | 4 +-
.../process/traversal/CoreTraversalTest.java | 2 +-
.../tinkerpop/gremlin/structure/EdgeTest.java | 2 +-
.../tinkerpop/gremlin/structure/VertexTest.java | 11 +-
.../tinkergraph/structure/TinkerGraph.java | 135 ++++++++++++-------
.../tinkergraph/structure/TinkerHelper.java | 43 +++++-
.../tinkergraph/structure/TinkerVertex.java | 15 ++-
.../structure/TinkerVertexProperty.java | 13 +-
9 files changed, 158 insertions(+), 85 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/59028c8a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GraphStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GraphStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GraphStep.java
index bb78fbe..832100e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GraphStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GraphStep.java
@@ -50,24 +50,10 @@ public class GraphStep<S extends Element> extends StartStep<S> implements Engine
super(traversal);
this.returnClass = returnClass;
this.ids = ids;
- //validate that all elements are either ids or elements. mixed is not supported.
- boolean foundElements = false;
- for (Object id : this.ids) {
- boolean idIsElement = id instanceof Element;
- if (foundElements && !idIsElement) {
- throw Graph.Exceptions.idArgsMustBeEitherIdOrElement();
- } else {
- foundElements = foundElements || idIsElement;
- }
- }
- if (foundElements) {
- List<S> elementList = Arrays.asList(this.ids).stream().map(id->(S)id).collect(Collectors.toList());
- this.iteratorSupplier = elementList::iterator;
- } else {
- this.iteratorSupplier = () -> (Iterator<S>) (Vertex.class.isAssignableFrom(this.returnClass) ?
+
+ this.iteratorSupplier = () -> (Iterator<S>) (Vertex.class.isAssignableFrom(this.returnClass) ?
this.getTraversal().getGraph().get().vertices(this.ids) :
this.getTraversal().getGraph().get().edges(this.ids));
- }
}
public String toString() {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/59028c8a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/LoadGraphWith.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/LoadGraphWith.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/LoadGraphWith.java
index b893891..20dac12 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/LoadGraphWith.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/LoadGraphWith.java
@@ -93,7 +93,7 @@ public @interface LoadGraphWith {
add(FeatureRequirement.Factory.create(FEATURE_MULTI_PROPERTIES, Graph.Features.VertexFeatures.class));
}};
- private static final List<FeatureRequirement> featuresRequiredByClassicDouble = new ArrayList<FeatureRequirement>() {{
+ private static final List<FeatureRequirement> featuresRequiredByModern = new ArrayList<FeatureRequirement>() {{
add(FeatureRequirement.Factory.create(FEATURE_STRING_VALUES, VertexPropertyFeatures.class));
add(FeatureRequirement.Factory.create(FEATURE_INTEGER_VALUES, VertexPropertyFeatures.class));
add(FeatureRequirement.Factory.create(FEATURE_DOUBLE_VALUES, EdgePropertyFeatures.class));
@@ -126,7 +126,7 @@ public @interface LoadGraphWith {
case CREW:
return featuresRequiredByCrew;
case MODERN:
- return featuresRequiredByClassicDouble;
+ return featuresRequiredByModern;
case GRATEFUL:
return featuresRequiredByGrateful;
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/59028c8a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/CoreTraversalTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/CoreTraversalTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/CoreTraversalTest.java
index b208290..75216a1 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/CoreTraversalTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/CoreTraversalTest.java
@@ -81,7 +81,7 @@ public class CoreTraversalTest extends AbstractGremlinProcessTest {
@Test
@LoadGraphWith(MODERN)
- public void shouldLoadEdgesViaVertices() {
+ public void shouldLoadEdgesViaEdges() {
List<Edge> edges = g.E().toList();
List<Edge> edgesReloaded = g.E(edges.toArray()).toList();
assertEquals(edges.size(), edgesReloaded.size());
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/59028c8a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/EdgeTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/EdgeTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/EdgeTest.java
index 35b427b..67eedf3 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/EdgeTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/EdgeTest.java
@@ -120,7 +120,7 @@ public class EdgeTest {
@Test(expected = NoSuchElementException.class)
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldThrowNoSuchElementExceptionIfEdgeWithIdNotPresent() {
- g.E("this-id-should-not-be-in-the-modern-graph").next();
+ g.E(graphProvider.convertId(100)).next();
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/59028c8a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/VertexTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/VertexTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/VertexTest.java
index 7821601..c281e27 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/VertexTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/VertexTest.java
@@ -24,6 +24,7 @@ import org.apache.tinkerpop.gremlin.FeatureRequirement;
import org.apache.tinkerpop.gremlin.FeatureRequirementSet;
import org.apache.tinkerpop.gremlin.GraphManager;
import org.apache.tinkerpop.gremlin.LoadGraphWith;
+import org.apache.tinkerpop.gremlin.process.traversal.FastNoSuchElementException;
import org.apache.tinkerpop.gremlin.process.traversal.T;
import org.apache.tinkerpop.gremlin.structure.Graph.Features.VertexFeatures;
import org.apache.tinkerpop.gremlin.structure.Graph.Features.VertexPropertyFeatures;
@@ -136,14 +137,8 @@ public class VertexTest {
@Test(expected = NoSuchElementException.class)
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
- public void shouldThrowNoSuchElementExceptionIfVertexWithIdNotPresentViaTraversal() {
- graph.vertices("this-id-should-not-be-in-the-modern-graph").next();
- }
-
- @Test(expected = NoSuchElementException.class)
- @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
- public void shouldThrowNoSuchElementExceptionIfVertexWithIdNotPresentViaIterators() {
- graph.vertices("this-id-should-not-be-in-the-modern-graph").next();
+ public void shouldThrowNoSuchElementExceptionIfVertexWithIdNotPresent() {
+ graph.vertices(graphProvider.convertId(100)).next();
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/59028c8a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
index 730c7ea..71d3eba 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
@@ -84,9 +84,9 @@ public class TinkerGraph implements Graph {
private final static TinkerGraph EMPTY_GRAPH = new TinkerGraph();
- private Class<?> vertexIdClass = null;
- private Class<?> edgeIdClass = null;
- private Class<?> vertexPropertyIdClass = null;
+ protected Class<?> vertexIdClass = null;
+ protected Class<?> edgeIdClass = null;
+ protected Class<?> vertexPropertyIdClass = null;
/**
* An empty private constructor that initializes {@link TinkerGraph}.
@@ -141,11 +141,13 @@ public class TinkerGraph implements Graph {
if (this.vertices.containsKey(idValue))
throw Exceptions.vertexWithIdAlreadyExists(idValue);
} else {
- idValue = TinkerHelper.getNextId(this);
+ idValue = TinkerHelper.getNextId(this, Vertex.class);
}
// todo: enforce vertex id consistency with tests
- if (vertexIdClass == null)
+ // if no value is defined on the graph for the expected id type then use whatever is currently set, otherwise
+ // if there is a value, ensure that the expected type matches what was provided.
+ if (null == vertexIdClass)
vertexIdClass = idValue.getClass();
else if (!idValue.getClass().equals(vertexIdClass)) {
throw new IllegalStateException(String.format("Expecting a vertex identifier of %s but was %s", vertexIdClass, idValue.getClass()));
@@ -208,6 +210,7 @@ public class TinkerGraph implements Graph {
@Override
public Iterator<Vertex> vertices(final Object... vertexIds) {
+ // todo: this code looks a lot like edges() code - better reuse here somewhere?
if (0 == vertexIds.length) {
return this.vertices.values().iterator();
} else if (1 == vertexIds.length) {
@@ -242,50 +245,40 @@ public class TinkerGraph implements Graph {
}
}
- private UnaryOperator<Object> convertToId(final Object id, final Class<?> elementIdClass) {
- if (id instanceof Number) {
- if (elementIdClass != null) {
- if (elementIdClass.equals(Long.class)) {
- return o -> ((Number) o).longValue();
- } else if (elementIdClass.equals(Integer.class)) {
- return o -> ((Number) o).intValue();
- } else if (elementIdClass.equals(Double.class)) {
- return o -> ((Number) o).doubleValue();
- } else if (elementIdClass.equals(Float.class)) {
- return o -> ((Number) o).floatValue();
- } else if (elementIdClass.equals(String.class)) {
- return o -> o.toString();
- }
- }
- } else if (id instanceof String) {
- if (elementIdClass != null) {
- final String s = (String) id;
- if (elementIdClass.equals(Long.class)) {
- return o -> Long.parseLong(s);
- } else if (elementIdClass.equals(Integer.class)) {
- return o -> Integer.parseInt(s);
- } else if (elementIdClass.equals(Double.class)) {
- return o -> Double.parseDouble(s);
- } else if (elementIdClass.equals(Float.class)) {
- return o -> Float.parseFloat(s);
- } else if (elementIdClass.equals(UUID.class)) {
- return o -> UUID.fromString(s);
- }
- }
- }
-
- return UnaryOperator.identity();
- }
-
@Override
public Iterator<Edge> edges(final Object... edgeIds) {
if (0 == edgeIds.length) {
return this.edges.values().iterator();
} else if (1 == edgeIds.length) {
- final Edge edge = this.edges.get(edgeIds[0]);
- return null == edge ? Collections.emptyIterator() : IteratorUtils.of(edge);
- } else
- return Stream.of(edgeIds).map(this.edges::get).filter(Objects::nonNull).iterator();
+ if (edgeIds[0] instanceof Edge) {
+ // no need to get the edge again, so just flip it back - some implementation may want to treat this
+ // as a refresh operation. that's not necessary for tinkergraph.
+ return IteratorUtils.of((Edge) edgeIds[0]);
+ } else {
+ // convert the id to the expected data type and lookup the vertex
+ final UnaryOperator<Object> conversionFunction = convertToId(edgeIds[0], edgeIdClass);
+ final Edge edge = this.edges.get(conversionFunction.apply(edgeIds[0]));
+ return null == edge ? Collections.emptyIterator() : IteratorUtils.of(edge);
+ }
+ } else {
+ // base the conversion function on the first item in the id list as the expectation is that these
+ // id values will be a uniform list
+ if (edgeIds[0] instanceof Edge) {
+ // based on the first item assume all vertices in the argument list
+ if (!Stream.of(edgeIds).allMatch(id -> id instanceof Edge))
+ throw Graph.Exceptions.idArgsMustBeEitherIdOrElement();
+
+ // no need to get the vertices again, so just flip it back - some implementation may want to treat this
+ // as a refresh operation. that's not necessary for tinkergraph.
+ return Stream.of(edgeIds).map(id -> (Edge) id).iterator();
+ } else {
+ final Class<?> firstClass = edgeIds[0].getClass();
+ if (!Stream.of(edgeIds).map(Object::getClass).allMatch(firstClass::equals))
+ throw Graph.Exceptions.idArgsMustBeEitherIdOrElement(); // todo: change exception to be ids of the same type
+ final UnaryOperator<Object> conversionFunction = convertToId(edgeIds[0], vertexIdClass);
+ return Stream.of(edgeIds).map(conversionFunction).map(this.edges::get).filter(Objects::nonNull).iterator();
+ }
+ }
}
/**
@@ -325,11 +318,11 @@ public class TinkerGraph implements Graph {
public String toString() {
return StringFactory.featureString(this);
}
- }
+ }
public static class TinkerGraphVertexFeatures implements Features.VertexFeatures {
- static final TinkerGraphVertexFeatures INSTANCE = new TinkerGraphVertexFeatures();
+ static final TinkerGraphVertexFeatures INSTANCE = new TinkerGraphVertexFeatures();
private TinkerGraphVertexFeatures() {
}
@@ -337,11 +330,11 @@ public class TinkerGraph implements Graph {
public boolean supportsCustomIds() {
return false;
}
- }
+ }
public static class TinkerGraphEdgeFeatures implements Features.EdgeFeatures {
- static final TinkerGraphEdgeFeatures INSTANCE = new TinkerGraphEdgeFeatures();
+ static final TinkerGraphEdgeFeatures INSTANCE = new TinkerGraphEdgeFeatures();
private TinkerGraphEdgeFeatures() {
}
@@ -349,11 +342,11 @@ public class TinkerGraph implements Graph {
public boolean supportsCustomIds() {
return false;
}
- }
+ }
public static class TinkerGraphGraphFeatures implements Features.GraphFeatures {
- static final TinkerGraphGraphFeatures INSTANCE = new TinkerGraphGraphFeatures();
+ static final TinkerGraphGraphFeatures INSTANCE = new TinkerGraphGraphFeatures();
private TinkerGraphGraphFeatures() {
}
@@ -371,6 +364,7 @@ public class TinkerGraph implements Graph {
public boolean supportsThreadedTransactions() {
return false;
}
+
}
///////////// GRAPH SPECIFIC INDEXING METHODS ///////////////
@@ -429,4 +423,45 @@ public class TinkerGraph implements Graph {
throw new IllegalArgumentException("Class is not indexable: " + elementClass);
}
}
+
+ ///////////// HELPERS METHODS ///////////////
+
+ /**
+ * Function to coerce a provided identifier to a different type given the expected id type of an element.
+ * This allows something like {@code g.V(1,2,3)} and {@code g.V(1l,2l,3l)} to both mean the same thing.
+ */
+ private UnaryOperator<Object> convertToId(final Object id, final Class<?> elementIdClass) {
+ if (id instanceof Number) {
+ if (elementIdClass != null) {
+ if (elementIdClass.equals(Long.class)) {
+ return o -> ((Number) o).longValue();
+ } else if (elementIdClass.equals(Integer.class)) {
+ return o -> ((Number) o).intValue();
+ } else if (elementIdClass.equals(Double.class)) {
+ return o -> ((Number) o).doubleValue();
+ } else if (elementIdClass.equals(Float.class)) {
+ return o -> ((Number) o).floatValue();
+ } else if (elementIdClass.equals(String.class)) {
+ return o -> o.toString();
+ }
+ }
+ } else if (id instanceof String) {
+ if (elementIdClass != null) {
+ final String s = (String) id;
+ if (elementIdClass.equals(Long.class)) {
+ return o -> Long.parseLong(s);
+ } else if (elementIdClass.equals(Integer.class)) {
+ return o -> Integer.parseInt(s);
+ } else if (elementIdClass.equals(Double.class)) {
+ return o -> Double.parseDouble(s);
+ } else if (elementIdClass.equals(Float.class)) {
+ return o -> Float.parseFloat(s);
+ } else if (elementIdClass.equals(UUID.class)) {
+ return o -> UUID.fromString(s);
+ }
+ }
+ }
+
+ return UnaryOperator.identity();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/59028c8a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerHelper.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerHelper.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerHelper.java
index c84d37c..1b1311e 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerHelper.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerHelper.java
@@ -21,6 +21,7 @@ package org.apache.tinkerpop.gremlin.tinkergraph.structure;
import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
@@ -46,8 +47,35 @@ public final class TinkerHelper {
private TinkerHelper() {
}
- protected final synchronized static long getNextId(final TinkerGraph graph) {
- return Stream.generate(() -> (++graph.currentId)).filter(id -> !graph.vertices.containsKey(id) && !graph.edges.containsKey(id)).findAny().get();
+ protected final synchronized static Number getNextId(final TinkerGraph graph, final Class<? extends Element> element) {
+ final Class<?> idClass;
+ if (Vertex.class.isAssignableFrom(element))
+ idClass = graph.vertexIdClass;
+ else if (Edge.class.isAssignableFrom(element))
+ idClass = graph.edgeIdClass;
+ else if (VertexProperty.class.isAssignableFrom(element))
+ idClass = graph.vertexPropertyIdClass;
+ else
+ throw new IllegalArgumentException(String.format("Unexpected request for id for %s", element));
+
+ final Number next = Stream.generate(() -> (++graph.currentId)).filter(id -> !graph.vertices.containsKey(id) && !graph.edges.containsKey(id)).findAny().get();
+
+ // the class hasn't been set yet so assume Long - the class should be set by the caller after this
+ // value is returned
+ if (null == idClass)
+ return next.longValue();
+
+ if (idClass.equals(Long.class))
+ return next.longValue();
+ else if (idClass.equals(Integer.class))
+ return next.intValue();
+ else if (idClass.equals(Double.class))
+ return next.doubleValue();
+ else if (idClass.equals(Float.class))
+ return next.floatValue();
+ else
+ throw new IllegalStateException(String.format("TinkerGraph generates numeric identifiers, but this instance has already been initialized a identifier of type %s for %s", idClass, element));
+
}
protected static Edge addEdge(final TinkerGraph graph, final TinkerVertex outVertex, final TinkerVertex inVertex, final String label, final Object... keyValues) {
@@ -61,7 +89,16 @@ public final class TinkerHelper {
if (graph.edges.containsKey(idValue))
throw Graph.Exceptions.edgeWithIdAlreadyExists(idValue);
} else {
- idValue = TinkerHelper.getNextId(graph);
+ idValue = TinkerHelper.getNextId(graph, Edge.class);
+ }
+
+ // todo: enforce edge id consistency with tests
+ // if no value is defined on the graph for the expected id type then use whatever is currently set, otherwise
+ // if there is a value, ensure that the expected type matches what was provided.
+ if (null == graph.edgeIdClass)
+ graph.edgeIdClass = idValue.getClass();
+ else if (!idValue.getClass().equals(graph.edgeIdClass)) {
+ throw new IllegalStateException(String.format("Expecting a edge identifier of %s but was %s", graph.edgeIdClass, idValue.getClass()));
}
edge = new TinkerEdge(idValue, outVertex, label, inVertex);
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/59028c8a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertex.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertex.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertex.java
index 9cdc7db..a5713cc 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertex.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertex.java
@@ -96,9 +96,18 @@ public class TinkerVertex extends TinkerElement implements Vertex {
ElementHelper.attachProperties(vertexProperty, keyValues);
return vertexProperty;
} else {
- final VertexProperty<V> vertexProperty = optionalId.isPresent() ?
- new TinkerVertexProperty<V>(optionalId.get(), this, key, value) :
- new TinkerVertexProperty<V>(this, key, value);
+ final Object idValue = optionalId.isPresent() ? optionalId.get() : TinkerHelper.getNextId(graph, VertexProperty.class);
+
+ // todo: enforce vertexproperty id consistency with tests
+ // if no value is defined on the graph for the expected id type then use whatever is currently set, otherwise
+ // if there is a value, ensure that the expected type matches what was provided.
+ if (null == graph.vertexPropertyIdClass)
+ graph.vertexPropertyIdClass = idValue.getClass();
+ else if (!idValue.getClass().equals(graph.vertexPropertyIdClass))
+ throw new IllegalStateException(String.format("Expecting a vertex identifier of %s but was %s", graph.vertexPropertyIdClass, idValue.getClass()));
+
+ final VertexProperty<V> vertexProperty = new TinkerVertexProperty<V>(idValue, this, key, value);
+
if (null == this.properties) this.properties = new HashMap<>();
final List<VertexProperty> list = this.properties.getOrDefault(key, new ArrayList<>());
list.add(vertexProperty);
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/59028c8a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertexProperty.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertexProperty.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertexProperty.java
index 66f15ea..2470733 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertexProperty.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertexProperty.java
@@ -19,11 +19,13 @@
package org.apache.tinkerpop.gremlin.tinkergraph.structure;
import org.apache.tinkerpop.gremlin.structure.Element;
+import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+import org.apache.tinkerpop.gremlin.tinkergraph.process.computer.TinkerGraphView;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
import java.util.Collections;
@@ -44,8 +46,13 @@ public class TinkerVertexProperty<V> extends TinkerElement implements VertexProp
private final String key;
private final V value;
+ /**
+ * This constructor will not validate the ID type against the {@link Graph}. It will always just use a
+ * {@code Long} for its identifier. This is useful for constructing a {@link VertexProperty} for usage
+ * with {@link TinkerGraphView}.
+ */
public TinkerVertexProperty(final TinkerVertex vertex, final String key, final V value, final Object... propertyKeyValues) {
- super(TinkerHelper.getNextId((TinkerGraph) vertex.graph()), key);
+ super(TinkerHelper.getNextId((TinkerGraph) vertex.graph(), VertexProperty.class), key);
this.vertex = vertex;
this.key = key;
this.value = value;
@@ -53,6 +60,10 @@ public class TinkerVertexProperty<V> extends TinkerElement implements VertexProp
ElementHelper.attachProperties(this, propertyKeyValues);
}
+ /**
+ * Use this constructor to construct {@link VertexProperty} instances for {@link TinkerGraph} where the {@code id}
+ * can be explicitly set and validated against the expected data type.
+ */
public TinkerVertexProperty(final Object id, final TinkerVertex vertex, final String key, final V value, final Object... propertyKeyValues) {
super(id, key);
this.vertex = vertex;