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 22:54:53 UTC

incubator-tinkerpop git commit: Generate numeric ids from the owning TinkerGraph instance.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/TINKERPOP3-581 16d97e077 -> b67712a9d


Generate numeric ids from the owning TinkerGraph instance.

The enum should haven't have been maintaining the counters.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/b67712a9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/b67712a9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/b67712a9

Branch: refs/heads/TINKERPOP3-581
Commit: b67712a9d6c0f532c8333ab93c87112aba2a19a0
Parents: 16d97e0
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Apr 9 16:53:41 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Apr 9 16:53:41 2015 -0400

----------------------------------------------------------------------
 .../gremlin/tinkergraph/structure/TinkerGraph.java    | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b67712a9/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 25b3a3e..1d26304 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
@@ -42,6 +42,7 @@ import java.util.Objects;
 import java.util.Set;
 import java.util.UUID;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicLong;
 import java.util.function.UnaryOperator;
 import java.util.stream.Stream;
 
@@ -75,7 +76,7 @@ public class TinkerGraph implements Graph {
     public static final String CONFIG_EDGE_ID = "tinkergraph.edge.id";
     public static final String CONFIG_VERTEX_PROPERTY_ID = "tinkergraph.vertex-property.id";
 
-    protected Long currentId = -1l;
+    protected AtomicLong currentId = new AtomicLong(-1l);
     protected Map<Object, Vertex> vertices = new ConcurrentHashMap<>();
     protected Map<Object, Edge> edges = new ConcurrentHashMap<>();
 
@@ -217,7 +218,7 @@ public class TinkerGraph implements Graph {
         this.vertices.clear();
         this.edges.clear();
         this.variables = null;
-        this.currentId = 0l;
+        this.currentId.set(-1l);
         this.vertexIndex = null;
         this.edgeIndex = null;
     }
@@ -480,10 +481,9 @@ public class TinkerGraph implements Graph {
          * {@link Long} and will also attempt to convert {@code String} values
          */
         LONG {
-            private long currentId = -1l;
             @Override
             public Long getNextId(final TinkerGraph graph) {
-                return Stream.generate(() -> (++currentId)).filter(id -> !graph.vertices.containsKey(id) && !graph.edges.containsKey(id)).findAny().get();
+                return Stream.generate(() -> (graph.currentId.incrementAndGet())).filter(id -> !graph.vertices.containsKey(id) && !graph.edges.containsKey(id)).findAny().get();
             }
 
             @Override
@@ -502,10 +502,9 @@ public class TinkerGraph implements Graph {
          * {@link Integer} and will also attempt to convert {@code String} values
          */
         INTEGER {
-            private int currentId = -1;
             @Override
             public Integer getNextId(final TinkerGraph graph) {
-                return Stream.generate(() -> (++currentId)).filter(id -> !graph.vertices.containsKey(id) && !graph.edges.containsKey(id)).findAny().get();
+                return Stream.generate(() -> (graph.currentId.incrementAndGet())).map(Long::intValue).filter(id -> !graph.vertices.containsKey(id) && !graph.edges.containsKey(id)).findAny().get();
             }
 
             @Override
@@ -547,10 +546,9 @@ public class TinkerGraph implements Graph {
          * {@link TinkerGraph}, it will generate {@link Long} values for identifiers.
          */
         ANY {
-            private long currentId = -1l;
             @Override
             public Long getNextId(final TinkerGraph graph) {
-                return Stream.generate(() -> (++currentId)).filter(id -> !graph.vertices.containsKey(id) && !graph.edges.containsKey(id)).findAny().get();
+                return Stream.generate(() -> (graph.currentId.incrementAndGet())).filter(id -> !graph.vertices.containsKey(id) && !graph.edges.containsKey(id)).findAny().get();
             }
 
             @Override