Skip to content

Commit 90069a2

Browse files
committed
Replace GraphProjectConfig#graphStoreFactory with service loading
1 parent 2ac4adf commit 90069a2

File tree

22 files changed

+266
-184
lines changed

22 files changed

+266
-184
lines changed

applications/graph-store-catalog/src/main/java/org/neo4j/gds/applications/graphstorecatalog/GraphStoreFromDatabaseLoader.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.neo4j.gds.api.ResultStore;
2626
import org.neo4j.gds.config.GraphProjectConfig;
2727
import org.neo4j.gds.core.GraphDimensions;
28-
import org.neo4j.gds.core.ImmutableGraphLoader;
28+
import org.neo4j.gds.core.GraphStoreFactorySupplier;
2929
import org.neo4j.gds.mem.MemoryEstimation;
3030

3131
public class GraphStoreFromDatabaseLoader implements GraphStoreCreator {
@@ -79,12 +79,6 @@ public MemoryEstimation estimateMemoryUsageAfterLoading() {
7979
}
8080

8181
private GraphStoreFactory<?, ?> graphStoreFactory() {
82-
return ImmutableGraphLoader
83-
.builder()
84-
.context(graphLoaderContext)
85-
.username(username)
86-
.projectConfig(graphProjectConfig)
87-
.build()
88-
.graphStoreFactory();
82+
return GraphStoreFactorySupplier.supplier(graphProjectConfig).get(graphLoaderContext);
8983
}
9084
}

applications/graph-store-catalog/src/test/java/org/neo4j/gds/applications/graphstorecatalog/StubGraphProjectConfig.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ public Map<String, Object> asProcedureResultConfigurationField() {
5858
throw new UnsupportedOperationException("TODO");
5959
}
6060

