tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [tinkerpop] branch master updated: Fixed SparqlStrategy so that it could be used with RemoteStrategy
Date Fri, 11 Jan 2019 18:06:46 GMT
This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git


The following commit(s) were added to refs/heads/master by this push:
     new 8f8b044  Fixed SparqlStrategy so that it could be used with RemoteStrategy
8f8b044 is described below

commit 8f8b0446cfd849e2aa3616e9acb6808e1dc815b4
Author: Stephen Mallette <spmva@genoprime.com>
AuthorDate: Fri Jan 11 13:05:24 2019 -0500

    Fixed SparqlStrategy so that it could be used with RemoteStrategy
    
    Remote traversals and the new traversal() construction method were not working with SparqTraversalSource.
Had to correct a few minor things. CTR
---
 CHANGELOG.asciidoc                                     |  2 ++
 .../traversal/dsl/sparql/SparqlTraversalSource.java    | 10 ++++++++--
 .../process/traversal/strategy/SparqlStrategy.java     | 18 +++++-------------
 3 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 854a81b..ce8be65 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -25,6 +25,8 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 
 This release also includes changes from <<release-3-3-6, 3.3.6>>.
 
+* Fixed up `SparqlStrategy` so that it could be used properly with `RemoteStrategy`.
+
 [[release-3-4-0]]
 === TinkerPop 3.4.0 (Release Date: January 2, 2019)
 
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
index c02442e..754a351 100644
--- a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
@@ -31,6 +31,7 @@ import org.apache.tinkerpop.gremlin.sparql.process.traversal.strategy.SparqlStra
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.Transaction;
 import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
 
 /**
  * A {@link TraversalSource} implementation that spawns {@link SparqlTraversal} instances.
@@ -52,6 +53,12 @@ public class SparqlTraversalSource implements TraversalSource {
         this(graph, TraversalStrategies.GlobalCache.getStrategies(graph.getClass()));
     }
 
+    public SparqlTraversalSource(final RemoteConnection connection) {
+        this(EmptyGraph.instance(), TraversalStrategies.GlobalCache.getStrategies(EmptyGraph.class).clone());
+        this.connection = connection;
+        this.strategies.addStrategies(new RemoteStrategy(connection));
+    }
+
     @Override
     public TraversalStrategies getStrategies() {
         return this.strategies;
@@ -122,8 +129,7 @@ public class SparqlTraversalSource implements TraversalSource {
      * The start step for a SPARQL based traversal that accepts a string representation of
the query to execute.
      */
     public <S> SparqlTraversal<S,?> sparql(final String query) {
-        final SparqlTraversalSource clone = this.clone();
-        clone.getStrategies().addStrategies(SparqlStrategy.instance());
+        final SparqlTraversalSource clone = this.withStrategies(SparqlStrategy.instance()).clone();
 
         // the inject() holds the sparql which the SparqlStrategy then detects and converts
to a traversal
         clone.bytecode.addStep(GraphTraversal.Symbols.inject, query);
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java
b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java
index 05cfd47..3a98fc0 100644
--- a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java
@@ -21,7 +21,6 @@ package org.apache.tinkerpop.gremlin.sparql.process.traversal.strategy;
 import org.apache.tinkerpop.gremlin.process.remote.traversal.strategy.decoration.RemoteStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
-import org.apache.tinkerpop.gremlin.process.traversal.step.map.ConstantStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.InjectStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep;
 import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
@@ -35,9 +34,9 @@ import java.util.Set;
 
 /**
  * This {@link TraversalStrategy} is used in conjunction with the {@link SparqlTraversalSource}
which has a single
- * {@code sparql()} start step. That step adds a {@link ConstantStep} to the traversal with
the SPARQL query within
+ * {@code sparql()} start step. That step adds a {@link InjectStep} to the traversal with
the SPARQL query within
  * it as a string value. This strategy finds that step and compiles it to a Gremlin traversal
which then replaces
- * the {@link ConstantStep}.
+ * the {@link InjectStep}.
  *
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
@@ -45,7 +44,7 @@ public class SparqlStrategy extends AbstractTraversalStrategy<TraversalStrategy.
         implements TraversalStrategy.DecorationStrategy {
     private static final SparqlStrategy INSTANCE = new SparqlStrategy();
 
-    private static final Set<Class<? extends DecorationStrategy>> POSTS = Collections.singleton(RemoteStrategy.class);
+    private static final Set<Class<? extends DecorationStrategy>> PRIORS = Collections.singleton(RemoteStrategy.class);
 
     private SparqlStrategy() {}
 
@@ -54,11 +53,10 @@ public class SparqlStrategy extends AbstractTraversalStrategy<TraversalStrategy.
     }
 
     @Override
-    public Set<Class<? extends DecorationStrategy>> applyPost() {
-        return POSTS;
+    public Set<Class<? extends DecorationStrategy>> applyPrior() {
+        return PRIORS;
     }
 
-
     @Override
     public void apply(final Traversal.Admin<?, ?> traversal) {
         if (!(traversal.getParent() instanceof EmptyStep))
@@ -73,13 +71,7 @@ public class SparqlStrategy extends AbstractTraversalStrategy<TraversalStrategy.
                         traversal.getGraph().get(), sparql);
                 TraversalHelper.removeAllSteps(traversal);
                 sparqlTraversal.asAdmin().getSteps().forEach(s -> traversal.addStep(s));
-            } else {
-                // The ConstantStep expects a string value
-                throw new IllegalStateException("SparqlStrategy cannot be applied to a traversal
that does not consist of a single InjectStep<String> with one injection");
             }
-        } else {
-            // SparqlStrategy requires that there be one step and it be a ConstantStep that
contains some SPARQL
-            throw new IllegalStateException("SparqlStrategy cannot be applied to a traversal
that does not consist of a single InjectStep<String> with one injection");
         }
     }
 }


Mime
View raw message