From ec607faceb961d9540eef5f7ccd2810d84f56c65 Mon Sep 17 00:00:00 2001 From: wenshao Date: Sun, 17 Jul 2011 04:37:12 +0000 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81HA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://code.alibabatech.com/svn/druid/trunk@455 b9813039-fb51-4c41-a8b9-e21c2acb5095 --- .../alibaba/druid/pool/ha/HADataSource.java | 68 +---------------- .../druid/pool/ha/MultiDataSource.java | 75 +++++++++++++++++++ 2 files changed, 78 insertions(+), 65 deletions(-) create mode 100644 src/main/java/com/alibaba/druid/pool/ha/MultiDataSource.java diff --git a/src/main/java/com/alibaba/druid/pool/ha/HADataSource.java b/src/main/java/com/alibaba/druid/pool/ha/HADataSource.java index deef026c2a..7c3284a2eb 100644 --- a/src/main/java/com/alibaba/druid/pool/ha/HADataSource.java +++ b/src/main/java/com/alibaba/druid/pool/ha/HADataSource.java @@ -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 dataSources = new CopyOnWriteArrayList(); - - private int loginTimeout = 0; - private PrintWriter logWriter = new PrintWriter(System.out); - - private AtomicInteger requestCount = new AtomicInteger(); - - public List 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 unwrap(Class 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(); - } + } diff --git a/src/main/java/com/alibaba/druid/pool/ha/MultiDataSource.java b/src/main/java/com/alibaba/druid/pool/ha/MultiDataSource.java new file mode 100644 index 0000000000..f331391e16 --- /dev/null +++ b/src/main/java/com/alibaba/druid/pool/ha/MultiDataSource.java @@ -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 dataSources = new CopyOnWriteArrayList(); + + private int loginTimeout = 0; + private PrintWriter logWriter = new PrintWriter(System.out); + + public List 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 unwrap(Class 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(); + } +}