Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
spmallette committed Mar 12, 2013
2 parents f2d386b + ca64cf8 commit ddcf98c
Show file tree
Hide file tree
Showing 22 changed files with 382 additions and 175 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.textile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -37,13 +35,7 @@ public <T> T getProperty(final String key) {
}

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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tinkerpop.blueprints.util;

import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Element;

import java.util.ArrayList;
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,60 @@ public abstract class IdElement implements Element {

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() {
Expand Down
Loading

0 comments on commit ddcf98c

Please sign in to comment.