61-
// @Override
62-
// public GraphStoreFactory.Supplier graphStoreFactory() {
63-
// throw new UnsupportedOperationException("TODO");
64-
// }
65-
6661
@Override
6762
public Optional<String> usernameOverride() {
6863
throw new UnsupportedOperationException("TODO");

config-api/src/main/java/org/neo4j/gds/config/GraphProjectConfig.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,6 @@ default boolean validateRelationships() {
9595
return false;
9696
}
9797

98-
// @Configuration.Ignore
99-
// default GraphStoreFactory.Supplier graphStoreFactory() {
100-
// return loaderContext -> {
101-
// throw new UnsupportedOperationException("GraphStoreFactory not set");
102-
// };
103-
// }
104-
10598
@Configuration.Check
10699
default void validateReadConcurrency() {
107100
ConcurrencyValidatorService

config-api/src/main/java/org/neo4j/gds/config/GraphProjectFromGraphConfig.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,6 @@ default Map<String, Object> parameters() {
8080
return Collections.emptyMap();
8181
}
8282

83-
// @Configuration.Ignore
84-
// @Override
85-
// default GraphStoreFactory.Supplier graphStoreFactory() {
86-
// return originalConfig().graphStoreFactory();
87-
// }
88-
8983
// Inherited, but ignored config keys
9084

9185
@Override

config-api/src/main/java/org/neo4j/gds/config/GraphSampleProcConfig.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,4 @@ default Map<String, Object> asProcedureResultConfigurationField() {
4646
@Configuration.Parameter
4747
GraphSampleAlgoConfig sampleAlgoConfig();
4848

49-
// @Configuration.Ignore
50-
// @Override
51-
// default GraphStoreFactory.Supplier graphStoreFactory() {
52-
// return originalConfig().graphStoreFactory();
53-
// }
54-
5549
}

config-api/src/main/java/org/neo4j/gds/config/RandomGraphGeneratorConfig.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,6 @@ default RelationshipProjections relationshipProjections() {
116116
.build();
117117
}
118118

119-
// @Configuration.Ignore
120-
// @Override
121-
// default GraphStoreFactory.Supplier graphStoreFactory() {
122-
// // TODO: maybe we could introduce a RandomGraphFactory
123-
// throw new UnsupportedOperationException("RandomGraphGeneratorConfig requires explicit graph generation.");
124-
// }
125-
126119
@Configuration.Ignore
127120
default Set<String> outputFieldDenylist() {
128121
return Set.of(READ_CONCURRENCY_KEY, NODE_COUNT_KEY, RELATIONSHIP_COUNT_KEY, "validateRelationships");

core/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ dependencies {
2424
implementation project(':config-api')
2525
implementation project(':core-utils')
2626
implementation project(':gds-values')
27+
implementation project(':graph-schema-api')
2728
implementation project(':licensing')
2829
implementation project(':logging')
29-
implementation project(':graph-schema-api')
3030
implementation project(':memory-usage')
3131
implementation project(':open-licensing')
3232
implementation project(':string-formatting')
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.neo4j.gds.api;
21+
22+
import org.neo4j.annotations.service.Service;
23+
import org.neo4j.gds.config.GraphProjectConfig;
24+
25+
@Service
26+
public interface GraphStoreFactorySupplierProvider {
27+
boolean canSupplyFactoryFor(GraphProjectConfig graphProjectConfig);
28+
GraphStoreFactory.Supplier supplier(GraphProjectConfig graphProjectConfig);
29+
}

core/src/main/java/org/neo4j/gds/core/GraphLoader.java

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,36 @@
1919
*/
2020
package org.neo4j.gds.core;
2121

22-
import org.immutables.value.Value;
23-
import org.neo4j.gds.annotation.ValueClass;
2422
import org.neo4j.gds.api.Graph;
25-
import org.neo4j.gds.api.GraphLoaderContext;
2623
import org.neo4j.gds.api.GraphStore;
2724
import org.neo4j.gds.api.GraphStoreFactory;
2825
import org.neo4j.gds.config.GraphProjectConfig;
2926

30-
@ValueClass
31-
public interface GraphLoader {
27+
public class GraphLoader {
28+
private final GraphProjectConfig projectConfig;
29+
private final GraphStoreFactory<? extends GraphStore, ? extends GraphProjectConfig> graphStoreFactory;
3230

33-
GraphLoaderContext context();
34-
35-
@Value.Default
36-
default String username() {
37-
return projectConfig().username();
31+
public GraphLoader(
32+
GraphProjectConfig projectConfig,
33+
GraphStoreFactory<? extends GraphStore, ? extends GraphProjectConfig> graphStoreFactory
34+
) {
35+
this.projectConfig = projectConfig;
36+
this.graphStoreFactory = graphStoreFactory;
3837
}
3938

40-
GraphProjectConfig projectConfig();
41-
42-
default Graph graph() {
39+
public Graph graph() {
4340
return graphStore().getUnion();
4441
}
4542

46-
default GraphStore graphStore() {
47-
return graphStoreFactory().build();
43+
public GraphStore graphStore() {
44+
return graphStoreFactory.build();
45+
}
46+
47+
public GraphProjectConfig projectConfig() {
48+
return projectConfig;
4849
}
4950

50-
default GraphStoreFactory<? extends GraphStore, ? extends GraphProjectConfig> graphStoreFactory() {
51-
return GraphStoreFactorySupplier
52-
.supplier(projectConfig())
53-
.get(context());
51+
public GraphStoreFactory<? extends GraphStore, ? extends GraphProjectConfig> graphStoreFactory() {
52+
return graphStoreFactory;
5453
}
5554
}

core/src/main/java/org/neo4j/gds/core/GraphStoreFactorySupplier.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,37 @@
2020
package org.neo4j.gds.core;
2121

2222
import org.neo4j.gds.api.GraphStoreFactory;
23+
import org.neo4j.gds.api.GraphStoreFactorySupplierProvider;
2324
import org.neo4j.gds.config.GraphProjectConfig;
2425

26+
import java.util.List;
27+
import java.util.ServiceLoader;
28+
import java.util.stream.Collectors;
29+
30+
import static org.neo4j.gds.utils.StringFormatting.formatWithLocale;
31+
2532
public final class GraphStoreFactorySupplier {
2633

2734
private GraphStoreFactorySupplier() {}
2835

29-
public static GraphStoreFactory.Supplier supplier(GraphProjectConfig graphProjectConfig) {
30-
return null;
36+
private static final List<GraphStoreFactorySupplierProvider> PROVIDERS;
37+
38+
static {
39+
PROVIDERS = ServiceLoader
40+
.load(GraphStoreFactorySupplierProvider.class, GraphStoreFactorySupplierProvider.class.getClassLoader())
41+
.stream()
42+
.map(ServiceLoader.Provider::get)
43+
.collect(Collectors.toList());
3144
}
3245

46+
public static GraphStoreFactory.Supplier supplier(GraphProjectConfig graphProjectConfig) {
47+
return PROVIDERS.stream()
48+
.filter(f -> f.canSupplyFactoryFor(graphProjectConfig))
49+
.findFirst()
50+
.orElseThrow(() -> new UnsupportedOperationException(formatWithLocale(
51+
"%s does not support GraphStoreFactory creation",
52+
graphProjectConfig.getClass().getName()
53+
)))
54+
.supplier(graphProjectConfig);
55+
}
3356
}

0 commit comments

Comments
 (0)