@Test public void canOnlyConnectOnce() throws CommandException { thrown.expect(CommandException.class); thrown.expectMessage("Already connected"); try { boltStateHandler.connect(); } catch (Throwable e) { fail("Should not throw here: " + e); } boltStateHandler.connect(); }
@Override public void connect( @Nonnull ConnectionConfig connectionConfig, ThrowingAction<CommandException> command) throws CommandException { if (isConnected()) { throw new CommandException("Already connected"); } final AuthToken authToken = AuthTokens.basic(connectionConfig.username(), connectionConfig.password()); try { String previousDatabaseName = activeDatabaseNameAsSetByUser; try { activeDatabaseNameAsSetByUser = connectionConfig.database(); driver = getDriver(connectionConfig, authToken); reconnect(activeDatabaseNameAsSetByUser, previousDatabaseName, command); } catch (org.neo4j.driver.exceptions.ServiceUnavailableException e) { String scheme = connectionConfig.scheme(); String fallbackScheme; switch ( scheme ) { case Scheme.NEO4J_URI_SCHEME: fallbackScheme = Scheme.BOLT_URI_SCHEME; break; case Scheme.NEO4J_LOW_TRUST_URI_SCHEME: fallbackScheme = Scheme.BOLT_LOW_TRUST_URI_SCHEME; break; case Scheme.NEO4J_HIGH_TRUST_URI_SCHEME: fallbackScheme = Scheme.BOLT_HIGH_TRUST_URI_SCHEME; break; default: throw e; } connectionConfig = new ConnectionConfig( fallbackScheme, connectionConfig.host(), connectionConfig.port(), connectionConfig.username(), connectionConfig.password(), connectionConfig.encryption(), connectionConfig.database()); driver = getDriver(connectionConfig, authToken); reconnect(activeDatabaseNameAsSetByUser, previousDatabaseName, command); } } catch (Throwable t) { try { silentDisconnect(); } catch (Exception e) { t.addSuppressed(e); } throw t; } }
BoltStateHandler implements TransactionHandler, Connector, DatabaseManager { @Override public void connect( @Nonnull ConnectionConfig connectionConfig, ThrowingAction<CommandException> command) throws CommandException { if (isConnected()) { throw new CommandException("Already connected"); } final AuthToken authToken = AuthTokens.basic(connectionConfig.username(), connectionConfig.password()); try { String previousDatabaseName = activeDatabaseNameAsSetByUser; try { activeDatabaseNameAsSetByUser = connectionConfig.database(); driver = getDriver(connectionConfig, authToken); reconnect(activeDatabaseNameAsSetByUser, previousDatabaseName, command); } catch (org.neo4j.driver.exceptions.ServiceUnavailableException e) { String scheme = connectionConfig.scheme(); String fallbackScheme; switch ( scheme ) { case Scheme.NEO4J_URI_SCHEME: fallbackScheme = Scheme.BOLT_URI_SCHEME; break; case Scheme.NEO4J_LOW_TRUST_URI_SCHEME: fallbackScheme = Scheme.BOLT_LOW_TRUST_URI_SCHEME; break; case Scheme.NEO4J_HIGH_TRUST_URI_SCHEME: fallbackScheme = Scheme.BOLT_HIGH_TRUST_URI_SCHEME; break; default: throw e; } connectionConfig = new ConnectionConfig( fallbackScheme, connectionConfig.host(), connectionConfig.port(), connectionConfig.username(), connectionConfig.password(), connectionConfig.encryption(), connectionConfig.database()); driver = getDriver(connectionConfig, authToken); reconnect(activeDatabaseNameAsSetByUser, previousDatabaseName, command); } } catch (Throwable t) { try { silentDisconnect(); } catch (Exception e) { t.addSuppressed(e); } throw t; } } }
BoltStateHandler implements TransactionHandler, Connector, DatabaseManager { @Override public void connect( @Nonnull ConnectionConfig connectionConfig, ThrowingAction<CommandException> command) throws CommandException { if (isConnected()) { throw new CommandException("Already connected"); } final AuthToken authToken = AuthTokens.basic(connectionConfig.username(), connectionConfig.password()); try { String previousDatabaseName = activeDatabaseNameAsSetByUser; try { activeDatabaseNameAsSetByUser = connectionConfig.database(); driver = getDriver(connectionConfig, authToken); reconnect(activeDatabaseNameAsSetByUser, previousDatabaseName, command); } catch (org.neo4j.driver.exceptions.ServiceUnavailableException e) { String scheme = connectionConfig.scheme(); String fallbackScheme; switch ( scheme ) { case Scheme.NEO4J_URI_SCHEME: fallbackScheme = Scheme.BOLT_URI_SCHEME; break; case Scheme.NEO4J_LOW_TRUST_URI_SCHEME: fallbackScheme = Scheme.BOLT_LOW_TRUST_URI_SCHEME; break; case Scheme.NEO4J_HIGH_TRUST_URI_SCHEME: fallbackScheme = Scheme.BOLT_HIGH_TRUST_URI_SCHEME; break; default: throw e; } connectionConfig = new ConnectionConfig( fallbackScheme, connectionConfig.host(), connectionConfig.port(), connectionConfig.username(), connectionConfig.password(), connectionConfig.encryption(), connectionConfig.database()); driver = getDriver(connectionConfig, authToken); reconnect(activeDatabaseNameAsSetByUser, previousDatabaseName, command); } } catch (Throwable t) { try { silentDisconnect(); } catch (Exception e) { t.addSuppressed(e); } throw t; } } BoltStateHandler(boolean isInteractive);   BoltStateHandler(TriFunction<String, AuthToken, Config, Driver> driverProvider,
                     boolean isInteractive); }
