Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit 2961db8

Browse files
committed
structure refactoring
1 parent 25db550 commit 2961db8

16 files changed

+289
-239
lines changed

src/main/java/com/arangodb/tinkerpop/gremlin/jsr223/ArangoDBGremlinPlugin.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,20 @@ public class ArangoDBGremlinPlugin extends AbstractGremlinPlugin {
4848
// structure
4949
ArangoDBEdge.class,
5050
ArangoDBElement.class,
51-
ArangoDBEntityElement.class,
51+
ArangoDBPersistentElement.class,
5252
ArangoDBProperty.class,
53+
ArangoDBSimpleElement.class,
5354
ArangoDBVertex.class,
5455
ArangoDBVertexProperty.class,
5556
ArangoDBGraph.class,
5657
ArangoDBGraphVariables.class,
5758

5859
// persistence
59-
PersistentData.class,
6060
AdbValue.class,
6161
EdgeData.class,
6262
PropertyData.class,
63+
PersistentData.class,
64+
SimplePropertyData.class,
6365
VertexData.class,
6466
VertexPropertyData.class
6567
)

src/main/java/com/arangodb/tinkerpop/gremlin/persistence/AdbValue.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ public class AdbValue {
3939
this.valueType = valueType;
4040
}
4141

42-
public AdbValue(Object value) {
43-
this.value = value;
44-
valueType = (value != null ? value.getClass() : Void.class).getCanonicalName();
42+
public static AdbValue of(Object value) {
43+
return new AdbValue(value, (value != null ? value.getClass() : Void.class).getCanonicalName());
4544
}
4645

4746
public Object getValue() {

src/main/java/com/arangodb/tinkerpop/gremlin/persistence/EdgeData.java

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,61 @@
2020
package com.arangodb.tinkerpop.gremlin.persistence;
2121

2222
import com.arangodb.serde.*;
23+
import com.arangodb.shaded.fasterxml.jackson.annotation.JsonProperty;
24+
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
2325

2426
import java.util.*;
2527

26-
public class EdgeData extends PersistentData<AdbValue> {
28+
public class EdgeData extends SimplePropertyData implements PersistentData {
29+
30+
@JsonProperty
31+
private String label;
32+
33+
@InternalKey
34+
private String key;
2735

2836
@InternalFrom
2937
private String from;
3038

3139
@InternalTo
3240
private String to;
3341

34-
private final Map<String, AdbValue> properties = new HashMap<>();
35-
3642
public EdgeData() {
3743
}
3844

45+
// FIXME: static factory method
3946
public EdgeData(
4047
String label,
4148
String key,
4249
String from,
4350
String to
4451
) {
45-
super(label, key);
52+
ElementHelper.validateLabel(label);
53+
if (key != null && key.isEmpty()) throw new IllegalArgumentException("empty key");
4654
Objects.requireNonNull(from, "from");
4755
Objects.requireNonNull(to, "to");
4856

57+
this.label = label;
58+
this.key = key;
4959
this.from = from;
5060
this.to = to;
5161
}
5262

63+
@Override
64+
public String getLabel() {
65+
return label;
66+
}
67+
68+
@Override
69+
public String getKey() {
70+
return key;
71+
}
72+
73+
@Override
74+
public void setKey(String key) {
75+
this.key = key;
76+
}
77+
5378
public String getFrom() {
5479
return from;
5580
}
@@ -66,31 +91,26 @@ public void setTo(String to) {
6691
this.to = to;
6792
}
6893

69-
@Override
70-
public Map<String, AdbValue> getProperties() {
71-
return properties;
72-
}
73-
7494
@Override
7595
public String toString() {
7696
return "EdgeData{" +
7797
"from='" + from + '\'' +
98+
", label='" + label + '\'' +
99+
", key='" + key + '\'' +
78100
", to='" + to + '\'' +
79-
", properties=" + properties +
80101
", super=" + super.toString() +
81102
'}';
82103
}
83104

84105
@Override
85106
public boolean equals(Object o) {
86107
if (!(o instanceof EdgeData)) return false;
87-
if (!super.equals(o)) return false;
88108
EdgeData edgeData = (EdgeData) o;
89-
return Objects.equals(from, edgeData.from) && Objects.equals(to, edgeData.to) && Objects.equals(properties, edgeData.properties);
109+
return Objects.equals(label, edgeData.label) && Objects.equals(key, edgeData.key) && Objects.equals(from, edgeData.from) && Objects.equals(to, edgeData.to);
90110
}
91111

92112
@Override
93113
public int hashCode() {
94-
return Objects.hash(super.hashCode(), from, to, properties);
114+
return Objects.hash(label, key, from, to);
95115
}
96116
}

src/main/java/com/arangodb/tinkerpop/gremlin/persistence/PersistentData.java

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -19,58 +19,10 @@
1919

2020
package com.arangodb.tinkerpop.gremlin.persistence;
2121

22-
import com.arangodb.serde.InternalKey;
23-
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
22+
public interface PersistentData {
23+
String getLabel();
2424

25-
import java.util.Objects;
25+
String getKey();
2626

27-
public abstract class PersistentData<V> implements PropertyData<V> {
28-
29-
private String label;
30-
@InternalKey
31-
private String key;
32-
33-
public PersistentData() {
34-
}
35-
36-
public PersistentData(String label, String key) {
37-
ElementHelper.validateLabel(label);
38-
if (key != null && key.isEmpty()) throw new IllegalArgumentException("empty key");
39-
40-
this.label = label;
41-
this.key = key;
42-
}
43-
44-
public String getKey() {
45-
return key;
46-
}
47-
48-
public void setKey(String key) {
49-
this.key = key;
50-
}
51-
52-
public String getLabel() {
53-
return label;
54-
}
55-
56-
@Override
57-
public String toString() {
58-
return "PersistentData{" +
59-
"key='" + key + '\'' +
60-
", label='" + label + '\'' +
61-
'}';
62-
}
63-
64-
@Override
65-
public boolean equals(Object o) {
66-
if (!(o instanceof PersistentData)) return false;
67-
PersistentData<?> that = (PersistentData<?>) o;
68-
return Objects.equals(label, that.label) && Objects.equals(key, that.key);
69-
}
70-
71-
@Override
72-
public int hashCode() {
73-
return Objects.hash(label, key);
74-
}
27+
void setKey(String key);
7528
}
76-

src/main/java/com/arangodb/tinkerpop/gremlin/persistence/PropertyData.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
package com.arangodb.tinkerpop.gremlin.persistence;
2121

2222
import java.util.Map;
23+
import java.util.stream.Stream;
2324

24-
public interface PropertyData<P> {
25-
Map<String, P> getProperties();
25+
public interface PropertyData<V> {
26+
27+
Stream<Map.Entry<String, V>> entries();
28+
29+
void add(String key, V value);
2630
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package com.arangodb.tinkerpop.gremlin.persistence;
21+
22+
23+
import com.arangodb.shaded.fasterxml.jackson.annotation.JsonProperty;
24+
25+
import java.util.HashMap;
26+
import java.util.Map;
27+
import java.util.Objects;
28+
import java.util.stream.Stream;
29+
30+
public class SimplePropertyData implements PropertyData<AdbValue> {
31+
32+
@JsonProperty
33+
private final Map<String, AdbValue> properties = new HashMap<>();
34+
35+
@Override
36+
public Stream<Map.Entry<String, AdbValue>> entries() {
37+
return properties.entrySet().stream();
38+
}
39+
40+
@Override
41+
public void add(String key, AdbValue value) {
42+
properties.put(key, value);
43+
}
44+
45+
public void remove(String key) {
46+
properties.remove(key);
47+
}
48+
49+
@Override
50+
public String toString() {
51+
return "SimplePropertyData{" +
52+
"properties=" + properties +
53+
'}';
54+
}
55+
56+
@Override
57+
public boolean equals(Object o) {
58+
if (!(o instanceof SimplePropertyData)) return false;
59+
SimplePropertyData that = (SimplePropertyData) o;
60+
return Objects.equals(properties, that.properties);
61+
}
62+
63+
@Override
64+
public int hashCode() {
65+
return Objects.hashCode(properties);
66+
}
67+
}

src/main/java/com/arangodb/tinkerpop/gremlin/persistence/VertexData.java

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,45 +19,86 @@
1919

2020
package com.arangodb.tinkerpop.gremlin.persistence;
2121

22-
import java.util.HashMap;
23-
import java.util.List;
24-
import java.util.Map;
25-
import java.util.Objects;
22+
import com.arangodb.serde.InternalKey;
23+
import com.arangodb.shaded.fasterxml.jackson.annotation.JsonProperty;
24+
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
2625

27-
public class VertexData extends PersistentData<List<VertexPropertyData>> {
26+
import java.util.*;
27+
import java.util.stream.Stream;
2828

29-
private final Map<String, List<VertexPropertyData>> properties = new HashMap<>();
29+
public class VertexData implements PropertyData<VertexPropertyData>, PersistentData {
30+
31+
@JsonProperty
32+
private String label;
33+
34+
@InternalKey
35+
private String key;
36+
37+
@JsonProperty
38+
private final Map<String, Set<VertexPropertyData>> properties = new HashMap<>();
3039

3140
public VertexData() {
3241
}
3342

3443
public VertexData(String label, String key) {
35-
super(label, key);
44+
ElementHelper.validateLabel(label);
45+
if (key != null && key.isEmpty()) throw new IllegalArgumentException("empty key");
46+
this.label = label;
47+
this.key = key;
48+
}
49+
50+
@Override
51+
public String getLabel() {
52+
return label;
53+
}
54+
55+
@Override
56+
public String getKey() {
57+
return key;
3658
}
3759

3860
@Override
39-
public Map<String, List<VertexPropertyData>> getProperties() {
40-
return properties;
61+
public void setKey(String key) {
62+
this.key = key;
63+
}
64+
65+
@Override
66+
public Stream<Map.Entry<String, VertexPropertyData>> entries() {
67+
return properties.entrySet().stream().flatMap(e -> e.getValue().stream()
68+
.map(v -> new AbstractMap.SimpleImmutableEntry<>(e.getKey(), v)));
69+
}
70+
71+
@Override
72+
public void add(String key, VertexPropertyData value) {
73+
properties.computeIfAbsent(key, k -> new HashSet<>()).add(value);
74+
}
75+
76+
public void remove(String key, VertexPropertyData value) {
77+
Set<VertexPropertyData> props = properties.getOrDefault(key, Collections.emptySet());
78+
props.remove(value);
79+
if (props.isEmpty()) {
80+
properties.remove(key);
81+
}
4182
}
4283

4384
@Override
4485
public String toString() {
4586
return "VertexData{" +
46-
"properties=" + properties +
47-
", super=" + super.toString() +
87+
"key='" + key + '\'' +
88+
", label='" + label + '\'' +
89+
", properties=" + properties +
4890
'}';
4991
}
5092

5193
@Override
5294
public boolean equals(Object o) {
5395
if (!(o instanceof VertexData)) return false;
54-
if (!super.equals(o)) return false;
5596
VertexData that = (VertexData) o;
56-
return Objects.equals(properties, that.properties);
97+
return Objects.equals(label, that.label) && Objects.equals(key, that.key) && Objects.equals(properties, that.properties);
5798
}
5899

59100
@Override
60101
public int hashCode() {
61-
return Objects.hash(super.hashCode(), properties);
102+
return Objects.hash(label, key, properties);
62103
}
63104
}

0 commit comments

Comments
 (0)