Permalink
Browse files

Merge remote-tracking branch 'origin/master'

  • Loading branch information...
spmallette committed Mar 12, 2013
2 parents f2d386b + ca64cf8 commit ddcf98c459c4829671adfd09a071402f79ab9404
Showing with 382 additions and 175 deletions.
  1. +2 −0 CHANGELOG.textile
  2. +1 −9 blueprints-core/src/main/java/com/tinkerpop/blueprints/impls/tg/TinkerElement.java
  3. +23 −0 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/ElementHelper.java
  4. +9 −1 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/ExceptionFactory.java
  5. +1 −1 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/id/IdEdge.java
  6. +27 −12 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/id/IdElement.java
  7. +136 −81 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/id/IdGraph.java
  8. +3 −2 blueprints-core/src/main/java/com/tinkerpop/blueprints/util/wrappers/id/IdVertex.java
  9. +3 −9 blueprints-dex-graph/src/main/java/com/tinkerpop/blueprints/impls/dex/DexElement.java
  10. +1 −7 blueprints-neo4j-graph/src/main/java/com/tinkerpop/blueprints/impls/neo4j/Neo4jElement.java
  11. +1 −1 blueprints-neo4j-graph/src/main/java/com/tinkerpop/blueprints/impls/neo4j/batch/Neo4jBatchEdge.java
  12. +1 −1 ...prints-neo4j-graph/src/main/java/com/tinkerpop/blueprints/impls/neo4j/batch/Neo4jBatchVertex.java
  13. +1 −7 blueprints-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientElement.java
  14. +1 −7 blueprints-rexster-graph/src/main/java/com/tinkerpop/blueprints/impls/rexster/RexsterElement.java
  15. +39 −0 blueprints-test/src/main/java/com/tinkerpop/blueprints/EdgeTestSuite.java
  16. +41 −0 blueprints-test/src/main/java/com/tinkerpop/blueprints/GraphTestSuite.java
  17. +0 −26 blueprints-test/src/main/java/com/tinkerpop/blueprints/KeyIndexableGraphTestSuite.java
  18. +2 −0 blueprints-test/src/main/java/com/tinkerpop/blueprints/QueryTestSuite.java
  19. +33 −0 blueprints-test/src/main/java/com/tinkerpop/blueprints/VertexTestSuite.java
  20. +7 −7 blueprints-test/src/test/java/com/tinkerpop/blueprints/util/io/graphson/GraphSONReaderTest.java
  21. +4 −4 blueprints-test/src/test/java/com/tinkerpop/blueprints/util/io/graphson/GraphSONUtilityTest.java
  22. +46 −0 blueprints-test/src/test/java/com/tinkerpop/blueprints/util/wrappers/id/IdGraphTest.java
