summaryrefslogtreecommitdiffstats
path: root/aai-core/src/main
diff options
context:
space:
mode:
authorThreefoot, Jane (jt6620) <jt6620@att.com>2017-08-31 16:49:41 -0400
committerThreefoot, Jane (jt6620) <jt6620@att.com>2017-09-01 11:41:05 -0400
commit752504bac2b1066f9c8a979b54fccc8281ef8aeb (patch)
tree53ce297682fcc08de9890baaa83d9b15252533f1 /aai-core/src/main
parentc5959920f7b8920dcde45150247ef529221c71a8 (diff)
Added until and simplePath to QueryBuilder
Issue-ID: AAI-253 Change-Id: I0ad83d37bb15260b72e8f1745dc40ecd8df98229 Signed-off-by: Threefoot, Jane (jt6620) <jt6620@att.com>
Diffstat (limited to 'aai-core/src/main')
-rw-r--r--aai-core/src/main/java/org/openecomp/aai/query/builder/GraphTraversalBuilder.java32
-rw-r--r--aai-core/src/main/java/org/openecomp/aai/query/builder/GremlinQueryBuilder.java18
-rw-r--r--aai-core/src/main/java/org/openecomp/aai/query/builder/QueryBuilder.java9
3 files changed, 52 insertions, 7 deletions
diff --git a/aai-core/src/main/java/org/openecomp/aai/query/builder/GraphTraversalBuilder.java b/aai-core/src/main/java/org/openecomp/aai/query/builder/GraphTraversalBuilder.java
index 73b57d06..72c2efb0 100644
--- a/aai-core/src/main/java/org/openecomp/aai/query/builder/GraphTraversalBuilder.java
+++ b/aai-core/src/main/java/org/openecomp/aai/query/builder/GraphTraversalBuilder.java
@@ -30,7 +30,6 @@ import java.util.Set;
import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal.Admin;
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
@@ -70,7 +69,7 @@ public abstract class GraphTraversalBuilder<E> extends QueryBuilder<E> {
public GraphTraversalBuilder(Loader loader, GraphTraversalSource source) {
super(loader, source);
- traversal = new DefaultGraphTraversal<>();
+ traversal = (GraphTraversal<Vertex, E>) __.<E>start();
}
@@ -83,7 +82,7 @@ public abstract class GraphTraversalBuilder<E> extends QueryBuilder<E> {
public GraphTraversalBuilder(Loader loader, GraphTraversalSource source, Vertex start) {
super(loader, source, start);
- traversal = new DefaultGraphTraversal<>();
+ traversal = (GraphTraversal<Vertex, E>) __.__(start);
}
@@ -404,6 +403,24 @@ public abstract class GraphTraversalBuilder<E> extends QueryBuilder<E> {
}
@Override
+ public QueryBuilder<E> until(QueryBuilder<E> builder) {
+ this.traversal.until((GraphTraversal<Vertex,E>)builder.getQuery());
+ stepIndex++;
+
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public QueryBuilder<E> simplePath(){
+ this.traversal.simplePath();
+ stepIndex++;
+ return this;
+ }
+
+ @Override
public QueryBuilder<Edge> outE() {
this.traversal.outE();
stepIndex++;
@@ -594,17 +611,18 @@ public abstract class GraphTraversalBuilder<E> extends QueryBuilder<E> {
private void executeQuery() {
- Admin<Vertex, Vertex> admin;
+ Admin admin;
if (start != null) {
- admin = source.V(start).asAdmin();
+ this.completeTraversal = traversal.asAdmin();
} else {
admin = source.V().asAdmin();
+ TraversalHelper.insertTraversal(admin.getEndStep(), traversal.asAdmin(), admin);
+
+ this.completeTraversal = (Admin<Vertex, E>) admin;
}
- TraversalHelper.insertTraversal(admin.getEndStep(), traversal.asAdmin(), admin);
- this.completeTraversal = (Admin<Vertex, E>) admin;
}
@Override
diff --git a/aai-core/src/main/java/org/openecomp/aai/query/builder/GremlinQueryBuilder.java b/aai-core/src/main/java/org/openecomp/aai/query/builder/GremlinQueryBuilder.java
index f93bc484..b151d9d8 100644
--- a/aai-core/src/main/java/org/openecomp/aai/query/builder/GremlinQueryBuilder.java
+++ b/aai-core/src/main/java/org/openecomp/aai/query/builder/GremlinQueryBuilder.java
@@ -394,6 +394,24 @@ public abstract class GremlinQueryBuilder<E> extends QueryBuilder<E> {
}
@Override
+ public QueryBuilder<E> until(QueryBuilder<E> builder) {
+ this.list.add(".until(__" + builder.getQuery() + ")");
+ stepIndex++;
+
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public QueryBuilder<E> simplePath(){
+ this.list.add(".simplePath()");
+ stepIndex++;
+ return this;
+ }
+
+ @Override
public QueryBuilder<Edge> outE() {
this.list.add(".outE()");
stepIndex++;
diff --git a/aai-core/src/main/java/org/openecomp/aai/query/builder/QueryBuilder.java b/aai-core/src/main/java/org/openecomp/aai/query/builder/QueryBuilder.java
index 009f4fdf..717033fa 100644
--- a/aai-core/src/main/java/org/openecomp/aai/query/builder/QueryBuilder.java
+++ b/aai-core/src/main/java/org/openecomp/aai/query/builder/QueryBuilder.java
@@ -298,6 +298,15 @@ public abstract class QueryBuilder<E> implements Iterator<E> {
public abstract QueryBuilder<E> not(QueryBuilder<E> builder);
public abstract QueryBuilder<E> as(String name);
public abstract QueryBuilder<E> select(String name);
+ public abstract QueryBuilder<E> until(QueryBuilder<E> builder);
+
+ /**
+ * Used to prevent the traversal from repeating its path through the graph.
+ * See http://tinkerpop.apache.org/docs/3.0.1-incubating/#simplepath-step for more info.
+ *
+ * @return a QueryBuilder with the simplePath step appended to its traversal
+ */
+ public abstract QueryBuilder<E> simplePath();
public abstract void markContainer();