Permalink
Browse files

Support adding the old value of a modified vertex/edge property as a

part of the property modification event data.
  • Loading branch information...
1 parent ce58c16 commit 04e60e18f0b1894d787f3c5116431eadacc9f81f @asaf asaf committed Jan 5, 2013
@@ -32,16 +32,16 @@ protected EventElement(final Element baseElement, final List<GraphChangedListene
this.trigger = trigger;
}
- protected void onVertexPropertyChanged(final Vertex vertex, final String key, final Object newValue) {
- this.trigger.addEvent(new VertexPropertyChangedEvent(vertex, key, newValue));
+ protected void onVertexPropertyChanged(final Vertex vertex, final String key, final Object oldValue, final Object newValue) {
+ this.trigger.addEvent(new VertexPropertyChangedEvent(vertex, key, oldValue, newValue));
}
- protected void onEdgePropertyChanged(final Edge edge, final String key, final Object newValue) {
- this.trigger.addEvent(new EdgePropertyChangedEvent(edge, key, newValue));
+ protected void onEdgePropertyChanged(final Edge edge, final String key, final Object oldValue, final Object newValue) {
+ this.trigger.addEvent(new EdgePropertyChangedEvent(edge, key, oldValue, newValue));
}
- protected void onVertexPropertyRemoved(final Vertex vertex, final String key, final Object newValue) {
- this.trigger.addEvent(new VertexPropertyRemovedEvent(vertex, key, newValue));
+ protected void onVertexPropertyRemoved(final Vertex vertex, final String key, final Object removedValue) {
+ this.trigger.addEvent(new VertexPropertyRemovedEvent(vertex, key, removedValue));
}
protected void onEdgePropertyRemoved(final Edge edge, final String key, final Object removedValue) {
@@ -79,12 +79,13 @@ public Object getProperty(final String key) {
* Raises a vertexPropertyRemoved or edgePropertyChanged event.
*/
public void setProperty(final String key, final Object value) {
+ Object oldValue = this.baseElement.getProperty(key);
this.baseElement.setProperty(key, value);
if (this instanceof Vertex) {
- this.onVertexPropertyChanged((Vertex) this, key, value);
+ this.onVertexPropertyChanged((Vertex) this, key, oldValue, value);
} else if (this instanceof Edge) {
- this.onEdgePropertyChanged((Edge) this, key, value);
+ this.onEdgePropertyChanged((Edge) this, key, oldValue, value);
}
}
@@ -21,8 +21,8 @@ public void vertexAdded(final Vertex vertex) {
System.out.println("Vertex [" + vertex.toString() + "] added to graph [" + graph.toString() + "]");
}
- public void vertexPropertyChanged(final Vertex vertex, final String key, final Object setValue) {
- System.out.println("Vertex [" + vertex.toString() + "] property [" + key + "] set to value of [" + setValue + "] in graph [" + graph.toString() + "]");
+ public void vertexPropertyChanged(final Vertex vertex, final String key, final Object oldValue, final Object newValue) {
+ System.out.println("Vertex [" + vertex.toString() + "] property [" + key + "] set to value of [" + oldValue + "->" + newValue + "] in graph [" + graph.toString() + "]");
}
public void vertexPropertyRemoved(final Vertex vertex, final String key, final Object removedValue) {
@@ -37,8 +37,8 @@ public void edgeAdded(final Edge edge) {
System.out.println("Edge [" + edge.toString() + "] added to graph [" + graph.toString() + "]");
}
- public void edgePropertyChanged(final Edge edge, final String key, final Object setValue) {
- System.out.println("Edge [" + edge.toString() + "] property [" + key + "] set to value of [" + setValue + "] in graph [" + graph.toString() + "]");
+ public void edgePropertyChanged(final Edge edge, final String key, final Object oldValue, final Object newValue) {
+ System.out.println("Edge [" + edge.toString() + "] property [" + key + "] set to value of [" + oldValue + "->" + newValue + "] in graph [" + graph.toString() + "]");
}
public void edgePropertyRemoved(final Edge edge, final String key, final Object removedValue) {
@@ -4,12 +4,12 @@
public class EdgePropertyChangedEvent extends EdgePropertyEvent {
- public EdgePropertyChangedEvent(Edge edge, String key, Object newValue) {
- super(edge, key, newValue);
+ public EdgePropertyChangedEvent(Edge edge, String key, Object oldValue, Object newValue) {
+ super(edge, key, oldValue, newValue);
}
@Override
- void fire(GraphChangedListener listener, Edge edge, String key, Object newValue) {
- listener.edgePropertyChanged(edge, key, newValue);
+ void fire(GraphChangedListener listener, Edge edge, String key, Object oldValue, Object newValue) {
+ listener.edgePropertyChanged(edge, key, oldValue, newValue);
}
}
@@ -8,20 +8,22 @@
private final Edge edge;
private final String key;
+ private final Object oldValue;
private final Object newValue;
- public EdgePropertyEvent(Edge edge, String key, Object newValue) {
+ public EdgePropertyEvent(Edge edge, String key, Object oldValue, Object newValue) {
this.edge = edge;
this.key = key;
+ this.oldValue = oldValue;
this.newValue = newValue;
}
- abstract void fire(GraphChangedListener listener, Edge edge, String key, Object newValue);
+ abstract void fire(GraphChangedListener listener, Edge edge, String key, Object oldValue, Object newValue);
@Override
public void fireEvent(Iterator<GraphChangedListener> eventListeners) {
while (eventListeners.hasNext()) {
- fire(eventListeners.next(), edge, key, newValue);
+ fire(eventListeners.next(), edge, key, oldValue, newValue);
}
}
}
@@ -4,12 +4,12 @@
public class EdgePropertyRemovedEvent extends EdgePropertyEvent {
- public EdgePropertyRemovedEvent(Edge vertex, String key, Object newValue) {
- super(vertex, key, newValue);
+ public EdgePropertyRemovedEvent(Edge vertex, String key, Object oldValue) {
+ super(vertex, key, oldValue, null);
}
@Override
- void fire(GraphChangedListener listener, Edge edge, String key, Object newValue) {
- listener.edgePropertyRemoved(edge, key, newValue);
+ void fire(GraphChangedListener listener, Edge edge, String key, Object oldValue, Object newValue) {
+ listener.edgePropertyRemoved(edge, key, oldValue);
}
}
@@ -27,7 +27,7 @@
* @param key the key of the property that changed
* @param setValue the new value of the property
*/
- public void vertexPropertyChanged(final Vertex vertex, final String key, final Object setValue);
+ public void vertexPropertyChanged(final Vertex vertex, final String key, final Object oldValue, final Object setValue);
/**
* Raised after a vertex property was removed.
@@ -59,7 +59,7 @@
* @param key the key of the property that changed
* @param setValue the new value of the property
*/
- public void edgePropertyChanged(final Edge edge, final String key, final Object setValue);
+ public void edgePropertyChanged(final Edge edge, final String key, final Object oldValue, final Object setValue);
/**
* Raised after an edge property was removed.
@@ -40,9 +40,9 @@ public void vertexAdded(Vertex vertex) {
order.add("v-added-" + vertex.getId());
}
- public void vertexPropertyChanged(Vertex vertex, String s, Object o) {
+ public void vertexPropertyChanged(Vertex vertex, String s, Object o, Object n) {
vertexPropertyChangedEvent++;
- order.add("v-property-changed-" + vertex.getId() + "-" + s + ":" + o);
+ order.add("v-property-changed-" + vertex.getId() + "-" + s + ":" + o + "->" + n);
}
public void vertexPropertyRemoved(Vertex vertex, String s, Object o) {
@@ -60,9 +60,9 @@ public void edgeAdded(Edge edge) {
order.add("e-added-" + edge.getId());
}
- public void edgePropertyChanged(Edge edge, String s, Object o) {
+ public void edgePropertyChanged(Edge edge, String s, Object o, Object n) {
edgePropertyChangedEvent++;
- order.add("e-property-changed-" + edge.getId() + "-" + s + ":" + o);
+ order.add("e-property-changed-" + edge.getId() + "-" + s + ":" + o + "->" + n);
}
public void edgePropertyRemoved(Edge edge, String s, Object o) {
@@ -4,12 +4,12 @@
public class VertexPropertyChangedEvent extends VertexPropertyEvent {
- public VertexPropertyChangedEvent(Vertex vertex, String key, Object newValue) {
- super(vertex, key, newValue);
+ public VertexPropertyChangedEvent(Vertex vertex, String key, Object oldValue, Object newValue) {
+ super(vertex, key, oldValue, newValue);
}
@Override
- void fire(GraphChangedListener listener, Vertex vertex, String key, Object newValue) {
- listener.vertexPropertyChanged(vertex, key, newValue);
+ void fire(GraphChangedListener listener, Vertex vertex, String key, Object oldValue, Object newValue) {
+ listener.vertexPropertyChanged(vertex, key, oldValue, newValue);
}
}
@@ -8,21 +8,23 @@
private final Vertex vertex;
private final String key;
+ private final Object oldValue;
private final Object newValue;
- public VertexPropertyEvent(Vertex vertex, String key, Object newValue) {
+ public VertexPropertyEvent(Vertex vertex, String key, Object oldValue, Object newValue) {
this.vertex = vertex;
this.key = key;
+ this.oldValue = oldValue;
this.newValue = newValue;
}
- abstract void fire(GraphChangedListener listener, Vertex vertex, String key, Object newValue);
+ abstract void fire(GraphChangedListener listener, Vertex vertex, String key, Object oldValue, Object newValue);
@Override
public void fireEvent(Iterator<GraphChangedListener> eventListeners) {
while (eventListeners.hasNext()) {
- fire(eventListeners.next(), vertex, key, newValue);
+ fire(eventListeners.next(), vertex, key, oldValue, newValue);
}
}
}
@@ -4,12 +4,12 @@
public class VertexPropertyRemovedEvent extends VertexPropertyEvent {
- public VertexPropertyRemovedEvent(Vertex vertex, String key, Object newValue) {
- super(vertex, key, newValue);
+ public VertexPropertyRemovedEvent(Vertex vertex, String key, Object removedValue) {
+ super(vertex, key, removedValue, null);
}
@Override
- void fire(GraphChangedListener listener, Vertex vertex, String key, Object newValue) {
- listener.vertexPropertyRemoved(vertex, key, newValue);
+ void fire(GraphChangedListener listener, Vertex vertex, String key, Object oldValue, Object newValue) {
+ listener.vertexPropertyRemoved(vertex, key, oldValue);
}
}
@@ -378,6 +378,7 @@ public void testTransactionSeriesOrder() {
Edge e1 = graph.addEdge(100, v1, v2, "friend");
e1.setProperty("eee", "fff");
e1.setProperty("ggg", "hhh");
+ e1.setProperty("ggg", "hhhh");
e1.removeProperty("eee");
Edge e2 = graph.addEdge(101, v1, v2, "enemy");
@@ -391,18 +392,19 @@ public void testTransactionSeriesOrder() {
List<String> order = graphChangedListener.getOrder();
assertEquals("v-added-10", order.get(0));
- assertEquals("v-property-changed-10-aaa:bbb", order.get(1));
- assertEquals("v-property-changed-10-ccc:ddd", order.get(2));
+ assertEquals("v-property-changed-10-aaa:null->bbb", order.get(1));
+ assertEquals("v-property-changed-10-ccc:null->ddd", order.get(2));
assertEquals("v-property-removed-10-aaa:bbb", order.get(3));
assertEquals("v-added-20", order.get(4));
assertEquals("v-added-30", order.get(5));
assertEquals("e-added-100", order.get(6));
- assertEquals("e-property-changed-100-eee:fff", order.get(7));
- assertEquals("e-property-changed-100-ggg:hhh", order.get(8));
- assertEquals("e-property-removed-100-eee:fff", order.get(9));
- assertEquals("e-added-101", order.get(10));
- assertEquals("e-removed-101", order.get(11));
- assertEquals("v-removed-30", order.get(12));
+ assertEquals("e-property-changed-100-eee:null->fff", order.get(7));
+ assertEquals("e-property-changed-100-ggg:null->hhh", order.get(8));
+ assertEquals("e-property-changed-100-ggg:hhh->hhhh", order.get(9));
+ assertEquals("e-property-removed-100-eee:fff", order.get(10));
+ assertEquals("e-added-101", order.get(11));
+ assertEquals("e-removed-101", order.get(12));
+ assertEquals("v-removed-30", order.get(13));
}

0 comments on commit 04e60e1

Please sign in to comment.