Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

GraphQuery work.

  • Loading branch information...
commit 5cee0a6e37584b207b58451b99e4ae138ce78f2c 2 parents 74e1cfa + 961739b
@okram okram authored
Showing with 880 additions and 346 deletions.
  1. +1 −0  CHANGELOG.textile
  2. +7 −0 blueprints-core/src/main/java/com/tinkerpop/blueprints/Graph.java
  3. +21 −0 blueprints-core/src/main/java/com/tinkerpop/blueprints/GraphQuery.java
  4. +7 −36 blueprints-core/src/main/java/com/tinkerpop/blueprints/Query.java
  5. +1 −1  blueprints-core/src/main/java/com/tinkerpop/blueprints/Vertex.java
  6. +56 −0 blueprints-core/src/main/java/com/tinkerpop/blueprints/VertexQuery.java
  7. +6 −0 blueprints-core/src/main/java/com/tinkerpop/blueprints/impls/tg/TinkerGraph.java
  8. +4 −4 blueprints-core/src/main/java/com/tinkerpop/blueprints/impls/tg/TinkerVertex.java
  9. +150 −0 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/DefaultGraphQuery.java
  10. +2 −149 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/DefaultQuery.java
  11. +162 −0 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/DefaultVertexQuery.java
  12. +10 −3 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/PropertyFilteredIterable.java
  13. +41 −0 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/WrappedGraphQuery.java
  14. +10 −10 ...ore/src/main/java/com/tinkerpop/blueprints/util/wrappers/{WrapperQuery.java → WrapperVertexQuery.java}
  15. +9 −6 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/batch/BatchGraph.java
  16. +6 −0 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/batch/WritethroughGraph.java
  17. +17 −0 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/event/EventGraph.java
  18. +4 −7 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/event/EventVertex.java
  19. +17 −0 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/id/IdGraph.java
  20. +4 −4 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/id/IdVertex.java
  21. +17 −0 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/partition/PartitionGraph.java
  22. +4 −4 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/partition/PartitionVertex.java
  23. +16 −0 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/readonly/ReadOnlyGraph.java
  24. +4 −4 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/readonly/ReadOnlyVertex.java
  25. +16 −0 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/wrapped/WrappedGraph.java
  26. +4 −4 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/wrapped/WrappedVertex.java
  27. +7 −5 blueprints-dex-graph/src/main/java/com/tinkerpop/blueprints/impls/dex/DexGraph.java
  28. +4 −4 blueprints-dex-graph/src/main/java/com/tinkerpop/blueprints/impls/dex/DexVertex.java
  29. +3 −3 blueprints-neo4j-graph/pom.xml
  30. +6 −0 blueprints-neo4j-graph/src/main/java/com/tinkerpop/blueprints/impls/neo4j/Neo4jGraph.java
  31. +4 −4 blueprints-neo4j-graph/src/main/java/com/tinkerpop/blueprints/impls/neo4j/Neo4jVertex.java
  32. +1 −1  blueprints-neo4jbatch-graph/pom.xml
  33. +6 −0 blueprints-neo4jbatch-graph/src/main/java/com/tinkerpop/blueprints/impls/neo4jbatch/Neo4jBatchGraph.java
  34. +2 −2 blueprints-neo4jbatch-graph/src/main/java/com/tinkerpop/blueprints/impls/neo4jbatch/Neo4jBatchVertex.java
  35. +6 −0 blueprints-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientBaseGraph.java
  36. +4 −4 blueprints-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientVertex.java
  37. +6 −0 blueprints-rexster-graph/src/main/java/com/tinkerpop/blueprints/impls/rexster/RexsterGraph.java
  38. +3 −3 blueprints-rexster-graph/src/main/java/com/tinkerpop/blueprints/impls/rexster/RexsterVertex.java
  39. +9 −9 ...aph/src/main/java/com/tinkerpop/blueprints/impls/rexster/{RexsterQuery.java → RexsterVertexQuery.java}
  40. +6 −0 blueprints-sail-graph/src/main/java/com/tinkerpop/blueprints/impls/sail/SailGraph.java
  41. +4 −4 blueprints-sail-graph/src/main/java/com/tinkerpop/blueprints/impls/sail/SailVertex.java
  42. +128 −18 blueprints-test/src/main/java/com/tinkerpop/blueprints/QueryTestSuite.java
  43. +6 −0 blueprints-test/src/test/java/com/tinkerpop/blueprints/impls/tg/MockTransactionalGraph.java
  44. +7 −0 blueprints-test/src/test/java/com/tinkerpop/blueprints/impls/tg/TinkerGraphTest.java
  45. +72 −57 blueprints-test/src/test/java/com/tinkerpop/blueprints/util/wrappers/batch/BatchGraphTest.java
