Skip to content

Commit e62f21c

Browse files
committed
chore: generate database configuration adapter
Signed-off-by: Otavio Santana <[email protected]>
1 parent c2985fb commit e62f21c

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Apache License v2.0 which accompanies this distribution.
6+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+
*
9+
* You may elect to redistribute this code under either of these licenses.
10+
*
11+
* Contributors:
12+
*
13+
* Otavio Santana
14+
*/
15+
package org.eclipse.jnosql.databases.tinkerpop.communication;
16+
17+
import org.apache.tinkerpop.gremlin.structure.Graph;
18+
import org.eclipse.jnosql.communication.Settings;
19+
import org.eclipse.jnosql.communication.semistructured.DatabaseConfiguration;
20+
import org.eclipse.jnosql.communication.semistructured.DatabaseManager;
21+
import org.eclipse.jnosql.communication.semistructured.DatabaseManagerFactory;
22+
23+
import java.util.logging.Logger;
24+
25+
public class DatabaseConfigurationAdapter implements DatabaseConfiguration {
26+
27+
28+
private static final Logger LOGGER = Logger.getLogger(DatabaseConfigurationAdapter.class.getName());
29+
30+
@Override
31+
public DatabaseManagerFactory apply(Settings settings) {
32+
LOGGER.fine(() -> "Creating graph database manager based on settings and GraphConfiguration SPI");
33+
var configuration = GraphConfiguration.getConfiguration();
34+
var graph = configuration.apply(settings);
35+
return GraphDatabaseManagerFactory.of(graph);
36+
}
37+
38+
static class GraphDatabaseManagerFactory implements DatabaseManagerFactory {
39+
40+
private final Graph graph;
41+
42+
private GraphDatabaseManagerFactory(Graph graph) {
43+
this.graph = graph;
44+
}
45+
46+
@Override
47+
public void close() {
48+
49+
}
50+
51+
@Override
52+
public DatabaseManager apply(String database) {
53+
LOGGER.fine(() -> "Creating graph database manager where we will ignore the database name: " + database);
54+
return TinkerpopGraphDatabaseManager.of(graph);
55+
}
56+
57+
public static GraphDatabaseManagerFactory of(Graph graph) {
58+
return new GraphDatabaseManagerFactory(graph);
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)