Skip to content

Commit

Permalink
Use the supportMultiDb feature detection result, to choose the databa…
Browse files Browse the repository at this point in the history
…se to connect.
  • Loading branch information
Zhen Li committed Nov 29, 2019
1 parent 19a4bd7 commit ec65910
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@
import org.neo4j.driver.internal.spi.Connection;

import static org.neo4j.driver.internal.DatabaseNameUtil.defaultDatabase;
import static org.neo4j.driver.internal.DatabaseNameUtil.systemDatabase;
import static org.neo4j.driver.internal.InternalBookmark.empty;

/**
* A {@link Connection} shall fulfil this {@link ImmutableConnectionContext} when acquired from a connection provider.
*/
public class ImmutableConnectionContext implements ConnectionContext
{
private static final ConnectionContext SIMPLE = new ImmutableConnectionContext( defaultDatabase(), empty(), AccessMode.READ );
private static final ConnectionContext SINGLE_DB_CONTEXT = new ImmutableConnectionContext( defaultDatabase(), empty(), AccessMode.READ );
private static final ConnectionContext MULTI_DB_CONTEXT = new ImmutableConnectionContext( systemDatabase(), empty(), AccessMode.READ );

private final DatabaseName databaseName;
private final AccessMode mode;
Expand Down Expand Up @@ -65,10 +67,10 @@ public Bookmark rediscoveryBookmark()
/**
* A simple context is used to test connectivity with a remote server/cluster.
* As long as there is a read only service, the connection shall be established successfully.
* This context should be applicable for both bolt v4 and bolt v3 routing table rediscovery.
* Depending on whether multidb is supported or not, this method returns different context for routing table discovery.
*/
public static ConnectionContext simple()
public static ConnectionContext simple( boolean supportsMultiDb )
{
return SIMPLE;
return supportsMultiDb ? MULTI_DB_CONTEXT : SINGLE_DB_CONTEXT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,20 @@ public CompletionStage<Connection> acquireConnection( ConnectionContext context
@Override
public CompletionStage<Void> verifyConnectivity()
{
return routingTables.refreshRoutingTable( simple() ).handle( ( ignored, error ) -> {
return this.supportsMultiDbAsync().handle( ( supports, error ) -> {
if ( error != null )
{
Throwable cause = Futures.completionExceptionCause( error );
if ( cause instanceof ServiceUnavailableException )
{
throw Futures.asCompletionException( new ServiceUnavailableException(
"Unable to connect to database, ensure the database is running and that there is a working network connection to it.", cause ) );
"Unable to connect to database management service, ensure the database is running and that there is a working network connection to it.",
cause ) );
}
throw Futures.asCompletionException( cause );
}
return null;
} );
return supports;
} ).thenCompose( supports -> routingTables.refreshRoutingTable( simple( supports ) ) ).thenApply( ignored -> null );
}

@Override
Expand Down

0 comments on commit ec65910

Please sign in to comment.