You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by dk...@apache.org on 2015/06/03 02:12:27 UTC

[22/50] [abbrv] incubator-tinkerpop git commit: clean ups in Neo4j -- making things really nice.

clean ups in Neo4j -- making things really nice.


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

Branch: refs/heads/preprocessor
Commit: 7441b6be99e323ba945fe77d4be33ad39bc497ff
Parents: bbc6a0e
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Fri May 29 14:15:16 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Fri May 29 14:15:16 2015 -0600

----------------------------------------------------------------------
 .../gremlin/neo4j/structure/Neo4jEdge.java      | 25 ++++++++++++++++++++
 .../gremlin/neo4j/structure/Neo4jElement.java   | 25 --------------------
 .../gremlin/neo4j/structure/Neo4jGraph.java     |  4 +---
 .../gremlin/neo4j/structure/Neo4jHelper.java    | 23 ------------------
 .../neo4j/structure/Neo4jVertexProperty.java    |  1 -
 .../structure/trait/MultiMetaNeo4jTrait.java    |  4 ++--
 .../trait/NoMultiNoMetaNeo4jTrait.java          |  5 ++--
 7 files changed, 31 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7441b6be/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jEdge.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jEdge.java b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jEdge.java
index f0a5139..71e36eb 100644
--- a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jEdge.java
+++ b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jEdge.java
@@ -104,4 +104,29 @@ public final class Neo4jEdge extends Neo4jElement implements Edge, WrappedEdge<N
         return IteratorUtils.map(filter,
                 key -> new Neo4jProperty<>(this, key, (V) this.baseElement.getProperty(key)));
     }
