Skip to content

Commit 25d8c0f

Browse files
s1ckknutwalkerbreakanalysis
committed
Allow setting database name in @GdlGraph
Co-Authored-By: Paul Horn <paul.horn@neotechnology.com> Co-Authored-By: Jacob Sznajdman <breakanalysis@gmail.com>
1 parent fb70ff3 commit 25d8c0f

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

test-utils/src/main/java/org/neo4j/gds/extension/BaseGdlSupportExtension.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252

5353
public abstract class BaseGdlSupportExtension {
5454

55-
public static final DatabaseId DATABASE_ID = DatabaseId.of("GDL");
55+
static final String DATABASE_NAME = "GDL";
56+
public static final DatabaseId DATABASE_ID = DatabaseId.of(DATABASE_NAME);
5657

5758
void beforeAction(ExtensionContext context) {
5859
Class<?> requiredTestClass = context.getRequiredTestClass();
@@ -113,6 +114,7 @@ private static Stream<GdlGraphSetup> gdlGraphsForField(Field field) {
113114
.indexInverse(annotation.indexInverse())
114115
.idOffset(annotation.idOffset())
115116
.addToCatalog(annotation.addToCatalog())
117+
.databaseId(DatabaseId.of(annotation.databaseName()))
116118
.build()
117119
);
118120
}
@@ -137,7 +139,7 @@ private static void injectGraphStore(GdlGraphSetup gdlGraphSetup, ExtensionConte
137139
.builder()
138140
.nodeIdFunction(nodeIdFunction)
139141
.graphProjectConfig(graphProjectConfig)
140-
.databaseId(DATABASE_ID)
142+
.databaseId(gdlGraphSetup.databaseId())
141143
.build();
142144

143145
GraphDimensions dimensions = gdlFactory.dimensions();
@@ -198,5 +200,8 @@ interface GdlGraphSetup {
198200
default boolean addToCatalog() {
199201
return false;
200202
}
203+
204+
@Value.Auxiliary
205+
DatabaseId databaseId();
201206
}
202207
}

test-utils/src/main/java/org/neo4j/gds/extension/GdlGraph.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,9 @@
6262
* {@code 'graph'} if no prefix is set.
6363
*/
6464
boolean addToCatalog() default false;
65+
66+
/**
67+
* If set, the graph will be created using the specified database.
68+
*/
69+
String databaseName() default BaseGdlSupportExtension.DATABASE_NAME;
6570
}

test-utils/src/test/java/org/neo4j/gds/extension/GdlSupportPerMethodExtensionTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.neo4j.gds.extension;
2121

2222
import org.junit.jupiter.api.Test;
23+
import org.neo4j.gds.api.GraphStore;
2324

2425
import static org.assertj.core.api.Assertions.assertThat;
2526

@@ -33,6 +34,7 @@ class GdlSupportPerMethodExtensionTest {
3334
@Inject
3435
private IdFunction idOffsetIdFunction;
3536

37+
3638
@Test
3739
void testIdOffset() {
3840
assertThat(idOffsetGraph.nodeCount()).isEqualTo(2L);
@@ -42,4 +44,24 @@ void testIdOffset() {
4244
assertThat(idOffsetGraph.toMappedNodeId(42L)).isEqualTo(0L);
4345
assertThat(idOffsetGraph.toMappedNodeId(43L)).isEqualTo(1L);
4446
}
47+
48+
@GdlGraph(graphNamePrefix = "withoutDatabase")
49+
public static final String WITHOUT_DATABASE_GRAPH = "(a)-[:REL]->(b)";
50+
@Inject
51+
private GraphStore withoutDatabaseGraphStore;
52+
53+
@Test
54+
void withoutDatabaseName() {
55+
assertThat(withoutDatabaseGraphStore.databaseInfo().databaseId().databaseName()).isEqualTo("gdl");
56+
}
57+
58+
@GdlGraph(graphNamePrefix = "withDatabase", databaseName = "foobar")
59+
public static final String WITH_DATABASE_GRAPH = "(a)-[:REL]->(b)";
60+
@Inject
61+
private GraphStore withDatabaseGraphStore;
62+
63+
@Test
64+
void withDatabaseName() {
65+
assertThat(withDatabaseGraphStore.databaseInfo().databaseId().databaseName()).isEqualTo("foobar");
66+
}
4567
}

0 commit comments

Comments
 (0)