|
|
@@ -0,0 +1,90 @@
|
|
|
+package com.uas.platform.b2b.data.support;
|
|
|
+
|
|
|
+import java.io.PrintWriter;
|
|
|
+import java.sql.Connection;
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.sql.SQLFeatureNotSupportedException;
|
|
|
+import java.util.Properties;
|
|
|
+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 {
|
|
|
+
|
|
|
+ private ApplicationContext applicationContext = null;
|
|
|
+ private DataSource dataSource = null;
|
|
|
+ private Properties connectionProperties = null;
|
|
|
+
|
|
|
+ public Connection getConnection() throws SQLException {
|
|
|
+ return getDataSource().getConnection();
|
|
|
+ }
|
|
|
+
|
|
|
+ public Connection getConnection(String arg0, String arg1) throws SQLException {
|
|
|
+ return getDataSource().getConnection(arg0, arg1);
|
|
|
+ }
|
|
|
+
|
|
|
+ public PrintWriter getLogWriter() throws SQLException {
|
|
|
+ return getDataSource().getLogWriter();
|
|
|
+ }
|
|
|
+
|
|
|
+ public Properties getConnectionProperties() {
|
|
|
+ return connectionProperties;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setConnectionProperties(Properties connectionProperties) {
|
|
|
+ this.connectionProperties = connectionProperties;
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getLoginTimeout() throws SQLException {
|
|
|
+ return getDataSource().getLoginTimeout();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setLogWriter(PrintWriter arg0) throws SQLException {
|
|
|
+ getDataSource().setLogWriter(arg0);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setLoginTimeout(int arg0) throws SQLException {
|
|
|
+ getDataSource().setLoginTimeout(arg0);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
|
|
+ this.applicationContext = applicationContext;
|
|
|
+ }
|
|
|
+
|
|
|
+ public DataSource getDataSource(String dataSourceName) {
|
|
|
+ if (dataSourceName == null || dataSourceName.equals("")) {
|
|
|
+ return this.dataSource;
|
|
|
+ }
|
|
|
+ return (DataSource) this.applicationContext.getBean(dataSourceName);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setDataSource(DataSource dataSource) {
|
|
|
+ this.dataSource = dataSource;
|
|
|
+ }
|
|
|
+
|
|
|
+ public DataSource getDataSource() {
|
|
|
+ String sp = SpObserver.getSp();
|
|
|
+ return getDataSource(sp);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public <T> T unwrap(Class<T> iface) throws SQLException {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Logger getParentLogger() throws SQLFeatureNotSupportedException {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|