You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2017/05/09 17:58:39 UTC

[1/7] tinkerpop git commit: TINKERPOP-786 Improved social DSL example a bit.

Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-786 d70043e6f -> 7e8de9c20


TINKERPOP-786 Improved social DSL example a bit.

Made persons() take a varargs of names to filter with so that you can do: g.persons('marko')


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

Branch: refs/heads/TINKERPOP-786
Commit: 321d523650e5687b94b4c5b0230a8ce75bdd974a
Parents: d70043e
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue May 9 10:24:55 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 9 10:24:55 2017 -0400

----------------------------------------------------------------------
 .../src/main/java/SocialTraversalDsl.java          |  2 +-
 .../src/main/java/SocialTraversalSourceDsl.java    | 17 +++++++++++++----
 .../src/test/java/SocialDslTest.java               |  2 ++
 3 files changed, 16 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/321d5236/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
index add44aa..e8a2ded 100644
--- a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
@@ -25,7 +25,7 @@ import org.apache.tinkerpop.gremlin.structure.Vertex;
 
 @GremlinDsl(traversalSource = "${package}.SocialTraversalSourceDsl")
 public interface SocialTraversalDsl<S, E> extends GraphTraversal.Admin<S, E> {
-    public default GraphTraversal<S, Vertex> knows(final String personName) {
+    public default GraphTraversal<S, Vertex> knows(String personName) {
         return out("knows").hasLabel("person").has("name", personName);
     }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/321d5236/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
index 0117914..9b5b136 100644
--- a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
@@ -41,11 +41,20 @@ public class SocialTraversalSourceDsl extends GraphTraversalSource {
         super(graph);
     }
 
-    public GraphTraversal<Vertex, Vertex> persons() {
-        final GraphTraversalSource clone = this.clone();
+    public GraphTraversal<Vertex, Vertex> persons(String... names) {
+        GraphTraversalSource clone = this.clone();
         clone.getBytecode().addStep(GraphTraversal.Symbols.V);
         clone.getBytecode().addStep(GraphTraversal.Symbols.hasLabel, "person");
-        final GraphTraversal.Admin<Vertex, Vertex> traversal = new DefaultGraphTraversal<>(clone);
-        return TraversalHelper.addHasContainer(traversal.addStep(new GraphStep<>(traversal, Vertex.class, true)), new HasContainer(T.label.getAccessor(), P.eq("person")));
+
+        GraphTraversal.Admin<Vertex, Vertex> traversal = new DefaultGraphTraversal<>(clone);
+        traversal.addStep(new GraphStep<>(traversal, Vertex.class, true));
+        TraversalHelper.addHasContainer(traversal, new HasContainer(T.label.getAccessor(), P.eq("person")));
+
+        if (names.length > 0) {
+            clone.getBytecode().addStep(GraphTraversal.Symbols.has, P.within(names));
+            TraversalHelper.addHasContainer(traversal, new HasContainer("name", P.within(names)));
+        }
+
+        return traversal;
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/321d5236/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/test/java/SocialDslTest.java
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/test/java/SocialDslTest.java b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/test/java/SocialDslTest.java
index be73500..5967244 100644
--- a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/test/java/SocialDslTest.java
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/test/java/SocialDslTest.java
@@ -36,12 +36,14 @@ public class SocialDslTest {
     public void shouldValidateThatMarkoKnowsJosh() {
         SocialTraversalSource social = graph.traversal(SocialTraversalSource.class);
         assertTrue(social.V().has("name","marko").knows("josh").hasNext());
+        assertTrue(social.persons("marko").knows("josh").hasNext());
     }
 
     @Test
     public void shouldGetAgeOfYoungestFriendOfMarko() {
         SocialTraversalSource social = graph.traversal(SocialTraversalSource.class);
         assertEquals(27, social.V().has("name","marko").youngestFriendsAge().next().intValue());
+        assertEquals(27, social.persons("marko").youngestFriendsAge().next().intValue());
     }
 
     @Test


[5/7] tinkerpop git commit: TINKERPOP-786 Improved TraversalSource for testing purposes

Posted by sp...@apache.org.
TINKERPOP-786 Improved TraversalSource for testing purposes


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

Branch: refs/heads/TINKERPOP-786
Commit: cf3e8ad1bf1a1acdf19afd11752eae61123f7bd5
Parents: b8f47fa
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue May 9 13:52:42 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 9 13:52:42 2017 -0400

----------------------------------------------------------------------
 .../dsl/SocialPackageTraversalSourceDsl.java         | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cf3e8ad1/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialPackageTraversalSourceDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialPackageTraversalSourceDsl.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialPackageTraversalSourceDsl.java
index 143a5c9..64859eb 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialPackageTraversalSourceDsl.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialPackageTraversalSourceDsl.java
@@ -44,11 +44,16 @@ public class SocialPackageTraversalSourceDsl extends GraphTraversalSource {
         super(graph);
     }
 
-    public GraphTraversal<Vertex, Vertex> persons() {
-        final GraphTraversalSource clone = this.clone();
+    public GraphTraversal<Vertex, Vertex> persons(String... names) {
+        GraphTraversalSource clone = this.clone();
+
         clone.getBytecode().addStep(GraphTraversal.Symbols.V);
-        clone.getBytecode().addStep(GraphTraversal.Symbols.hasLabel, "person");
-        final GraphTraversal.Admin<Vertex, Vertex> traversal = new DefaultGraphTraversal<>(clone);
-        return TraversalHelper.addHasContainer(traversal.addStep(new GraphStep<>(traversal, Vertex.class, true)), new HasContainer(T.label.getAccessor(), P.eq("person")));
+        GraphTraversal<Vertex, Vertex> traversal = new DefaultGraphTraversal<>(clone);
+        traversal.asAdmin().addStep(new GraphStep<>(traversal.asAdmin(), Vertex.class, true));
+
+        traversal = traversal.hasLabel("person");
+        if (names.length > 0) traversal = traversal.has("name", P.within(names));
+
+        return traversal;
     }
 }


[3/7] tinkerpop git commit: TINKERPOP-786 Updated README for gremlin-archetype-dsl

Posted by sp...@apache.org.
TINKERPOP-786 Updated README for gremlin-archetype-dsl


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

Branch: refs/heads/TINKERPOP-786
Commit: 58f8c38157d1d1c23b3992a96302e8d4df3b7a3f
Parents: 9684233
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue May 9 11:21:45 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 9 11:21:45 2017 -0400

----------------------------------------------------------------------
 .../src/main/resources/archetype-resources/README.asciidoc   | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/58f8c381/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/README.asciidoc
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/README.asciidoc b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/README.asciidoc
index 1e131b1..b50bdc7 100644
--- a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/README.asciidoc
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/README.asciidoc
@@ -17,7 +17,10 @@ limitations under the License.
 Gremlin DSL
 ===========
 
-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+This is a starter project that demonstrates how a basic
+link:http://tinkerpop.apache.org/docs/${project.version}/reference/#dsl[Domain Specific Language] (DSL) project is
+structured with Java and Maven. The DSL is built to work with the TinkerPop "modern" toy graph. Please see the unit
+tests in `SocialDslTest` for actual DSL usage.
 
 Prerequisites
 -------------
@@ -29,5 +32,4 @@ Building and Running
 --------------------
 
 [source,text]
-mvn clean package
-mvn exec:java -Dexec.mainClass="${package}.App"
\ No newline at end of file
+mvn clean install
\ No newline at end of file


[2/7] tinkerpop git commit: TINKERPOP-786 Updated javadocs in dsl archetype

Posted by sp...@apache.org.
TINKERPOP-786 Updated javadocs in dsl archetype


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

Branch: refs/heads/TINKERPOP-786
Commit: 9684233fd73ef9e2797631d46412405d678f0663
Parents: 321d523
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue May 9 11:16:48 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 9 11:16:48 2017 -0400

----------------------------------------------------------------------
 .../src/main/java/SocialTraversalDsl.java       | 22 ++++++++++++++++++++
 .../src/main/java/SocialTraversalSourceDsl.java |  9 ++++++++
 2 files changed, 31 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9684233f/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
index e8a2ded..af1f039 100644
--- a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
@@ -23,12 +23,34 @@ import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 
+/**
+ * This Social DSL is meant to be used with the TinkerPop "modern" toy graph.
+ * <p/>
+ * All DSLs should extend {@code GraphTraversal.Admin} and be suffixed with "TraversalDsl". Simply add DSL traversal
+ * methods to this interface. Use Gremlin's steps to build the underlying traversal in these methods to ensure
+ * compatibility with the rest of the TinkerPop stack and provider implementations.
+ * <p/>
+ * Arguments provided to the {@code GremlinDsl} annotation are all optional. In this case, a {@code traversalSource} is
+ * specified which points to a specific implementation to use. Had that argument not been specified then a default
+ * {@code TraversalSource} would have been generated.
+ */
 @GremlinDsl(traversalSource = "${package}.SocialTraversalSourceDsl")
 public interface SocialTraversalDsl<S, E> extends GraphTraversal.Admin<S, E> {
+
+    /**
+     * From a {@code Vertex} traverse "knows" edges to adjacent "person" vertices and filter those vertices on the
+     * "name" property.
+     *
+     * @param personName the name of the person to filter on
+     */
     public default GraphTraversal<S, Vertex> knows(String personName) {
         return out("knows").hasLabel("person").has("name", personName);
     }
 
+    /**
+     * From a {@code Vertex} traverse "knows" edges to adjacent "person" vertices and determine the youngest age of
+     * those persons.
+     */
     public default <E2 extends Number> GraphTraversal<S, E2> youngestFriendsAge() {
         return out("knows").hasLabel("person").values("age").min();
     }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9684233f/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
index 9b5b136..3bd8297 100644
--- a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
@@ -31,6 +31,9 @@ import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.T;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 
+/**
+ * See {@code SocialTraversalDsl} for more information about this DSL.
+ */
 public class SocialTraversalSourceDsl extends GraphTraversalSource {
 
     public SocialTraversalSourceDsl(final Graph graph, final TraversalStrategies traversalStrategies) {
@@ -41,6 +44,12 @@ public class SocialTraversalSourceDsl extends GraphTraversalSource {
         super(graph);
     }
 
+    /**
+     * Starts a traversal that finds all vertices with a "person" label and optionally allows filtering of those
+     * vertices on the "name" property.
+     *
+     * @param names list of person names to filter on
+     */
     public GraphTraversal<Vertex, Vertex> persons(String... names) {
         GraphTraversalSource clone = this.clone();
         clone.getBytecode().addStep(GraphTraversal.Symbols.V);


[7/7] tinkerpop git commit: TINKERPOP-786 Updated changelog for DSL work

Posted by sp...@apache.org.
TINKERPOP-786 Updated changelog for DSL work


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

Branch: refs/heads/TINKERPOP-786
Commit: 7e8de9c20da62cecb5acb98b2d8b9771c06c666a
Parents: 0730735
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue May 9 13:58:05 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 9 13:58:05 2017 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7e8de9c2/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 6fb3372..638fb10 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,6 +26,8 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 TinkerPop 3.2.5 (Release Date: NOT OFFICIALLY RELEASED YET)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+* Added the `gremlin-archetype-dsl` to demonstrate how to structure a Maven project for a DSL.
+* Developed and documented patterns for Domain Specific Language implementations.
 * Maintained type information on `Traversal.promise()`.
 * Propagated exception to `Future` instead of calling thread in `RemoteConnection`.
 * Fixed a bug in `RepeatUnrollStrategy` where `LoopsStep` and `LambdaHolder` should invalidate the strategy's application.


[6/7] tinkerpop git commit: TINKERPOP-786 Added some initial documentation for DSLs

Posted by sp...@apache.org.
TINKERPOP-786 Added some initial documentation for DSLs


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

Branch: refs/heads/TINKERPOP-786
Commit: 0730735d8541acba891633a79d71c85670b58c2b
Parents: cf3e8ad
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue May 9 13:57:48 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 9 13:57:48 2017 -0400

----------------------------------------------------------------------
 docs/src/reference/the-traversal.asciidoc | 154 +++++++++++++++++++++++++
 1 file changed, 154 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0730735d/docs/src/reference/the-traversal.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/the-traversal.asciidoc b/docs/src/reference/the-traversal.asciidoc
index 2612309..1be365d 100644
--- a/docs/src/reference/the-traversal.asciidoc
+++ b/docs/src/reference/the-traversal.asciidoc
@@ -2939,3 +2939,157 @@ g.V().outE().inV().
     by().
     by('name')
 ----
+
+[[dsl]]
+Domain Specific Languages
+-------------------------
+
+Gremlin is a link:http://en.wikipedia.org/wiki/Domain-specific_language[domain specific language] (DSL) for traversing
+graphs. It operates in the language of vertices, edges and properties. Typically, applications built with Gremlin are
+not of the graph domain, but instead model their domain within a graph. For example, the "modern" toy graph models
+software and person domain objects with the relationships between them (i.e. a person "knows" another person and a
+person "created" software).
+
+image::tinkerpop-modern.png[width=350]
+
+An analyst who wanted to find all the people who "marko" knows could write the following Gremlin:
+
+[source,java]
+----
+g.V().hasLabel('person').has('name','marko').out('knows')
+----
+
+While this method achieves the desired answer, it requires the analyst to traverse the graph in the domain language
+of the graph rather than the domain language of the social network. A more natural way for the analyst to write this
+traversal might be:
+
+[source,java]
+----
+g.persons('marko').knows()
+----
+
+In the statement above, the traversal is written in the language of the domain, abstracting away the underlying
+graph structure from the query. The two traversal results are equivalent and, indeed, the "Social Network DSL" produces
+the same set of traversal steps as the "Graph DSL" thus producing equivalent strategy application and performance
+runtimes.
+
+The following sections explain how to develop application specific DSLs for different <<gremlin-variants,Gremlin Language Variants>>.
+
+[[gremlin-java-dsl]
+Gremlin-Java
+~~~~~~~~~~~~
+
+Creating a DSL in Java requires the `@GremlinDsl` Java annotation in `gremlin-core`. This annotation should be applied
+to a "DSL interface" that extends `GraphTraversal.Admin`.
+
+[source,java]
+----
+@GremlinDsl
+public interface SocialTraversalDsl<S, E> extends GraphTraversal.Admin<S, E> {
+}
+----
+
+IMPORTANT: The name of the DSL interface should be suffixed with "TraversalDSL". All characters in the interface name
+before that become the "name" of the DSL.
+
+In this interface, define the methods that the DSL will be composed of:
+
+[source,java]
+----
+@GremlinDsl
+public interface SocialTraversalDsl<S, E> extends GraphTraversal.Admin<S, E> {
+    public default GraphTraversal<S, Vertex> knows(String personName) {
+        return out("knows").hasLabel("person").has("name", personName);
+    }
+
+    public default <E2 extends Number> GraphTraversal<S, E2> youngestFriendsAge() {
+        return out("knows").hasLabel("person").values("age").min();
+    }
+}
+----
+
+The `@GremlinDsl` annotation is used by the link:https://docs.oracle.com/javase/8/docs/api/index.html?javax/annotation/processing/Processor.html[Java Annotation Processor]
+to generate the boilerplate class structure required to properly use the DSL within the TinkerPop framework. These
+classes can be generated and maintained by hand, but it would be time consuming, monotonous and error-prone to do so.
+Typically, the Java compilation process is automatically configured to detect annotation processors on the classpath
+and will automatically use them when found. If that does not happen, it may be necessary to make configuration changes
+to the build to allow for the compilation process to be aware of the following `javax.annotation.processing.Processor`
+implementation:
+
+[source,java]
+----
+org.apache.tinkerpop.gremlin.process.traversal.dsl.GremlinDslProcessor
+----
+
+The annotation processor will generate several classes for the DSL:
+
+* `SocialTraversal` - A `Traversal` interface that extends the `SocialTraversalDsl` proxying methods to its underlying
+interfaces (such as `GraphTraversal`) to instead return a `SocialTraversal`
+* `DefaultSocialTraversal` - A default implementation of `SocialTraversal` (typically not used directly by the user)
+* `SocialTraversalSource` - Spawns `DefaultSocialTraversal` instances.
+
+Using the DSL then just involves telling the `Graph` to use it:
+
+[source,java]
+----
+SocialTraversalSource social = graph.traversal(SocialTraversalSource.class);
+social.V().has("name","marko").knows("josh");
+----
+
+The `SocialTraversalSource` can also be customized with DSL functions. As an additional step, include a class that
+extends from `GraphTraversalSource` and with a name that is suffixed with "TraversalSourceDsl". Include in this class,
+any custom methods required by the DSL:
+
+[source,java]
+----
+public class SocialTraversalSourceDsl extends GraphTraversalSource {
+
+    public SocialTraversalSourceDsl(final Graph graph, final TraversalStrategies traversalStrategies) {
+        super(graph, traversalStrategies);
+    }
+
+    public SocialTraversalSourceDsl(final Graph graph) {
+        super(graph);
+    }
+
+    public GraphTraversal<Vertex, Vertex> persons(String... names) {
+        GraphTraversalSource clone = this.clone();
+
+        // Manually add a "start" step for the traversal in this case the equivalent of V(). GraphStep is marked
+        // as a "start" step by passing "true" in the constructor.
+        clone.getBytecode().addStep(GraphTraversal.Symbols.V);
+        GraphTraversal<Vertex, Vertex> traversal = new DefaultGraphTraversal<>(clone);
+        traversal.asAdmin().addStep(new GraphStep<>(traversal.asAdmin(), Vertex.class, true));
+
+        traversal = traversal.hasLabel("person");
+        if (names.length > 0) traversal = traversal.has("name", P.within(names));
+
+        return traversal;
+    }
+}
+----
+
+Then, back in the `SocialTraversal` interface, update the `GremlinDsl` annotation with the `traversalSource` argument
+to point to the fully qualified class name of the `SocialTraversalSourceDsl`:
+
+[source,java]
+----
+@GremlinDsl(traversalSource = "com.company.SocialTraversalSourceDsl")
+public interface SocialTraversalDsl<S, E> extends GraphTraversal.Admin<S, E> {
+    ...
+}
+----
+
+It is then possible to use the `persons()` method to start traversals:
+
+[source,java]
+----
+SocialTraversalSource social = graph.traversal(SocialTraversalSource.class);
+social.persons().count();
+----
+
+NOTE: Using Maven, as shown in the `gremlin-archetype-dsl` module, makes developing DSLs with the annotation processor
+straightforward in that it sets up appropriate paths to the generated code automatically.
+
+Gremlin-Python
+~~~~~~~~~~~~~~


[4/7] tinkerpop git commit: TINKERPOP-786 Improved the TraversalSource definition in the archetype

Posted by sp...@apache.org.
TINKERPOP-786 Improved the TraversalSource definition in the archetype


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

Branch: refs/heads/TINKERPOP-786
Commit: b8f47fa91053355ea4915a5f5f107fc942cb6d81
Parents: 58f8c38
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue May 9 13:47:31 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 9 13:47:31 2017 -0400

----------------------------------------------------------------------
 .../src/main/java/SocialTraversalSourceDsl.java     | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b8f47fa9/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
index 3bd8297..d14b843 100644
--- a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
@@ -52,17 +52,15 @@ public class SocialTraversalSourceDsl extends GraphTraversalSource {
      */
     public GraphTraversal<Vertex, Vertex> persons(String... names) {
         GraphTraversalSource clone = this.clone();
-        clone.getBytecode().addStep(GraphTraversal.Symbols.V);
-        clone.getBytecode().addStep(GraphTraversal.Symbols.hasLabel, "person");
 
-        GraphTraversal.Admin<Vertex, Vertex> traversal = new DefaultGraphTraversal<>(clone);
-        traversal.addStep(new GraphStep<>(traversal, Vertex.class, true));
-        TraversalHelper.addHasContainer(traversal, new HasContainer(T.label.getAccessor(), P.eq("person")));
+        // Manually add a "start" step for the traversal in this case the equivalent of V(). GraphStep is marked
+        // as a "start" step by passing "true" in the constructor.
+        clone.getBytecode().addStep(GraphTraversal.Symbols.V);
+        GraphTraversal<Vertex, Vertex> traversal = new DefaultGraphTraversal<>(clone);
+        traversal.asAdmin().addStep(new GraphStep<>(traversal.asAdmin(), Vertex.class, true));
 
-        if (names.length > 0) {
-            clone.getBytecode().addStep(GraphTraversal.Symbols.has, P.within(names));
-            TraversalHelper.addHasContainer(traversal, new HasContainer("name", P.within(names)));
-        }
+        traversal = traversal.hasLabel("person");
+        if (names.length > 0) traversal = traversal.has("name", P.within(names));
 
         return traversal;
     }