/** * Determine the connection synchronization order to use for the given * DataSource. Decreased for every level of nesting that a DataSource * has, checked through the level of DelegatingDataSource nesting. * @param dataSource the DataSource to check * @return the connection synchronization order to use * @see #CONNECTION_SYNCHRONIZATION_ORDER */ private static int getConnectionSynchronizationOrder(DataSource dataSource) { int order = CONNECTION_SYNCHRONIZATION_ORDER; DataSource currDs = dataSource; while (currDs instanceof DelegatingDataSource) { order--; currDs = ((DelegatingDataSource) currDs).getTargetDataSource(); } return order; }
/** * Obtain the target {@code DataSource} for actual use (never {@code null}). * @since 5.0 */ protected DataSource obtainTargetDataSource() { DataSource dataSource = getTargetDataSource(); Assert.state(dataSource != null, "No 'targetDataSource' set"); return dataSource; }
@Override public void afterPropertiesSet() { if (getTargetDataSource() == null) { throw new IllegalArgumentException("Property 'targetDataSource' is required"); } }
private static DataSource getTargetDataSource(DataSource dataSource) { if (dataSource instanceof DelegatingDataSource) { return ((DelegatingDataSource) dataSource).getTargetDataSource(); } return null; }
@Override public DataSource resolve(DataSource dataSource) { while (dataSource instanceof DelegatingDataSource) { dataSource = ((DelegatingDataSource) dataSource).getTargetDataSource(); } return dataSource; } }
public void afterPropertiesSet() { if (getTargetDataSource() == null) { throw new IllegalArgumentException("Property 'targetDataSource' is required"); } }
@Override public void afterPropertiesSet() { if (getTargetDataSource() == null) { throw new IllegalArgumentException("Property 'targetDataSource' is required"); } }
public Connection getConnection() throws SQLException { return getTargetDataSource().getConnection(); }
@SuppressWarnings("unchecked") public <T> T unwrap(Class<T> iface) throws SQLException { if (iface.isInstance(this)) { return (T) this; } return getTargetDataSource().unwrap(iface); }
@Override public DataSource getTargetDataSource() { if (super.getTargetDataSource() == null) { setTargetDataSource(jndiDataSourceConfiguration()); } return super.getTargetDataSource(); }
public DataSource getTargetDataSource() { if (super.getTargetDataSource() == null) { setTargetDataSource(embeddedDataSourceConfiguration()); } return super.getTargetDataSource(); }
public void setLoginTimeout(int seconds) throws SQLException { getTargetDataSource().setLoginTimeout(seconds); }
@Override public void reload() throws Exception { // switch data source ComboPooledDataSource oldTargetDataSource = (ComboPooledDataSource)proxyDataSource.getTargetDataSource(); ComboPooledDataSource newTargetDataSource = createNewDataSource(); newTargetDataSource.getConnection().close(); // initialize a connection (+ throw it away) to force the datasource to initialize the pool proxyDataSource.setTargetDataSource(newTargetDataSource); oldTargetDataSource.close(); } });
@Override public void reload() throws Exception { // switch data source BoneCPDataSource oldTargetDataSource = (BoneCPDataSource)proxyDataSource.getTargetDataSource(); BoneCPDataSource newTargetDataSource = createNewDataSource(); newTargetDataSource.getConnection().close(); // initialize a connection (+ throw it away) to force the datasource to initialize the pool proxyDataSource.setTargetDataSource(newTargetDataSource); oldTargetDataSource.close(); } });
public static void assertPoolProperties(DataSource dataSource, int maxActive, int minIdle, long maxWait) { if (dataSource instanceof DelegatingDataSource) { dataSource = ((DelegatingDataSource) dataSource).getTargetDataSource(); } assertCommonsPoolProperties(dataSource, maxActive, minIdle, maxWait); }
public static void assertDataSourceType(DataSource dataSource, Class clazz) throws ClassNotFoundException { if (dataSource instanceof DelegatingDataSource) { dataSource = ((DelegatingDataSource) dataSource).getTargetDataSource(); } assertThat(dataSource, instanceOf(clazz)); } }
@Override public void reload() throws Exception { // switch data source DruidDataSource oldTargetDataSource = (DruidDataSource)proxyDataSource.getTargetDataSource(); DruidDataSource newTargetDataSource = createNewDataSource(); newTargetDataSource.getConnection().close(); // initialize a connection (+ throw it away) to force the datasource to initialize the pool proxyDataSource.setTargetDataSource(newTargetDataSource); oldTargetDataSource.close(); } });
public static void assertConnectionProperties(DataSource dataSource, Properties connectionProp) { if (dataSource instanceof DelegatingDataSource) { dataSource = ((DelegatingDataSource) dataSource).getTargetDataSource(); } assertEquals(connectionProp, ReflectionUtils.getValue(dataSource, "connectionProperties")); }
private void assertConnectionProperties(DataSource dataSource, Properties connectionProp) { if (dataSource instanceof DelegatingDataSource) { dataSource = ((DelegatingDataSource) dataSource).getTargetDataSource(); } assertEquals(connectionProp, ReflectionTestUtils.getField(dataSource, "connectionProperties")); }
public static void assertConnectionProperty(DataSource dataSource, String key, Object value) { if (dataSource instanceof DelegatingDataSource) { dataSource = ((DelegatingDataSource) dataSource).getTargetDataSource(); } assertEquals(value, ReflectionUtils.getValue(dataSource, key)); }