mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
ha
This commit is contained in:
@@ -52,6 +52,8 @@ import com.alibaba.druid.proxy.jdbc.StatementProxy;
|
||||
* @author wenshao<szujobs@hotmail.com>
|
||||
*/
|
||||
public interface FilterChain {
|
||||
|
||||
int getFilterSize();
|
||||
|
||||
FilterChain cloneChain();
|
||||
|
||||
|
||||
@@ -82,6 +82,10 @@ public class FilterChainImpl implements FilterChain {
|
||||
this.filterSize = getFilters().size();
|
||||
}
|
||||
|
||||
public int getFilterSize() {
|
||||
return filterSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FilterChain cloneChain() {
|
||||
return new FilterChainImpl(dataSource, pos);
|
||||
|
||||
@@ -26,7 +26,6 @@ import com.alibaba.druid.pool.WrapperAdapter;
|
||||
import com.alibaba.druid.proxy.jdbc.CallableStatementProxyImpl;
|
||||
import com.alibaba.druid.proxy.jdbc.ConnectionProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.DataSourceProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl;
|
||||
|
||||
public class MultiDataSourceConnection extends WrapperAdapter implements Connection, ConnectionProxy {
|
||||
|
||||
@@ -337,7 +336,7 @@ public class MultiDataSourceConnection extends WrapperAdapter implements Connect
|
||||
PreparedStatement stmt = conn.prepareStatement(sql);
|
||||
long stmtId = haDataSource.createStatementId();
|
||||
|
||||
return new PreparedStatementProxyImpl(this, stmt, sql, stmtId);
|
||||
return new MultiDataSourcePreparedStatement(this, stmt, sql, stmtId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -358,7 +357,7 @@ public class MultiDataSourceConnection extends WrapperAdapter implements Connect
|
||||
PreparedStatement stmt = conn.prepareStatement(sql, resultSetType, resultSetConcurrency);
|
||||
long stmtId = haDataSource.createStatementId();
|
||||
|
||||
return new PreparedStatementProxyImpl(this, stmt, sql, stmtId);
|
||||
return new MultiDataSourcePreparedStatement(this, stmt, sql, stmtId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -388,7 +387,7 @@ public class MultiDataSourceConnection extends WrapperAdapter implements Connect
|
||||
PreparedStatement stmt = conn.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
|
||||
long stmtId = haDataSource.createStatementId();
|
||||
|
||||
return new PreparedStatementProxyImpl(this, stmt, sql, stmtId);
|
||||
return new MultiDataSourcePreparedStatement(this, stmt, sql, stmtId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -409,7 +408,7 @@ public class MultiDataSourceConnection extends WrapperAdapter implements Connect
|
||||
PreparedStatement stmt = conn.prepareStatement(sql, autoGeneratedKeys);
|
||||
long stmtId = haDataSource.createStatementId();
|
||||
|
||||
return new PreparedStatementProxyImpl(this, stmt, sql, stmtId);
|
||||
return new MultiDataSourcePreparedStatement(this, stmt, sql, stmtId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -419,7 +418,7 @@ public class MultiDataSourceConnection extends WrapperAdapter implements Connect
|
||||
PreparedStatement stmt = conn.prepareStatement(sql, columnIndexes);
|
||||
long stmtId = haDataSource.createStatementId();
|
||||
|
||||
return new PreparedStatementProxyImpl(this, stmt, sql, stmtId);
|
||||
return new MultiDataSourcePreparedStatement(this, stmt, sql, stmtId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -429,7 +428,7 @@ public class MultiDataSourceConnection extends WrapperAdapter implements Connect
|
||||
PreparedStatement stmt = conn.prepareStatement(sql, columnNames);
|
||||
long stmtId = haDataSource.createStatementId();
|
||||
|
||||
return new PreparedStatementProxyImpl(this, stmt, sql, stmtId);
|
||||
return new MultiDataSourcePreparedStatement(this, stmt, sql, stmtId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.alibaba.druid.pool.ha;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.alibaba.druid.filter.FilterChain;
|
||||
import com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl;
|
||||
|
||||
|
||||
public class MultiDataSourcePreparedStatement extends PreparedStatementProxyImpl {
|
||||
private MultiDataSourceConnection multiConnection;
|
||||
|
||||
public MultiDataSourcePreparedStatement(MultiDataSourceConnection connection, PreparedStatement statement, String sql, long id){
|
||||
super(connection, statement, sql, id);
|
||||
|
||||
multiConnection = connection;
|
||||
}
|
||||
|
||||
public MultiDataSourceConnection getConnection() {
|
||||
return multiConnection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute() throws SQLException {
|
||||
FilterChain chain = createChain();
|
||||
|
||||
if (chain.getFilterSize() == 0) {
|
||||
return this.statement.execute();
|
||||
}
|
||||
|
||||
return chain.preparedStatement_execute(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet executeQuery() throws SQLException {
|
||||
FilterChain chain = createChain();
|
||||
|
||||
if (chain.getFilterSize() == 0) {
|
||||
return this.statement.executeQuery();
|
||||
}
|
||||
|
||||
return chain.preparedStatement_executeQuery(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int executeUpdate() throws SQLException {
|
||||
FilterChain chain = createChain();
|
||||
|
||||
if (chain.getFilterSize() == 0) {
|
||||
return this.statement.executeUpdate();
|
||||
}
|
||||
|
||||
return chain.preparedStatement_executeUpdate(this);
|
||||
}
|
||||
}
|
||||
@@ -41,8 +41,8 @@ import java.util.Calendar;
|
||||
*/
|
||||
public class PreparedStatementProxyImpl extends StatementProxyImpl implements PreparedStatementProxy {
|
||||
|
||||
private final PreparedStatement statement;
|
||||
private final String sql;
|
||||
protected final PreparedStatement statement;
|
||||
protected final String sql;
|
||||
|
||||
public PreparedStatementProxyImpl(ConnectionProxy connection, PreparedStatement statement, String sql, long id){
|
||||
super(connection, statement, id);
|
||||
|
||||
Reference in New Issue
Block a user