tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject tinkerpop git commit: TINKERPOP-1831 Added KeyedProperty/VertexProperty for EventStrategy
Date Wed, 13 Jun 2018 14:16:06 GMT
Repository: tinkerpop
Updated Branches:
  refs/heads/master 61238bfe6 -> fc866751e


TINKERPOP-1831 Added KeyedProperty/VertexProperty for EventStrategy

This is a minor but necessary change from the previous approach that used EmptyProperty/VertexProperty
for "new" property additions. Use of "empty" was not sufficient because it didn't allow the
MutationListener to know the key being updated. CTR


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/fc866751
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/fc866751
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/fc866751

Branch: refs/heads/master
Commit: fc866751e11768666ed347f772d86d888a2dec16
Parents: 61238bf
Author: Stephen Mallette <spmva@genoprime.com>
Authored: Wed Jun 13 10:13:15 2018 -0400
Committer: Stephen Mallette <spmva@genoprime.com>
Committed: Wed Jun 13 10:15:55 2018 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |   2 +-
 docs/src/upgrade/release-3.4.x.asciidoc         |   4 +-
 .../step/sideEffect/AddPropertyStep.java        |   8 +-
 .../util/empty/EmptyVertexProperty.java         |   2 +-
 .../structure/util/keyed/KeyedProperty.java     |  85 ++++++++++++++
 .../util/keyed/KeyedVertexProperty.java         | 114 +++++++++++++++++++
 .../decoration/EventStrategyProcessTest.java    |  29 +++--
 7 files changed, 228 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc866751/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 5e36f57..2320162 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -38,7 +38,7 @@ This release also includes changes from <<release-3-3-3, 3.3.3>>.
 * Changed the order of `select()` scopes. The order is now: maps, side-effects, paths.
 * Removed previously deprecated Credentials DSL infrastructure.
 * Moved `TraversalEngine` to `gremlin-test` as it has long been only used in testing infrastructure.
-* Events from `EventStrategy` raised from "new" mutations will now return a true "empty"
property from `VertexProperty.empty()` or `Property.empty()` as is appropriate.
+* Events from `EventStrategy` raised from "new" mutations will now return a `KeyedVertexProperty`
or `KeyedProperty` as is appropriate.
 * `MutationListener#vertexPropertyChanged(Vertex, VertexProperty, Object, Object...)` no
longer has a default implementation.
 * Removed previously deprecated `MutationListener#vertexPropertyChanged(Vertex, Property,
Object, Object...)`.
 * Removed previously deprecated `OpSelectorHandler` constructor.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc866751/docs/src/upgrade/release-3.4.x.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/upgrade/release-3.4.x.asciidoc b/docs/src/upgrade/release-3.4.x.asciidoc
