|
|
@@ -9,18 +9,22 @@ import java.util.logging.Logger;
|
|
|
|
|
|
import javax.sql.DataSource;
|
|
|
|
|
|
-import org.apache.commons.dbcp.BasicDataSource;
|
|
|
import org.springframework.beans.BeansException;
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.context.ApplicationContextAware;
|
|
|
|
|
|
-public class MultiDataSource extends BasicDataSource implements DataSource, ApplicationContextAware {
|
|
|
+import com.alibaba.druid.pool.DruidDataSource;
|
|
|
+import com.alibaba.druid.pool.DruidPooledConnection;
|
|
|
+
|
|
|
+public class MultiDataSource extends DruidDataSource implements DataSource, ApplicationContextAware {
|
|
|
+
|
|
|
+ private static final long serialVersionUID = 1L;
|
|
|
|
|
|
private ApplicationContext applicationContext = null;
|
|
|
- private DataSource dataSource = null;
|
|
|
+ private DruidDataSource dataSource = null;
|
|
|
private Properties connectionProperties = null;
|
|
|
|
|
|
- public Connection getConnection() throws SQLException {
|
|
|
+ public DruidPooledConnection getConnection() throws SQLException {
|
|
|
return getDataSource().getConnection();
|
|
|
}
|
|
|
|
|
|
@@ -28,7 +32,7 @@ public class MultiDataSource extends BasicDataSource implements DataSource, Appl
|
|
|
return getDataSource().getConnection(arg0, arg1);
|
|
|
}
|
|
|
|
|
|
- public PrintWriter getLogWriter() throws SQLException {
|
|
|
+ public PrintWriter getLogWriter() {
|
|
|
return getDataSource().getLogWriter();
|
|
|
}
|
|
|
|
|
|
@@ -40,7 +44,7 @@ public class MultiDataSource extends BasicDataSource implements DataSource, Appl
|
|
|
this.connectionProperties = connectionProperties;
|
|
|
}
|
|
|
|
|
|
- public int getLoginTimeout() throws SQLException {
|
|
|
+ public int getLoginTimeout() {
|
|
|
return getDataSource().getLoginTimeout();
|
|
|
}
|
|
|
|
|
|
@@ -48,7 +52,7 @@ public class MultiDataSource extends BasicDataSource implements DataSource, Appl
|
|
|
getDataSource().setLogWriter(arg0);
|
|
|
}
|
|
|
|
|
|
- public void setLoginTimeout(int arg0) throws SQLException {
|
|
|
+ public void setLoginTimeout(int arg0) {
|
|
|
getDataSource().setLoginTimeout(arg0);
|
|
|
}
|
|
|
|
|
|
@@ -56,29 +60,29 @@ public class MultiDataSource extends BasicDataSource implements DataSource, Appl
|
|
|
this.applicationContext = applicationContext;
|
|
|
}
|
|
|
|
|
|
- public DataSource getDataSource(String dataSourceName) {
|
|
|
+ public DruidDataSource getDataSource(String dataSourceName) {
|
|
|
if (dataSourceName == null || dataSourceName.equals("")) {
|
|
|
return this.dataSource;
|
|
|
}
|
|
|
- return (DataSource) this.applicationContext.getBean(dataSourceName);
|
|
|
+ return this.applicationContext.getBean(dataSourceName, DruidDataSource.class);
|
|
|
}
|
|
|
|
|
|
- public void setDataSource(DataSource dataSource) {
|
|
|
+ public void setDataSource(DruidDataSource dataSource) {
|
|
|
this.dataSource = dataSource;
|
|
|
}
|
|
|
|
|
|
- public DataSource getDataSource() {
|
|
|
+ public DruidDataSource getDataSource() {
|
|
|
String sp = SpObserver.getSp();
|
|
|
return getDataSource(sp);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public <T> T unwrap(Class<T> iface) throws SQLException {
|
|
|
+ public <T> T unwrap(Class<T> iface) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
|
|
+ public boolean isWrapperFor(Class<?> iface) {
|
|
|
return false;
|
|
|
}
|
|
|
|