View
@@ -15,6 +15,8 @@ h3. Version 2.3.0 (NOT OFFICIALLY RELEASED YET)
</dependency>
```
+* Generalized @IdGraph@ to selectively enable custom vertex or edge IDs
+* Stricter testing of property keys/value to ensure legal Blueprints values (no id, label, empty string, null)
* @Element.getProperty()@ API signature changed to support automatic typing to declared variable type
* Moved @PropertyGraphSail@, which provides a dynamic RDF view of any Blueprints graph, from Tinkubator into @blueprints-graph-sail@
* Bumped major versions of Ripple and SesameTools
@@ -5,8 +5,6 @@
import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.util.ElementHelper;
-import com.tinkerpop.blueprints.util.ExceptionFactory;
-import com.tinkerpop.blueprints.util.StringFactory;
import java.io.Serializable;
import java.util.HashMap;
@@ -37,13 +35,7 @@ protected TinkerElement(final String id, final TinkerGraph graph) {
}
public void setProperty(final String key, final Object value) {
- if (key.equals(StringFactory.ID))
- throw ExceptionFactory.propertyKeyIdIsReserved();
- if (key.equals(StringFactory.LABEL) && this instanceof Edge)
- throw ExceptionFactory.propertyKeyLabelIsReservedForEdges();
- if (key.equals(StringFactory.EMPTY_STRING))
- throw ExceptionFactory.elementKeyCanNotBeEmpty();
-
+ ElementHelper.validateProperty(this, key, value);
Object oldValue = this.properties.put(key, value);
if (this instanceof TinkerVertex)
this.graph.vertexKeyIndex.autoUpdate(key, value, oldValue, (TinkerVertex) this);
@@ -1,5 +1,6 @@
package com.tinkerpop.blueprints.util;
+import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Element;
import java.util.ArrayList;
@@ -13,6 +14,28 @@
*/
public class ElementHelper {
+ /**
+ * Determines whether the property key/value for the specified element can be legally set.
+ * This is typically used as a pre-condition check prior to setting a property.
+ *
+ * @param element the element for the property to be set
+ * @param key the key of the property
+ * @param value the value of the property
+ * @throws IllegalArgumentException whether the triple is legal and if not, a clear reason message is provided
+ */
+ public static final void validateProperty(final Element element, final String key, final Object value) throws IllegalArgumentException {
+ if (null == value)
+ throw ExceptionFactory.propertyValueCanNotBeNull();
+ if (null == key)
+ throw ExceptionFactory.propertyKeyCanNotBeNull();
+ if (key.equals(StringFactory.ID))
+ throw ExceptionFactory.propertyKeyIdIsReserved();
+ if (element instanceof Edge && key.equals(StringFactory.LABEL))
+ throw ExceptionFactory.propertyKeyLabelIsReservedForEdges();
+ if (key.isEmpty())
+ throw ExceptionFactory.propertyKeyCanNotBeEmpty();
+ }
+
/**
* Copy the properties (key and value) from one element to another.
* The properties are preserved on the from element.
@@ -44,10 +44,18 @@ public static IllegalArgumentException propertyKeyLabelIsReservedForEdges() {
return new IllegalArgumentException("Property key is reserved for all edges: label");
}
- public static IllegalArgumentException elementKeyCanNotBeEmpty() {
+ public static IllegalArgumentException propertyKeyCanNotBeEmpty() {
return new IllegalArgumentException("Property key can not be the empty string");
}
+ public static IllegalArgumentException propertyKeyCanNotBeNull() {
+ return new IllegalArgumentException("Property key can not be null");
+ }
+
+ public static IllegalArgumentException propertyValueCanNotBeNull() {
+ return new IllegalArgumentException("Property value can not be null");
+ }
+
// IndexableGraph related exceptions
public static IllegalArgumentException indexAlreadyExists(final String indexName) {
@@ -11,7 +11,7 @@
public class IdEdge extends IdElement implements Edge {
protected IdEdge(final Edge base, final IdGraph idGraph) {
- super(base, idGraph);
+ super(base, idGraph, idGraph.getSupportEdgeIds());
}
public Edge getBaseEdge() {
@@ -16,45 +16,60 @@
protected final IdGraph idGraph;
- protected IdElement(final Element baseElement, final IdGraph idGraph) {
+ protected final boolean propertyBased;
+
+ protected IdElement(final Element baseElement,
+ final IdGraph idGraph,
+ final boolean propertyBased) {
this.baseElement = baseElement;
this.idGraph = idGraph;
+ this.propertyBased = propertyBased;
}
public <T> T getProperty(final String key) {
- if (key.equals(IdGraph.ID)) {
+ if (propertyBased && key.equals(IdGraph.ID)) {
return null;
}
return baseElement.getProperty(key);
}
public Set<String> getPropertyKeys() {
- final Set<String> keys = baseElement.getPropertyKeys();
- final Set<String> s = new HashSet<String>();
- s.addAll(keys);
- s.remove(IdGraph.ID);
- return s;
+ if (propertyBased) {
+ final Set<String> keys = baseElement.getPropertyKeys();
+ final Set<String> s = new HashSet<String>();
+ s.addAll(keys);
+ s.remove(IdGraph.ID);
+ return s;
+ } else {
+ return baseElement.getPropertyKeys();
+ }
}
public void setProperty(final String key, final Object value) {
- if (key.equals(IdGraph.ID)) {
- throw new IllegalArgumentException("Unable to set value for reserved property " + IdGraph.ID);
+ if (propertyBased) {
+ if (key.equals(IdGraph.ID)) {
+ throw new IllegalArgumentException("Unable to set value for reserved property " + IdGraph.ID);
+ }
}
baseElement.setProperty(key, value);
}
public <T> T removeProperty(final String key) {
- if (key.equals(IdGraph.ID)) {
- throw new IllegalArgumentException("Unable to remove value for reserved property " + IdGraph.ID);
+ if (propertyBased) {
+ if (key.equals(IdGraph.ID)) {
+ throw new IllegalArgumentException("Unable to remove value for reserved property " + IdGraph.ID);
+ }
}
return baseElement.removeProperty(key);
}
public Object getId() {
- return baseElement.getProperty(IdGraph.ID);
+ return propertyBased
+ ? baseElement.getProperty(IdGraph.ID)
+ : baseElement.getId();
}
public int hashCode() {
Oops, something went wrong.

0 comments on commit ddcf98c

Please sign in to comment.