mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor & bug fixed.
This commit is contained in:
@@ -146,7 +146,12 @@ public class FilterChainImpl implements FilterChain {
|
||||
String url = dataSource.getRawJdbcUrl();
|
||||
|
||||
Connection nativeConnection = driver.connect(url, info);
|
||||
return wrap(nativeConnection, info);
|
||||
|
||||
if (nativeConnection == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ConnectionProxyImpl(dataSource, nativeConnection, info, dataSource.createConnectionId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -238,7 +243,11 @@ public class FilterChainImpl implements FilterChain {
|
||||
}
|
||||
|
||||
Statement statement = connection.getRawObject().createStatement();
|
||||
return wrap(connection, statement);
|
||||
|
||||
if (statement == null) {
|
||||
return null;
|
||||
}
|
||||
return new StatementProxyImpl(connection, statement, dataSource.createStatementId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -249,7 +258,10 @@ public class FilterChainImpl implements FilterChain {
|
||||
}
|
||||
|
||||
Statement statement = connection.getRawObject().createStatement(resultSetType, resultSetConcurrency);
|
||||
return wrap(connection, statement);
|
||||
if (statement == null) {
|
||||
return null;
|
||||
}
|
||||
return new StatementProxyImpl(connection, statement, dataSource.createStatementId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -263,7 +275,10 @@ public class FilterChainImpl implements FilterChain {
|
||||
|
||||
Statement statement = connection.getRawObject().createStatement(resultSetType, resultSetConcurrency,
|
||||
resultSetHoldability);
|
||||
return wrap(connection, statement);
|
||||
if (statement == null) {
|
||||
return null;
|
||||
}
|
||||
return new StatementProxyImpl(connection, statement, dataSource.createStatementId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -413,7 +428,10 @@ public class FilterChainImpl implements FilterChain {
|
||||
}
|
||||
|
||||
CallableStatement statement = connection.getRawObject().prepareCall(sql);
|
||||
return wrap(connection, statement, sql);
|
||||
if (statement == null) {
|
||||
return null;
|
||||
}
|
||||
return new CallableStatementProxyImpl(connection, statement, sql, dataSource.createStatementId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -424,7 +442,10 @@ public class FilterChainImpl implements FilterChain {
|
||||
}
|
||||
|
||||
CallableStatement statement = connection.getRawObject().prepareCall(sql, resultSetType, resultSetConcurrency);
|
||||
return wrap(connection, statement, sql);
|
||||
if (statement == null) {
|
||||
return null;
|
||||
}
|
||||
return new CallableStatementProxyImpl(connection, statement, sql, dataSource.createStatementId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -438,7 +459,10 @@ public class FilterChainImpl implements FilterChain {
|
||||
|
||||
CallableStatement statement = connection.getRawObject().prepareCall(sql, resultSetType, resultSetConcurrency,
|
||||
resultSetHoldability);
|
||||
return wrap(connection, statement, sql);
|
||||
if (statement == null) {
|
||||
return null;
|
||||
}
|
||||
return new CallableStatementProxyImpl(connection, statement, sql, dataSource.createStatementId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -449,7 +473,12 @@ public class FilterChainImpl implements FilterChain {
|
||||
}
|
||||
|
||||
PreparedStatement statement = connection.getRawObject().prepareStatement(sql);
|
||||
return wrap(connection, statement, sql);
|
||||
|
||||
if (statement == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new PreparedStatementProxyImpl(connection, statement, sql, dataSource.createStatementId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -460,7 +489,12 @@ public class FilterChainImpl implements FilterChain {
|
||||
}
|
||||
|
||||
PreparedStatement statement = connection.getRawObject().prepareStatement(sql, autoGeneratedKeys);
|
||||
return wrap(connection, statement, sql);
|
||||
|
||||
if (statement == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new PreparedStatementProxyImpl(connection, statement, sql, dataSource.createStatementId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -473,7 +507,11 @@ public class FilterChainImpl implements FilterChain {
|
||||
|
||||
PreparedStatement statement = connection.getRawObject().prepareStatement(sql, resultSetType,
|
||||
resultSetConcurrency);
|
||||
return wrap(connection, statement, sql);
|
||||
if (statement == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new PreparedStatementProxyImpl(connection, statement, sql, dataSource.createStatementId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -488,7 +526,11 @@ public class FilterChainImpl implements FilterChain {
|
||||
PreparedStatement statement = connection.getRawObject().prepareStatement(sql, resultSetType,
|
||||
resultSetConcurrency,
|
||||
resultSetHoldability);
|
||||
return wrap(connection, statement, sql);
|
||||
if (statement == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new PreparedStatementProxyImpl(connection, statement, sql, dataSource.createStatementId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -499,7 +541,11 @@ public class FilterChainImpl implements FilterChain {
|
||||
}
|
||||
|
||||
PreparedStatement statement = connection.getRawObject().prepareStatement(sql, columnIndexes);
|
||||
return wrap(connection, statement, sql);
|
||||
if (statement == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new PreparedStatementProxyImpl(connection, statement, sql, dataSource.createStatementId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -510,7 +556,11 @@ public class FilterChainImpl implements FilterChain {
|
||||
}
|
||||
|
||||
PreparedStatement statement = connection.getRawObject().prepareStatement(sql, columnNames);
|
||||
return wrap(connection, statement, sql);
|
||||
if (statement == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new PreparedStatementProxyImpl(connection, statement, sql, dataSource.createStatementId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -967,7 +1017,13 @@ public class FilterChainImpl implements FilterChain {
|
||||
if (this.pos < filterSize) {
|
||||
return nextFilter().resultSet_getMetaData(this, resultSet);
|
||||
}
|
||||
return wrap(resultSet.getResultSetRaw().getMetaData(), resultSet);
|
||||
|
||||
ResultSetMetaData metaData = resultSet.getResultSetRaw().getMetaData();
|
||||
if (metaData == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ResultSetMetaDataProxyImpl(metaData, dataSource.createMetaDataId(), resultSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -979,7 +1035,9 @@ public class FilterChainImpl implements FilterChain {
|
||||
Object obj = resultSet.getResultSetRaw().getObject(columnIndex);
|
||||
|
||||
if (obj instanceof ResultSet) {
|
||||
return wrap(resultSet.getStatementProxy(), (ResultSet) obj);
|
||||
StatementProxy statement = resultSet.getStatementProxy();
|
||||
return new ResultSetProxyImpl(statement, (ResultSet) obj, dataSource.createResultSetId(),
|
||||
statement.getLastExecuteSql());
|
||||
}
|
||||
|
||||
if (obj instanceof Clob) {
|
||||
@@ -998,7 +1056,9 @@ public class FilterChainImpl implements FilterChain {
|
||||
Object obj = resultSet.getResultSetRaw().getObject(columnLabel);
|
||||
|
||||
if (obj instanceof ResultSet) {
|
||||
return wrap(resultSet.getStatementProxy(), (ResultSet) obj);
|
||||
StatementProxy statement = resultSet.getStatementProxy();
|
||||
return new ResultSetProxyImpl(statement, (ResultSet) obj, dataSource.createResultSetId(),
|
||||
statement.getLastExecuteSql());
|
||||
}
|
||||
|
||||
if (obj instanceof Clob) {
|
||||
@@ -1655,7 +1715,9 @@ public class FilterChainImpl implements FilterChain {
|
||||
Object obj = resultSet.getResultSetRaw().getObject(columnIndex, map);
|
||||
|
||||
if (obj instanceof ResultSet) {
|
||||
return wrap(resultSet.getStatementProxy(), (ResultSet) obj);
|
||||
StatementProxy statement = resultSet.getStatementProxy();
|
||||
return new ResultSetProxyImpl(statement, (ResultSet) obj, dataSource.createResultSetId(),
|
||||
statement.getLastExecuteSql());
|
||||
}
|
||||
|
||||
if (obj instanceof Clob) {
|
||||
@@ -1713,7 +1775,9 @@ public class FilterChainImpl implements FilterChain {
|
||||
Object obj = resultSet.getResultSetRaw().getObject(columnLabel, map);
|
||||
|
||||
if (obj instanceof ResultSet) {
|
||||
return wrap(resultSet.getStatementProxy(), (ResultSet) obj);
|
||||
StatementProxy statement = resultSet.getStatementProxy();
|
||||
return new ResultSetProxyImpl(statement, (ResultSet) obj, dataSource.createResultSetId(),
|
||||
statement.getLastExecuteSql());
|
||||
}
|
||||
|
||||
if (obj instanceof Clob) {
|
||||
@@ -2366,7 +2430,8 @@ public class FilterChainImpl implements FilterChain {
|
||||
return null;
|
||||
}
|
||||
|
||||
return wrap(statement, resultSet);
|
||||
return new ResultSetProxyImpl(statement, resultSet, dataSource.createResultSetId(),
|
||||
statement.getLastExecuteSql());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2501,7 +2566,8 @@ public class FilterChainImpl implements FilterChain {
|
||||
return null;
|
||||
}
|
||||
|
||||
return wrap(statement, resultSet);
|
||||
return new ResultSetProxyImpl(statement, resultSet, dataSource.createResultSetId(),
|
||||
statement.getLastExecuteSql());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2619,7 +2685,11 @@ public class FilterChainImpl implements FilterChain {
|
||||
}
|
||||
|
||||
ResultSet resultSet = statement.getRawObject().getGeneratedKeys();
|
||||
return wrap(statement, resultSet);
|
||||
if (resultSet == null) {
|
||||
return null;
|
||||
}
|
||||
return new ResultSetProxyImpl(statement, resultSet, dataSource.createResultSetId(),
|
||||
statement.getLastExecuteSql());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2712,7 +2782,11 @@ public class FilterChainImpl implements FilterChain {
|
||||
}
|
||||
|
||||
ResultSet resultSet = statement.getRawObject().executeQuery();
|
||||
return wrap(statement, resultSet);
|
||||
if (resultSet == null) {
|
||||
return null;
|
||||
}
|
||||
return new ResultSetProxyImpl(statement, resultSet, dataSource.createResultSetId(),
|
||||
statement.getLastExecuteSql());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -3396,7 +3470,8 @@ public class FilterChainImpl implements FilterChain {
|
||||
Object obj = statement.getRawObject().getObject(parameterIndex);
|
||||
|
||||
if (obj instanceof ResultSet) {
|
||||
return wrap(statement, (ResultSet) obj);
|
||||
return new ResultSetProxyImpl(statement, (ResultSet) obj, dataSource.createResultSetId(),
|
||||
statement.getLastExecuteSql());
|
||||
}
|
||||
|
||||
if (obj instanceof Clob) {
|
||||
@@ -3416,7 +3491,8 @@ public class FilterChainImpl implements FilterChain {
|
||||
Object obj = statement.getRawObject().getObject(parameterIndex, map);
|
||||
|
||||
if (obj instanceof ResultSet) {
|
||||
return wrap(statement, (ResultSet) obj);
|
||||
return new ResultSetProxyImpl(statement, (ResultSet) obj, dataSource.createResultSetId(),
|
||||
statement.getLastExecuteSql());
|
||||
}
|
||||
|
||||
if (obj instanceof Clob) {
|
||||
@@ -3436,7 +3512,8 @@ public class FilterChainImpl implements FilterChain {
|
||||
Object obj = statement.getRawObject().getObject(parameterName);
|
||||
|
||||
if (obj instanceof ResultSet) {
|
||||
return wrap(statement, (ResultSet) obj);
|
||||
return new ResultSetProxyImpl(statement, (ResultSet) obj, dataSource.createResultSetId(),
|
||||
statement.getLastExecuteSql());
|
||||
}
|
||||
|
||||
if (obj instanceof Clob) {
|
||||
@@ -3456,7 +3533,8 @@ public class FilterChainImpl implements FilterChain {
|
||||
Object obj = statement.getRawObject().getObject(parameterName, map);
|
||||
|
||||
if (obj instanceof ResultSet) {
|
||||
return wrap(statement, (ResultSet) obj);
|
||||
return new ResultSetProxyImpl(statement, (ResultSet) obj, dataSource.createResultSetId(),
|
||||
statement.getLastExecuteSql());
|
||||
}
|
||||
|
||||
if (obj instanceof Clob) {
|
||||
@@ -4435,55 +4513,6 @@ public class FilterChainImpl implements FilterChain {
|
||||
|
||||
// ////////////
|
||||
|
||||
public ConnectionProxy wrap(Connection connection, Properties info) {
|
||||
if (connection == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ConnectionProxyImpl(dataSource, connection, info, dataSource.createConnectionId());
|
||||
}
|
||||
|
||||
public StatementProxy wrap(ConnectionProxy connection, Statement statement) {
|
||||
if (statement == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new StatementProxyImpl(connection, statement, dataSource.createStatementId());
|
||||
}
|
||||
|
||||
public PreparedStatementProxy wrap(ConnectionProxy connection, PreparedStatement statement, String sql) {
|
||||
if (statement == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new PreparedStatementProxyImpl(connection, statement, sql, dataSource.createStatementId());
|
||||
}
|
||||
|
||||
public CallableStatementProxy wrap(ConnectionProxy connection, CallableStatement statement, String sql) {
|
||||
if (statement == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CallableStatementProxyImpl(connection, statement, sql, dataSource.createStatementId());
|
||||
}
|
||||
|
||||
public ResultSetProxy wrap(StatementProxy statement, ResultSet resultSet) {
|
||||
if (resultSet == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ResultSetProxyImpl(statement, resultSet, dataSource.createResultSetId(),
|
||||
statement.getLastExecuteSql());
|
||||
}
|
||||
|
||||
public ResultSetMetaDataProxy wrap(ResultSetMetaData metaData, ResultSetProxy resultSet) {
|
||||
if (metaData == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ResultSetMetaDataProxyImpl(metaData, dataSource.createMetaDataId(), resultSet);
|
||||
}
|
||||
|
||||
public ClobProxy wrap(ConnectionProxy conn, Clob clob) {
|
||||
if (clob == null) {
|
||||
return null;
|
||||
|
||||
@@ -105,6 +105,8 @@ public class SQLVariantRefExpr extends SQLExprImpl {
|
||||
}
|
||||
|
||||
public SQLVariantRefExpr clone() {
|
||||
return new SQLVariantRefExpr(name, global);
|
||||
SQLVariantRefExpr var = new SQLVariantRefExpr(name, global);
|
||||
var.index = index;
|
||||
return var;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -1436,7 +1436,13 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
|
||||
accept(Token.END);
|
||||
|
||||
if (lexer.token() != Token.SEMI) {
|
||||
Token token = lexer.token();
|
||||
|
||||
if (token == Token.EOF) {
|
||||
return block;
|
||||
}
|
||||
|
||||
if (token != Token.SEMI) {
|
||||
String endLabel = lexer.stringVal();
|
||||
accept(Token.IDENTIFIER);
|
||||
block.setEndLabel(endLabel);
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Types;
|
||||
|
||||
import com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl;
|
||||
import org.junit.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
@@ -48,25 +49,6 @@ public class FilterChainImplTest extends TestCase {
|
||||
Assert.assertNull(new FilterChainImpl(dataSource).unwrap(null, null));
|
||||
}
|
||||
|
||||
public void test_unwrap_1() throws Exception {
|
||||
Assert.assertNull(new FilterChainImpl(dataSource).wrap((Connection) null, null));
|
||||
}
|
||||
|
||||
public void test_unwrap_2() throws Exception {
|
||||
Assert.assertNull(new FilterChainImpl(dataSource).wrap((ConnectionProxy) dataSource.getConnection().getConnection(),
|
||||
(Statement) null));
|
||||
}
|
||||
|
||||
public void test_unwrap_3() throws Exception {
|
||||
Assert.assertNull(new FilterChainImpl(dataSource).wrap((ConnectionProxy) dataSource.getConnection().getConnection(),
|
||||
(PreparedStatement) null, ""));
|
||||
}
|
||||
|
||||
public void test_unwrap_4() throws Exception {
|
||||
Assert.assertNull(new FilterChainImpl(dataSource).wrap((ConnectionProxy) dataSource.getConnection().getConnection(),
|
||||
(CallableStatement) null, ""));
|
||||
}
|
||||
|
||||
public void test_unwrap_5() throws Exception {
|
||||
Assert.assertNull(new FilterChainImpl(dataSource).wrap((ConnectionProxy) dataSource.getConnection().getConnection(),
|
||||
(Clob) null));
|
||||
|
||||
Reference in New Issue
Block a user