@Override public void migrate(Connection connection) throws Exception { if ("sqlserver".equals(type) || "hsqldb".equals(type)) { //we don't have this problem with sqlserver or in memory DB logger.info("Skipping 4.0.4 migration for " + type + ", not affected by 3.9.9 back ports."); return; } ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); SingleConnectionDataSource dataSource = new SingleConnectionDataSource(connection, true); JdbcTemplate template = new JdbcTemplate(dataSource); boolean run = false; for (Map.Entry<String, String> script : getScripts()) { int count = template.queryForObject(checkExistsSql, Integer.class, script.getKey()); if (count == 0) { String path = "org/cloudfoundry/identity/uaa/db/" + type + "/" + script.getValue(); logger.info(String.format("[4.0.4] Adding script for version %s with path %s", script.getKey(), path)); populator.addScript(new ClassPathResource(path)); run = true; } } if (run) { logger.info("Running missing migrations."); populator.setContinueOnError(false); populator.setIgnoreFailedDrops(true); populator.populate(connection); logger.info("Completed missing migrations."); } else { logger.info("Skipping 4.0.4 migrations, no migrations missing."); } }
@AfterClass public static void dropDatabase() throws Exception { DATABASE_HELPER.getDataSource().destroy(); }
/** * Specifying a custom username and password doesn't make sense * with a single Connection. Returns the single Connection if given * the same username and password; throws a SQLException else. */ @Override public Connection getConnection(String username, String password) throws SQLException { if (ObjectUtils.nullSafeEquals(username, getUsername()) && ObjectUtils.nullSafeEquals(password, getPassword())) { return getConnection(); } else { throw new SQLException("SingleConnectionDataSource does not support custom username and password"); } }
public void createDatabase() throws Exception { // Use a different connection url so the tests can run in parallel String connectionUrl; String sqlClassPathResource; if (!withAclClassIdType) { connectionUrl = "jdbc:hsqldb:mem:lookupstrategytest"; sqlClassPathResource = ACL_SCHEMA_SQL_FILE; } else { connectionUrl = "jdbc:hsqldb:mem:lookupstrategytestWithAclClassIdType"; sqlClassPathResource = ACL_SCHEMA_SQL_FILE_WITH_ACL_CLASS_ID; } dataSource = new SingleConnectionDataSource(connectionUrl, "sa", "", true); dataSource.setDriverClassName("org.hsqldb.jdbcDriver"); jdbcTemplate = new JdbcTemplate(dataSource); Resource resource = new ClassPathResource(sqlClassPathResource); String sql = new String(FileCopyUtils.copyToByteArray(resource.getInputStream())); jdbcTemplate.execute(sql); }
@Bean public DataSource dataSource() { SingleConnectionDataSource dataSource = new SingleConnectionDataSource(); dataSource.setSuppressClose(true); dataSource.setUrl(""); dataSource.setUsername("scott"); dataSource.setPassword("tiger"); return dataSource; }
public static SingleConnectionDataSource getDataSourceFrom(String databaseFile) { SingleConnectionDataSource dataSource = new SingleConnectionDataSource(); dataSource.setDriverClassName("org.sqlite.JDBC"); dataSource.setUrl("jdbc:sqlite:" + databaseFile); return dataSource; }
ds = new SingleConnectionDataSource(connUrl, username, password, true); ds.setConnectionProperties(properties); new SingleConnectionDataSource(connUrl, hiveAdminUserName, hiveAdminUserPassword, true) );
SingleConnectionDataSource ds = new SingleConnectionDataSource(); ds.setDriverClassName("org.hsqldb.jdbcDriver"); ds.setUrl("jdbc:hsqldb:data/tutorial"); ds.setUsername("sa"); ds.setPassword(""); JdbcTemplate jt = new JdbcTemplate(ds); jt.execute("insert into employee (id, name) values (?, ?)", 1, "Tom");
connection = ds.getConnection(username(), password()); scds = new SingleConnectionDataSource(connection, true); dgds.setTargetDataSource(scds); scds.destroy(); connection.close();
@Override protected JdbcTemplate createJdbcTemplate() { SingleConnectionDataSource ds = new SingleConnectionDataSource(); ds.setUrl(JDBC_URL_BASE + getDbFile()); ds.setSuppressClose(true); return new JdbcTemplate(ds); }
sendWebSocketMessage(WorkbenchWebSocketController.WorkbenchWebSocketCommand.GET_CONNECTION, queryIndex, queryEditorId, workbenchId, webSocketId); connection = singleConnectionDataSource.getConnection();
@Bean public DataSource dataSource() { SingleConnectionDataSource dataSource = new SingleConnectionDataSource(); dataSource.setSuppressClose(true); // defaults from Postgres.app // dataSource.setUrl("jdbc:sqlserver://localhost:1433;databaseName=master;user=sa;password=your_password"); dataSource.setUrl("jdbc:sqlserver://localhost:1433;databaseName=master"); dataSource.setUsername("sa"); dataSource.setPassword("Cent-Quick-Space-Bath-8"); return dataSource; }
@Bean public DataSource jdbcDataSource() { SingleConnectionDataSource ds = new SingleConnectionDataSource(); ds.setDriverClassName("org.sqlite.JDBC"); ds.setUrl("jdbc:sqlite:stats.db"); return ds; }
SingleConnectionDataSource ds = new SingleConnectionDataSource(config.getURL(), config.getUsername(), config.getPassword(), suppressClose); ds.setConnectionProperties(props);
@Test public void testLeaveConnectionOpenOnRequest() throws Exception { String sql = "SELECT ID, FORENAME FROM CUSTMR WHERE ID < 3"; given(this.resultSet.next()).willReturn(false); given(this.connection.isClosed()).willReturn(false); given(this.connection.createStatement()).willReturn(this.preparedStatement); // if close is called entire test will fail willThrow(new RuntimeException()).given(this.connection).close(); SingleConnectionDataSource scf = new SingleConnectionDataSource(this.dataSource.getConnection(), false); this.template = new JdbcTemplate(scf, false); RowCountCallbackHandler rcch = new RowCountCallbackHandler(); this.template.query(sql, rcch); verify(this.resultSet).close(); verify(this.preparedStatement).close(); }
@Bean public DataSource dataSource() { SingleConnectionDataSource dataSource = new SingleConnectionDataSource(); dataSource.setSuppressClose(true); // https://mariadb.com/kb/en/mariadb/about-mariadb-connector-j/ dataSource.setUrl("jdbc:mariadb://localhost:3307/jdbc?serverTimezone=UTC"); dataSource.setUsername("jdbc"); dataSource.setPassword("Cent-Quick-Space-Bath-8"); return dataSource; }
@AfterClass public static void dropDatabase() throws Exception { DATABASE_HELPER.getDataSource().destroy(); }
/** * Specifying a custom username and password doesn't make sense * with a single Connection. Returns the single Connection if given * the same username and password; throws a SQLException else. */ @Override public Connection getConnection(String username, String password) throws SQLException { if (ObjectUtils.nullSafeEquals(username, getUsername()) && ObjectUtils.nullSafeEquals(password, getPassword())) { return getConnection(); } else { throw new SQLException("SingleConnectionDataSource does not support custom username and password"); } }
@Before public void setUp() throws SQLException { given(connection.createStatement()).willReturn(statement); given(connection.prepareStatement(anyString())).willReturn(preparedStatement); given(statement.executeQuery(anyString())).willReturn(resultSet); given(preparedStatement.executeQuery()).willReturn(resultSet); given(resultSet.next()).willReturn(true, true, false); given(resultSet.getString(1)).willReturn("tb1", "tb2"); given(resultSet.getInt(2)).willReturn(1, 2); template.setDataSource(new SingleConnectionDataSource(connection, false)); template.setExceptionTranslator(new SQLStateSQLExceptionTranslator()); template.afterPropertiesSet(); }
@Bean public DataSource dataSource() { SingleConnectionDataSource dataSource = new SingleConnectionDataSource(); dataSource.setSuppressClose(true); // https://www.firebirdsql.org/file/documentation/drivers_documentation/java/faq.html#jdbc-urls-java.sql.drivermanager // https://github.com/FirebirdSQL/jaybird/wiki/Jaybird-and-Firebird-3 dataSource.setUrl("jdbc:firebirdsql://localhost:3050/jdbc?charSet=utf-8"); // https://github.com/almeida/docker-firebird dataSource.setUsername("jdbc"); dataSource.setPassword("Cent-Quick-Space-Bath-8"); return dataSource; }