/** * This implementation delegates to {@code getConnectionFromDriver}, * using the default username and password of this DataSource. * @see #getConnectionFromDriver(String, String) * @see #setUsername * @see #setPassword */ @Override public Connection getConnection() throws SQLException { return getConnectionFromDriver(getUsername(), getPassword()); }
/** * Build properties for the Driver, including the given username and password (if any), * and obtain a corresponding Connection. * @param username the name of the user * @param password the password to use * @return the obtained Connection * @throws SQLException in case of failure * @see java.sql.Driver#connect(String, java.util.Properties) */ protected Connection getConnectionFromDriver(@Nullable String username, @Nullable String password) throws SQLException { Properties mergedProps = new Properties(); Properties connProps = getConnectionProperties(); if (connProps != null) { mergedProps.putAll(connProps); } if (username != null) { mergedProps.setProperty("user", username); } if (password != null) { mergedProps.setProperty("password", password); } Connection con = getConnectionFromDriver(mergedProps); if (this.catalog != null) { con.setCatalog(this.catalog); } if (this.schema != null) { con.setSchema(this.schema); } return con; }
/** * This implementation delegates to {@code getConnectionFromDriver}, * using the given username and password. * @see #getConnectionFromDriver(String, String) */ @Override public Connection getConnection(String username, String password) throws SQLException { return getConnectionFromDriver(username, password); }
/** * Build properties for the Driver, including the given username and password (if any), * and obtain a corresponding Connection. * @param username the name of the user * @param password the password to use * @return the obtained Connection * @throws SQLException in case of failure * @see java.sql.Driver#connect(String, java.util.Properties) */ protected Connection getConnectionFromDriver(@Nullable String username, @Nullable String password) throws SQLException { Properties mergedProps = new Properties(); Properties connProps = getConnectionProperties(); if (connProps != null) { mergedProps.putAll(connProps); } if (username != null) { mergedProps.setProperty("user", username); } if (password != null) { mergedProps.setProperty("password", password); } Connection con = getConnectionFromDriver(mergedProps); if (this.catalog != null) { con.setCatalog(this.catalog); } if (this.schema != null) { con.setSchema(this.schema); } return con; }
private void assertCorrectSetupForSingleDataSource(String file, Predicate<String> urlPredicate) { ConfigurableApplicationContext context = context(file); try { DataSource dataSource = context.getBean(DataSource.class); assertNumRowsInTestTable(new JdbcTemplate(dataSource), 1); assertTrue(dataSource instanceof AbstractDriverBasedDataSource); AbstractDriverBasedDataSource adbDataSource = (AbstractDriverBasedDataSource) dataSource; assertTrue(urlPredicate.test(adbDataSource.getUrl())); } finally { context.close(); } }
/** * This implementation delegates to {@code getConnectionFromDriver}, * using the given username and password. * @see #getConnectionFromDriver(String, String) */ public Connection getConnection(String username, String password) throws SQLException { return getConnectionFromDriver(username, password); }
private void assertCorrectSetupAndCloseContext(String file, int count, String... dataSources) { ConfigurableApplicationContext context = context(file); try { for (String dataSourceName : dataSources) { DataSource dataSource = context.getBean(dataSourceName, DataSource.class); assertNumRowsInTestTable(new JdbcTemplate(dataSource), count); assertTrue(dataSource instanceof AbstractDriverBasedDataSource); AbstractDriverBasedDataSource adbDataSource = (AbstractDriverBasedDataSource) dataSource; assertThat(adbDataSource.getUrl(), containsString(dataSourceName)); } } finally { context.close(); } }
/** * This implementation delegates to {@code getConnectionFromDriver}, * using the default username and password of this DataSource. * @see #getConnectionFromDriver(String, String) * @see #setUsername * @see #setPassword */ public Connection getConnection() throws SQLException { return getConnectionFromDriver(getUsername(), getPassword()); }
/** * Build properties for the Driver, including the given username and password (if any), * and obtain a corresponding Connection. * @param username the name of the user * @param password the password to use * @return the obtained Connection * @throws SQLException in case of failure * @see java.sql.Driver#connect(String, java.util.Properties) */ protected Connection getConnectionFromDriver(String username, String password) throws SQLException { Properties mergedProps = new Properties(); Properties connProps = getConnectionProperties(); if (connProps != null) { mergedProps.putAll(connProps); } if (username != null) { mergedProps.setProperty("user", username); } if (password != null) { mergedProps.setProperty("password", password); } return getConnectionFromDriver(mergedProps); }
/** * This implementation delegates to {@code getConnectionFromDriver}, * using the default username and password of this DataSource. * @see #getConnectionFromDriver(String, String) * @see #setUsername * @see #setPassword */ @Override public Connection getConnection() throws SQLException { return getConnectionFromDriver(getUsername(), getPassword()); }