From 31c8c68bb39ee9bdb5cf919fae4e0747394a25d1 Mon Sep 17 00:00:00 2001 From: Marco Brandizi Date: Thu, 14 Mar 2024 11:41:40 +0000 Subject: [PATCH] XNeo4jDriver, minor improvements. --- .../rothamsted/neo4j/utils/XNeo4jDriver.java | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/neo4j-utils/src/main/java/uk/ac/rothamsted/neo4j/utils/XNeo4jDriver.java b/neo4j-utils/src/main/java/uk/ac/rothamsted/neo4j/utils/XNeo4jDriver.java index f9e1c4a..2988fd6 100644 --- a/neo4j-utils/src/main/java/uk/ac/rothamsted/neo4j/utils/XNeo4jDriver.java +++ b/neo4j-utils/src/main/java/uk/ac/rothamsted/neo4j/utils/XNeo4jDriver.java @@ -22,6 +22,8 @@ * An extended version of the {@link Driver Neo4j driver class}, which has * some utilities, such as keeping a default DB name and using it with a * {@link #defaultSessionConfig()}. + * + * TODO: * * @author Marco Brandizi *
Date:
13 Mar 2024
@@ -30,15 +32,14 @@ public class XNeo4jDriver implements Driver { private Driver driver; + private String databaseName; private SessionConfig defaultSessionConfig; public XNeo4jDriver ( Driver driver, String databaseName ) { super (); this.driver = driver; - this.defaultSessionConfig = databaseName == null - ? SessionConfig.defaultConfig () - : SessionConfig.forDatabase ( databaseName ); + this.defaultSessionConfig = sessionConfigBuilder ().build (); } /** @@ -58,15 +59,38 @@ public XNeo4jDriver ( Driver driver ) { * with this default, eg, {@link #session()}, {@link #session(Class)} create * sessions that use this. * + * If the database name is null, this defaults to {@link SessionConfig#defaultConfig()}. + * + * Note that this session config is cached, so, if you don't need a custom session config, + * this is a bit faster than {@link #sessionConfigBuilder()}. + * * The original database name can be fetched via {@link SessionConfig#database()}. * - * If the database name is null, this defaults to {@link SessionConfig#defaultConfig()}. + * */ public SessionConfig defaultSessionConfig () { return defaultSessionConfig; } + /** + * An initial session builder which embeds the database name. + * + * This can be used as an alternative to {@link #defaultSessionConfig()}, + * to build a custom session with the parameters you wish. + * + * Note that {@link #defaultSessionConfig()} is cached, so, if you don't need + * a special session, use that method. + */ + public SessionConfig.Builder sessionConfigBuilder () + { + SessionConfig.Builder builder = SessionConfig.builder (); + if ( databaseName != null ) builder = builder.withDatabase ( databaseName ); + return builder; + } + + + public ExecutableQuery executableQuery ( String query ) { return driver.executableQuery ( query );