git-svn-id: http://code.alibabatech.com/svn/druid/trunk@455 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-07-17 04:37:12 +00:00
parent d4970087cc
commit ec607faceb
2 changed files with 78 additions and 65 deletions
@@ -1,75 +1,16 @@
package com.alibaba.druid.pool.ha;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;
import javax.sql.DataSource;
import com.alibaba.druid.pool.DruidDataSource;
public class HADataSource implements DataSource {
public class HADataSource extends MultiDataSource implements DataSource {
private final List<DruidDataSource> dataSources = new CopyOnWriteArrayList<DruidDataSource>();
private int loginTimeout = 0;
private PrintWriter logWriter = new PrintWriter(System.out);
private AtomicInteger requestCount = new AtomicInteger();
public List<DruidDataSource> getDataSources() {
return dataSources;
}
@Override
public PrintWriter getLogWriter() throws SQLException {
return logWriter;
}
@Override
public void setLogWriter(PrintWriter out) throws SQLException {
this.logWriter = out;
}
@Override
public void setLoginTimeout(int seconds) throws SQLException {
loginTimeout = seconds;
}
@Override
public int getLoginTimeout() throws SQLException {
return loginTimeout;
}
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
if (iface == null) {
return false;
}
if (iface.isInstance(this)) {
return true;
}
return false;
}
@SuppressWarnings("unchecked")
@Override
public <T> T unwrap(Class<T> iface) throws SQLException {
if (iface == null) {
return null;
}
if (iface.isInstance(this)) {
return (T) this;
}
return null;
}
private AtomicInteger requestCount = new AtomicInteger();
@Override
public Connection getConnection() throws SQLException {
@@ -83,9 +24,6 @@ public class HADataSource implements DataSource {
return conn;
}
@Override
public Connection getConnection(String username, String password) throws SQLException {
throw new UnsupportedOperationException();
}
}
@@ -0,0 +1,75 @@
package com.alibaba.druid.pool.ha;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.sql.DataSource;
import com.alibaba.druid.pool.DruidDataSource;
public abstract class MultiDataSource implements DataSource {
protected final List<DruidDataSource> dataSources = new CopyOnWriteArrayList<DruidDataSource>();
private int loginTimeout = 0;
private PrintWriter logWriter = new PrintWriter(System.out);
public List<DruidDataSource> getDataSources() {
return dataSources;
}
@Override
public PrintWriter getLogWriter() throws SQLException {
return logWriter;
}
@Override
public void setLogWriter(PrintWriter out) throws SQLException {
this.logWriter = out;
}
@Override
public void setLoginTimeout(int seconds) throws SQLException {
loginTimeout = seconds;
}
@Override
public int getLoginTimeout() throws SQLException {
return loginTimeout;
}
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
if (iface == null) {
return false;
}
if (iface.isInstance(this)) {
return true;
}
return false;
}
@SuppressWarnings("unchecked")
@Override
public <T> T unwrap(Class<T> iface) throws SQLException {
if (iface == null) {
return null;
}
if (iface.isInstance(this)) {
return (T) this;
}
return null;
}
@Override
public Connection getConnection(String username, String password) throws SQLException {
throw new UnsupportedOperationException();
}
}