Skip to content

Commit 0f11dfb

Browse files
author
Michael Rappazzo
committed
fixup! properties: upgrade HBaseVertex to support multi-properties
1 parent 3847afe commit 0f11dfb

File tree

5 files changed

+49
-18
lines changed

5 files changed

+49
-18
lines changed

src/main/java/io/hgraphdb/HBaseEdge.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ public Set<String> keys() {
173173
return Collections.unmodifiableSet(properties.keySet());
174174
}
175175

176-
@Override
177-
public boolean removeProperty(String key) {
176+
public void removeProperty(String key) {
178177
Object value = getProperty(key);
179178
if (value != null) {
180179
// delete from index model before removing property
@@ -188,10 +187,7 @@ public boolean removeProperty(String key) {
188187

189188
Mutator writer = getModel().clearProperty(this, key);
190189
Mutators.write(getTable(), writer);
191-
192-
return true;
193190
}
194-
return false;
195191
}
196192

197193
@Override

src/main/java/io/hgraphdb/HBaseElement.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ public void load() {
106106

107107
public abstract boolean hasProperty(String key);
108108

109-
public abstract boolean removeProperty(String key);
110-
111109
public abstract Stream<Map.Entry<String, Object>> propertyEntriesStream();
112110

113111
public abstract int propertySize();

src/main/java/io/hgraphdb/HBaseProperty.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.hgraphdb;
22

3+
import org.apache.tinkerpop.gremlin.structure.Edge;
34
import org.apache.tinkerpop.gremlin.structure.Element;
45
import org.apache.tinkerpop.gremlin.structure.Property;
56
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
@@ -26,7 +27,11 @@ public Element element() {
2627

2728
@Override
2829
public void remove() {
29-
element.removeProperty(this.key);
30+
if (this.element instanceof Edge) {
31+
((HBaseEdge)this.element).removeProperty(this.key);
32+
} else {
33+
((HBaseVertex)this.element).removeProperty(this.key, this.value);
34+
}
3035
}
3136

3237
@Override

src/main/java/io/hgraphdb/HBaseVertex.java

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,26 @@ public <V> VertexProperty<V> property(final VertexProperty.Cardinality cardinali
191191
}
192192

193193
//this will mutate the graph
194-
final Optional<VertexProperty<V>> existingProperty = ElementHelper.stageVertexProperty(this, cardinality, key, value, keyValues);
195-
if (existingProperty.isPresent()) {
196-
return existingProperty
197-
.map(v -> v instanceof HBaseVertexProperty ? v : new HBaseVertexProperty<>(graph, this, v.key(), v.value()))
198-
.get();
194+
VertexProperty<V> existingProperty = null;
195+
if (cardinality.equals(VertexProperty.Cardinality.single)) {
196+
this.properties.remove(key);
197+
} else if (cardinality.equals(VertexProperty.Cardinality.set)) {
198+
Iterator<VertexProperty<V>> itty = this.properties(key);
199+
while (itty.hasNext()) {
200+
final VertexProperty<V> property = itty.next();
201+
if (property.value().equals(value)) {
202+
ElementHelper.attachProperties(property, keyValues);
203+
existingProperty = property;
204+
break;
205+
}
206+
}
207+
}
208+
if (existingProperty != null) {
209+
if (existingProperty instanceof HBaseVertexProperty) {
210+
return existingProperty;
211+
} else {
212+
return new HBaseVertexProperty<>(graph, this, existingProperty.key(), existingProperty.value());
213+
}
199214
}
200215

201216
if (hasIndex) {
@@ -263,10 +278,27 @@ public boolean hasProperty(String key) {
263278
return !getProperties().getOrDefault(key, Collections.emptyList()).isEmpty();
264279
}
265280

266-
@Override
267-
public boolean removeProperty(String key) {
268-
Collection<?> c = getProperties().remove(key);
269-
return c != null && !c.isEmpty();
281+
public boolean removeProperty(String key, Object value) {
282+
boolean removed = false;
283+
if (null != this.properties && this.properties.containsKey(key)) {
284+
Collection<Object> values = this.properties.get(key);
285+
removed = values.remove(value);
286+
if (removed) {
287+
updatedAt(System.currentTimeMillis());
288+
Mutator writer;
289+
if (values.isEmpty()) {
290+
boolean hasIndex = hasIndex(OperationType.WRITE, key);
291+
deleteFromIndexModel(key, null);
292+
//clear
293+
writer = getModel().clearProperty(this, key);
294+
} else {
295+
//cardinality is non-single
296+
writer = getModel().writeProperty(this, key, preparePropertyWriteValue(VertexProperty.Cardinality.list, value, values));
297+
}
298+
Mutators.write(getTable(), writer);
299+
}
300+
}
301+
return removed;
270302
}
271303

272304
@Override

src/main/java/io/hgraphdb/HBaseVertexProperty.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public <U> Property<U> property(final String key, final U value) {
6262

6363
@Override
6464
public void remove() {
65-
vertex.removeProperty(this.key);
65+
((HBaseVertex)vertex).removeProperty(this.key, this.value);
6666
}
6767

6868
@Override

0 commit comments

Comments
 (0)