You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2015/03/09 18:27:03 UTC
incubator-tinkerpop git commit: new API --- TraversalContext.
Repository: incubator-tinkerpop
Updated Branches:
refs/heads/newapi [created] f897f6c30
new API --- TraversalContext.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/f897f6c3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/f897f6c3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/f897f6c3
Branch: refs/heads/newapi
Commit: f897f6c302789de8e6f518177ceeec571176bb36
Parents: 0ef3857
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Mon Mar 9 11:26:54 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Mon Mar 9 11:26:54 2015 -0600
----------------------------------------------------------------------
.../gremlin/process/TraversalContext.java | 35 ++++++++
.../graph/traversal/GraphTraversalContext.java | 87 ++++++++++++++++++++
.../tinkerpop/gremlin/structure/Graph.java | 13 +++
.../tinkergraph/structure/TinkerGraphTest.java | 14 ++--
4 files changed, 140 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/f897f6c3/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/TraversalContext.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/TraversalContext.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/TraversalContext.java
new file mode 100644
index 0000000..df77651
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/TraversalContext.java
@@ -0,0 +1,35 @@
+/*
+ * 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.process;
+
+import org.apache.tinkerpop.gremlin.structure.Graph;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public interface TraversalContext {
+
+ public interface Builder<C extends TraversalContext> {
+ public Builder engine(final TraversalEngine engine);
+
+ public Builder strategy(final TraversalStrategy strategy);
+
+ public C create(final Graph graph);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/f897f6c3/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/GraphTraversalContext.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/GraphTraversalContext.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/GraphTraversalContext.java
new file mode 100644
index 0000000..ecf8601
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/GraphTraversalContext.java
@@ -0,0 +1,87 @@
+/*
+ * 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.process.graph.traversal;
+
+import org.apache.tinkerpop.gremlin.process.TraversalContext;
+import org.apache.tinkerpop.gremlin.process.TraversalEngine;
+import org.apache.tinkerpop.gremlin.process.TraversalStrategies;
+import org.apache.tinkerpop.gremlin.process.TraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.graph.traversal.step.sideEffect.GraphStep;
+import org.apache.tinkerpop.gremlin.process.traversal.engine.StandardTraversalEngine;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Transaction;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class GraphTraversalContext implements TraversalContext {
+
+ private final Graph graph;
+ private final TraversalEngine engine;
+ private final TraversalStrategies strategies;
+
+ public GraphTraversalContext(final Graph graph, final TraversalEngine engine, final TraversalStrategy... strategies) {
+ this.graph = graph;
+ this.engine = engine;
+ this.strategies = TraversalStrategies.GlobalCache.getStrategies(this.graph.getClass()).addStrategies(strategies);
+ }
+
+ public GraphTraversal<Vertex, Vertex> V(final Object... vertexIds) {
+ final GraphTraversal.Admin<Vertex, Vertex> traversal = new DefaultGraphTraversal<>(this);
+ traversal.setEngine(this.engine);
+ traversal.setStrategies(this.strategies);
+ return traversal.addStep(new GraphStep<>(traversal, this.graph, Vertex.class, vertexIds));
+ }
+
+ public Transaction tx() {
+ return this.graph.tx();
+ }
+
+ public static Builder of() {
+ return new Builder();
+ }
+
+ //////
+
+ public static class Builder implements TraversalContext.Builder<GraphTraversalContext> {
+
+ private TraversalEngine engine = StandardTraversalEngine.standard;
+ private List<TraversalStrategy> strategies = new ArrayList<>();
+
+ public Builder engine(final TraversalEngine engine) {
+ this.engine = engine;
+ return this;
+ }
+
+ public Builder strategy(final TraversalStrategy strategy) {
+ this.strategies.add(strategy);
+ return this;
+ }
+
+ public GraphTraversalContext create(final Graph graph) {
+ return new GraphTraversalContext(graph, this.engine, this.strategies.toArray(new TraversalStrategy[this.strategies.size()]));
+ }
+
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/f897f6c3/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
index 6ede86f..803c98e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
@@ -21,6 +21,7 @@ package org.apache.tinkerpop.gremlin.structure;
import org.apache.commons.configuration.Configuration;
import org.apache.tinkerpop.gremlin.process.T;
import org.apache.tinkerpop.gremlin.process.Traversal;
+import org.apache.tinkerpop.gremlin.process.TraversalContext;
import org.apache.tinkerpop.gremlin.process.TraversalEngine;
import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
import org.apache.tinkerpop.gremlin.process.graph.traversal.DefaultGraphTraversal;
@@ -201,6 +202,18 @@ public interface Graph extends AutoCloseable {
*/
public void engine(final TraversalEngine traversalEngine);
+ public default <C extends TraversalContext> C traversal(final TraversalContext.Builder<C> contextBuilder) {
+ return contextBuilder.create(this);
+ }
+
+ public default Iterator<Vertex> vertices(final Object... vertexIds) {
+ return this.iterators().vertexIterator(vertexIds);
+ }
+
+ public default Iterator<Edge> edges(final Object... edgeIds) {
+ return this.iterators().edgeIterator(edgeIds);
+ }
+
/**
* Configure and control the transactions for those graphs that support this feature.
*/
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/f897f6c3/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
index 853c9df..923fe13 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
@@ -20,10 +20,10 @@ package org.apache.tinkerpop.gremlin.tinkergraph.structure;
import org.apache.commons.io.FileUtils;
import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
-import org.apache.tinkerpop.gremlin.process.Scope;
+import org.apache.tinkerpop.gremlin.process.graph.traversal.GraphTraversalContext;
import org.apache.tinkerpop.gremlin.process.T;
import org.apache.tinkerpop.gremlin.process.Traversal;
-import org.apache.tinkerpop.gremlin.process.traversal.engine.ComputerTraversalEngine;
+import org.apache.tinkerpop.gremlin.process.traversal.engine.StandardTraversalEngine;
import org.apache.tinkerpop.gremlin.structure.*;
import org.apache.tinkerpop.gremlin.structure.io.GraphReader;
import org.apache.tinkerpop.gremlin.structure.io.graphml.GraphMLWriter;
@@ -136,13 +136,9 @@ public class TinkerGraphTest {
@Test
@Ignore
public void testPlay3() throws Exception {
- Graph g = TinkerFactory.createModern();
- g.engine(ComputerTraversalEngine.computer);
- Traversal t = g.V().hasLabel("software").group().by("name").by(bothE().values("weight").fold()).by(max(Scope.local));
- //Traversal t = ComputerTestHelper.compute("g.V().out('created').groupCount().by('name').values('name')", g);
- System.out.println(t);
- t.forEachRemaining(System.out::println);
- System.out.println(t);
+ Graph graph = TinkerFactory.createModern();
+ GraphTraversalContext g = graph.traversal(GraphTraversalContext.of().engine(StandardTraversalEngine.standard));
+ g.V().out().out().values("name").forEachRemaining(System.out::println);
}
@Test