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:14 UTC
[09/50] [abbrv] incubator-tinkerpop git commit: Neo4jTrait now exists
-- NoMultiNoMetaNeo4jTrait and MultiMetaNeo4jTrait. Simpler code.
Neo4jTrait now exists -- NoMultiNoMetaNeo4jTrait and MultiMetaNeo4jTrait. Simpler code.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/b8876819
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/b8876819
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/b8876819
Branch: refs/heads/preprocessor
Commit: b88768191e4d6b77ff4923c392e0dcc64d2662db
Parents: 4db0e1c
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Fri May 29 10:39:00 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Fri May 29 10:39:17 2015 -0600
----------------------------------------------------------------------
.../tinkerpop/gremlin/structure/Vertex.java | 6 +-
.../step/sideEffect/Neo4jGraphStep.java | 21 +-
.../neo4j/process/util/Neo4jCypherIterator.java | 6 +-
.../gremlin/neo4j/structure/Neo4jEdge.java | 12 +-
.../gremlin/neo4j/structure/Neo4jElement.java | 1 -
.../gremlin/neo4j/structure/Neo4jGraph.java | 64 +++--
.../gremlin/neo4j/structure/Neo4jHelper.java | 24 ++
.../gremlin/neo4j/structure/Neo4jProperty.java | 2 +-
.../gremlin/neo4j/structure/Neo4jVertex.java | 55 ++--
.../neo4j/structure/Neo4jVertexProperty.java | 54 +++-
.../neo4j/structure/full/FullNeo4jGraph.java | 80 ------
.../neo4j/structure/full/FullNeo4jProperty.java | 56 ----
.../neo4j/structure/full/FullNeo4jVertex.java | 162 ------------
.../structure/full/FullNeo4jVertexProperty.java | 151 -----------
.../structure/simple/SimpleNeo4jGraph.java | 109 --------
.../structure/simple/SimpleNeo4jVertex.java | 101 -------
.../simple/SimpleNeo4jVertexProperty.java | 67 -----
.../structure/trait/MultiMetaNeo4jTrait.java | 261 +++++++++++++++++++
.../neo4j/structure/trait/Neo4jTrait.java | 67 +++++
.../trait/NoMultiNoMetaNeo4jTrait.java | 134 ++++++++++
.../gremlin/neo4j/FullNeo4jGraphProvider.java | 45 ----
.../neo4j/MultiMetaNeo4jGraphProvider.java | 45 ++++
.../neo4j/NoMultiNoMetaNeo4jGraphProvider.java | 48 ++++
.../gremlin/neo4j/SimpleNeo4jGraphProvider.java | 48 ----
.../FullNeo4jGraphProcessStandardTest.java | 37 ---
.../MultiMetaNeo4jGraphProcessStandardTest.java | 36 +++
...ultiNoMetaNeo4jGraphProcessStandardTest.java | 36 +++
.../SimpleNeo4jGraphProcessStandardTest.java | 36 ---
...FullNeo4jGraphGroovyProcessStandardTest.java | 33 ---
...MetaNeo4jGraphGroovyProcessStandardTest.java | 33 +++
...metaNeo4jGraphGroovyProcessStandardTest.java | 36 +++
...mpleNeo4jGraphGroovyProcessStandardTest.java | 36 ---
.../FullNeo4jGraphNativeNeo4jTest.java | 36 ---
.../FullNeo4jGraphStructureStandardTest.java | 36 ---
.../MultiMetaNeo4jGraphNativeNeo4jTest.java | 35 +++
...ultiMetaNeo4jGraphStructureStandardTest.java | 35 +++
.../structure/NativeNeo4jStructureTest.java | 24 +-
.../NoMultiNoMetaNeo4jGraphNativeNeo4jTest.java | 35 +++
...tiNoMetaNeo4jGraphStructureStandardTest.java | 35 +++
.../SimpleNeo4jGraphNativeNeo4jTest.java | 36 ---
.../SimpleNeo4jGraphStructureStandardTest.java | 36 ---
41 files changed, 996 insertions(+), 1214 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b8876819/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Vertex.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Vertex.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Vertex.java
index 934000a..a26d1d8 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Vertex.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Vertex.java
@@ -94,7 +94,7 @@ public interface Vertex extends Element, Host {
/**
* Set the provided key to the provided value using default {@link VertexProperty.Cardinality} for that key.
* The default cardinality can be vendor defined and is usually tied to the graph schema.
- * If the vendor does not have a preference, then the default cardinality should be {@link VertexProperty.Cardinality#single}.
+ * The default implementation of this method determines the cardinality {@code graph().features().vertex().getCardinality(key)}.
* The provided key/values are the properties of the newly created {@link VertexProperty}.
* These key/values must be provided in an even number where the odd numbered arguments are {@link String}.
*
@@ -104,7 +104,9 @@ public interface Vertex extends Element, Host {
* @param <V> the type of the value of the vertex property
* @return the newly created vertex property
*/
- public <V> VertexProperty<V> property(final String key, final V value, final Object... keyValues);
+ public default <V> VertexProperty<V> property(final String key, final V value, final Object... keyValues) {
+ return this.property(graph().features().vertex().getCardinality(key), key, value, keyValues);
+ }
/**
* Create a new vertex property.
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b8876819/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/process/traversal/step/sideEffect/Neo4jGraphStep.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/process/traversal/step/sideEffect/Neo4jGraphStep.java b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/process/traversal/step/sideEffect/Neo4jGraphStep.java
index 9d215f8..dbc5a32 100644
--- a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/process/traversal/step/sideEffect/Neo4jGraphStep.java
+++ b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/process/traversal/step/sideEffect/Neo4jGraphStep.java
@@ -21,8 +21,7 @@ package org.apache.tinkerpop.gremlin.neo4j.process.traversal.step.sideEffect;
import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jEdge;
import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jGraph;
import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jVertex;
-import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jVertexProperty;
-import org.apache.tinkerpop.gremlin.neo4j.structure.full.FullNeo4jVertexProperty;
+import org.apache.tinkerpop.gremlin.neo4j.structure.trait.MultiMetaNeo4jTrait;
import org.apache.tinkerpop.gremlin.process.traversal.Compare;
import org.apache.tinkerpop.gremlin.process.traversal.Contains;
import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.GraphStep;
@@ -107,12 +106,12 @@ public final class Neo4jGraphStep<S extends Element> extends GraphStep<S> {
final Iterable<Neo4jNode> iterator2 = graph.getBaseGraph().findNodes(hasContainer.getKey(), T.value.getAccessor(), hasContainer.getValue());
final Stream<Neo4jVertex> stream1 = IteratorUtils.stream(iterator1)
.filter(node -> ElementHelper.idExists(node.getId(), this.ids))
- .map(node -> graph.createVertex(node));
+ .map(node -> new Neo4jVertex(node,graph));
final Stream<Neo4jVertex> stream2 = IteratorUtils.stream(iterator2)
.filter(node -> ElementHelper.idExists(node.getId(), this.ids))
.filter(node -> node.getProperty(T.key.getAccessor()).equals(hasContainer.getKey()))
.map(node -> node.relationships(Neo4jDirection.INCOMING).iterator().next().start())
- .map(node -> graph.createVertex(node));
+ .map(node -> new Neo4jVertex(node,graph));
return Stream.concat(stream1, stream2);
}
@@ -120,30 +119,30 @@ public final class Neo4jGraphStep<S extends Element> extends GraphStep<S> {
//System.out.println("labels: " + labels);
final Neo4jGraph graph = (Neo4jGraph) this.getTraversal().getGraph().get();
return labels.stream()
- .filter(label -> !label.equals(FullNeo4jVertexProperty.VERTEX_PROPERTY_LABEL))
+ .filter(label -> !label.equals(MultiMetaNeo4jTrait.VERTEX_PROPERTY_LABEL)) // TODO: use predicates
.flatMap(label -> IteratorUtils.stream(graph.getBaseGraph().findNodes(label)))
- .filter(node -> !node.hasLabel(FullNeo4jVertexProperty.VERTEX_PROPERTY_LABEL))
+ .filter(node -> !node.hasLabel(MultiMetaNeo4jTrait.VERTEX_PROPERTY_LABEL))
.filter(node -> ElementHelper.idExists(node.getId(), this.ids))
- .map(node -> graph.createVertex(node));
+ .map(node -> new Neo4jVertex(node,graph));
}
private Stream<Neo4jVertex> getVerticesUsingAutomaticIndex(final HasContainer hasContainer) {
//System.out.println("automatic index: " + hasContainer);
final Neo4jGraph graph = (Neo4jGraph) this.getTraversal().getGraph().get();
return IteratorUtils.stream(graph.getBaseGraph().findNodes(hasContainer.getKey(), hasContainer.getValue()).iterator())
- .map(node -> node.hasLabel(FullNeo4jVertexProperty.VERTEX_PROPERTY_LABEL) ?
+ .map(node -> node.hasLabel(MultiMetaNeo4jTrait.VERTEX_PROPERTY_LABEL) ?
node.relationships(Neo4jDirection.INCOMING).iterator().next().start() :
node)
.filter(node -> ElementHelper.idExists(node.getId(), this.ids))
- .map(node -> graph.createVertex(node));
+ .map(node -> new Neo4jVertex(node,graph));
}
private Stream<Neo4jEdge> getEdgesUsingAutomaticIndex(final HasContainer hasContainer) {
final Neo4jGraph graph = (Neo4jGraph) this.getTraversal().getGraph().get();
return IteratorUtils.stream(graph.getBaseGraph().findRelationships(hasContainer.getKey(), hasContainer.getValue()).iterator())
.filter(relationship -> ElementHelper.idExists(relationship.getId(), this.ids))
- .filter(relationship -> !relationship.type().startsWith(FullNeo4jVertexProperty.VERTEX_PROPERTY_PREFIX))
- .map(relationship -> graph.createEdge(relationship));
+ .filter(relationship -> !relationship.type().startsWith(MultiMetaNeo4jTrait.VERTEX_PROPERTY_PREFIX))
+ .map(relationship -> new Neo4jEdge(relationship,graph));
}
private Pair<String, HasContainer> getHasContainerForLabelIndex() {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b8876819/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/process/util/Neo4jCypherIterator.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/process/util/Neo4jCypherIterator.java b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/process/util/Neo4jCypherIterator.java
index c54d901..9117ab2 100644
--- a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/process/util/Neo4jCypherIterator.java
+++ b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/process/util/Neo4jCypherIterator.java
@@ -18,7 +18,9 @@
*/
package org.apache.tinkerpop.gremlin.neo4j.process.util;
+import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jEdge;
import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jGraph;
+import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jVertex;
import org.neo4j.tinkerpop.api.Neo4jNode;
import org.neo4j.tinkerpop.api.Neo4jRelationship;
@@ -51,9 +53,9 @@ public final class Neo4jCypherIterator<T> implements Iterator<Map<String, T>> {
entry -> {
final T val = entry.getValue();
if (Neo4jNode.class.isAssignableFrom(val.getClass())) {
- return (T) this.graph.createVertex((Neo4jNode) val);
+ return (T) new Neo4jVertex((Neo4jNode) val, this.graph);
} else if (Neo4jRelationship.class.isAssignableFrom(val.getClass())) {
- return (T) this.graph.createEdge((Neo4jRelationship) val);
+ return (T) new Neo4jEdge((Neo4jRelationship) val, this.graph);
} else {
return val;
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b8876819/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 0de9e97..c2bbd6b 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
@@ -33,7 +33,7 @@ import java.util.Iterator;
/**
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
-public class Neo4jEdge extends Neo4jElement implements Edge, WrappedEdge<Neo4jRelationship> {
+public final class Neo4jEdge extends Neo4jElement implements Edge, WrappedEdge<Neo4jRelationship> {
public Neo4jEdge(final Neo4jRelationship relationship, final Neo4jGraph graph) {
super(relationship, graph);
@@ -41,12 +41,12 @@ public class Neo4jEdge extends Neo4jElement implements Edge, WrappedEdge<Neo4jRe
@Override
public Vertex outVertex() {
- return this.graph.createVertex(this.getBaseEdge().start());
+ return new Neo4jVertex(this.getBaseEdge().start(), this.graph);
}
@Override
public Vertex inVertex() {
- return this.graph.createVertex(this.getBaseEdge().end());
+ return new Neo4jVertex(this.getBaseEdge().end(), this.graph);
}
@Override
@@ -54,11 +54,11 @@ public class Neo4jEdge extends Neo4jElement implements Edge, WrappedEdge<Neo4jRe
this.graph.tx().readWrite();
switch (direction) {
case OUT:
- return IteratorUtils.of(this.graph.createVertex(this.getBaseEdge().start()));
+ return IteratorUtils.of(new Neo4jVertex(this.getBaseEdge().start(), this.graph));
case IN:
- return IteratorUtils.of(this.graph.createVertex(this.getBaseEdge().end()));
+ return IteratorUtils.of(new Neo4jVertex(this.getBaseEdge().end(), this.graph));
default:
- return IteratorUtils.of(this.graph.createVertex(this.getBaseEdge().start()), this.graph.createVertex(this.getBaseEdge().end()));
+ return IteratorUtils.of(new Neo4jVertex(this.getBaseEdge().start(), this.graph), new Neo4jVertex(this.getBaseEdge().end(), this.graph));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b8876819/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 770d763..9e9bdb7 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
@@ -76,7 +76,6 @@ public abstract class Neo4jElement implements Element, WrappedElement<Neo4jEntit
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);
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b8876819/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 82510e7..898286d 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
@@ -23,8 +23,9 @@ import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationConverter;
import org.apache.tinkerpop.gremlin.neo4j.process.traversal.step.sideEffect.CypherStartStep;
import org.apache.tinkerpop.gremlin.neo4j.process.util.Neo4jCypherIterator;
-import org.apache.tinkerpop.gremlin.neo4j.structure.full.FullNeo4jGraph;
-import org.apache.tinkerpop.gremlin.neo4j.structure.simple.SimpleNeo4jGraph;
+import org.apache.tinkerpop.gremlin.neo4j.structure.trait.MultiMetaNeo4jTrait;
+import org.apache.tinkerpop.gremlin.neo4j.structure.trait.Neo4jTrait;
+import org.apache.tinkerpop.gremlin.neo4j.structure.trait.NoMultiNoMetaNeo4jTrait;
import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
@@ -32,6 +33,7 @@ import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Transaction;
import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.apache.tinkerpop.gremlin.structure.util.AbstractTransaction;
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
@@ -63,7 +65,7 @@ import java.util.stream.Stream;
@Graph.OptIn(Graph.OptIn.SUITE_GROOVY_ENVIRONMENT)
@Graph.OptIn(Graph.OptIn.SUITE_GROOVY_ENVIRONMENT_INTEGRATE)
@Graph.OptIn(Graph.OptIn.SUITE_GROOVY_ENVIRONMENT_PERFORMANCE)
-public abstract class Neo4jGraph implements Graph, WrappedGraph<Neo4jGraphAPI> {
+public final class Neo4jGraph implements Graph, WrappedGraph<Neo4jGraphAPI> {
protected Features features = new Neo4jGraphFeatures();
@@ -80,18 +82,22 @@ public abstract class Neo4jGraph implements Graph, WrappedGraph<Neo4jGraphAPI> {
private Neo4jGraphVariables neo4jGraphVariables;
protected boolean checkElementsInTransaction = false;
- protected boolean supportsMetaProperties = false;
- protected boolean supportsMultiProperties = false;
+
+ protected Neo4jTrait trait;
private void initialize(final Neo4jGraphAPI baseGraph, final Configuration configuration) {
this.configuration.copy(configuration);
this.baseGraph = baseGraph;
this.checkElementsInTransaction = this.configuration.getBoolean(CONFIG_CHECK_ELEMENTS_IN_TRANSACTION, false);
- this.supportsMetaProperties = this.configuration.getBoolean(CONFIG_META_PROPERTIES, false);
- this.supportsMultiProperties = this.configuration.getBoolean(CONFIG_MULTI_PROPERTIES, false);
- if (this.supportsMultiProperties != this.supportsMetaProperties)
+ boolean supportsMetaProperties = this.configuration.getBoolean(CONFIG_META_PROPERTIES, false);
+ boolean supportsMultiProperties = this.configuration.getBoolean(CONFIG_MULTI_PROPERTIES, false);
+ if (supportsMultiProperties != supportsMetaProperties)
throw new IllegalArgumentException(this.getClass().getSimpleName() + " currently supports either both meta-properties and multi-properties or neither");
this.neo4jGraphVariables = new Neo4jGraphVariables(this);
+ if (supportsMultiProperties)
+ this.trait = new MultiMetaNeo4jTrait();
+ else
+ this.trait = new NoMultiNoMetaNeo4jTrait();
}
protected Neo4jGraph(final Neo4jGraphAPI baseGraph, final Configuration configuration) {
@@ -116,16 +122,7 @@ public abstract class Neo4jGraph implements Graph, WrappedGraph<Neo4jGraphAPI> {
if (null == configuration) throw Graph.Exceptions.argumentCanNotBeNull("configuration");
if (!configuration.containsKey(CONFIG_DIRECTORY))
throw new IllegalArgumentException(String.format("Neo4j configuration requires that the %s be set", CONFIG_DIRECTORY));
-
- final boolean supportsMetaProperties = configuration.getBoolean(CONFIG_META_PROPERTIES, false);
- final boolean supportsMultiProperties = configuration.getBoolean(CONFIG_MULTI_PROPERTIES, false);
- if (supportsMultiProperties != supportsMetaProperties)
- throw new IllegalArgumentException(Neo4jGraph.class.getSimpleName() + " currently supports either both meta-properties and multi-properties or neither");
- if (supportsMetaProperties) {
- return new FullNeo4jGraph(configuration);
- } else {
- return new SimpleNeo4jGraph(configuration);
- }
+ return new Neo4jGraph(configuration);
}
/**
@@ -137,21 +134,13 @@ public abstract class Neo4jGraph implements Graph, WrappedGraph<Neo4jGraphAPI> {
return open(config);
}
- public abstract Neo4jVertex createVertex(final Neo4jNode node);
-
- public abstract Neo4jEdge createEdge(final Neo4jRelationship relationship);
-
- public abstract Predicate<Neo4jNode> getNodePredicate();
-
- public abstract Predicate<Neo4jRelationship> getRelationshipPredicate();
-
@Override
public Vertex addVertex(final Object... keyValues) {
ElementHelper.legalPropertyKeyValueArray(keyValues);
if (ElementHelper.getIdValue(keyValues).isPresent())
throw Vertex.Exceptions.userSuppliedIdsNotSupported();
this.tx().readWrite();
- final Neo4jVertex vertex = this.createVertex(this.baseGraph.createNode(ElementHelper.getLabelValue(keyValues).orElse(Vertex.DEFAULT_LABEL).split(Neo4jVertex.LABEL_DELIMINATOR)));
+ final Neo4jVertex vertex = new Neo4jVertex(this.baseGraph.createNode(ElementHelper.getLabelValue(keyValues).orElse(Vertex.DEFAULT_LABEL).split(Neo4jVertex.LABEL_DELIMINATOR)), this);
ElementHelper.attachProperties(vertex, keyValues);
return vertex;
}
@@ -160,11 +149,11 @@ public abstract class Neo4jGraph implements Graph, WrappedGraph<Neo4jGraphAPI> {
public Iterator<Vertex> vertices(final Object... vertexIds) {
this.tx().readWrite();
if (0 == vertexIds.length) {
- final Predicate<Neo4jNode> nodePredicate = this.getNodePredicate();
+ final Predicate<Neo4jNode> nodePredicate = this.trait.getNodePredicate();
return IteratorUtils.stream(this.getBaseGraph().allNodes())
.filter(node -> !this.checkElementsInTransaction || !Neo4jHelper.isDeleted(node))
.filter(nodePredicate)
- .map(node -> (Vertex) this.createVertex(node)).iterator();
+ .map(node -> (Vertex) new Neo4jVertex(node, this)).iterator();
} else {
ElementHelper.validateMixedElementIds(Vertex.class, vertexIds);
return Stream.of(vertexIds)
@@ -180,7 +169,7 @@ public abstract class Neo4jGraph implements Graph, WrappedGraph<Neo4jGraphAPI> {
})
.flatMap(id -> {
try {
- return Stream.of((Vertex) this.createVertex(this.getBaseGraph().getNodeById(id)));
+ return Stream.of((Vertex) new Neo4jVertex(this.baseGraph.getNodeById(id), this));
} catch (final RuntimeException e) {
if (Neo4jHelper.isNotFound(e)) return Stream.empty();
throw e;
@@ -193,11 +182,11 @@ public abstract class Neo4jGraph implements Graph, WrappedGraph<Neo4jGraphAPI> {
public Iterator<Edge> edges(final Object... edgeIds) {
this.tx().readWrite();
if (0 == edgeIds.length) {
- final Predicate<Neo4jRelationship> relationshipPredicate = this.getRelationshipPredicate();
+ final Predicate<Neo4jRelationship> relationshipPredicate = this.trait.getRelationshipPredicate();
return IteratorUtils.stream(this.getBaseGraph().allRelationships())
.filter(relationship -> !this.checkElementsInTransaction || !Neo4jHelper.isDeleted(relationship))
.filter(relationshipPredicate)
- .map(relationship -> (Edge) this.createEdge(relationship)).iterator();
+ .map(relationship -> (Edge) new Neo4jEdge(relationship, this)).iterator();
} else {
ElementHelper.validateMixedElementIds(Edge.class, edgeIds);
return Stream.of(edgeIds)
@@ -213,7 +202,7 @@ public abstract class Neo4jGraph implements Graph, WrappedGraph<Neo4jGraphAPI> {
})
.flatMap(id -> {
try {
- return Stream.of((Edge) this.createEdge(this.getBaseGraph().getRelationshipById(id)));
+ return Stream.of((Edge) new Neo4jEdge(this.baseGraph.getRelationshipById(id), this));
} catch (final RuntimeException e) {
if (Neo4jHelper.isNotFound(e)) return Stream.empty();
throw e;
@@ -432,18 +421,23 @@ public abstract class Neo4jGraph implements Graph, WrappedGraph<Neo4jGraphAPI> {
@Override
public boolean supportsMetaProperties() {
- return Neo4jGraph.this.supportsMetaProperties;
+ return trait.supportsMetaProperties();
}
@Override
public boolean supportsMultiProperties() {
- return Neo4jGraph.this.supportsMultiProperties;
+ return trait.supportsMultiProperties();
}
@Override
public boolean supportsUserSuppliedIds() {
return false;
}
+
+ @Override
+ public VertexProperty.Cardinality getCardinality(final String key) {
+ return trait.getCardinality(key);
+ }
}
public class Neo4jEdgeFeatures extends Neo4jElementFeatures implements EdgeFeatures {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b8876819/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 e5de427..d6679dd 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
@@ -19,6 +19,8 @@
package org.apache.tinkerpop.gremlin.neo4j.structure;
import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Element;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.neo4j.tinkerpop.api.Neo4jNode;
import org.neo4j.tinkerpop.api.Neo4jRelationship;
@@ -60,4 +62,26 @@ public final class Neo4jHelper {
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;
+ }
+
+ public static void setVertexPropertyNode(final Neo4jVertexProperty vertexProperty, final Neo4jNode node) {
+ vertexProperty.vertexPropertyNode = node;
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b8876819/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jProperty.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jProperty.java b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jProperty.java
index 14c5a34..d283269 100644
--- a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jProperty.java
+++ b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jProperty.java
@@ -27,7 +27,7 @@ import org.neo4j.tinkerpop.api.Neo4jEntity;
/**
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
-public class Neo4jProperty<V> implements Property<V> {
+public final class Neo4jProperty<V> implements Property<V> {
protected final Element element;
protected final String key;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b8876819/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jVertex.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jVertex.java b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jVertex.java
index b9c216e..d7bdf4f 100644
--- a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jVertex.java
+++ b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jVertex.java
@@ -18,7 +18,6 @@
*/
package org.apache.tinkerpop.gremlin.neo4j.structure;
-import org.apache.tinkerpop.gremlin.neo4j.structure.full.FullNeo4jVertexProperty;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Element;
@@ -36,12 +35,11 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
-import java.util.function.Predicate;
/**
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
-public abstract class Neo4jVertex extends Neo4jElement implements Vertex, WrappedVertex<Neo4jNode> {
+public final class Neo4jVertex extends Neo4jElement implements Vertex, WrappedVertex<Neo4jNode> {
public static final String LABEL_DELIMINATOR = "::";
@@ -52,7 +50,7 @@ public abstract class Neo4jVertex extends Neo4jElement implements Vertex, Wrappe
@Override
public Edge addEdge(final String label, final Vertex inVertex, final Object... keyValues) {
if (null == inVertex) throw Graph.Exceptions.argumentCanNotBeNull("inVertex");
- if (this.removed) throw Element.Exceptions.elementAlreadyRemoved(Vertex.class, this.getBaseVertex().getId());
+ if (this.removed) throw Element.Exceptions.elementAlreadyRemoved(Vertex.class, this.id());
ElementHelper.validateLabel(label);
ElementHelper.legalPropertyKeyValueArray(keyValues);
if (ElementHelper.getIdValue(keyValues).isPresent())
@@ -60,7 +58,7 @@ public abstract class Neo4jVertex extends Neo4jElement implements Vertex, Wrappe
this.graph.tx().readWrite();
final Neo4jNode node = (Neo4jNode) this.baseElement;
- final Neo4jEdge edge = this.graph.createEdge(node.connectTo(((Neo4jVertex) inVertex).getBaseVertex(), label));
+ final Neo4jEdge edge = new Neo4jEdge(node.connectTo(((Neo4jVertex) inVertex).getBaseVertex(), label), this.graph);
ElementHelper.attachProperties(edge, keyValues);
return edge;
}
@@ -71,15 +69,33 @@ public abstract class Neo4jVertex extends Neo4jElement implements Vertex, Wrappe
}
@Override
- public <V> VertexProperty<V> property(final String key, final V value, final Object... keyValues) {
- return this.property(this.graph.features().vertex().getCardinality(key), key, value, keyValues);
+ public void remove() {
+ if (this.removed) throw Element.Exceptions.elementAlreadyRemoved(Vertex.class, this.id());
+ this.removed = true;
+ this.graph.tx().readWrite();
+ this.graph.trait.removeVertex(this);
+ }
+
+ @Override
+ public <V> VertexProperty<V> property(final VertexProperty.Cardinality cardinality, final String key, final V value, final Object... keyValues) {
+ if (this.removed) throw Element.Exceptions.elementAlreadyRemoved(Vertex.class, this.id());
+ this.graph.tx().readWrite();
+ return this.graph.trait.setVertexProperty(this, cardinality, key, value, keyValues);
}
@Override
- public abstract <V> VertexProperty<V> property(final String key);
+ public <V> VertexProperty<V> property(final String key) {
+ if (this.removed) throw Element.Exceptions.elementAlreadyRemoved(Vertex.class, this.id());
+ this.graph.tx().readWrite();
+ return this.graph.trait.getVertexProperty(this, key);
+ }
@Override
- public abstract <V> Iterator<VertexProperty<V>> properties(final String... propertyKeys);
+ public <V> Iterator<VertexProperty<V>> properties(final String... propertyKeys) {
+ if (this.removed) throw Element.Exceptions.elementAlreadyRemoved(Vertex.class, this.id());
+ this.graph.tx().readWrite();
+ return this.graph.trait.getVertexProperties(this, propertyKeys);
+ }
@Override
public Neo4jNode getBaseVertex() {
@@ -98,7 +114,7 @@ public abstract class Neo4jVertex extends Neo4jElement implements Vertex, Wrappe
return new Iterator<Vertex>() {
final Iterator<Neo4jRelationship> relationshipIterator = IteratorUtils.filter(0 == edgeLabels.length ?
getBaseVertex().relationships(Neo4jHelper.mapDirection(direction)).iterator() :
- getBaseVertex().relationships(Neo4jHelper.mapDirection(direction), (edgeLabels)).iterator(), graph.getRelationshipPredicate());
+ getBaseVertex().relationships(Neo4jHelper.mapDirection(direction), (edgeLabels)).iterator(), graph.trait.getRelationshipPredicate());
@Override
public boolean hasNext() {
@@ -107,7 +123,7 @@ public abstract class Neo4jVertex extends Neo4jElement implements Vertex, Wrappe
@Override
public Neo4jVertex next() {
- return graph.createVertex(this.relationshipIterator.next().other(getBaseVertex()));
+ return new Neo4jVertex(this.relationshipIterator.next().other(getBaseVertex()), graph);
}
};
}
@@ -118,7 +134,7 @@ public abstract class Neo4jVertex extends Neo4jElement implements Vertex, Wrappe
return new Iterator<Edge>() {
final Iterator<Neo4jRelationship> relationshipIterator = IteratorUtils.filter(0 == edgeLabels.length ?
getBaseVertex().relationships(Neo4jHelper.mapDirection(direction)).iterator() :
- getBaseVertex().relationships(Neo4jHelper.mapDirection(direction), (edgeLabels)).iterator(), graph.getRelationshipPredicate());
+ getBaseVertex().relationships(Neo4jHelper.mapDirection(direction), (edgeLabels)).iterator(), graph.trait.getRelationshipPredicate());
@Override
public boolean hasNext() {
@@ -127,7 +143,7 @@ public abstract class Neo4jVertex extends Neo4jElement implements Vertex, Wrappe
@Override
public Neo4jEdge next() {
- return graph.createEdge(this.relationshipIterator.next());
+ return new Neo4jEdge(this.relationshipIterator.next(), graph);
}
};
}
@@ -155,17 +171,4 @@ public abstract class Neo4jVertex extends Neo4jElement implements Vertex, Wrappe
return StringFactory.vertexString(this);
}
- protected boolean existsInNeo4j(final String key) {
- try {
- return this.getBaseVertex().hasProperty(key);
- } catch (IllegalStateException ex) {
- // if vertex is removed before/after transaction close
- throw Element.Exceptions.elementAlreadyRemoved(Vertex.class, this.id());
- } catch (RuntimeException ex) {
- // if vertex is removed before/after transaction close
- if (Neo4jHelper.isNotFound(ex))
- throw Element.Exceptions.elementAlreadyRemoved(Vertex.class, this.id());
- throw ex;
- }
- }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b8876819/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 c8f818b..12e55e1 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
@@ -19,27 +19,40 @@
package org.apache.tinkerpop.gremlin.neo4j.structure;
import org.apache.tinkerpop.gremlin.structure.Element;
+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.neo4j.tinkerpop.api.Neo4jNode;
+import java.util.Iterator;
import java.util.NoSuchElementException;
+import java.util.Optional;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public abstract class Neo4jVertexProperty<V> implements VertexProperty<V> {
+public final class Neo4jVertexProperty<V> implements VertexProperty<V> {
protected final Neo4jVertex vertex;
protected final String key;
protected final V value;
+ protected Neo4jNode vertexPropertyNode;
public Neo4jVertexProperty(final Neo4jVertex vertex, final String key, final V value) {
this.vertex = vertex;
this.key = key;
this.value = value;
+ this.vertexPropertyNode = null;
+ }
+
+ public Neo4jVertexProperty(final Neo4jVertex vertex, final String key, final V value, final Neo4jNode vertexPropertyNode) {
+ this.vertex = vertex;
+ this.key = key;
+ this.value = value;
+ this.vertexPropertyNode = vertexPropertyNode;
}
@Override
@@ -54,16 +67,6 @@ public abstract class Neo4jVertexProperty<V> implements VertexProperty<V> {
}
@Override
- public boolean equals(final Object object) {
- return ElementHelper.areEqual(this, object);
- }
-
- @Override
- public int hashCode() {
- return ElementHelper.hashCode((Element) this);
- }
-
- @Override
public String key() {
return this.key;
}
@@ -76,13 +79,38 @@ public abstract class Neo4jVertexProperty<V> implements VertexProperty<V> {
@Override
public boolean isPresent() {
return null != this.value;
+ }
+ @Override
+ public <U> Iterator<Property<U>> properties(final String... propertyKeys) {
+ this.vertex.graph.tx().readWrite();
+ return this.vertex.graph.trait.getProperties(this, propertyKeys);
}
@Override
- public String toString() {
- return StringFactory.propertyString(this);
+ public <U> Property<U> property(final String key, final U value) {
+ this.vertex.graph.tx().readWrite();
+ return this.vertex.graph.trait.setProperty(this, key, value);
}
+ @Override
+ public void remove() {
+ this.vertex.graph.tx().readWrite();
+ this.vertex.graph.trait.removeVertexProperty(this);
+ }
+ @Override
+ public boolean equals(final Object object) {
+ return ElementHelper.areEqual(this, object);
+ }
+
+ @Override
+ public int hashCode() {
+ return ElementHelper.hashCode((Element) this);
+ }
+
+ @Override
+ public String toString() {
+ return StringFactory.propertyString(this);
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b8876819/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/full/FullNeo4jGraph.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/full/FullNeo4jGraph.java b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/full/FullNeo4jGraph.java
deleted file mode 100644
index c959ddd..0000000
--- a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/full/FullNeo4jGraph.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- *
- * * 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.neo4j.structure.full;
-
-import org.apache.commons.configuration.BaseConfiguration;
-import org.apache.commons.configuration.Configuration;
-import org.apache.tinkerpop.gremlin.neo4j.process.traversal.strategy.optimization.Neo4jGraphStepStrategy;
-import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jEdge;
-import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jGraph;
-import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jVertex;
-import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
-import org.apache.tinkerpop.gremlin.structure.Graph;
-import org.neo4j.tinkerpop.api.Neo4jGraphAPI;
-import org.neo4j.tinkerpop.api.Neo4jNode;
-import org.neo4j.tinkerpop.api.Neo4jRelationship;
-
-import java.util.function.Predicate;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public final class FullNeo4jGraph extends Neo4jGraph {
-
- private static final Configuration EMPTY_CONFIGURATION = new BaseConfiguration() {{
- this.setProperty(Graph.GRAPH, FullNeo4jGraph.class.getName());
- this.setProperty(Neo4jGraph.CONFIG_META_PROPERTIES, true);
- this.setProperty(Neo4jGraph.CONFIG_MULTI_PROPERTIES, true);
- }};
-
- static {
- TraversalStrategies.GlobalCache.registerStrategies(FullNeo4jGraph.class, TraversalStrategies.GlobalCache.getStrategies(Graph.class).clone().addStrategies(Neo4jGraphStepStrategy.instance()));
- }
-
- public FullNeo4jGraph(final Configuration configuration) {
- super(configuration);
- }
-
- public FullNeo4jGraph(final Neo4jGraphAPI baseGraph) {
- super(baseGraph, EMPTY_CONFIGURATION);
- }
-
- @Override
- public Neo4jVertex createVertex(final Neo4jNode node) {
- return new FullNeo4jVertex(node, this);
- }
-
- @Override
- public Neo4jEdge createEdge(final Neo4jRelationship relationship) {
- return new Neo4jEdge(relationship, this);
- }
-
- @Override
- public Predicate<Neo4jNode> getNodePredicate() {
- return node -> !node.hasLabel(FullNeo4jVertexProperty.VERTEX_PROPERTY_LABEL);
- }
-
- @Override
- public Predicate<Neo4jRelationship> getRelationshipPredicate() {
- return relationship -> !relationship.type().startsWith(FullNeo4jVertexProperty.VERTEX_PROPERTY_PREFIX);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b8876819/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/full/FullNeo4jProperty.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/full/FullNeo4jProperty.java b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/full/FullNeo4jProperty.java
deleted file mode 100644
index 4952240..0000000
--- a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/full/FullNeo4jProperty.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- *
- * * 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.neo4j.structure.full;
-
-import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jElement;
-import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jProperty;
-import org.apache.tinkerpop.gremlin.structure.Element;
-import org.apache.tinkerpop.gremlin.structure.VertexProperty;
-import org.neo4j.tinkerpop.api.Neo4jEntity;
-import org.neo4j.tinkerpop.api.Neo4jNode;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-final class FullNeo4jProperty<V> extends Neo4jProperty {
-
- public FullNeo4jProperty(final Element element, final String key, final V value) {
- super(element, key, value);
- }
-
- @Override
- public void remove() {
- this.graph.tx().readWrite();
- if (this.element instanceof VertexProperty) {
- final Neo4jNode node = ((FullNeo4jVertexProperty) this.element).getBaseVertexProperty();
- if (null != node && node.hasProperty(this.key)) {
- node.removeProperty(this.key);
- }
- } else {
- final Neo4jEntity entity = ((Neo4jElement) this.element).getBaseElement();
- if (entity.hasProperty(this.key)) {
- entity.removeProperty(this.key);
- }
- }
- }
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b8876819/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/full/FullNeo4jVertex.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/full/FullNeo4jVertex.java b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/full/FullNeo4jVertex.java
deleted file mode 100644
index 07d24ad..0000000
--- a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/full/FullNeo4jVertex.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- *
- * * 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.neo4j.structure.full;
-
-import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jEdge;
-import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jGraph;
-import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jHelper;
-import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jVertex;
-import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jVertexProperty;
-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.Property;
-import org.apache.tinkerpop.gremlin.structure.T;
-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.util.iterator.IteratorUtils;
-import org.neo4j.tinkerpop.api.Neo4jDirection;
-import org.neo4j.tinkerpop.api.Neo4jNode;
-import org.neo4j.tinkerpop.api.Neo4jRelationship;
-
-import java.util.Iterator;
-import java.util.Optional;
-import java.util.stream.Stream;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-final class FullNeo4jVertex extends Neo4jVertex {
-
- public FullNeo4jVertex(final Neo4jNode node, final Neo4jGraph neo4jGraph) {
- super(node, neo4jGraph);
- }
-
-
-
- @Override
- public <V> VertexProperty<V> property(final String key) {
- if (this.removed) throw Element.Exceptions.elementAlreadyRemoved(Vertex.class, this.getBaseVertex().getId());
- this.graph.tx().readWrite();
- if (existsInNeo4j(key)) {
- if (this.getBaseVertex().getProperty(key).equals(FullNeo4jVertexProperty.VERTEX_PROPERTY_TOKEN)) {
- if (this.getBaseVertex().degree(Neo4jDirection.OUTGOING, FullNeo4jVertexProperty.VERTEX_PROPERTY_PREFIX.concat(key)) > 1)
- throw Vertex.Exceptions.multiplePropertiesExistForProvidedKey(key);
- else
- return new FullNeo4jVertexProperty<>(this, this.getBaseVertex().relationships(
- Neo4jDirection.OUTGOING,
- FullNeo4jVertexProperty.VERTEX_PROPERTY_PREFIX.concat(key))
- .iterator().next().end());
- } else {
- return new FullNeo4jVertexProperty<>(this, key, (V) this.getBaseVertex().getProperty(key));
- }
- } else
- return VertexProperty.<V>empty();
-
- }
-
- @Override
- public <V> VertexProperty<V> property(final VertexProperty.Cardinality cardinality, final String key, final V value, final Object... keyValues) {
- if (this.removed) throw Element.Exceptions.elementAlreadyRemoved(Vertex.class, this.getBaseVertex().getId());
- ElementHelper.validateProperty(key, value);
- if (ElementHelper.getIdValue(keyValues).isPresent())
- throw VertexProperty.Exceptions.userSuppliedIdsNotSupported();
- this.graph.tx().readWrite();
- try {
- final Optional<VertexProperty<V>> optionalVertexProperty = ElementHelper.stageVertexProperty(this, cardinality, key, value, keyValues);
- if (optionalVertexProperty.isPresent()) return optionalVertexProperty.get();
-
- final String prefixedKey = FullNeo4jVertexProperty.VERTEX_PROPERTY_PREFIX.concat(key);
- if (this.getBaseVertex().hasProperty(key)) {
- if (this.getBaseVertex().getProperty(key).equals(FullNeo4jVertexProperty.VERTEX_PROPERTY_TOKEN)) {
- final Neo4jNode node = this.graph.getBaseGraph().createNode(FullNeo4jVertexProperty.VERTEX_PROPERTY_LABEL, key);
- node.setProperty(T.key.getAccessor(), key);
- node.setProperty(T.value.getAccessor(), value);
- this.getBaseVertex().connectTo(node, prefixedKey);
- final Neo4jVertexProperty<V> property = new FullNeo4jVertexProperty<>(this, node);
- ElementHelper.attachProperties(property, keyValues); // TODO: make this inlined
- return property;
- } else {
- Neo4jNode node = this.graph.getBaseGraph().createNode(FullNeo4jVertexProperty.VERTEX_PROPERTY_LABEL, key);
- node.setProperty(T.key.getAccessor(), key);
- node.setProperty(T.value.getAccessor(), this.getBaseVertex().removeProperty(key));
- this.getBaseVertex().connectTo(node, prefixedKey);
- this.getBaseVertex().setProperty(key, FullNeo4jVertexProperty.VERTEX_PROPERTY_TOKEN);
- node = this.graph.getBaseGraph().createNode(FullNeo4jVertexProperty.VERTEX_PROPERTY_LABEL, key);
- node.setProperty(T.key.getAccessor(), key);
- node.setProperty(T.value.getAccessor(), value);
- this.getBaseVertex().connectTo(node, prefixedKey);
- final Neo4jVertexProperty<V> property = new FullNeo4jVertexProperty<>(this, node);
- ElementHelper.attachProperties(property, keyValues); // TODO: make this inlined
- return property;
- }
- } else {
- this.getBaseVertex().setProperty(key, value);
- final Neo4jVertexProperty<V> property = new FullNeo4jVertexProperty<>(this, key, value);
- ElementHelper.attachProperties(property, keyValues); // TODO: make this inlined
- return property;
- }
- } catch (IllegalArgumentException iae) {
- throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(value);
- }
- }
-
- @Override
- public <V> Iterator<VertexProperty<V>> properties(final String... propertyKeys) {
- this.graph.tx().readWrite();
- return IteratorUtils.stream(getBaseVertex().getKeys())
- .filter(key -> ElementHelper.keyExists(key, propertyKeys))
- .flatMap(key -> {
- if (getBaseVertex().getProperty(key).equals(FullNeo4jVertexProperty.VERTEX_PROPERTY_TOKEN))
- return IteratorUtils.stream(getBaseVertex().relationships(Neo4jDirection.OUTGOING, (FullNeo4jVertexProperty.VERTEX_PROPERTY_PREFIX.concat(key))))
- .map(relationship -> (VertexProperty<V>) new FullNeo4jVertexProperty(FullNeo4jVertex.this, relationship.end()));
- else
- return Stream.of(new FullNeo4jVertexProperty<>(FullNeo4jVertex.this, key, (V) this.getBaseVertex().getProperty(key)));
- }).iterator();
- }
-
- @Override
- public void remove() {
- if (this.removed) throw Element.Exceptions.elementAlreadyRemoved(Vertex.class, this.getBaseVertex().getId());
- this.removed = true;
- this.graph.tx().readWrite();
- try {
- final Neo4jNode node = this.getBaseVertex();
- for (final Neo4jRelationship relationship : node.relationships(Neo4jDirection.BOTH)) {
- final Neo4jNode otherNode = relationship.other(node);
- if (otherNode.hasLabel(FullNeo4jVertexProperty.VERTEX_PROPERTY_LABEL)) {
- otherNode.relationships(null).forEach(Neo4jRelationship::delete);
- otherNode.delete(); // meta property node
- } else
- relationship.delete();
- }
- node.delete();
- } catch (final IllegalStateException ignored) {
- // this one happens if the vertex is still chilling in the tx
- } catch (final RuntimeException ex) {
- if (!Neo4jHelper.isNotFound(ex)) throw ex;
- // this one happens if the vertex is committed
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b8876819/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/full/FullNeo4jVertexProperty.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/full/FullNeo4jVertexProperty.java b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/full/FullNeo4jVertexProperty.java
deleted file mode 100644
index 2f48841..0000000
--- a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/full/FullNeo4jVertexProperty.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- *
- * * 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.neo4j.structure.full;
-
-import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jHelper;
-import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jVertex;
-import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jVertexProperty;
-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.T;
-import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
-import org.apache.tinkerpop.gremlin.structure.util.wrapped.WrappedGraph;
-import org.apache.tinkerpop.gremlin.structure.util.wrapped.WrappedVertexProperty;
-import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
-import org.neo4j.tinkerpop.api.Neo4jDirection;
-import org.neo4j.tinkerpop.api.Neo4jGraphAPI;
-import org.neo4j.tinkerpop.api.Neo4jNode;
-import org.neo4j.tinkerpop.api.Neo4jRelationship;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public final class FullNeo4jVertexProperty<V> extends Neo4jVertexProperty<V> implements WrappedVertexProperty<Neo4jNode> {
-
- public static final String VERTEX_PROPERTY_LABEL = "vertexProperty";
- public static final String VERTEX_PROPERTY_PREFIX = Graph.Hidden.hide("");
- public static final String VERTEX_PROPERTY_TOKEN = Graph.Hidden.hide("vertexProperty");
-
-
- private Neo4jNode node;
-
- public FullNeo4jVertexProperty(final Neo4jVertex vertex, final String key, final V value) {
- super(vertex, key, value);
- }
-
- public FullNeo4jVertexProperty(final Neo4jVertex vertex, final Neo4jNode node) {
- super(vertex, (String) node.getProperty(T.key.getAccessor()), (V) node.getProperty(T.value.getAccessor()));
- this.node = node;
- }
-
- @Override
- public Set<String> keys() {
- if (isNode()) {
- this.vertex.graph().tx().readWrite();
- final Set<String> keys = new HashSet<>();
- for (final String key : this.node.getKeys()) {
- if (!Graph.Hidden.isHidden(key))
- keys.add(key);
- }
- return keys;
- } else {
- return Collections.emptySet();
- }
- }
-
- @Override
- public <U> Property<U> property(String key, U value) {
- ElementHelper.validateProperty(key, value);
- this.vertex.graph().tx().readWrite();
- if (isNode()) {
- this.node.setProperty(key, value);
- return new FullNeo4jProperty<>(this, key, value);
- } else {
- this.node = ((WrappedGraph<Neo4jGraphAPI>) this.vertex.graph()).getBaseGraph().createNode(VERTEX_PROPERTY_LABEL, this.label());
- this.node.setProperty(T.key.getAccessor(), this.key);
- this.node.setProperty(T.value.getAccessor(), this.value);
- this.node.setProperty(key, value);
- this.vertex.getBaseVertex().connectTo(this.node, VERTEX_PROPERTY_PREFIX.concat(this.key));
- this.vertex.getBaseVertex().setProperty(this.key, VERTEX_PROPERTY_TOKEN);
- return new FullNeo4jProperty<>(this, key, value);
- }
- }
-
- @Override
- public <U> Property<U> property(final String key) {
- this.vertex.graph().tx().readWrite();
- try {
- if (isNode() && this.node.hasProperty(key))
- return new FullNeo4jProperty<>(this, key, (U) this.node.getProperty(key));
- else
- return Property.empty();
- } catch (IllegalStateException ex) {
- throw Element.Exceptions.elementAlreadyRemoved(this.getClass(), this.id());
- } catch (RuntimeException ex) {
- if (Neo4jHelper.isNotFound(ex))
- throw Element.Exceptions.elementAlreadyRemoved(this.getClass(), this.id());
- throw ex;
- }
- }
-
- @Override
- public void remove() {
- this.vertex.graph().tx().readWrite();
- if (isNode()) {
- this.node.relationships(null).forEach(Neo4jRelationship::delete);
- this.node.delete();
- if (this.vertex.getBaseVertex().degree(Neo4jDirection.OUTGOING, VERTEX_PROPERTY_PREFIX.concat(this.key)) == 0) {
- if (this.vertex.getBaseVertex().hasProperty(this.key))
- this.vertex.getBaseVertex().removeProperty(this.key);
- }
- } else {
- if (this.vertex.getBaseVertex().degree(Neo4jDirection.OUTGOING, VERTEX_PROPERTY_PREFIX.concat(this.key)) == 0) {
- if (this.vertex.getBaseVertex().hasProperty(this.key))
- this.vertex.getBaseVertex().removeProperty(this.key);
- }
- }
- }
-
- protected boolean isNode() {
- return null != this.node;
- }
-
- @Override
- public <U> Iterator<Property<U>> properties(final String... propertyKeys) {
- if (!isNode()) return Collections.emptyIterator();
- else {
- this.vertex.graph().tx().readWrite();
- return IteratorUtils.map(IteratorUtils.filter(this.node.getKeys().iterator(), key -> !key.equals(T.key.getAccessor()) && !key.equals(T.value.getAccessor()) && ElementHelper.keyExists(key, propertyKeys)), key -> (Property<U>) new FullNeo4jProperty<>(FullNeo4jVertexProperty.this, key, (V) this.node.getProperty(key)));
- }
- }
-
- @Override
- public Neo4jNode getBaseVertexProperty() {
- return this.node;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b8876819/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/simple/SimpleNeo4jGraph.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/simple/SimpleNeo4jGraph.java b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/simple/SimpleNeo4jGraph.java
deleted file mode 100644
index 50d14cc..0000000
--- a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/simple/SimpleNeo4jGraph.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- *
- * * 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.neo4j.structure.simple;
-
-import org.apache.commons.configuration.BaseConfiguration;
-import org.apache.commons.configuration.Configuration;
-import org.apache.tinkerpop.gremlin.neo4j.process.traversal.strategy.optimization.Neo4jGraphStepStrategy;
-import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jEdge;
-import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jGraph;
-import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jHelper;
-import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jVertex;
-import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
-import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.apache.tinkerpop.gremlin.structure.Graph;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.VertexProperty;
-import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
-import org.neo4j.tinkerpop.api.Neo4jGraphAPI;
-import org.neo4j.tinkerpop.api.Neo4jNode;
-import org.neo4j.tinkerpop.api.Neo4jRelationship;
-
-import java.util.Iterator;
-import java.util.function.Predicate;
-import java.util.stream.Stream;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public final class SimpleNeo4jGraph extends Neo4jGraph {
-
- private static final Configuration EMPTY_CONFIGURATION = new BaseConfiguration() {{
- this.setProperty(Graph.GRAPH, SimpleNeo4jGraph.class.getName());
- this.setProperty(Neo4jGraph.CONFIG_META_PROPERTIES, false);
- this.setProperty(Neo4jGraph.CONFIG_MULTI_PROPERTIES, false);
- }};
-
- static {
- TraversalStrategies.GlobalCache.registerStrategies(SimpleNeo4jGraph.class, TraversalStrategies.GlobalCache.getStrategies(Graph.class).clone().addStrategies(Neo4jGraphStepStrategy.instance()));
- }
-
- public SimpleNeo4jGraph(final Configuration configuration) {
- super(configuration);
- this.features = new SimpleNeo4jGraphFeatures();
- }
-
- public SimpleNeo4jGraph(final Neo4jGraphAPI baseGraph) {
- super(baseGraph, EMPTY_CONFIGURATION);
- this.features = new SimpleNeo4jGraphFeatures();
- }
-
- @Override
- public Neo4jVertex createVertex(final Neo4jNode node) {
- return new SimpleNeo4jVertex(node, this);
- }
-
- @Override
- public Neo4jEdge createEdge(final Neo4jRelationship relationship) {
- return new Neo4jEdge(relationship, this);
- }
-
- @Override
- public Predicate<Neo4jNode> getNodePredicate() {
- return node -> true;
- }
-
- @Override
- public Predicate<Neo4jRelationship> getRelationshipPredicate() {
- return relationship -> true;
- }
-
- ////////////////////////
-
- public class SimpleNeo4jGraphFeatures extends Neo4jGraphFeatures {
-
- public SimpleNeo4jGraphFeatures() {
- this.vertexFeatures = new SimpleNeo4jVertexFeatures();
- }
-
- public class SimpleNeo4jVertexFeatures extends Neo4jVertexFeatures {
-
- SimpleNeo4jVertexFeatures() {
- super();
- }
-
- public VertexProperty.Cardinality getCardinality(final String key) {
- return VertexProperty.Cardinality.single;
- }
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b8876819/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/simple/SimpleNeo4jVertex.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/simple/SimpleNeo4jVertex.java b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/simple/SimpleNeo4jVertex.java
deleted file mode 100644
index b4cb95f..0000000
--- a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/simple/SimpleNeo4jVertex.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- *
- * * 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.neo4j.structure.simple;
-
-import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jGraph;
-import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jHelper;
-import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jVertex;
-import org.apache.tinkerpop.gremlin.structure.Element;
-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.util.iterator.IteratorUtils;
-import org.neo4j.tinkerpop.api.Neo4jDirection;
-import org.neo4j.tinkerpop.api.Neo4jNode;
-import org.neo4j.tinkerpop.api.Neo4jRelationship;
-
-import java.util.Iterator;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-final class SimpleNeo4jVertex extends Neo4jVertex {
-
- public SimpleNeo4jVertex(final Neo4jNode node, final Neo4jGraph neo4jGraph) {
- super(node, neo4jGraph);
- }
-
- @Override
- public <V> VertexProperty<V> property(final String key) {
- if (this.removed) throw Element.Exceptions.elementAlreadyRemoved(Vertex.class, this.getBaseVertex().getId());
- this.graph.tx().readWrite();
- if (existsInNeo4j(key)) {
- return new SimpleNeo4jVertexProperty<>(this, key, (V) this.getBaseVertex().getProperty(key));
- } else
- return VertexProperty.<V>empty();
-
- }
-
- @Override
- public <V> VertexProperty<V> property(final VertexProperty.Cardinality cardinality, final String key, final V value, final Object... keyValues) {
- if (this.removed) throw Element.Exceptions.elementAlreadyRemoved(Vertex.class, this.getBaseVertex().getId());
- if (cardinality != VertexProperty.Cardinality.single)
- throw VertexProperty.Exceptions.multiPropertiesNotSupported();
- if (keyValues.length > 0)
- throw VertexProperty.Exceptions.metaPropertiesNotSupported();
- ElementHelper.validateProperty(key, value);
- try {
- this.getBaseVertex().setProperty(key, value);
- return new SimpleNeo4jVertexProperty<>(this, key, value);
- } catch (final IllegalArgumentException iae) {
- throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(value);
- }
- }
-
- @Override
- public <V> Iterator<VertexProperty<V>> properties(final String... propertyKeys) {
- this.graph.tx().readWrite();
- return (Iterator) IteratorUtils.stream(getBaseVertex().getKeys())
- .filter(key -> ElementHelper.keyExists(key, propertyKeys))
- .map(key -> new SimpleNeo4jVertexProperty<>(SimpleNeo4jVertex.this, key, (V) this.getBaseVertex().getProperty(key))).iterator();
- }
-
- @Override
- public void remove() {
- if (this.removed) throw Element.Exceptions.elementAlreadyRemoved(Vertex.class, this.getBaseVertex().getId());
- this.removed = true;
- this.graph.tx().readWrite();
- try {
- final Neo4jNode node = this.getBaseVertex();
- for (final Neo4jRelationship relationship : node.relationships(Neo4jDirection.BOTH)) {
- relationship.delete();
- }
- node.delete();
- } catch (final IllegalStateException ignored) {
- // this one happens if the vertex is still chilling in the tx
- } catch (final RuntimeException ex) {
- if (!Neo4jHelper.isNotFound(ex)) throw ex;
- // this one happens if the vertex is committed
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b8876819/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/simple/SimpleNeo4jVertexProperty.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/simple/SimpleNeo4jVertexProperty.java b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/simple/SimpleNeo4jVertexProperty.java
deleted file mode 100644
index 4de7462..0000000
--- a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/simple/SimpleNeo4jVertexProperty.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- *
- * * 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.neo4j.structure.simple;
-
-import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jVertex;
-import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jVertexProperty;
-import org.apache.tinkerpop.gremlin.structure.Property;
-import org.apache.tinkerpop.gremlin.structure.VertexProperty;
-
-import java.util.Iterator;
-import java.util.Set;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-final class SimpleNeo4jVertexProperty<V> extends Neo4jVertexProperty<V> {
-
- public SimpleNeo4jVertexProperty(final Neo4jVertex vertex, final String key, final V value) {
- super(vertex, key, value);
- }
-
- @Override
- public Set<String> keys() {
- throw VertexProperty.Exceptions.metaPropertiesNotSupported();
- }
-
- @Override
- public <U> Property<U> property(String key, U value) {
- throw VertexProperty.Exceptions.metaPropertiesNotSupported();
- }
-
- @Override
- public <U> Property<U> property(final String key) {
- throw VertexProperty.Exceptions.metaPropertiesNotSupported();
- }
-
- @Override
- public void remove() {
- this.vertex.graph().tx().readWrite();
- if (this.vertex.getBaseVertex().hasProperty(this.key))
- this.vertex.getBaseVertex().removeProperty(this.key);
- }
-
- @Override
- public <U> Iterator<Property<U>> properties(final String... propertyKeys) {
- throw VertexProperty.Exceptions.metaPropertiesNotSupported();
- }
-}