Skip to content

Commit

Permalink
XNeo4jDriver, minor improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-brandizi committed Mar 14, 2024
1 parent ea5a466 commit 31c8c68
Showing 1 changed file with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <dl><dt>Date:</dt><dd>13 Mar 2024</dd></dl>
Expand All @@ -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 ();
}

/**
Expand All @@ -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 );
Expand Down

0 comments on commit 31c8c68

Please sign in to comment.