BoltStateHandler implements TransactionHandler, Connector, DatabaseManager { @Override public void connect( @Nonnull ConnectionConfig connectionConfig, ThrowingAction<CommandException> command) throws CommandException { if (isConnected()) { throw new CommandException("Already connected"); } final AuthToken authToken = AuthTokens.basic(connectionConfig.username(), connectionConfig.password()); try { String previousDatabaseName = activeDatabaseNameAsSetByUser; try { activeDatabaseNameAsSetByUser = connectionConfig.database(); driver = getDriver(connectionConfig, authToken); reconnect(activeDatabaseNameAsSetByUser, previousDatabaseName, command); } catch (org.neo4j.driver.exceptions.ServiceUnavailableException e) { String scheme = connectionConfig.scheme(); String fallbackScheme; switch ( scheme ) { case Scheme.NEO4J_URI_SCHEME: fallbackScheme = Scheme.BOLT_URI_SCHEME; break; case Scheme.NEO4J_LOW_TRUST_URI_SCHEME: fallbackScheme = Scheme.BOLT_LOW_TRUST_URI_SCHEME; break; case Scheme.NEO4J_HIGH_TRUST_URI_SCHEME: fallbackScheme = Scheme.BOLT_HIGH_TRUST_URI_SCHEME; break; default: throw e; } connectionConfig = new ConnectionConfig( fallbackScheme, connectionConfig.host(), connectionConfig.port(), connectionConfig.username(), connectionConfig.password(), connectionConfig.encryption(), connectionConfig.database()); driver = getDriver(connectionConfig, authToken); reconnect(activeDatabaseNameAsSetByUser, previousDatabaseName, command); } } catch (Throwable t) { try { silentDisconnect(); } catch (Exception e) { t.addSuppressed(e); } throw t; } } BoltStateHandler(boolean isInteractive);   BoltStateHandler(TriFunction<String, AuthToken, Config, Driver> driverProvider,
                     boolean isInteractive); @Override void setActiveDatabase(String databaseName); @Override String getActiveDatabaseAsSetByUser(); @Override String getActualDatabaseAsReportedByServer(); @Override void beginTransaction(); @Override void commitTransaction(); @Override void rollbackTransaction(); Neo4jException handleException( Neo4jException e ); @Override boolean isTransactionOpen(); @Override boolean isConnected(); @Override void connect( @Nonnull ConnectionConfig connectionConfig, ThrowingAction<CommandException> command); @Nonnull @Override String getServerVersion(); @Nonnull Optional<BoltResult> runCypher(@Nonnull String cypher,
                                          @Nonnull Map<String, Object> queryParams); void updateActualDbName(@Nonnull ResultSummary resultSummary); void changePassword( @Nonnull ConnectionConfig connectionConfig ); void reset(); void disconnect(); }
BoltStateHandler implements TransactionHandler, Connector, DatabaseManager { @Override public void connect( @Nonnull ConnectionConfig connectionConfig, ThrowingAction<CommandException> command) throws CommandException { if (isConnected()) { throw new CommandException("Already connected"); } final AuthToken authToken = AuthTokens.basic(connectionConfig.username(), connectionConfig.password()); try { String previousDatabaseName = activeDatabaseNameAsSetByUser; try { activeDatabaseNameAsSetByUser = connectionConfig.database(); driver = getDriver(connectionConfig, authToken); reconnect(activeDatabaseNameAsSetByUser, previousDatabaseName, command); } catch (org.neo4j.driver.exceptions.ServiceUnavailableException e) { String scheme = connectionConfig.scheme(); String fallbackScheme; switch ( scheme ) { case Scheme.NEO4J_URI_SCHEME: fallbackScheme = Scheme.BOLT_URI_SCHEME; break; case Scheme.NEO4J_LOW_TRUST_URI_SCHEME: fallbackScheme = Scheme.BOLT_LOW_TRUST_URI_SCHEME; break; case Scheme.NEO4J_HIGH_TRUST_URI_SCHEME: fallbackScheme = Scheme.BOLT_HIGH_TRUST_URI_SCHEME; break; default: throw e; } connectionConfig = new ConnectionConfig( fallbackScheme, connectionConfig.host(), connectionConfig.port(), connectionConfig.username(), connectionConfig.password(), connectionConfig.encryption(), connectionConfig.database()); driver = getDriver(connectionConfig, authToken); reconnect(activeDatabaseNameAsSetByUser, previousDatabaseName, command); } } catch (Throwable t) { try { silentDisconnect(); } catch (Exception e) { t.addSuppressed(e); } throw t; } } BoltStateHandler(boolean isInteractive);   BoltStateHandler(TriFunction<String, AuthToken, Config, Driver> driverProvider,
                     boolean isInteractive); @Override void setActiveDatabase(String databaseName); @Override String getActiveDatabaseAsSetByUser(); @Override String getActualDatabaseAsReportedByServer(); @Override void beginTransaction(); @Override void commitTransaction(); @Override void rollbackTransaction(); Neo4jException handleException( Neo4jException e ); @Override boolean isTransactionOpen(); @Override boolean isConnected(); @Override void connect( @Nonnull ConnectionConfig connectionConfig, ThrowingAction<CommandException> command); @Nonnull @Override String getServerVersion(); @Nonnull Optional<BoltResult> runCypher(@Nonnull String cypher,
                                          @Nonnull Map<String, Object> queryParams); void updateActualDbName(@Nonnull ResultSummary resultSummary); void changePassword( @Nonnull ConnectionConfig connectionConfig ); void reset(); void disconnect();  }