@Override public Connection getConnection(String username, String password) throws SQLException { return determineTargetDataSource().getConnection(username, password); }
protected DataSource determineTargetDataSource() { DataSource returnDataSource; if(SqlExecutionContext.getType().equals(SqlExcutionType.Write)){ returnDataSource = writeDataSource; } else if(SqlExecutionContext.getType().equals(SqlExcutionType.Read)){ int index = determindIndex(); returnDataSource = readDataSources.get(index); }else{ if(null == defaultDataSource) { throw new DataAccessException("default data source must not be null while sql execution type is unknown"); } returnDataSource = defaultDataSource; } return returnDataSource; }
@Override public Connection getConnection() throws SQLException { return determineTargetDataSource().getConnection(); }
@Override public Logger getParentLogger() throws SQLFeatureNotSupportedException { return determineTargetDataSource().getParentLogger(); } }
@Override public boolean isWrapperFor(Class<?> iface) throws SQLException { return determineTargetDataSource().isWrapperFor(iface); }
@Override public void setLoginTimeout(int seconds) throws SQLException { determineTargetDataSource().setLoginTimeout(seconds); }
@Override public int getLoginTimeout() throws SQLException { return determineTargetDataSource().getLoginTimeout(); }
@Override public <T> T unwrap(Class<T> iface) throws SQLException { return determineTargetDataSource().unwrap(iface); }
@Override public PrintWriter getLogWriter() throws SQLException { return determineTargetDataSource().getLogWriter(); }
@Override public void setLogWriter(PrintWriter out) throws SQLException { determineTargetDataSource().setLogWriter(out); }