Skip to content

Commit 21098f0

Browse files
authored
[DE-1069] Remove collections prefixes (#18)
* removed requiring graph prefix in collection names * fixed demo
1 parent c9acaa2 commit 21098f0

28 files changed

+176
-299
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ implementation 'com.arangodb:arangodb-tinkerpop-provider:x.y.z'
5555
To use the provider in the Gremlin Console, first you need to install it:
5656

5757
```text
58-
:install com.arangodb arangodb-tinkerpop-provider 3.0.1
58+
:install com.arangodb arangodb-tinkerpop-provider 3.1.0-SNAPSHOT
5959
```
6060

6161
Then, after restarting the console, you can use it:
@@ -90,7 +90,7 @@ gremlin> g.V().hasLabel("person").values("name")
9090
To use the provider as Gremlin Server plugin, first you need to install it:
9191

9292
```text
93-
./bin/gremlin-server.sh install com.arangodb arangodb-tinkerpop-provider 3.0.1
93+
./bin/gremlin-server.sh install com.arangodb arangodb-tinkerpop-provider 3.1.0-SNAPSHOT
9494
```
9595

9696
Then, you need to create the graph configuration, e.g. in the file

demo/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.example</groupId>
88
<artifactId>arango-tinkerpop-demo</artifactId>
9-
<version>3.0.1</version>
9+
<version>3.1.0-SNAPSHOT</version>
1010

1111
<properties>
1212
<maven.compiler.source>21</maven.compiler.source>
@@ -18,7 +18,7 @@
1818
<dependency>
1919
<groupId>com.arangodb</groupId>
2020
<artifactId>arangodb-tinkerpop-provider</artifactId>
21-
<version>3.0.1</version>
21+
<version>3.1.0-SNAPSHOT</version>
2222
</dependency>
2323
<dependency>
2424
<groupId>ch.qos.logback</groupId>

demo/src/main/java/org/example/Main.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public static void main(String[] args) {
136136

137137
System.out.println("Find \"marko\" in the graph using AQL");
138138
String query = """
139-
FOR d IN tinkerpop_vertex
139+
FOR d IN vertex
140140
FILTER d.name == @name
141141
RETURN d
142142
""";
@@ -247,13 +247,13 @@ public static void main(String[] args) {
247247

248248
String shortestPathQuery = """
249249
LET start = FIRST(
250-
FOR d IN tinkerpop_vertex
250+
FOR d IN vertex
251251
FILTER d.code == @start
252252
RETURN d
253253
)
254254
255255
LET target = FIRST(
256-
FOR d IN tinkerpop_vertex
256+
FOR d IN vertex
257257
FILTER d.code == @target
258258
RETURN d
259259
)
@@ -278,7 +278,7 @@ public static void main(String[] args) {
278278

279279
String traversalQuery = """
280280
LET start = FIRST(
281-
FOR d IN tinkerpop_vertex
281+
FOR d IN vertex
282282
FILTER d.code == @start
283283
RETURN d
284284
)

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<groupId>com.arangodb</groupId>
1414
<artifactId>arangodb-tinkerpop-provider</artifactId>
15-
<version>3.0.1</version>
15+
<version>3.1.0-SNAPSHOT</version>
1616
<packaging>jar</packaging>
1717

1818
<name>arangodb-tinkerpop-provider</name>

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,28 @@
2020

2121
public abstract class ElementId {
2222

23-
protected final String prefix;
2423
protected final String collection;
2524
protected String key;
2625

2726
public static void validateIdParts(String... names) {
2827
for (String name : names) {
2928
if (name == null)
3029
continue;
31-
if (name.contains("_")) {
32-
throw new IllegalArgumentException(String.format("id part (%s) contains invalid character '_'", name));
33-
}
3430
if (name.contains("/")) {
3531
throw new IllegalArgumentException(String.format("id part (%s) contains invalid character '/'", name));
3632
}
3733
}
3834
}
3935

40-
protected ElementId(String prefix, String collection, String key) {
41-
this.prefix = prefix;
36+
protected ElementId(String collection, String key) {
4237
this.collection = collection;
4338
this.key = key;
4439
}
4540

4641
public abstract String getLabel();
4742

4843
public String getCollection() {
49-
return prefix + "_" + collection;
44+
return collection;
5045
}
5146

5247
public abstract String getId();
@@ -64,7 +59,7 @@ public String toJson() {
6459
if (key == null) {
6560
return null;
6661
} else {
67-
return prefix + "_" + collection + "/" + key;
62+
return collection + "/" + key;
6863
}
6964
}
7065

@@ -77,12 +72,12 @@ public String toString() {
7772
public boolean equals(Object o) {
7873
if (!(o instanceof ElementId)) return false;
7974
ElementId elementId = (ElementId) o;
80-
return Objects.equals(prefix, elementId.prefix) && Objects.equals(collection, elementId.collection) && Objects.equals(key, elementId.key);
75+
return Objects.equals(collection, elementId.collection) && Objects.equals(key, elementId.key);
8176
}
8277

8378
@Override
8479
public int hashCode() {
85-
return Objects.hash(prefix, collection, key);
80+
return Objects.hash(collection, key);
8681
}
8782

8883
}

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ protected ElementIdFactory(ArangoDBGraphConfig config) {
5555

5656
protected abstract void validateId(String id, String label);
5757

58-
protected abstract ElementId doCreate(String prefix, String collection, String key);
58+
protected abstract ElementId doCreate(String collection, String key);
5959

6060
private String extractKey(final String id) {
6161
String[] parts = id.split("/");
6262
return parts[parts.length - 1];
6363
}
6464

6565
private String extractCollection(final String id) {
66-
String[] parts = id.replaceFirst("^" + config.prefix, "").split("/");
66+
String[] parts = id.split("/");
6767
if (parts.length > 2) {
6868
throw new IllegalArgumentException(String.format("key (%s) contains invalid character '/'", id));
6969
}
@@ -113,18 +113,18 @@ public List<ElementId> parseEdgeIds(Object[] ids) {
113113
public ElementId parseId(String id) {
114114
String collection = extractCollection(id);
115115
String key = extractKey(id);
116-
return of(config.graphName, collection, key);
116+
return of(collection, key);
117117
}
118118

119119
private ElementId parseWithDefaultCollection(String id, String defaultCollection) {
120120
String collection = inferCollection(extractCollection(id), null, defaultCollection);
121121
String key = extractKey(id);
122-
return of(config.graphName, collection, key);
122+
return of(collection, key);
123123
}
124124

125125
private ElementId createId(String label, Object nullableId, String defaultCollection) {
126126
if (nullableId == null) {
127-
return of(config.graphName, inferCollection(null, label, defaultCollection), null);
127+
return of(inferCollection(null, label, defaultCollection), null);
128128
}
129129

130130
if (!(nullableId instanceof String)) {
@@ -133,13 +133,12 @@ private ElementId createId(String label, Object nullableId, String defaultCollec
133133

134134
String id = (String) nullableId;
135135
validateId(id, label);
136-
return of(config.graphName, inferCollection(extractCollection(id), label, defaultCollection), extractKey(id));
136+
return of(inferCollection(extractCollection(id), label, defaultCollection), extractKey(id));
137137
}
138138

139-
private ElementId of(String graphName, String collection, String key) {
140-
Objects.requireNonNull(graphName);
139+
private ElementId of(String collection, String key) {
141140
Objects.requireNonNull(collection);
142-
ElementId.validateIdParts(graphName, collection, key);
143-
return doCreate(graphName, collection, key);
141+
ElementId.validateIdParts(collection, key);
142+
return doCreate(collection, key);
144143
}
145144
}

src/main/java/com/arangodb/tinkerpop/gremlin/persistence/complex/ComplexElementIdFactory.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ protected String inferCollection(final String collection, final String label, fi
5555

5656
@Override
5757
protected void validateId(String id, String label) {
58-
if (id.contains("_")) {
59-
throw new IllegalArgumentException(String.format("id (%s) contains invalid character '_'", id));
60-
}
6158
int idx = id.indexOf('/');
6259
if (idx <= 0) {
6360
String l = label != null ? label : "<label>";
@@ -72,8 +69,8 @@ protected void validateId(String id, String label) {
7269
}
7370

7471
@Override
75-
protected ElementId doCreate(String prefix, String collection, String key) {
76-
return new ComplexId(prefix, collection, key);
72+
protected ElementId doCreate(String collection, String key) {
73+
return new ComplexId(collection, key);
7774
}
7875

7976
}

src/main/java/com/arangodb/tinkerpop/gremlin/persistence/complex/ComplexId.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
public class ComplexId extends ElementId {
2222

23-
public ComplexId(String prefix, String collection, String key) {
24-
super(prefix, collection, key);
23+
public ComplexId(String collection, String key) {
24+
super(collection, key);
2525
}
2626

2727
@Override

src/main/java/com/arangodb/tinkerpop/gremlin/persistence/simple/SimpleElementIdFactory.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ public class SimpleElementIdFactory extends ElementIdFactory {
2828

2929
public SimpleElementIdFactory(ArangoDBGraphConfig config) {
3030
super(config);
31-
defaultVertexCollection = config.vertices.iterator().next()
32-
.replaceFirst(config.prefix, "");
33-
defaultEdgeCollection = config.edges.iterator().next()
34-
.replaceFirst(config.prefix, "");
31+
defaultVertexCollection = config.vertices.iterator().next();
32+
defaultEdgeCollection = config.edges.iterator().next();
3533
}
3634

3735
@Override
@@ -51,16 +49,13 @@ protected String inferCollection(final String collection, final String label, fi
5149

5250
@Override
5351
protected void validateId(String id, String label) {
54-
if (id.contains("_")) {
55-
throw new IllegalArgumentException(String.format("id (%s) contains invalid character '_'", id));
56-
}
5752
if (id.contains("/")) {
5853
throw new IllegalArgumentException(String.format("id (%s) contains invalid character '/'", id));
5954
}
6055
}
6156

6257
@Override
63-
protected ElementId doCreate(String prefix, String collection, String key) {
64-
return new SimpleId(prefix, collection, key);
58+
protected ElementId doCreate(String collection, String key) {
59+
return new SimpleId(collection, key);
6560
}
6661
}

src/main/java/com/arangodb/tinkerpop/gremlin/persistence/simple/SimpleId.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
public class SimpleId extends ElementId {
2222

23-
public SimpleId(String prefix, String collection, String key) {
24-
super(prefix, collection, key);
23+
public SimpleId(String collection, String key) {
24+
super(collection, key);
2525
}
2626

2727
@Override

0 commit comments

Comments
 (0)