index 68f7cd3..8829569 100644
--- a/docs/src/upgrade/release-3.4.x.asciidoc
+++ b/docs/src/upgrade/release-3.4.x.asciidoc
@@ -129,8 +129,8 @@ have originally been the correct signature of `vertexPropertyChanged(Vertex,
Ver
 prior versions when this method and its related `edgePropertyChanged()` and `vertexPropertyPropertyChanged()`
were
 triggered by way of the addition of a new property a "fake" property was included with a
`null` value for the
 "oldValue" argument to these methods (as it did not exist prior to this event). That was
a bit awkward to reason about
-when dealing with that event. To make this easier, the event now raises with a `VertexProperty.empty()`
or
-`Property.empty()` instance, which can be evaluated with `equals()` easily to determine if
the property is new or not.
+when dealing with that event. To make this easier, the event now raises with a `KeyedVertexProperty`
or
+`KeyedProperty` instance, which only contains a property key and no value in them.
 
 link:https://issues.apache.org/jira/browse/TINKERPOP-1831[TINKERPOP-1831]
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc866751/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/AddPropertyStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/AddPropertyStep.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/AddPropertyStep.java
index 3589c0c..6b814c3 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/AddPropertyStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/AddPropertyStep.java
@@ -37,6 +37,8 @@ import org.apache.tinkerpop.gremlin.structure.T;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
 import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+import org.apache.tinkerpop.gremlin.structure.util.keyed.KeyedProperty;
+import org.apache.tinkerpop.gremlin.structure.util.keyed.KeyedVertexProperty;
 
 import java.util.List;
 import java.util.Set;
@@ -97,17 +99,17 @@ public final class AddPropertyStep<S extends Element> extends SideEffectStep<S>
             if (element instanceof Vertex)
                 evt = new Event.VertexPropertyChangedEvent(eventStrategy.detach((Vertex)
element),
                         newProperty ?
-                                VertexProperty.empty() :
+                                new KeyedVertexProperty(key) :
                                 eventStrategy.detach((VertexProperty) currentProperty), value,
vertexPropertyKeyValues);
             else if (element instanceof Edge)
                 evt = new Event.EdgePropertyChangedEvent(eventStrategy.detach((Edge) element),
                         newProperty ?
-                                Property.empty() :
+                                new KeyedProperty(key) :
                                 eventStrategy.detach(currentProperty), value);
             else if (element instanceof VertexProperty)
                 evt = new Event.VertexPropertyPropertyChangedEvent(eventStrategy.detach((VertexProperty)
element),
                         newProperty ?
-                                Property.empty() :
+                                new KeyedProperty(key) :
                                 eventStrategy.detach(currentProperty), value);
             else
                 throw new IllegalStateException(String.format("The incoming object cannot
be processed by change eventing in %s:  %s", AddPropertyStep.class.getName(), element));

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc866751/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/empty/EmptyVertexProperty.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/empty/EmptyVertexProperty.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/empty/EmptyVertexProperty.java
index a77fd6f..c7a5b44 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/empty/EmptyVertexProperty.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/empty/EmptyVertexProperty.java
@@ -90,7 +90,7 @@ public final class EmptyVertexProperty<V> implements VertexProperty<V>
{
     }
 
     @Override
-    public <U> Iterator<Property<U>> properties(String... propertyKeys)
{
+    public <U> Iterator<Property<U>> properties(final String... propertyKeys)
{
         return Collections.emptyIterator();
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc866751/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/keyed/KeyedProperty.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/keyed/KeyedProperty.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/keyed/KeyedProperty.java
new file mode 100644
index 0000000..5532f06
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/keyed/KeyedProperty.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.structure.util.keyed;
+
+import org.apache.tinkerpop.gremlin.structure.Element;
+import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+
+import java.util.NoSuchElementException;
+
+/**
+ * A utility implementation of a {@link Property} that only has a key but no value.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public final class KeyedProperty<V> implements Property<V> {
+
+    private final String key;
+
+    public KeyedProperty(final String key) {
+        if (null == key || key.isEmpty()) throw new IllegalArgumentException("key cannot
be null");
+        this.key = key;
+    }
+
+    @Override
+    public String key() {
+        return this.key;
+    }
+
+    @Override
+    public V value() throws NoSuchElementException {
+        throw Exceptions.propertyDoesNotExist();
+    }
+
+    @Override
+    public boolean isPresent() {
+        return false;
+    }
+
+    @Override
+    public Element element() {
+        throw Exceptions.propertyDoesNotExist();
+    }
+
+    @Override
+    public void remove() {
+
+    }
+
+    @Override
+    public String toString() {
+        return StringFactory.propertyString(this);
+    }
+
+    @Override
+    public boolean equals(final Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        final KeyedProperty<?> that = (KeyedProperty<?>) o;
+
+        return key.equals(that.key);
+    }
+
+    @Override
+    public int hashCode() {
+        return key.hashCode();
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc866751/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/keyed/KeyedVertexProperty.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/keyed/KeyedVertexProperty.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/keyed/KeyedVertexProperty.java
new file mode 100644
index 0000000..53cba69
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/keyed/KeyedVertexProperty.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.structure.util.keyed;
+
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+/**
+ * A utility implementation of a {@link Property} that only has a key but no value and no
meta-properties.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public final class KeyedVertexProperty<V> implements VertexProperty<V> {
+
+    private final String key;
+
+    public KeyedVertexProperty(final String key) {
+        if (null == key || key.isEmpty()) throw new IllegalArgumentException("key cannot
be null");
+        this.key = key;
+    }
+
+    @Override
+    public Vertex element() {
+        throw Property.Exceptions.propertyDoesNotExist();
+    }
+
+    @Override
+    public Object id() {
+        throw Property.Exceptions.propertyDoesNotExist();
+    }
+
+    @Override
+    public Graph graph() {
+        throw Property.Exceptions.propertyDoesNotExist();
+    }
+
+    @Override
+    public <U> Property<U> property(String key) {
+        return Property.<U>empty();
+    }
+
+    @Override
+    public <U> Property<U> property(String key, U value) {
+        return Property.<U>empty();
+    }
+
+    @Override
+    public String key() {
+        return this.key;
+    }
+
+    @Override
+    public V value() throws NoSuchElementException {
+        throw Property.Exceptions.propertyDoesNotExist();
+    }
+
+    @Override
+    public boolean isPresent() {
+        return false;
+    }
+
+    @Override
+    public void remove() {
+
+    }
+
+    @Override
+    public String toString() {
+        return StringFactory.propertyString(this);
+    }
+
+    @Override
+    public <U> Iterator<Property<U>> properties(final String... propertyKeys)
{
+        return Collections.emptyIterator();
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        final KeyedVertexProperty<?> that = (KeyedVertexProperty<?>) o;
+
+        return key.equals(that.key);
+    }
+
+    @Override
+    public int hashCode() {
+        return key.hashCode();
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc866751/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/EventStrategyProcessTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/EventStrategyProcessTest.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/EventStrategyProcessTest.java
index b527340..0992eae 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/EventStrategyProcessTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/EventStrategyProcessTest.java
@@ -31,6 +31,8 @@ import org.apache.tinkerpop.gremlin.structure.VertexProperty;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdge;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertexProperty;
+import org.apache.tinkerpop.gremlin.structure.util.keyed.KeyedProperty;
+import org.apache.tinkerpop.gremlin.structure.util.keyed.KeyedVertexProperty;
 import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceEdge;
 import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceVertex;
 import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceVertexProperty;
@@ -633,7 +635,8 @@ public class EventStrategyProcessTest extends AbstractGremlinProcessTest
{
                 assertThat(element, instanceOf(DetachedVertexProperty.class));
                 assertEquals(label, element.label());
                 assertEquals(value, element.value());
-                assertEquals(Property.empty(), oldValue);
+                assertThat(oldValue, instanceOf(KeyedProperty.class));
+                assertEquals("new", oldValue.key());
                 assertEquals("yay!", setValue);
                 triggered.set(true);
             }
@@ -750,7 +753,8 @@ public class EventStrategyProcessTest extends AbstractGremlinProcessTest
{
                 assertEquals(label, element.label());
                 assertEquals(inId, element.inVertex().id());
                 assertEquals(outId, element.outVertex().id());
-                assertEquals(Property.empty(), oldValue);
+                assertThat(oldValue, instanceOf(KeyedProperty.class));
+                assertEquals("new", oldValue.key());
                 assertEquals("yay!", setValue);
                 triggered.set(true);
             }
@@ -925,7 +929,8 @@ public class EventStrategyProcessTest extends AbstractGremlinProcessTest
{
                 assertThat(element, instanceOf(DetachedVertex.class));
                 assertEquals(label, element.label());
                 assertEquals(id, element.id());
-                assertEquals(VertexProperty.empty(), oldValue);
+                assertThat(oldValue, instanceOf(KeyedVertexProperty.class));
+                assertEquals("new", oldValue.key());
                 assertEquals("dah", setValue);
                 triggered.set(true);
             }
@@ -1102,7 +1107,8 @@ public class EventStrategyProcessTest extends AbstractGremlinProcessTest
{
                 assertThat(element, instanceOf(ReferenceVertexProperty.class));
                 assertEquals(label, element.label());
                 assertEquals(value, element.value());
-                assertEquals(Property.empty(), oldValue);
+                assertThat(oldValue, instanceOf(KeyedProperty.class));
+                assertEquals("new", oldValue.key());
                 assertEquals("yay!", setValue);
                 triggered.set(true);
             }
@@ -1219,7 +1225,8 @@ public class EventStrategyProcessTest extends AbstractGremlinProcessTest
{
                 assertEquals(label, element.label());
                 assertEquals(inId, element.inVertex().id());
                 assertEquals(outId, element.outVertex().id());
-                assertEquals(Property.empty(), oldValue);
+                assertThat(oldValue, instanceOf(KeyedProperty.class));
+                assertEquals("new", oldValue.key());
                 assertEquals("yay!", setValue);
                 triggered.set(true);
             }
@@ -1396,7 +1403,8 @@ public class EventStrategyProcessTest extends AbstractGremlinProcessTest
{
                 assertThat(element, instanceOf(ReferenceVertex.class));
                 assertEquals(label, element.label());
                 assertEquals(id, element.id());
-                assertEquals(VertexProperty.empty(), oldValue);
+                assertThat(oldValue, instanceOf(KeyedVertexProperty.class));
+                assertEquals("new", oldValue.key());
                 assertEquals("dah", setValue);
                 triggered.set(true);
             }
@@ -1572,7 +1580,8 @@ public class EventStrategyProcessTest extends AbstractGremlinProcessTest
{
                 assertEquals(vp, element);
                 assertEquals(label, element.label());
                 assertEquals(value, element.value());
-                assertEquals(Property.empty(), oldValue);
+                assertThat(oldValue, instanceOf(KeyedProperty.class));
+                assertEquals("new", oldValue.key());
                 assertEquals("yay!", setValue);
                 triggered.set(true);
             }
@@ -1689,7 +1698,8 @@ public class EventStrategyProcessTest extends AbstractGremlinProcessTest
{
                 assertEquals(label, element.label());
                 assertEquals(inId, element.inVertex().id());
                 assertEquals(outId, element.outVertex().id());
-                assertEquals(Property.empty(), oldValue);
+                assertThat(oldValue, instanceOf(KeyedProperty.class));
+                assertEquals("new", oldValue.key());
                 assertEquals("yay!", setValue);
                 triggered.set(true);
             }
@@ -1866,7 +1876,8 @@ public class EventStrategyProcessTest extends AbstractGremlinProcessTest
{
                 assertEquals(v, element);
                 assertEquals(label, element.label());
                 assertEquals(id, element.id());
-                assertEquals(VertexProperty.empty(), oldValue);
+                assertThat(oldValue, instanceOf(KeyedVertexProperty.class));
+                assertEquals("new", oldValue.key());
                 assertEquals("dah", setValue);
                 triggered.set(true);
             }


Mime
View raw message