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

Commit 62c5957

Browse files
committed
Adds support for creating graph variables collection if not present
1 parent 52c7111 commit 62c5957

File tree

5 files changed

+59
-6
lines changed

5 files changed

+59
-6
lines changed

src/main/java/com/arangodb/tinkerpop/gremlin/structure/ArangoDBGraph.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -598,10 +598,25 @@ public ArangoDBGraph(Configuration configuration) {
598598

599599
if (graph.exists()) {
600600
ArangoDBUtil.checkGraphForErrors(prefVCols, prefECols, edgeDefinitions, graph, options);
601-
ArangoDBGraphVariables iter = client.getGraphVariables();
602-
if (iter == null) {
603-
throw new ArangoDBGraphException("Existing graph does not have a Variables collection");
604-
}
601+
ArangoDBGraphVariables variables = null;
602+
try {
603+
variables = client.getGraphVariables();
604+
} catch (NullPointerException ex) {
605+
logger.warn("Existing graph missing Graph Variables collection ({}), will attempt to create one.", GRAPH_VARIABLES_COLLECTION);
606+
}
607+
if (variables == null) {
608+
variables = new ArangoDBGraphVariables(name, GRAPH_VARIABLES_COLLECTION, this);
609+
try {
610+
client.insertGraphVariables(variables);
611+
} catch (ArangoDBGraphException ex) {
612+
throw new ArangoDBGraphException(
613+
String.format(
614+
"Unable to add graph variables collection (%s) to existing graph. %s",
615+
ex.getMessage(),
616+
GRAPH_VARIABLES_COLLECTION)
617+
, ex);
618+
}
619+
}
605620
}
606621
else {
607622
graph = client.createGraph(name, edgeDefinitions, options);

src/main/java/com/arangodb/tinkerpop/gremlin/utils/ArangoDBConfigurationBuilder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ public class ArangoDBConfigurationBuilder {
5959
private static final String PROPERTY_KEY_ACQUIRE_HOST_LIST = "arangodb.acquireHostList";
6060
private static final String PROPERTY_KEY_LOAD_BALANCING_STRATEGY = "arangodb.loadBalancingStrategy";
6161
private static final String PROPERTY_KEY_PROTOCOL = "arangodb.protocol";
62-
private static final String PROPERTY_KEY_SHOULD_PREFIX_COLLECTION_NAMES = "arangodb.shouldPrefixCollectionNames";
6362

6463
/** The db name. */
6564
private String dbName = "tinkerpop";
@@ -195,7 +194,7 @@ public BaseConfiguration build() {
195194
config.addProperty(fullPropertyKey(PROPERTY_KEY_HOSTS), hosts.stream().collect(Collectors.joining(",")));
196195
}
197196
if(shouldPrefixCollectionNames != null){
198-
config.addProperty(fullPropertyKey(PROPERTY_KEY_SHOULD_PREFIX_COLLECTION_NAMES), shouldPrefixCollectionNames);
197+
config.addProperty(fullPropertyKey(ArangoDBGraph.PROPERTY_KEY_SHOULD_PREFIX_COLLECTION_NAMES), shouldPrefixCollectionNames);
199198
}
200199

201200
config.addProperty(Graph.GRAPH, ArangoDBGraph.class.getName());

src/main/java/com/arangodb/tinkerpop/gremlin/utils/ArangoDBUtil.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ public static void checkGraphForErrors(
325325
throw new ArangoDBGraphException(String.format("The graph has a surplus edge definition %s", edgeDefinitionString(existing)));
326326
}
327327
}
328+
328329
}
329330

330331
private static void checkGraphVertexCollections(List<String> verticesCollectionNames, ArangoGraph graph, GraphCreateOptions options) {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.arangodb.tinkerpop.gremlin;
2+
3+
import com.arangodb.tinkerpop.gremlin.structure.ArangoDBGraph;
4+
import com.arangodb.tinkerpop.gremlin.utils.ArangoDBConfigurationBuilder;
5+
import org.apache.commons.configuration.Configuration;
6+
7+
import java.io.File;
8+
9+
10+
public class Issue57 {
11+
12+
public static void main(String... args) {
13+
ArangoDBConfigurationBuilder builder = new ArangoDBConfigurationBuilder();
14+
builder.dataBase("Test02")
15+
.graph("Test02Graph01")
16+
.arangoUser("gremlin")
17+
.arangoPassword("gremlin")
18+
.arangoHosts("127.0.0.1:8529")
19+
.withEdgeCollection("testedge")
20+
.withVertexCollection("testfrom")
21+
.withVertexCollection("testto")
22+
.shouldPrefixCollectionNamesWithGraphName(false)
23+
.configureEdge("testedge", "testfrom", "testto");
24+
25+
ArangoDBGraph g = ArangoDBGraph.open(builder.build());
26+
}
27+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
gremlin.graph = com.arangodb.tinkerpop.gremlin.structure.ArangoDBGraph
2+
gremlin.arangodb.conf.graph.db = Test02
3+
gremlin.arangodb.conf.graph.name = Test02Graph01
4+
gremlin.arangodb.conf.graph.vertex = testfrom
5+
gremlin.arangodb.conf.graph.vertex = testto
6+
gremlin.arangodb.conf.graph.edge = testedge
7+
gremlin.arangodb.conf.graph.relation = testedge:testfrom->testto
8+
gremlin.arangodb.conf.graph.shouldPrefixCollectionNames = false
9+
gremlin.arangodb.conf.arangodb.hosts = 127.0.0.1:8529
10+
gremlin.arangodb.conf.arangodb.user = xxxx
11+
gremlin.arangodb.conf.arangodb.password = xxxx

0 commit comments

Comments
 (0)