+
+    @Override
+    public <V> Property<V> property(final String key) {
+        this.graph.tx().readWrite();
+        try {
+            if (this.baseElement.hasProperty(key))
+                return new Neo4jProperty<>(this, key, (V) this.baseElement.getProperty(key));
+            else
+                return Property.empty();
+        } catch (final IllegalStateException e) {
+            throw Element.Exceptions.elementAlreadyRemoved(this.getClass(), this.id());
+        }
+    }
+
+    @Override
+    public <V> Property<V> property(final String key, final V value) {
+        ElementHelper.validateProperty(key, value);
+        this.graph.tx().readWrite();
+        try {
+            this.baseElement.setProperty(key, value);
+            return new Neo4jProperty<>(this, key, value);
+        } catch (final IllegalArgumentException e) {
+            throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(value);
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7441b6be/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jElement.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jElement.java b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jElement.java
index 7dfc9a8..28644b6 100644
--- a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jElement.java
+++ b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jElement.java
@@ -60,31 +60,6 @@ public abstract class Neo4jElement implements Element, WrappedElement<Neo4jEntit
     }
 
     @Override
-    public <V> Property<V> property(final String key) {
-        this.graph.tx().readWrite();
-        try {
-            if (this.baseElement.hasProperty(key))
-                return new Neo4jProperty<>(this, key, (V) this.baseElement.getProperty(key));
-            else
-                return Property.empty();
-        } catch (final IllegalStateException e) {
-            throw Element.Exceptions.elementAlreadyRemoved(this.getClass(), this.id());
-        }
-    }
-
-    @Override
-    public <V> Property<V> property(final String key, final V value) {
-        ElementHelper.validateProperty(key, value);
-        this.graph.tx().readWrite();
-        try {
-            this.baseElement.setProperty(key, value);
-            return new Neo4jProperty<>(this, key, value);
-        } catch (final IllegalArgumentException e) {
-            throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(value);
-        }
-    }
-
-    @Override
     public boolean equals(final Object object) {
         return ElementHelper.areEqual(this, object);
     }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7441b6be/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraph.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraph.java b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraph.java
index a289bb9..2aeab7a 100644
--- a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraph.java
+++ b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraph.java
@@ -170,7 +170,6 @@ public final class Neo4jGraph implements Graph, WrappedGraph<Neo4jGraphAPI> {
         if (0 == vertexIds.length) {
             final Predicate<Neo4jNode> nodePredicate = this.trait.getNodePredicate();
             return IteratorUtils.stream(this.getBaseGraph().allNodes())
-                    //.filter(node -> !Neo4jHelper.isDeleted(node))
                     .filter(nodePredicate)
                     .map(node -> (Vertex) new Neo4jVertex(node, this)).iterator();
         } else {
@@ -203,7 +202,6 @@ public final class Neo4jGraph implements Graph, WrappedGraph<Neo4jGraphAPI> {
         if (0 == edgeIds.length) {
             final Predicate<Neo4jRelationship> relationshipPredicate = this.trait.getRelationshipPredicate();
             return IteratorUtils.stream(this.getBaseGraph().allRelationships())
-                    //.filter(relationship -> !Neo4jHelper.isDeleted(relationship))
                     .filter(relationshipPredicate)
                     .map(relationship -> (Edge) new Neo4jEdge(relationship, this)).iterator();
         } else {
@@ -217,7 +215,7 @@ public final class Neo4jGraph implements Graph, WrappedGraph<Neo4jGraphAPI> {
                         else if (id instanceof Neo4jEdge) {
                             return (Long) ((Neo4jEdge) id).id();
                         } else
-                            throw new IllegalArgumentException("Unknown vertex id type: " + id);
+                            throw new IllegalArgumentException("Unknown edge id type: " + id);
                     })
                     .flatMap(id -> {
                         try {

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7441b6be/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jHelper.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jHelper.java b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jHelper.java
index 524a089..7c8c0d0 100644
--- a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jHelper.java
+++ b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jHelper.java
@@ -50,33 +50,10 @@ public final class Neo4jHelper {
         }
     }
 
-    /*public static boolean isDeleted(final Neo4jRelationship relationship) {
-        try {
-            relationship.type();
-            return false;
-        } catch (final IllegalStateException e) {
-            return true;
-        }
-    }*/
-
     public static boolean isNotFound(RuntimeException ex) {
         return ex.getClass().getSimpleName().equals("NotFoundException");
     }
 
-    /*public static boolean keyExistsInNeo4j(final Neo4jNode node, final String key) {
-        try {
-            return node.hasProperty(key);
-        } catch (IllegalStateException ex) {
-            // if vertex is removed before/after transaction close
-            throw Element.Exceptions.elementAlreadyRemoved(Vertex.class, node.getId());
-        } catch (RuntimeException ex) {
-            // if vertex is removed before/after transaction close
-            if (Neo4jHelper.isNotFound(ex))
-                throw Element.Exceptions.elementAlreadyRemoved(Vertex.class, node.getId());
-            throw ex;
-        }
-    }*/
-
     public static Neo4jNode getVertexPropertyNode(final Neo4jVertexProperty vertexProperty) {
         return vertexProperty.vertexPropertyNode;
     }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7441b6be/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jVertexProperty.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jVertexProperty.java b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jVertexProperty.java
index 9c85dfc..74ff281 100644
--- a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jVertexProperty.java
+++ b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jVertexProperty.java
@@ -40,7 +40,6 @@ public final class Neo4jVertexProperty<V> implements VertexProperty<V> {
     protected Neo4jNode vertexPropertyNode;
     protected boolean removed = false;
 
-
     public Neo4jVertexProperty(final Neo4jVertex vertex, final String key, final V value) {
         this.vertex = vertex;
         this.key = key;

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7441b6be/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/trait/MultiMetaNeo4jTrait.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/trait/MultiMetaNeo4jTrait.java b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/trait/MultiMetaNeo4jTrait.java
index fb2e8c2..336858c 100644
--- a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/trait/MultiMetaNeo4jTrait.java
+++ b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/trait/MultiMetaNeo4jTrait.java
@@ -72,10 +72,10 @@ public class MultiMetaNeo4jTrait implements Neo4jTrait {
     public void removeVertex(final Neo4jVertex vertex) {
         try {
             final Neo4jNode node = vertex.getBaseVertex();
-            for (final Neo4jRelationship relationship : node.relationships(Neo4jDirection.BOTH)) {
+            for (final Neo4jRelationship relationship : node.relationships(Neo4jDirection.OUTGOING)) {
                 final Neo4jNode otherNode = relationship.other(node);
                 if (otherNode.hasLabel(VERTEX_PROPERTY_LABEL)) {
-                    otherNode.relationships(null).forEach(Neo4jRelationship::delete);
+                    otherNode.relationships(Neo4jDirection.BOTH).forEach(Neo4jRelationship::delete);
                     otherNode.delete(); // meta property node
                 } else
                     relationship.delete();

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7441b6be/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/trait/NoMultiNoMetaNeo4jTrait.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/trait/NoMultiNoMetaNeo4jTrait.java b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/trait/NoMultiNoMetaNeo4jTrait.java
index 25be842..d1647ad 100644
--- a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/trait/NoMultiNoMetaNeo4jTrait.java
+++ b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/trait/NoMultiNoMetaNeo4jTrait.java
@@ -111,8 +111,9 @@ public class NoMultiNoMetaNeo4jTrait implements Neo4jTrait {
 
     @Override
     public void removeVertexProperty(final Neo4jVertexProperty vertexProperty) {
-        if ((((Neo4jVertex) vertexProperty.element()).getBaseVertex().hasProperty(vertexProperty.key())))
-            ((Neo4jVertex) vertexProperty.element()).getBaseVertex().removeProperty(vertexProperty.key());
+        final Neo4jNode node = ((Neo4jVertex) vertexProperty.element()).getBaseVertex();
+        if (node.hasProperty(vertexProperty.key()))
+            node.removeProperty(vertexProperty.key());
     }
 
     @Override