private DataSource createDataSource(Config config) throws ClassNotFoundException { String url = config.getParameter(ExtConfig.JDBC_URL); String username = config.getParameter(ExtConfig.JDBC_USERNAME); String password = config.getParameter(ExtConfig.JDBC_PASSWORD); JdbcDataSource dataSource = new JdbcDataSource(); dataSource.setUrl(url); dataSource.setUser(username); dataSource.setPassword(password); return dataSource; }
private DataSource createDataSource(Config config) throws ClassNotFoundException { String url = config.getParameter(ExtConfig.JDBC_URL); String username = config.getParameter(ExtConfig.JDBC_USERNAME); String password = config.getParameter(ExtConfig.JDBC_PASSWORD); JdbcDataSource dataSource = new JdbcDataSource(); dataSource.setUrl(url); dataSource.setUser(username); dataSource.setPassword(password); return dataSource; }
@Override DataSource createDataSource() { JdbcDataSource dataSource = new JdbcDataSource(); dataSource.setUrl("jdbc:h2:~/testh2"); dataSource.setUser("sa"); dataSource.setPassword("sa"); return dataSource; } },
private Connection setupEmptySource() throws SQLException { JdbcDataSource dataSource = new JdbcDataSource(); dataSource.setUrl("jdbc:h2:mem:empty"); return dataSource.getConnection(); } }
@Override public DataSource getDataSource() { final JdbcDataSource dataSource = new JdbcDataSource(); dataSource.setUrl(getUrl()); return dataSource; }
@Override public void start() { final JdbcDataSource dataSource = new JdbcDataSource(); dataSource.setUrl(getUrl() + ";DB_CLOSE_DELAY=-1"); try (Connection conn = dataSource.getConnection()) { RunScript.execute(conn, new StringReader("SELECT 1")); } catch (SQLException x) { throw new RuntimeException(x); } }
private void createSimpleDataSource() { String url = DatabaseConfig.buildJdbcUrl(config); // By default, H2 closes database when all of the connections are closed. When database // is closed, data is gone with in-memory mode. It's unexpected. However, if here disables // that such behavior using DB_CLOSE_DELAY=-1 option, there're no methods to close the // database explicitly. Only way to close is to not disable shutdown hook of H2 database // (DB_CLOSE_ON_EXIT=TRUE). But this also causes unexpected behavior when PreDestroy is // triggered in a shutdown hook. Therefore, here needs to rely on injector to take care of // dependencies so that the database is closed after calling all other PreDestroy methods // that depend on this DataSourceProvider. // To solve this issue, here holds one Connection until PreDestroy. JdbcDataSource ds = new JdbcDataSource(); ds.setUrl(url + ";DB_CLOSE_ON_EXIT=FALSE"); logger.debug("Using database URL {}", url); try { this.closer = ds.getConnection(); } catch (SQLException ex) { throw Throwables.propagate(ex); } this.ds = ds; }
private Connection setupDataSource(File file) throws SQLException, IOException { JdbcDataSource dataSource = new JdbcDataSource(); dataSource.setUrl("jdbc:h2:mem:test"); String script = FileUtils.readAsString(file); Connection connection = dataSource.getConnection(); SqlUtils.executeSql(connection, script, ";"); return connection; }
@Override protected synchronized void before() throws Throwable { final UUID uuid = UUID.randomUUID(); this.pool = new JdbcDataSource(); this.pool.setUrl("jdbc:h2:mem:" + uuid.toString() + ";MODE=PostgreSQL"); this.pool.setUser("h2"); this.pool.setPassword("h2"); this.conn = this.pool.getConnection(); }
private DataSource createDataSource(Config config) throws ClassNotFoundException { String url = config.getParameter(ExtConfig.JDBC_URL); String username = config.getParameter(ExtConfig.JDBC_USERNAME); String password = config.getParameter(ExtConfig.JDBC_PASSWORD); JdbcDataSource dataSource = new JdbcDataSource(); dataSource.setUrl(url); dataSource.setUser(username); dataSource.setPassword(password); return dataSource; }
public void runScriptPreInitialize(InputStream scriptStream) { JdbcDataSource jds = new JdbcDataSource(); String url = "jdbc:h2:mem:" + databaseName + ";DB_CLOSE_DELAY=-1"; jds.setUrl(url); JdbcConnectionPool dataSource = JdbcConnectionPool.create(jds); dataSource.dispose(); }
JdbcDataSource jds = new JdbcDataSource(); String url = "jdbc:h2:mem:" + databaseName + ";DB_CLOSE_DELAY=-1"; jds.setUrl(url); dataSource = JdbcConnectionPool.create(jds); transactionManager = new DataSourceTransactionManager(dataSource);