public void tearDown() { try { new DBI(jdbcUri + ";drop=true").open().close(); } catch (UnableToObtainConnectionException e) { SQLException cause = (SQLException) e.getCause(); // error code "08006" indicates proper shutdown Assert.assertEquals(String.format("Derby not shutdown: [%s]", cause.toString()), "08006", cause.getSQLState() ); } }
@Override public Connection openConnection() { try { return DERBY_HELPER.getConnection(); } catch (SQLException e) { throw new UnableToObtainConnectionException(e); } } });
public static void createTablesWithRetry(IDBI dbi) { Duration delay = new Duration(2, TimeUnit.SECONDS); while (true) { try (Handle handle = dbi.open()) { createTables(handle.attach(SchemaDao.class)); return; } catch (UnableToObtainConnectionException e) { log.warn("Failed to connect to database. Will retry again in %s. Exception: %s", delay, e.getMessage()); sleep(delay); } } }
@Override public Connection openConnection() { try { return DERBY_HELPER.getConnection(); } catch (SQLException e) { throw new UnableToObtainConnectionException(e); } } });
public static void createTablesWithRetry(IDBI dbi) { Duration delay = new Duration(2, TimeUnit.SECONDS); while (true) { try (Handle handle = dbi.open()) { createTables(handle.attach(SchemaDao.class)); return; } catch (UnableToObtainConnectionException e) { log.warn("Failed to connect to database. Will retry again in %s. Exception: %s", delay, e.getMessage()); sleep(delay); } } }
public Handle open(final ConnectionFactory connectionFactory) { try { final long start = System.nanoTime(); Connection conn = prof.executeWithProfiling(ProfilingFeatureType.DAO_CONNECTION, "get", new WithProfilingCallback<Connection, SQLException>() { @Override public Connection execute() throws SQLException { return connectionFactory.openConnection(); } }); final long stop = System.nanoTime(); StatementBuilder cache = statementBuilderFactory.get().createStatementBuilder(conn); Handle h = new BasicHandle(transactionhandler.get(), statementLocator.get(), cache, statementRewriter.get(), conn, globalStatementAttributes, log.get(), timingCollector.get(), mappingRegistry.createChild(), foreman.createChild(), containerFactoryRegistry.createChild()); log.get().logObtainHandle((stop - start) / 1000000L, h); return h; } catch (SQLException e) { throw new UnableToObtainConnectionException(e); } }
public void tearDown() { try { new DBI(jdbcUri + ";drop=true").open().close(); } catch (UnableToObtainConnectionException e) { SQLException cause = (SQLException) e.getCause(); // error code "08006" indicates proper shutdown Assert.assertEquals(StringUtils.format("Derby not shutdown: [%s]", cause.toString()), "08006", cause.getSQLState()); } }
/** * Obtain a Handle to the data source wrapped by this DBI instance * * @return an open Handle instance */ public Handle open() { try { final long start = System.nanoTime(); Connection conn = connectionFactory.openConnection(); final long stop = System.nanoTime(); StatementBuilder cache = statementBuilderFactory.get().createStatementBuilder(conn); Handle h = new BasicHandle(transactionhandler.get(), statementLocator.get(), cache, statementRewriter.get(), conn, globalStatementAttributes, log.get(), timingCollector.get(), new MappingRegistry(mappingRegistry), foreman.createChild(), containerFactoryRegistry.createChild()); log.get().logObtainHandle((stop - start) / 1000000L, h); return h; } catch (SQLException e) { throw new UnableToObtainConnectionException(e); } }