return "Lazy Connection proxy for target DataSource [" + getTargetDataSource() + "]";
/** * Create a new LazyConnectionDataSourceProxy. * @param targetDataSource the target DataSource */ public LazyConnectionDataSourceProxy(DataSource targetDataSource) { setTargetDataSource(targetDataSource); afterPropertiesSet(); }
obtainTargetDataSource().getConnection(this.username, this.password) : obtainTargetDataSource().getConnection(); checkDefaultConnectionProperties(this.target); !this.transactionIsolation.equals(defaultTransactionIsolation())) { this.target.setTransactionIsolation(this.transactionIsolation);
public LazyConnectionInvocationHandler() { this.autoCommit = defaultAutoCommit(); this.transactionIsolation = defaultTransactionIsolation(); }
@Override public void afterPropertiesSet() { super.afterPropertiesSet(); // Determine default auto-commit and transaction isolation // via a Connection from the target DataSource, if possible. if (this.defaultAutoCommit == null || this.defaultTransactionIsolation == null) { try { try (Connection con = obtainTargetDataSource().getConnection()) { checkDefaultConnectionProperties(con); } } catch (SQLException ex) { logger.debug("Could not retrieve default auto-commit and transaction isolation settings", ex); } } }
final DataSource dsToUse = (lazyConnection ? new LazyConnectionDataSourceProxy(ds) : ds); tm = new DataSourceTransactionManager(dsToUse); TransactionTemplate tt = new TransactionTemplate(tm);
@Override public void afterPropertiesSet() throws Exception { if (this.shardsDataSources == null) { throw new IllegalArgumentException("Property 'shardsDataSources' is required"); } this.resolvedShardsDataSources = new HashMap<Object, DataSource>(this.shardsDataSources.size()); for (Map.Entry<Object, Object> entry : this.shardsDataSources.entrySet()) { DataSource dataSource = resolveSpecifiedDataSource(entry.getValue()); LazyConnectionDataSourceProxy lazyDataSourceProxy = new LazyConnectionDataSourceProxy(); lazyDataSourceProxy.setTargetDataSource(dataSource); this.resolvedShardsDataSources.put(entry.getKey(), lazyDataSourceProxy); } if (this.defaultDataSource == null) { throw new IllegalArgumentException("Property 'defaultDataSource' is required"); } if(this.defaultDataSource != null){ resolvedDefaultDataSource = this.resolveSpecifiedDataSource(defaultDataSource); } }
getTargetDataSource().getConnection(this.username, this.password) : getTargetDataSource().getConnection(); checkDefaultConnectionProperties(this.target); !this.transactionIsolation.equals(defaultTransactionIsolation())) { this.target.setTransactionIsolation(this.transactionIsolation);
@Override public void afterPropertiesSet() { super.afterPropertiesSet(); // Determine default auto-commit and transaction isolation // via a Connection from the target DataSource, if possible. if (this.defaultAutoCommit == null || this.defaultTransactionIsolation == null) { try { Connection con = getTargetDataSource().getConnection(); try { checkDefaultConnectionProperties(con); } finally { con.close(); } } catch (SQLException ex) { logger.warn("Could not retrieve default auto-commit and transaction isolation settings", ex); } } }
/** * Set the default transaction isolation level by the name of the corresponding * constant in {@link java.sql.Connection}, e.g. "TRANSACTION_SERIALIZABLE". * @param constantName name of the constant * @see #setDefaultTransactionIsolation * @see java.sql.Connection#TRANSACTION_READ_UNCOMMITTED * @see java.sql.Connection#TRANSACTION_READ_COMMITTED * @see java.sql.Connection#TRANSACTION_REPEATABLE_READ * @see java.sql.Connection#TRANSACTION_SERIALIZABLE */ public void setDefaultTransactionIsolationName(String constantName) { setDefaultTransactionIsolation(constants.asNumber(constantName).intValue()); }
@Override public void afterPropertiesSet() { super.afterPropertiesSet(); // Determine default auto-commit and transaction isolation // via a Connection from the target DataSource, if possible. if (this.defaultAutoCommit == null || this.defaultTransactionIsolation == null) { try { try (Connection con = obtainTargetDataSource().getConnection()) { checkDefaultConnectionProperties(con); } } catch (SQLException ex) { logger.debug("Could not retrieve default auto-commit and transaction isolation settings", ex); } } }
final DataSource dsToUse = (lazyConnection ? new LazyConnectionDataSourceProxy(ds) : ds); tm = new DataSourceTransactionManager(dsToUse); TransactionTemplate tt = new TransactionTemplate(tm);
public LazyConnectionInvocationHandler(String username, String password) { this(); this.username = username; this.password = password; }
/** * Set the default transaction isolation level by the name of the corresponding * constant in {@link java.sql.Connection}, e.g. "TRANSACTION_SERIALIZABLE". * @param constantName name of the constant * @see #setDefaultTransactionIsolation * @see java.sql.Connection#TRANSACTION_READ_UNCOMMITTED * @see java.sql.Connection#TRANSACTION_READ_COMMITTED * @see java.sql.Connection#TRANSACTION_REPEATABLE_READ * @see java.sql.Connection#TRANSACTION_SERIALIZABLE */ public void setDefaultTransactionIsolationName(String constantName) { setDefaultTransactionIsolation(constants.asNumber(constantName).intValue()); }
/** * Primary data source. * * @return the primary data source */ @Bean @Primary public DataSource dataSource() throws SQLException { DataSource dataSourceTarget = new HikariDataSource(getHikariConfig()); return new LazyConnectionDataSourceProxy(dataSourceTarget); }
/** * Create a new LazyConnectionDataSourceProxy. * @param targetDataSource the target DataSource */ public LazyConnectionDataSourceProxy(DataSource targetDataSource) { setTargetDataSource(targetDataSource); afterPropertiesSet(); }
public LazyConnectionInvocationHandler() { this.autoCommit = defaultAutoCommit(); this.transactionIsolation = defaultTransactionIsolation(); }
@Override protected void destroyInstance(DataSource instance) throws Exception { if (instance instanceof LazyConnectionDataSourceProxy) { DataSource targetDataSource = ((LazyConnectionDataSourceProxy) instance).getTargetDataSource(); if (targetDataSource instanceof ReadOnlyRoutingDataSource) { List<Object> dataSources = ((ReadOnlyRoutingDataSource) targetDataSource).getDataSources(); for (Object candidate : dataSources) { if (candidate instanceof DataSource) { super.destroyInstance(instance); } } } } } }
/** * Set the default transaction isolation level by the name of the corresponding * constant in {@link java.sql.Connection}, e.g. "TRANSACTION_SERIALIZABLE". * @param constantName name of the constant * @see #setDefaultTransactionIsolation * @see java.sql.Connection#TRANSACTION_READ_UNCOMMITTED * @see java.sql.Connection#TRANSACTION_READ_COMMITTED * @see java.sql.Connection#TRANSACTION_REPEATABLE_READ * @see java.sql.Connection#TRANSACTION_SERIALIZABLE */ public void setDefaultTransactionIsolationName(String constantName) { setDefaultTransactionIsolation(constants.asNumber(constantName).intValue()); }