View
1  CHANGELOG.textile
@@ -17,6 +17,7 @@ h3. Version 2.3.0 (NOT OFFICIALLY RELEASED YET)
```
* Bumped major versions of Ripple and SesameTools
+* Added @GraphQuery@ in order to support intelligent indexing systems (@Vertex.query()@ and @Graph.query()@)
* Refactoring of wrappers to ensure proper propagation of @Graph@ reference
* Fixed a @ConcurrentModificationException@ in TinkerGraph
* @Element@ API changed to support @Element.remove()@
View
7 blueprints-core/src/main/java/com/tinkerpop/blueprints/Graph.java
@@ -110,6 +110,13 @@
public Iterable<Edge> getEdges(String key, Object value);
/**
+ * Generate a query object that can be used to fine tune which edges/vertices are retrieved from the graph.
+ *
+ * @return a graph query object with methods for constraining which data is pulled from the underlying graph
+ */
+ public GraphQuery query();
+
+ /**
* A shutdown function is required to properly close the graph.
* This is important for implementations that utilize disk-based serializations.
*/
View
21 blueprints-core/src/main/java/com/tinkerpop/blueprints/GraphQuery.java
@@ -0,0 +1,21 @@
+package com.tinkerpop.blueprints;
+
+/**
+ * (c) Matthias Broecheler (me@matthiasb.com)
+ */
+
+public interface GraphQuery extends Query {
+
+ @Override
+ public GraphQuery has(final String key, final Object value);
+
+ @Override
+ public <T extends Comparable<T>> GraphQuery has(final String key, final T value, final Compare compare);
+
+ @Override
+ public <T extends Comparable<T>> GraphQuery interval(final String key, final T startValue, final T endValue);
+
+ @Override
+ public GraphQuery limit(final long max);
+
+}
View
43 blueprints-core/src/main/java/com/tinkerpop/blueprints/Query.java
@@ -1,11 +1,9 @@
package com.tinkerpop.blueprints;
/**
- * A Query object defines a collection of filters and modifiers that are used to intelligently select edges from a vertex.
- *
- * @author Matthias Brocheler (http://matthiasb.com)
- * @author Marko A. Rodriguez (http://markorodriguez.com)
+ * (c) Matthias Broecheler (me@matthiasb.com)
*/
+
public interface Query {
public enum Compare {
@@ -57,29 +55,6 @@ else if (this.equals(LESS_THAN))
*/
public <T extends Comparable<T>> Query interval(final String key, final T startValue, final T endValue);
- /**
- * The direction of the edges to retrieve.
- *
- * @param direction whether to retrieve the incoming, outgoing, or both directions
- * @return the modified query object
- */
- public Query direction(final Direction direction);
-
- /**
- * Filter out the edge if its label is not in set of provided labels.
- *
- * @param labels the labels to check against
- * @return the modified query object
- */
- public Query labels(final String... labels);
-
- /**
- * Filter out the edge if the max number of edges to retrieve has already been reached.
- *
- * @param max the max number of edges to return
- * @return the modified query object
- */
- public Query limit(final long max);
/**
* Execute the query and return the matching edges.
@@ -95,18 +70,14 @@ else if (this.equals(LESS_THAN))
*/
public Iterable<Vertex> vertices();
- /**
- * Execute the query and return the number of edges that are unfiltered.
- *
- * @return the number of unfiltered edges
- */
- public long count();
/**
- * Return the raw ids of the vertices on the other end of the edges.
+ * Filter out the edge if the max number of edges to retrieve has already been reached.
*
- * @return the raw ids of the vertices on the other end of the edges
+ * @param max the max number of edges to return
+ * @return the modified query object
*/
- public Object vertexIds();
+ public Query limit(final long max);
+
}
View
2  blueprints-core/src/main/java/com/tinkerpop/blueprints/Vertex.java
@@ -35,7 +35,7 @@
*
* @return a vertex query object with methods for constraining which data is pulled from the underlying graph
*/
- public Query query();
+ public VertexQuery query();
/**
* Add a new outgoing edge from this vertex to the parameter vertex with provided edge label.
View
56 blueprints-core/src/main/java/com/tinkerpop/blueprints/VertexQuery.java
@@ -0,0 +1,56 @@
+package com.tinkerpop.blueprints;
+
+/**
+ * A VertexQuery object defines a collection of filters and modifiers that are used to intelligently select edges from a vertex.
+ *
+ * @author Matthias Brocheler (http://matthiasb.com)
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public interface VertexQuery extends Query {
+
+
+ /**
+ * The direction of the edges to retrieve.
+ *
+ * @param direction whether to retrieve the incoming, outgoing, or both directions
+ * @return the modified query object
+ */
+ public VertexQuery direction(final Direction direction);
+
+ /**
+ * Filter out the edge if its label is not in set of provided labels.
+ *
+ * @param labels the labels to check against
+ * @return the modified query object
+ */
+ public VertexQuery labels(final String... labels);
+
+ /**
+ * Execute the query and return the number of edges that are unfiltered.
+ *
+ * @return the number of unfiltered edges
+ */
+ public long count();
+
+ /**
+ * Return the raw ids of the vertices on the other end of the edges.
+ *
+ * @return the raw ids of the vertices on the other end of the edges
+ */
+ public Object vertexIds();
+
+
+ @Override
+ public VertexQuery has(final String key, final Object value);
+
+ @Override
+ public <T extends Comparable<T>> VertexQuery has(final String key, final T value, final Compare compare);
+
+ @Override
+ public <T extends Comparable<T>> VertexQuery interval(final String key, final T startValue, final T endValue);
+
+ @Override
+ public VertexQuery limit(final long max);
+
+
+}
View
6 blueprints-core/src/main/java/com/tinkerpop/blueprints/impls/tg/TinkerGraph.java
@@ -5,11 +5,13 @@
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.Features;
+import com.tinkerpop.blueprints.GraphQuery;
import com.tinkerpop.blueprints.Index;
import com.tinkerpop.blueprints.IndexableGraph;
import com.tinkerpop.blueprints.KeyIndexableGraph;
import com.tinkerpop.blueprints.Parameter;
import com.tinkerpop.blueprints.Vertex;
+import com.tinkerpop.blueprints.util.DefaultGraphQuery;
import com.tinkerpop.blueprints.util.ExceptionFactory;
import com.tinkerpop.blueprints.util.KeyIndexableGraphHelper;
import com.tinkerpop.blueprints.util.PropertyFilteredIterable;
@@ -316,6 +318,10 @@ public void removeEdge(final Edge edge) {
this.edges.remove(edge.getId().toString());
}
+ public GraphQuery query() {
+ return new DefaultGraphQuery(this);
+ }
+
public String toString() {
if (null == this.directory)
View
8 blueprints-core/src/main/java/com/tinkerpop/blueprints/impls/tg/TinkerVertex.java
@@ -2,9 +2,9 @@
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
-import com.tinkerpop.blueprints.Query;
+import com.tinkerpop.blueprints.VertexQuery;
import com.tinkerpop.blueprints.Vertex;
-import com.tinkerpop.blueprints.util.DefaultQuery;
+import com.tinkerpop.blueprints.util.DefaultVertexQuery;
import com.tinkerpop.blueprints.util.MultiIterable;
import com.tinkerpop.blueprints.util.StringFactory;
import com.tinkerpop.blueprints.util.VerticesFromEdgesIterable;
@@ -98,8 +98,8 @@ protected TinkerVertex(final String id, final TinkerGraph graph) {
}
}
- public Query query() {
- return new DefaultQuery(this);
+ public VertexQuery query() {
+ return new DefaultVertexQuery(this);
}
public String toString() {
View
150 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/DefaultGraphQuery.java
@@ -0,0 +1,150 @@
+package com.tinkerpop.blueprints.util;
+
+import com.tinkerpop.blueprints.Edge;
+import com.tinkerpop.blueprints.Element;
+import com.tinkerpop.blueprints.Graph;
+import com.tinkerpop.blueprints.GraphQuery;
+import com.tinkerpop.blueprints.Vertex;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+/**
+ * For those graph engines that do not support the low-level querying of the vertices or edges, then DefaultQuery can be used.
+ * DefaultQuery assumes, at minimum, that Graph.getVertices() and Graph.getEdges() is implemented by the respective Graph.
+ *
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class DefaultGraphQuery extends DefaultQuery implements GraphQuery {
+
+ private final Graph graph;
+
+ public DefaultGraphQuery(final Graph graph) {
+ this.graph = graph;
+ }
+
+ public GraphQuery has(final String key, final Object value) {
+ this.hasContainers.add(new HasContainer(key, value, Compare.EQUAL));
+ return this;
+ }
+
+ public <T extends Comparable<T>> GraphQuery has(final String key, final T value, final Compare compare) {
+ this.hasContainers.add(new HasContainer(key, value, compare));
+ return this;
+ }
+
+ public <T extends Comparable<T>> GraphQuery interval(final String key, final T startValue, final T endValue) {
+ this.hasContainers.add(new HasContainer(key, startValue, Compare.GREATER_THAN_EQUAL));
+ this.hasContainers.add(new HasContainer(key, endValue, Compare.LESS_THAN));
+ return this;
+ }
+
+ public GraphQuery limit(final long max) {
+ this.limit = max;
+ return this;
+ }
+
+ public Iterable<Edge> edges() {
+ return new DefaultGraphQueryIterable<Edge>(false);
+ }
+
+ public Iterable<Vertex> vertices() {
+ return new DefaultGraphQueryIterable<Vertex>(true);
+ }
+
+ private class DefaultGraphQueryIterable<T extends Element> implements Iterable<T> {
+
+ private Iterable<T> iterable = null;
+
+ public DefaultGraphQueryIterable(final boolean forVertex) {
+ for (final HasContainer hasContainer : hasContainers) {
+ if (hasContainer.compare.equals(Compare.EQUAL)) {
+ if (forVertex)
+ this.iterable = (Iterable<T>) graph.getVertices(hasContainer.key, hasContainer.value);
+ else
+ this.iterable = (Iterable<T>) graph.getEdges(hasContainer.key, hasContainer.value);
+ break;
+ }
+ }
+ if (null == this.iterable) {
+ if (forVertex)
+ this.iterable = (Iterable<T>) graph.getVertices();
+ else
+ this.iterable = (Iterable<T>) graph.getEdges();
+ }
+ }
+
+ public Iterator<T> iterator() {
+ return new Iterator<T>() {
+ T nextElement = null;
+ final Iterator<T> itty = iterable.iterator();
+ long count = 0;
+
+ public boolean hasNext() {
+ if (null != this.nextElement) {
+ return true;
+ } else {
+ return this.loadNext();
+ }
+ }
+
+ public T next() {
+ while (true) {
+ if (this.nextElement != null) {
+ final T temp = this.nextElement;
+ this.nextElement = null;
+ return temp;
+ }
+
+ if (!this.loadNext())
+ throw new NoSuchElementException();
+ }
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ private boolean loadNext() {
+ this.nextElement = null;
+ if (count >= limit) return false;
+ while (this.itty.hasNext()) {
+ final T element = this.itty.next();
+ boolean filter = false;
+
+ /*if (!forVertex) {
+ filter = !containsLabel(((Edge) element).getLabel(), labels);
+ }*/
+
+ //if (!filter) {
+ for (final HasContainer hasContainer : hasContainers) {
+ if (!hasContainer.isLegal(element)) {
+ filter = true;
+ break;
+ }
+ }
+ //}
+ if (!filter) {
+ this.nextElement = element;
+ this.count++;
+ return true;
+ }
+ }
+ return false;
+ }
+ };
+ }
+
+ /*private boolean containsLabel(final String label, final String[] labels) {
+ if (labels.length == 0)
+ return true;
+
+ for (final String temp : labels) {
+ if (temp.equals(label))
+ return true;
+ }
+ return false;
+ }*/
+ }
+
+}
View
151 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/DefaultQuery.java
@@ -1,92 +1,25 @@
package com.tinkerpop.blueprints.util;
import com.tinkerpop.blueprints.Direction;
-import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.Query;
-import com.tinkerpop.blueprints.Vertex;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
-import java.util.NoSuchElementException;
/**
- * For those graph engines that do not support the low-level querying of the edges of a vertex, then DefaultQuery can be used.
- * DefaultQuery assumes, at minimum, that Vertex.getOutEdges() and Vertex.getInEdges() is implemented by the respective Graph.
- *
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public class DefaultQuery implements Query {
+public abstract class DefaultQuery implements Query {
private static final String[] EMPTY_LABELS = new String[]{};
- private final Vertex vertex;
public Direction direction = Direction.BOTH;
public String[] labels = EMPTY_LABELS;
public long limit = Long.MAX_VALUE;
public List<HasContainer> hasContainers = new ArrayList<HasContainer>();
- public DefaultQuery(final Vertex vertex) {
- this.vertex = vertex;
- }
-
- public Query has(final String key, final Object value) {
- this.hasContainers.add(new HasContainer(key, value, Compare.EQUAL));
- return this;
- }
-
- public <T extends Comparable<T>> Query has(final String key, final T value, final Compare compare) {
- this.hasContainers.add(new HasContainer(key, value, compare));
- return this;
- }
-
- public <T extends Comparable<T>> Query interval(final String key, final T startValue, final T endValue) {
- this.hasContainers.add(new HasContainer(key, startValue, Compare.GREATER_THAN_EQUAL));
- this.hasContainers.add(new HasContainer(key, endValue, Compare.LESS_THAN));
- return this;
- }
-
- public Query direction(final Direction direction) {
- this.direction = direction;
- return this;
- }
-
- public Query labels(final String... labels) {
- this.labels = labels;
- return this;
- }
-
- public Query limit(final long max) {
- this.limit = max;
- return this;
- }
-
- public Iterable<Edge> edges() {
- return new DefaultQueryIterable<Edge>(false);
- }
-
- public Iterable<Vertex> vertices() {
- return new DefaultQueryIterable<Vertex>(true);
- }
-
- public long count() {
- long count = 0;
- for (final Edge edge : this.edges()) {
- count++;
- }
- return count;
- }
-
- public Object vertexIds() {
- final List<Object> list = new ArrayList<Object>();
- for (final Vertex vertex : this.vertices()) {
- list.add(vertex.getId());
- }
- return list;
- }
-
- private class HasContainer {
+ protected class HasContainer {
public String key;
public Object value;
public Compare compare;
@@ -129,84 +62,4 @@ public boolean isLegal(final Element element) {
}
}
}
-
- private class DefaultQueryIterable<T extends Element> implements Iterable<T> {
-
- private Iterable<Edge> iterable;
- private boolean forVertex;
-
- public DefaultQueryIterable(final boolean forVertex) {
- this.forVertex = forVertex;
- this.iterable = vertex.getEdges(direction, labels);
- }
-
- public Iterator<T> iterator() {
- return new Iterator<T>() {
- Edge nextEdge = null;
- final Iterator<Edge> itty = iterable.iterator();
- long count = 0;
-
- public boolean hasNext() {
- if (null != this.nextEdge) {
- return true;
- } else {
- return this.loadNext();
- }
- }
-
- public T next() {
- while (true) {
- if (this.nextEdge != null) {
- final Edge temp = this.nextEdge;
- this.nextEdge = null;
- if (forVertex) {
- if (direction == Direction.OUT)
- return (T) temp.getVertex(Direction.IN);
- else if (direction == Direction.IN)
- return (T) temp.getVertex(Direction.OUT);
- else {
- if (temp.getVertex(Direction.OUT).equals(vertex)) {
- return (T) temp.getVertex(Direction.IN);
- } else {
- return (T) temp.getVertex(Direction.OUT);
- }
- }
-
- } else {
- return (T) temp;
- }
- }
-
- if (!this.loadNext())
- throw new NoSuchElementException();
- }
- }
-
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- private boolean loadNext() {
- this.nextEdge = null;
- if (count >= limit) return false;
- while (this.itty.hasNext()) {
- final Edge edge = this.itty.next();
- boolean filter = false;
- for (final HasContainer hasContainer : hasContainers) {
- if (!hasContainer.isLegal(edge)) {
- filter = true;
- break;
- }
- }
- if (!filter) {
- this.nextEdge = edge;
- this.count++;
- return true;
- }
- }
- return false;
- }
- };
- }
- }
}
View
162 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/DefaultVertexQuery.java
@@ -0,0 +1,162 @@
+package com.tinkerpop.blueprints.util;
+
+import com.tinkerpop.blueprints.Direction;
+import com.tinkerpop.blueprints.Edge;
+import com.tinkerpop.blueprints.Element;
+import com.tinkerpop.blueprints.VertexQuery;
+import com.tinkerpop.blueprints.Vertex;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+
+/**
+ * For those graph engines that do not support the low-level querying of the edges of a vertex, then DefaultQuery can be used.
+ * DefaultQuery assumes, at minimum, that Vertex.getOutEdges() and Vertex.getInEdges() is implemented by the respective Graph.
+ *
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class DefaultVertexQuery extends DefaultQuery implements VertexQuery {
+
+ private final Vertex vertex;
+
+ public DefaultVertexQuery(final Vertex vertex) {
+ this.vertex = vertex;
+ }
+
+ public VertexQuery has(final String key, final Object value) {
+ this.hasContainers.add(new HasContainer(key, value, Compare.EQUAL));
+ return this;
+ }
+
+ public <T extends Comparable<T>> VertexQuery has(final String key, final T value, final Compare compare) {
+ this.hasContainers.add(new HasContainer(key, value, compare));
+ return this;
+ }
+
+ public <T extends Comparable<T>> VertexQuery interval(final String key, final T startValue, final T endValue) {
+ this.hasContainers.add(new HasContainer(key, startValue, Compare.GREATER_THAN_EQUAL));
+ this.hasContainers.add(new HasContainer(key, endValue, Compare.LESS_THAN));
+ return this;
+ }
+
+ public VertexQuery direction(final Direction direction) {
+ this.direction = direction;
+ return this;
+ }
+
+ public VertexQuery labels(final String... labels) {
+ this.labels = labels;
+ return this;
+ }
+
+ public VertexQuery limit(final long max) {
+ this.limit = max;
+ return this;
+ }
+
+ public Iterable<Edge> edges() {
+ return new DefaultVertexQueryIterable<Edge>(false);
+ }
+
+ public Iterable<Vertex> vertices() {
+ return new DefaultVertexQueryIterable<Vertex>(true);
+ }
+
+ public long count() {
+ long count = 0;
+ for (final Edge edge : this.edges()) {
+ count++;
+ }
+ return count;
+ }
+
+ public Object vertexIds() {
+ final List<Object> list = new ArrayList<Object>();
+ for (final Vertex vertex : this.vertices()) {
+ list.add(vertex.getId());
+ }
+ return list;
+ }
+
+ private class DefaultVertexQueryIterable<T extends Element> implements Iterable<T> {
+
+ private Iterable<Edge> iterable;
+ private boolean forVertex;
+
+ public DefaultVertexQueryIterable(final boolean forVertex) {
+ this.forVertex = forVertex;
+ this.iterable = vertex.getEdges(direction, labels);
+ }
+
+ public Iterator<T> iterator() {
+ return new Iterator<T>() {
+ Edge nextEdge = null;
+ final Iterator<Edge> itty = iterable.iterator();
+ long count = 0;
+
+ public boolean hasNext() {
+ if (null != this.nextEdge) {
+ return true;
+ } else {
+ return this.loadNext();
+ }
+ }
+
+ public T next() {
+ while (true) {
+ if (this.nextEdge != null) {
+ final Edge temp = this.nextEdge;
+ this.nextEdge = null;
+ if (forVertex) {
+ if (direction == Direction.OUT)
+ return (T) temp.getVertex(Direction.IN);
+ else if (direction == Direction.IN)
+ return (T) temp.getVertex(Direction.OUT);
+ else {
+ if (temp.getVertex(Direction.OUT).equals(vertex)) {
+ return (T) temp.getVertex(Direction.IN);
+ } else {
+ return (T) temp.getVertex(Direction.OUT);
+ }
+ }
+
+ } else {
+ return (T) temp;
+ }
+ }
+
+ if (!this.loadNext())
+ throw new NoSuchElementException();
+ }
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ private boolean loadNext() {
+ this.nextEdge = null;
+ if (count >= limit) return false;
+ while (this.itty.hasNext()) {
+ final Edge edge = this.itty.next();
+ boolean filter = false;
+ for (final HasContainer hasContainer : hasContainers) {
+ if (!hasContainer.isLegal(edge)) {
+ filter = true;
+ break;
+ }
+ }
+ if (!filter) {
+ this.nextEdge = edge;
+ this.count++;
+ return true;
+ }
+ }
+ return false;
+ }
+ };
+ }
+ }
+}
View
13 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/PropertyFilteredIterable.java
@@ -47,9 +47,16 @@ public boolean hasNext() {
while (true) {
final T element = this.itty.next();
final Object temp = element.getProperty(key);
- if (null != temp && temp.equals(value)) {
- this.nextElement = element;
- return true;
+ if (null != temp) {
+ if (temp.equals(value)) {
+ this.nextElement = element;
+ return true;
+ }
+ } else {
+ if (value == null) {
+ this.nextElement = element;
+ return true;
+ }
}
}
} catch (NoSuchElementException e) {
View
41 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/WrappedGraphQuery.java
@@ -0,0 +1,41 @@
+package com.tinkerpop.blueprints.util.wrappers;
+
+import com.tinkerpop.blueprints.Edge;
+import com.tinkerpop.blueprints.GraphQuery;
+import com.tinkerpop.blueprints.Vertex;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public abstract class WrappedGraphQuery implements GraphQuery {
+
+ protected GraphQuery query;
+
+ public WrappedGraphQuery(final GraphQuery query) {
+ this.query = query;
+ }
+
+ public GraphQuery has(final String key, final Object value) {
+ this.query = this.query.has(key, value);
+ return this;
+ }
+
+ public <T extends Comparable<T>> GraphQuery has(final String key, final T value, final Compare compare) {
+ this.query = this.query.has(key, value, compare);
+ return this;
+ }
+
+ public <T extends Comparable<T>> GraphQuery interval(final String key, final T startValue, final T endValue) {
+ this.query = this.query.interval(key, startValue, endValue);
+ return this;
+ }
+
+ public GraphQuery limit(final long max) {
+ this.query = this.query.limit(max);
+ return this;
+ }
+
+ public abstract Iterable<Edge> edges();
+
+ public abstract Iterable<Vertex> vertices();
+}
View
20 ...lueprints/util/wrappers/WrapperQuery.java → ...nts/util/wrappers/WrapperVertexQuery.java
@@ -2,7 +2,7 @@
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
-import com.tinkerpop.blueprints.Query;
+import com.tinkerpop.blueprints.VertexQuery;
import com.tinkerpop.blueprints.Vertex;
/**
@@ -11,40 +11,40 @@
*
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public abstract class WrapperQuery implements Query {
+public abstract class WrapperVertexQuery implements VertexQuery {
- protected Query query;
+ protected VertexQuery query;
- public WrapperQuery(final Query query) {
+ public WrapperVertexQuery(final VertexQuery query) {
this.query = query;
}
- public Query has(final String key, final Object value) {
+ public VertexQuery has(final String key, final Object value) {
this.query = this.query.has(key, value);
return this;
}
- public <T extends Comparable<T>> Query has(final String key, final T value, final Compare compare) {
+ public <T extends Comparable<T>> VertexQuery has(final String key, final T value, final Compare compare) {
this.query = this.query.has(key, value, compare);
return this;
}
- public <T extends Comparable<T>> Query interval(final String key, final T startValue, final T endValue) {
+ public <T extends Comparable<T>> VertexQuery interval(final String key, final T startValue, final T endValue) {
this.query = this.query.interval(key, startValue, endValue);
return this;
}
- public Query direction(final Direction direction) {
+ public VertexQuery direction(final Direction direction) {
this.query = this.query.direction(direction);
return this;
}
- public Query limit(final long limit) {
+ public VertexQuery limit(final long limit) {
this.query = this.query.limit(limit);
return this;
}
- public Query labels(final String... labels) {
+ public VertexQuery labels(final String... labels) {
this.query = this.query.labels(labels);
return this;
}
View
15 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/batch/BatchGraph.java
@@ -4,16 +4,14 @@
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Features;
import com.tinkerpop.blueprints.Graph;
-import com.tinkerpop.blueprints.Query;
+import com.tinkerpop.blueprints.GraphQuery;
+import com.tinkerpop.blueprints.VertexQuery;
import com.tinkerpop.blueprints.TransactionalGraph;
import com.tinkerpop.blueprints.Vertex;
+import com.tinkerpop.blueprints.util.DefaultGraphQuery;
import com.tinkerpop.blueprints.util.ExceptionFactory;
import com.tinkerpop.blueprints.util.StringFactory;
import com.tinkerpop.blueprints.util.wrappers.WrapperGraph;
-import com.tinkerpop.blueprints.util.wrappers.batch.cache.LongIDVertexCache;
-import com.tinkerpop.blueprints.util.wrappers.batch.cache.ObjectIDVertexCache;
-import com.tinkerpop.blueprints.util.wrappers.batch.cache.StringIDVertexCache;
-import com.tinkerpop.blueprints.util.wrappers.batch.cache.URLCompression;
import com.tinkerpop.blueprints.util.wrappers.batch.cache.VertexCache;
import com.tinkerpop.blueprints.util.wrappers.id.IdGraph;
@@ -413,6 +411,11 @@ public void removeEdge(Edge edge) {
throw retrievalNotSupported();
}
+ @Override
+ public GraphQuery query() {
+ throw retrievalNotSupported();
+ }
+
private class BatchVertex implements Vertex {
private final Object externalID;
@@ -433,7 +436,7 @@ public void removeEdge(Edge edge) {
}
@Override
- public Query query() {
+ public VertexQuery query() {
throw retrievalNotSupported();
}
View
6 ...ts-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/batch/WritethroughGraph.java
@@ -3,6 +3,7 @@
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Features;
import com.tinkerpop.blueprints.Graph;
+import com.tinkerpop.blueprints.GraphQuery;
import com.tinkerpop.blueprints.TransactionalGraph;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.util.StringFactory;
@@ -111,6 +112,11 @@ public void removeEdge(final Edge edge) {
}
@Override
+ public GraphQuery query() {
+ return graph.query();
+ }
+
+ @Override
public Iterable<Edge> getEdges(final String key, final Object value) {
return graph.getEdges(key, value);
}
View
17 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/event/EventGraph.java
@@ -3,8 +3,10 @@
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Features;
import com.tinkerpop.blueprints.Graph;
+import com.tinkerpop.blueprints.GraphQuery;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.util.StringFactory;
+import com.tinkerpop.blueprints.util.wrappers.WrappedGraphQuery;
import com.tinkerpop.blueprints.util.wrappers.WrapperGraph;
import com.tinkerpop.blueprints.util.wrappers.event.listener.EdgeAddedEvent;
import com.tinkerpop.blueprints.util.wrappers.event.listener.EdgeRemovedEvent;
@@ -180,6 +182,21 @@ public void removeEdge(final Edge edge) {
return new EventEdgeIterable(this.baseGraph.getEdges(key, value), this);
}
+ public GraphQuery query() {
+ final EventGraph eventGraph = this;
+ return new WrappedGraphQuery(this.baseGraph.query()) {
+ @Override
+ public Iterable<Edge> edges() {
+ return new EventEdgeIterable(this.query.edges(), eventGraph);
+ }
+
+ @Override
+ public Iterable<Vertex> vertices() {
+ return new EventVertexIterable(this.query.vertices(), eventGraph);
+ }
+ };
+ }
+
public void shutdown() {
try {
this.baseGraph.shutdown();
View
11 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/event/EventVertex.java
@@ -2,12 +2,9 @@
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
-import com.tinkerpop.blueprints.Query;
+import com.tinkerpop.blueprints.VertexQuery;
import com.tinkerpop.blueprints.Vertex;
-import com.tinkerpop.blueprints.util.wrappers.WrapperQuery;
-import com.tinkerpop.blueprints.util.wrappers.event.listener.GraphChangedListener;
-
-import java.util.List;
+import com.tinkerpop.blueprints.util.wrappers.WrapperVertexQuery;
/**
* An vertex with a GraphChangedListener attached. Those listeners are notified when changes occur to
@@ -28,8 +25,8 @@ protected EventVertex(final Vertex rawVertex, final EventGraph eventGraph) {
return new EventVertexIterable(((Vertex) this.baseElement).getVertices(direction, labels), this.eventGraph);
}
- public Query query() {
- return new WrapperQuery(((Vertex) this.baseElement).query()) {
+ public VertexQuery query() {
+ return new WrapperVertexQuery(((Vertex) this.baseElement).query()) {
@Override
public Iterable<Vertex> vertices() {
return new EventVertexIterable(this.query.vertices(), eventGraph);
View
17 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/id/IdGraph.java
@@ -3,6 +3,7 @@
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.Features;
+import com.tinkerpop.blueprints.GraphQuery;
import com.tinkerpop.blueprints.Index;
import com.tinkerpop.blueprints.IndexableGraph;
import com.tinkerpop.blueprints.KeyIndexableGraph;
@@ -10,6 +11,7 @@
import com.tinkerpop.blueprints.TransactionalGraph;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.util.StringFactory;
+import com.tinkerpop.blueprints.util.wrappers.WrappedGraphQuery;
import com.tinkerpop.blueprints.util.wrappers.WrapperGraph;
import java.util.HashSet;
@@ -328,6 +330,21 @@ private boolean isVertexClass(final Class c) {
return Vertex.class.isAssignableFrom(c);
}
+ public GraphQuery query() {
+ final IdGraph idGraph = this;
+ return new WrappedGraphQuery(this.baseGraph.query()) {
+ @Override
+ public Iterable<Edge> edges() {
+ return new IdEdgeIterable(this.query.edges(), idGraph);
+ }
+
+ @Override
+ public Iterable<Vertex> vertices() {
+ return new IdVertexIterable(this.query.vertices(), idGraph);
+ }
+ };
+ }
+
/**
* A factory for IDs of newly-created vertices and edges (where an ID is not otherwise specified).
*/
View
8 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/id/IdVertex.java
@@ -2,10 +2,10 @@
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
-import com.tinkerpop.blueprints.Query;
+import com.tinkerpop.blueprints.VertexQuery;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.util.StringFactory;
-import com.tinkerpop.blueprints.util.wrappers.WrapperQuery;
+import com.tinkerpop.blueprints.util.wrappers.WrapperVertexQuery;
/**
* @author Joshua Shinavier (http://fortytwo.net)
@@ -28,8 +28,8 @@ public Vertex getBaseVertex() {
return new IdVertexIterable(((Vertex) this.baseElement).getVertices(direction, labels), this.idGraph);
}
- public Query query() {
- return new WrapperQuery(((Vertex) this.baseElement).query()) {
+ public VertexQuery query() {
+ return new WrapperVertexQuery(((Vertex) this.baseElement).query()) {
@Override
public Iterable<Vertex> vertices() {
return new IdVertexIterable(this.query.vertices(), idGraph);
View
17 ...s-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/partition/PartitionGraph.java
@@ -4,8 +4,10 @@
import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.Features;
import com.tinkerpop.blueprints.Graph;
+import com.tinkerpop.blueprints.GraphQuery;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.util.StringFactory;
+import com.tinkerpop.blueprints.util.wrappers.WrappedGraphQuery;
import com.tinkerpop.blueprints.util.wrappers.WrapperGraph;
import java.util.Arrays;
@@ -146,4 +148,19 @@ public String toString() {
public Features getFeatures() {
return this.features;
}
+
+ public GraphQuery query() {
+ final PartitionGraph partitionGraph = this;
+ return new WrappedGraphQuery(this.baseGraph.query()) {
+ @Override
+ public Iterable<Edge> edges() {
+ return new PartitionEdgeIterable(this.query.edges(), partitionGraph);
+ }
+
+ @Override
+ public Iterable<Vertex> vertices() {
+ return new PartitionVertexIterable(this.query.vertices(), partitionGraph);
+ }
+ };
+ }
}
View
8 ...-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/partition/PartitionVertex.java
@@ -2,9 +2,9 @@
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
-import com.tinkerpop.blueprints.Query;
+import com.tinkerpop.blueprints.VertexQuery;
import com.tinkerpop.blueprints.Vertex;
-import com.tinkerpop.blueprints.util.wrappers.WrapperQuery;
+import com.tinkerpop.blueprints.util.wrappers.WrapperVertexQuery;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -23,8 +23,8 @@ protected PartitionVertex(final Vertex baseVertex, final PartitionGraph graph) {
return new PartitionVertexIterable(((Vertex) this.baseElement).getVertices(direction, labels), this.graph);
}
- public Query query() {
- return new WrapperQuery(((Vertex) this.baseElement).query()) {
+ public VertexQuery query() {
+ return new WrapperVertexQuery(((Vertex) this.baseElement).query()) {
@Override
public Iterable<Vertex> vertices() {
return new PartitionVertexIterable(this.query.vertices(), graph);
View
16 ...nts-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/readonly/ReadOnlyGraph.java
@@ -3,8 +3,10 @@
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Features;
import com.tinkerpop.blueprints.Graph;
+import com.tinkerpop.blueprints.GraphQuery;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.util.StringFactory;
+import com.tinkerpop.blueprints.util.wrappers.WrappedGraphQuery;
import com.tinkerpop.blueprints.util.wrappers.WrapperGraph;
/**
@@ -100,6 +102,20 @@ public T getBaseGraph() {
return this.baseGraph;
}
+ public GraphQuery query() {
+ return new WrappedGraphQuery(this.baseGraph.query()) {
+ @Override
+ public Iterable<Edge> edges() {
+ return new ReadOnlyEdgeIterable(this.query.edges());
+ }
+
+ @Override
+ public Iterable<Vertex> vertices() {
+ return new ReadOnlyVertexIterable(this.query.vertices());
+ }
+ };
+ }
+
public Features getFeatures() {
return this.features;
}
View
8 ...ts-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/readonly/ReadOnlyVertex.java
@@ -2,9 +2,9 @@
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
-import com.tinkerpop.blueprints.Query;
+import com.tinkerpop.blueprints.VertexQuery;
import com.tinkerpop.blueprints.Vertex;
-import com.tinkerpop.blueprints.util.wrappers.WrapperQuery;
+import com.tinkerpop.blueprints.util.wrappers.WrapperVertexQuery;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -27,8 +27,8 @@ public Edge addEdge(final String label, final Vertex vertex) {
throw new UnsupportedOperationException(ReadOnlyTokens.MUTATE_ERROR_MESSAGE);
}
- public Query query() {
- return new WrapperQuery(((Vertex) this.baseElement).query()) {
+ public VertexQuery query() {
+ return new WrapperVertexQuery(((Vertex) this.baseElement).query()) {
@Override
public Iterable<Vertex> vertices() {
return new ReadOnlyVertexIterable(this.query.vertices());
View
16 ...rints-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/wrapped/WrappedGraph.java
@@ -3,8 +3,10 @@
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Features;
import com.tinkerpop.blueprints.Graph;
+import com.tinkerpop.blueprints.GraphQuery;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.util.StringFactory;
+import com.tinkerpop.blueprints.util.wrappers.WrappedGraphQuery;
import com.tinkerpop.blueprints.util.wrappers.WrapperGraph;
/**
@@ -81,6 +83,20 @@ public T getBaseGraph() {
return this.baseGraph;
}
+ public GraphQuery query() {
+ return new WrappedGraphQuery(this.baseGraph.query()) {
+ @Override
+ public Iterable<Edge> edges() {
+ return new WrappedEdgeIterable(this.query.edges());
+ }
+
+ @Override
+ public Iterable<Vertex> vertices() {
+ return new WrappedVertexIterable(this.query.vertices());
+ }
+ };
+ }
+
public String toString() {
return StringFactory.graphString(this, this.baseGraph.toString());
}
View
8 ...ints-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/wrapped/WrappedVertex.java
@@ -2,9 +2,9 @@
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
-import com.tinkerpop.blueprints.Query;
+import com.tinkerpop.blueprints.VertexQuery;
import com.tinkerpop.blueprints.Vertex;
-import com.tinkerpop.blueprints.util.wrappers.WrapperQuery;
+import com.tinkerpop.blueprints.util.wrappers.WrapperVertexQuery;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -23,8 +23,8 @@ protected WrappedVertex(final Vertex baseVertex) {
return new WrappedVertexIterable(((Vertex) this.baseElement).getVertices(direction, labels));
}
- public Query query() {
- return new WrapperQuery(((Vertex) this.baseElement).query()) {
+ public VertexQuery query() {
+ return new WrapperVertexQuery(((Vertex) this.baseElement).query()) {
@Override
public Iterable<Vertex> vertices() {
return new WrappedVertexIterable(this.query.vertices());
View
12 blueprints-dex-graph/src/main/java/com/tinkerpop/blueprints/impls/dex/DexGraph.java
@@ -6,11 +6,13 @@
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.Features;
+import com.tinkerpop.blueprints.GraphQuery;
import com.tinkerpop.blueprints.KeyIndexableGraph;
import com.tinkerpop.blueprints.MetaGraph;
import com.tinkerpop.blueprints.Parameter;
import com.tinkerpop.blueprints.TransactionalGraph;
import com.tinkerpop.blueprints.Vertex;
+import com.tinkerpop.blueprints.util.DefaultGraphQuery;
import com.tinkerpop.blueprints.util.ExceptionFactory;
import com.tinkerpop.blueprints.util.MultiIterable;
import com.tinkerpop.blueprints.util.PropertyFilteredIterable;
@@ -666,13 +668,9 @@ public Features getFeatures() {
* <p/>
* FIXME: In case the attribute is created, this always creates an String
* attribute, could this be set somehow?
- *
- * @see com.tinkerpop.blueprints.KeyIndexableGraph#createKeyIndex(String, Class)
- * @see #label
*/
@Override
- public <T extends Element> void createKeyIndex(String key,
- Class<T> elementClass, final Parameter... indexParameters) {
+ public <T extends Element> void createKeyIndex(String key, Class<T> elementClass, final Parameter... indexParameters) {
autoStartTransaction();
String label = this.label.get();
@@ -791,4 +789,8 @@ public void stopTransaction(Conclusion conclusion) {
else
rollback();
}
+
+ public GraphQuery query() {
+ return new DefaultGraphQuery(this);
+ }
}
View
8 blueprints-dex-graph/src/main/java/com/tinkerpop/blueprints/impls/dex/DexVertex.java
@@ -6,9 +6,9 @@
import com.tinkerpop.blueprints.CloseableIterable;
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
-import com.tinkerpop.blueprints.Query;
+import com.tinkerpop.blueprints.VertexQuery;
import com.tinkerpop.blueprints.Vertex;
-import com.tinkerpop.blueprints.util.DefaultQuery;
+import com.tinkerpop.blueprints.util.DefaultVertexQuery;
import com.tinkerpop.blueprints.util.MultiIterable;
import com.tinkerpop.blueprints.util.StringFactory;
import com.tinkerpop.blueprints.util.WrappingCloseableIterable;
@@ -219,8 +219,8 @@ else if (labels.length == 1) {
}
}
- public Query query() {
- return new DefaultQuery(this);
+ public VertexQuery query() {
+ return new DefaultVertexQuery(this);
}
public Edge addEdge(final String label, final Vertex vertex) {
View
6 blueprints-neo4j-graph/pom.xml
@@ -20,19 +20,19 @@
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
- <version>1.9.M04</version>
+ <version>1.9.M05</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ha</artifactId>
- <version>1.9.M04</version>
+ <version>1.9.M05</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-management</artifactId>
- <version>1.9.M04</version>
+ <version>1.9.M05</version>
<scope>compile</scope>
</dependency>
<dependency>
View
6 blueprints-neo4j-graph/src/main/java/com/tinkerpop/blueprints/impls/neo4j/Neo4jGraph.java
@@ -3,6 +3,7 @@
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.Features;
+import com.tinkerpop.blueprints.GraphQuery;
import com.tinkerpop.blueprints.Index;
import com.tinkerpop.blueprints.IndexableGraph;
import com.tinkerpop.blueprints.KeyIndexableGraph;
@@ -10,6 +11,7 @@
import com.tinkerpop.blueprints.Parameter;
import com.tinkerpop.blueprints.TransactionalGraph;
import com.tinkerpop.blueprints.Vertex;
+import com.tinkerpop.blueprints.util.DefaultGraphQuery;
import com.tinkerpop.blueprints.util.ExceptionFactory;
import com.tinkerpop.blueprints.util.KeyIndexableGraphHelper;
import com.tinkerpop.blueprints.util.PropertyFilteredIterable;
@@ -514,4 +516,8 @@ public Features getFeatures() {
public String toString() {
return StringFactory.graphString(this, this.rawGraph.toString());
}
+
+ public GraphQuery query() {
+ return new DefaultGraphQuery(this);
+ }
}
View
8 blueprints-neo4j-graph/src/main/java/com/tinkerpop/blueprints/impls/neo4j/Neo4jVertex.java
@@ -1,9 +1,9 @@
package com.tinkerpop.blueprints.impls.neo4j;
import com.tinkerpop.blueprints.Edge;
-import com.tinkerpop.blueprints.Query;
+import com.tinkerpop.blueprints.VertexQuery;
import com.tinkerpop.blueprints.Vertex;
-import com.tinkerpop.blueprints.util.DefaultQuery;
+import com.tinkerpop.blueprints.util.DefaultVertexQuery;
import com.tinkerpop.blueprints.util.MultiIterable;
import com.tinkerpop.blueprints.util.StringFactory;
import org.neo4j.graphdb.Direction;
@@ -47,8 +47,8 @@ public Edge addEdge(final String label, final Vertex vertex) {
return this.graph.addEdge(null, this, vertex, label);
}
- public Query query() {
- return new DefaultQuery(this);
+ public VertexQuery query() {
+ return new DefaultVertexQuery(this);
}
public boolean equals(final Object object) {
View
2  blueprints-neo4jbatch-graph/pom.xml
@@ -20,7 +20,7 @@
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
- <version>1.9.M04</version>
+ <version>1.9.M05</version>
<type>pom</type>
</dependency>
<!-- TESTING -->
View
6 ...jbatch-graph/src/main/java/com/tinkerpop/blueprints/impls/neo4jbatch/Neo4jBatchGraph.java
@@ -3,12 +3,14 @@
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.Features;
+import com.tinkerpop.blueprints.GraphQuery;
import com.tinkerpop.blueprints.Index;
import com.tinkerpop.blueprints.IndexableGraph;
import com.tinkerpop.blueprints.KeyIndexableGraph;
import com.tinkerpop.blueprints.MetaGraph;
import com.tinkerpop.blueprints.Parameter;
import com.tinkerpop.blueprints.Vertex;
+import com.tinkerpop.blueprints.util.DefaultGraphQuery;
import com.tinkerpop.blueprints.util.ExceptionFactory;
import com.tinkerpop.blueprints.util.StringFactory;
import org.neo4j.graphdb.DynamicRelationshipType;
@@ -414,4 +416,8 @@ public void dropIndex(final String indexName) throws UnsupportedOperationExcepti
public Features getFeatures() {
return FEATURES;
}
+
+ public GraphQuery query() {
+ throw new UnsupportedOperationException();
+ }
}
View
4 ...batch-graph/src/main/java/com/tinkerpop/blueprints/impls/neo4jbatch/Neo4jBatchVertex.java
@@ -2,7 +2,7 @@
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
-import com.tinkerpop.blueprints.Query;
+import com.tinkerpop.blueprints.VertexQuery;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.util.ExceptionFactory;
import com.tinkerpop.blueprints.util.StringFactory;
@@ -58,7 +58,7 @@ public Edge addEdge(final String label, final Vertex vertex) {
/**
* @throws UnsupportedOperationException
*/
- public Query query() throws UnsupportedOperationException {
+ public VertexQuery query() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
View
6 ...nts-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientBaseGraph.java
@@ -20,6 +20,7 @@
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Element;
+import com.tinkerpop.blueprints.GraphQuery;
import com.tinkerpop.blueprints.Index;
import com.tinkerpop.blueprints.IndexableGraph;
import com.tinkerpop.blueprints.KeyIndexableGraph;
@@ -27,6 +28,7 @@
import com.tinkerpop.blueprints.Parameter;
import com.tinkerpop.blueprints.TransactionalGraph.Conclusion;
import com.tinkerpop.blueprints.Vertex;
+import com.tinkerpop.blueprints.util.DefaultGraphQuery;
import com.tinkerpop.blueprints.util.ExceptionFactory;
import com.tinkerpop.blueprints.util.PropertyFilteredIterable;
import com.tinkerpop.blueprints.util.StringFactory;
@@ -493,4 +495,8 @@ else if (elementClass.isAssignableFrom(Edge.class))
className = OGraphDatabase.EDGE_CLASS_NAME;
return className;
}
+
+ public GraphQuery query() {
+ return new DefaultGraphQuery(this);
+ }
}
View
8 ...prints-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientVertex.java
@@ -5,9 +5,9 @@
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
-import com.tinkerpop.blueprints.Query;
+import com.tinkerpop.blueprints.VertexQuery;
import com.tinkerpop.blueprints.Vertex;
-import com.tinkerpop.blueprints.util.DefaultQuery;
+import com.tinkerpop.blueprints.util.DefaultVertexQuery;
import com.tinkerpop.blueprints.util.MultiIterable;
import com.tinkerpop.blueprints.util.StringFactory;
import com.tinkerpop.blueprints.util.VerticesFromEdgesIterable;
@@ -93,8 +93,8 @@ public Edge addEdge(final String label, final Vertex vertex) {
return this.graph.addEdge(null, this, vertex, label);
}
- public Query query() {
- return new DefaultQuery(this);
+ public VertexQuery query() {
+ return new DefaultVertexQuery(this);
}
View
6 ...ints-rexster-graph/src/main/java/com/tinkerpop/blueprints/impls/rexster/RexsterGraph.java
@@ -3,12 +3,14 @@
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.Features;
+import com.tinkerpop.blueprints.GraphQuery;
import com.tinkerpop.blueprints.Index;
import com.tinkerpop.blueprints.IndexableGraph;
import com.tinkerpop.blueprints.KeyIndexableGraph;
import com.tinkerpop.blueprints.MetaGraph;
import com.tinkerpop.blueprints.Parameter;
import com.tinkerpop.blueprints.Vertex;
+import com.tinkerpop.blueprints.util.DefaultGraphQuery;
import com.tinkerpop.blueprints.util.ExceptionFactory;
import com.tinkerpop.blueprints.util.StringFactory;
import org.codehaus.jettison.json.JSONArray;
@@ -329,4 +331,8 @@ public JSONArray execute(final String gremlinScript, final JSONObject scriptPara
return c;
}
+ public GraphQuery query() {
+ return new DefaultGraphQuery(this);
+ }
+
}
View
6 ...nts-rexster-graph/src/main/java/com/tinkerpop/blueprints/impls/rexster/RexsterVertex.java
@@ -2,7 +2,7 @@
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
-import com.tinkerpop.blueprints.Query;
+import com.tinkerpop.blueprints.VertexQuery;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.util.MultiIterable;
import com.tinkerpop.blueprints.util.StringFactory;
@@ -71,8 +71,8 @@ public Edge addEdge(final String label, final Vertex vertex) {
return this.graph.addEdge(null, this, vertex, label);
}
- public Query query() {
- return new RexsterQuery(this.graph.getGraphURI() + RexsterTokens.SLASH_VERTICES_SLASH + RestHelper.encode(this.getId()), graph);
+ public VertexQuery query() {
+ return new RexsterVertexQuery(this.graph.getGraphURI() + RexsterTokens.SLASH_VERTICES_SLASH + RestHelper.encode(this.getId()), graph);
}
public String toString() {
View
18 ...lueprints/impls/rexster/RexsterQuery.java → ...nts/impls/rexster/RexsterVertexQuery.java
@@ -3,7 +3,7 @@
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Element;
-import com.tinkerpop.blueprints.Query;
+import com.tinkerpop.blueprints.VertexQuery;
import com.tinkerpop.blueprints.Vertex;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject;
@@ -17,7 +17,7 @@
*
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
-public class RexsterQuery implements Query {
+public class RexsterVertexQuery implements VertexQuery {
private static final String[] EMPTY_LABELS = new String[]{};
@@ -28,38 +28,38 @@
public final String baseUri;
public final RexsterGraph graph;
- public RexsterQuery(final String uri, final RexsterGraph graph) {
+ public RexsterVertexQuery(final String uri, final RexsterGraph graph) {
this.baseUri = uri;
this.graph = graph;
}
- public Query has(final String key, final Object value) {
+ public VertexQuery has(final String key, final Object value) {
this.hasContainers.add(new HasContainer(key, value, Compare.EQUAL));
return this;
}
- public <T extends Comparable<T>> Query has(final String key, final T value, final Compare compare) {
+ public <T extends Comparable<T>> VertexQuery has(final String key, final T value, final Compare compare) {
this.hasContainers.add(new HasContainer(key, value, compare));
return this;
}
- public <T extends Comparable<T>> Query interval(final String key, final T startValue, final T endValue) {
+ public <T extends Comparable<T>> VertexQuery interval(final String key, final T startValue, final T endValue) {
this.hasContainers.add(new HasContainer(key, startValue, Compare.GREATER_THAN_EQUAL));
this.hasContainers.add(new HasContainer(key, endValue, Compare.LESS_THAN));
return this;
}
- public Query direction(final Direction direction) {
+ public VertexQuery direction(final Direction direction) {
this.direction = direction;
return this;
}
- public Query labels(final String... labels) {
+ public VertexQuery labels(final String... labels) {
this.labels = labels;
return this;
}
- public Query limit(final long max) {
+ public VertexQuery limit(final long max) {
this.limit = max;
return this;
}
View
6 blueprints-sail-graph/src/main/java/com/tinkerpop/blueprints/impls/sail/SailGraph.java
@@ -3,9 +3,11 @@
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Features;
+import com.tinkerpop.blueprints.GraphQuery;
import com.tinkerpop.blueprints.MetaGraph;
import com.tinkerpop.blueprints.TransactionalGraph;
import com.tinkerpop.blueprints.Vertex;
+import com.tinkerpop.blueprints.util.DefaultGraphQuery;
import com.tinkerpop.blueprints.util.ExceptionFactory;
import com.tinkerpop.blueprints.util.PropertyFilteredIterable;
import com.tinkerpop.blueprints.util.StringFactory;
@@ -462,6 +464,10 @@ public Features getFeatures() {
return FEATURES;
}
+ public GraphQuery query() {
+ return new DefaultGraphQuery(this);
+ }
+
/**
* Evaluate a SPARQL query against the SailGraph (http://www.w3.org/TR/rdf-sparql-query/). The result is a mapping between the ?-bindings and the bound URI, blank node, or literal represented as a Vertex.
*
View
8 blueprints-sail-graph/src/main/java/com/tinkerpop/blueprints/impls/sail/SailVertex.java
@@ -3,9 +3,9 @@
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
-import com.tinkerpop.blueprints.Query;
+import com.tinkerpop.blueprints.VertexQuery;
import com.tinkerpop.blueprints.Vertex;
-import com.tinkerpop.blueprints.util.DefaultQuery;
+import com.tinkerpop.blueprints.util.DefaultVertexQuery;
import com.tinkerpop.blueprints.util.ElementHelper;
import com.tinkerpop.blueprints.util.MultiIterable;
import com.tinkerpop.blueprints.util.StringFactory;
@@ -203,8 +203,8 @@ public Edge addEdge(final String label, final Vertex vertex) {
return this.graph.addEdge(null, this, vertex, label);
}
- public Query query() {
- return new DefaultQuery(this);
+ public VertexQuery query() {
+ return new DefaultVertexQuery(this);
}
public String toString() {
View
146 blueprints-test/src/main/java/com/tinkerpop/blueprints/QueryTestSuite.java
@@ -2,7 +2,9 @@
import com.tinkerpop.blueprints.impls.GraphTest;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -35,6 +37,9 @@ public void testVertexQuery() {
cHateA.setProperty("amount", 1.0);
cHateB.setProperty("amount", 0.4);
+ assertEquals(count(a.query().labels("friend").has("date", null).edges()), 1);
+ assertEquals(a.query().labels("friend").has("date", null).edges().iterator().next().getProperty("amount"), 0.5);
+
// out edges
List results = asList(a.query().direction(Direction.OUT).edges());
@@ -78,31 +83,31 @@ public void testVertexQuery() {
assertTrue(results.contains(b));
assertEquals(a.query().direction(Direction.OUT).labels("friend").has("amount", 1.0).count(), 1);
- results = asList(a.query().direction(Direction.OUT).labels("friend").has("amount", 1.0, Query.Compare.NOT_EQUAL).edges());
+ results = asList(a.query().direction(Direction.OUT).labels("friend").has("amount", 1.0, VertexQuery.Compare.NOT_EQUAL).edges());
assertEquals(results.size(), 1);
assertTrue(results.contains(aFriendC));
- results = asList(a.query().direction(Direction.OUT).labels("friend").has("amount", 1.0, Query.Compare.NOT_EQUAL).vertices());
+ results = asList(a.query().direction(Direction.OUT).labels("friend").has("amount", 1.0, VertexQuery.Compare.NOT_EQUAL).vertices());
assertEquals(results.size(), 1);
assertTrue(results.contains(c));
- assertEquals(a.query().direction(Direction.OUT).labels("friend").has("amount", 1.0, Query.Compare.NOT_EQUAL).count(), 1);
+ assertEquals(a.query().direction(Direction.OUT).labels("friend").has("amount", 1.0, VertexQuery.Compare.NOT_EQUAL).count(), 1);
- results = asList(a.query().direction(Direction.OUT).labels("friend").has("amount", 1.0, Query.Compare.LESS_THAN_EQUAL).edges());
+ results = asList(a.query().direction(Direction.OUT).labels("friend").has("amount", 1.0, VertexQuery.Compare.LESS_THAN_EQUAL).edges());
assertEquals(results.size(), 2);
assertTrue(results.contains(aFriendB));
assertTrue(results.contains(aFriendC));
- results = asList(a.query().direction(Direction.OUT).labels("friend").has("amount", 1.0, Query.Compare.LESS_THAN_EQUAL).vertices());
+ results = asList(a.query().direction(Direction.OUT).labels("friend").has("amount", 1.0, VertexQuery.Compare.LESS_THAN_EQUAL).vertices());
assertEquals(results.size(), 2);
assertTrue(results.contains(b));
assertTrue(results.contains(c));
- assertEquals(a.query().direction(Direction.OUT).labels("friend").has("amount", 1.0, Query.Compare.LESS_THAN_EQUAL).count(), 2);
+ assertEquals(a.query().direction(Direction.OUT).labels("friend").has("amount", 1.0, VertexQuery.Compare.LESS_THAN_EQUAL).count(), 2);
- results = asList(a.query().direction(Direction.OUT).has("amount", 1.0, Query.Compare.LESS_THAN).edges());
+ results = asList(a.query().direction(Direction.OUT).has("amount", 1.0, VertexQuery.Compare.LESS_THAN).edges());
assertEquals(results.size(), 1);
assertTrue(results.contains(aFriendC));
- results = asList(a.query().direction(Direction.OUT).has("amount", 1.0, Query.Compare.LESS_THAN).vertices());
+ results = asList(a.query().direction(Direction.OUT).has("amount", 1.0, VertexQuery.Compare.LESS_THAN).vertices());
assertEquals(results.size(), 1);
assertTrue(results.contains(c));
- assertEquals(a.query().direction(Direction.OUT).has("amount", 1.0, Query.Compare.LESS_THAN).count(), 1);
+ assertEquals(a.query().direction(Direction.OUT).has("amount", 1.0, VertexQuery.Compare.LESS_THAN).count(), 1);
results = asList(a.query().direction(Direction.OUT).labels("friend").has("amount", 0.5).edges());
assertEquals(results.size(), 1);
@@ -111,27 +116,27 @@ public void testVertexQuery() {
assertEquals(results.size(), 1);
assertTrue(results.contains(c));
- results = asList(a.query().direction(Direction.IN).labels("hate", "friend").has("amount", 0.5, Query.Compare.GREATER_THAN).edges());
+ results = asList(a.query().direction(Direction.IN).labels("hate", "friend").has("amount", 0.5, VertexQuery.Compare.GREATER_THAN).edges());
assertEquals(results.size(), 1);
assertTrue(results.contains(cHateA));
- results = asList(a.query().direction(Direction.IN).labels("hate", "friend").has("amount", 0.5, Query.Compare.GREATER_THAN).vertices());
+ results = asList(a.query().direction(Direction.IN).labels("hate", "friend").has("amount", 0.5, VertexQuery.Compare.GREATER_THAN).vertices());
assertEquals(results.size(), 1);
assertTrue(results.contains(c));
- assertEquals(a.query().direction(Direction.IN).labels("hate", "friend").has("amount", 0.5, Query.Compare.GREATER_THAN).count(), 1);
+ assertEquals(a.query().direction(Direction.IN).labels("hate", "friend").has("amount", 0.5, VertexQuery.Compare.GREATER_THAN).count(), 1);
- results = asList(a.query().direction(Direction.IN).labels("hate").has("amount", 1.0, Query.Compare.GREATER_THAN).edges());
+ results = asList(a.query().direction(Direction.IN).labels("hate").has("amount", 1.0, VertexQuery.Compare.GREATER_THAN).edges());
assertEquals(results.size(), 0);
- results = asList(a.query().direction(Direction.IN).labels("hate").has("amount", 1.0, Query.Compare.GREATER_THAN).vertices());
+ results = asList(a.query().direction(Direction.IN).labels("hate").has("amount", 1.0, VertexQuery.Compare.GREATER_THAN).vertices());
assertEquals(results.size(), 0);
- assertEquals(a.query().direction(Direction.IN).labels("hate").has("amount", 1.0, Query.Compare.GREATER_THAN).count(), 0);
+ assertEquals(a.query().direction(Direction.IN).labels("hate").has("amount", 1.0, VertexQuery.Compare.GREATER_THAN).count(), 0);
- results = asList(a.query().direction(Direction.IN).labels("hate").has("amount", 1.0, Query.Compare.GREATER_THAN_EQUAL).edges());
+ results = asList(a.query().direction(Direction.IN).labels("hate").has("amount", 1.0, VertexQuery.Compare.GREATER_THAN_EQUAL).edges());
assertEquals(results.size(), 1);
assertTrue(results.contains(cHateA));
- results = asList(a.query().direction(Direction.IN).labels("hate").has("amount", 1.0, Query.Compare.GREATER_THAN_EQUAL).vertices());
+ results = asList(a.query().direction(Direction.IN).labels("hate").has("amount", 1.0, VertexQuery.Compare.GREATER_THAN_EQUAL).vertices());
assertEquals(results.size(), 1);
assertTrue(results.contains(c));
- assertEquals(a.query().direction(Direction.IN).labels("hate").has("amount", 1.0, Query.Compare.GREATER_THAN_EQUAL).count(), 1);
+ assertEquals(a.query().direction(Direction.IN).labels("hate").has("amount", 1.0, VertexQuery.Compare.GREATER_THAN_EQUAL).count(), 1);
results = asList(a.query().direction(Direction.OUT).interval("date", 5, 10).edges());
assertEquals(results.size(), 0);
@@ -186,4 +191,109 @@ public void testVertexQuery() {
graph.shutdown();
}
+
+ public void testGraphQueryForVertices() {
+ Graph graph = graphTest.generateGraph();
+ if (graph.getFeatures().supportsVertexIndex && graph instanceof KeyIndexableGraph) {
+ ((KeyIndexableGraph) graph).createKeyIndex("name", Vertex.class);
+ }
+ if (graph.getFeatures().supportsVertexProperties) {
+ Vertex vertex = graph.addVertex(null);
+ vertex.setProperty(convertId(graph, "name"), "marko");
+ vertex.setProperty(convertId(graph, "age"), 33);
+ vertex = graph.addVertex(null);
+ vertex.setProperty(convertId(graph, "name"), "matthias");
+ vertex.setProperty(convertId(graph, "age"), 28);
+ graph.addVertex(null);
+
+ Iterable<Vertex> vertices = graph.query().vertices();
+ assertEquals(count(vertices), 3);
+ assertEquals(count(vertices), 3);
+ Set<String> names = new HashSet<String>();
+ for (Vertex v : vertices) {
+ names.add((String) v.getProperty(convertId(graph, "name")));
+ }
+ assertEquals(names.size(), 3);
+ assertTrue(names.contains("marko"));
+ assertTrue(names.contains(null));
+ assertTrue(names.contains("matthias"));
+
+ assertEquals(count(graph.query().limit(0).vertices()), 0);
+ assertEquals(count(graph.query().limit(1).vertices()), 1);
+ assertEquals(count(graph.query().limit(2).vertices()), 2);
+ assertEquals(count(graph.query().limit(3).vertices()), 3);
+ assertEquals(count(graph.query().limit(4).vertices()), 3);
+
+ vertices = graph.query().has("name", "marko").vertices();
+ assertEquals(count(vertices), 1);
+// assertEquals(vertices.iterator().next().getProperty("name"), "marko");
+
+ vertices = graph.query().has("age", 29, Query.Compare.GREATER_THAN_EQUAL).vertices();
+ assertEquals(count(vertices), 1);
+ assertEquals(vertices.iterator().next().getProperty("name"), "marko");
+ assertEquals(vertices.iterator().next().getProperty("age"), 33);
+
+ vertices = graph.query().has("age", 28, Query.Compare.GREATER_THAN_EQUAL).vertices();
+ assertEquals(count(vertices), 2);
+ names = new HashSet<String>();
+ for (Vertex v : vertices) {
+ names.add((String) v.getProperty(convertId(graph, "name")));
+ }
+ assertEquals(names.size(), 2);
+ assertTrue(names.contains("marko"));
+ assertTrue(names.contains("matthias"));
+
+ vertices = graph.query().interval("age", 28, 33).vertices();
+ assertEquals(count(vertices), 1);
+ assertEquals(vertices.iterator().next().getProperty("name"), "matthias");
+
+ assertEquals(count(graph.query().has("age", null).vertices()), 1);
+ assertEquals(count(graph.query().has("age", 28).has("name", "matthias").vertices()), 1);
+ assertEquals(count(graph.query().has("age", 28).has("name", "matthias").has("name", "matthias").vertices()), 1);
+ assertEquals(count(graph.query().interval("age", 28, 32).has("name", "marko").vertices()), 0);
+ graph.shutdown();
+ }
+ }
+
+ public void testGraphQueryForEdges() {
+ Graph graph = graphTest.generateGraph();
+ if (graph.getFeatures().supportsEdgeIndex && graph instanceof KeyIndexableGraph) {
+ ((KeyIndexableGraph) graph).createKeyIndex("type", Edge.class);
+ }
+ if (graph.getFeatures().supportsEdgeProperties && graph.getFeatures().supportsVertexProperties) {
+ Vertex marko = graph.addVertex(null);
+ marko.setProperty("name", "marko");
+ Vertex matthias = graph.addVertex(null);
+ matthias.setProperty("name", "matthias");
+ Vertex stephen = graph.addVertex(null);
+ stephen.setProperty("name", "stephen");
+
+ Edge edge = marko.addEdge("knows", stephen);
+ edge.setProperty("type", "tinkerpop");
+ edge.setProperty("weight", 1.0);
+ edge = marko.addEdge("knows", matthias);
+ edge.setProperty("type", "aurelius");
+
+ assertEquals(count(graph.query().edges()), 2);
+ assertEquals(count(graph.query().limit(0).edges()), 0);
+ assertEquals(count(graph.query().limit(1).edges()), 1);
+ assertEquals(count(graph.query().limit(2).edges()), 2);
+ assertEquals(count(graph.query().limit(3).edges()), 2);
+
+ assertEquals(count(graph.query().has("type", "tinkerpop").has("type", "tinkerpop").edges()), 1);
+ assertEquals(count(graph.query().has("type", "aurelius").edges()), 1);
+ assertEquals(count(graph.query().has("weight", null).edges()), 1);
+ assertEquals(graph.query().has("weight", null).edges().iterator().next().getProperty("type"), "aurelius");
+
+ assertEquals(count(graph.query().has("weight", 1.0).edges()), 1);
+ assertEquals(graph.query().has("weight", 1.0).edges().iterator().next().getProperty("type"), "tinkerpop");
+ assertEquals(count(graph.query().has("weight", 1.0).has("type", "tinkerpop").edges()), 1);
+ assertEquals(graph.query().has("weight", 1.0).has("type", "tinkerpop").edges().iterator().next().getProperty("type"), "tinkerpop");
+ assertEquals(count(graph.query().has("weight", 1.0).has("type", "aurelius").edges()), 0);
+
+ assertEquals(graph.query().interval("weight", 0.0, 1.1).edges().iterator().next().getProperty("type"), "tinkerpop");
+ assertEquals(count(graph.query().interval("weight", 0.0, 1.0).edges()), 0);
+ }
+ graph.shutdown();
+ }
}
View
6 blueprints-test/src/test/java/com/tinkerpop/blueprints/impls/tg/MockTransactionalGraph.java
@@ -3,6 +3,7 @@
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Features;
import com.tinkerpop.blueprints.Graph;
+import com.tinkerpop.blueprints.GraphQuery;
import com.tinkerpop.blueprints.TransactionalGraph;
import com.tinkerpop.blueprints.Vertex;
@@ -124,4 +125,9 @@ public void shutdown() {
graph.shutdown();
}
+ @Override
+ public GraphQuery query() {
+ return graph.query();
+ }
+
}
View
7 blueprints-test/src/test/java/com/tinkerpop/blueprints/impls/tg/TinkerGraphTest.java