support spring NativeJdbcExtractor

This commit is contained in:
wenshao
2012-01-04 16:49:23 +08:00
15 changed files with 273 additions and 384 deletions
File diff suppressed because it is too large Load Diff
@@ -559,7 +559,7 @@ public class MultiDataSourceConnection extends WrapperAdapter implements Connect
}
@Override
public Object getRawObject() {
public Connection getRawObject() {
return conn;
}
@@ -571,11 +571,6 @@ public class MultiDataSourceConnection extends WrapperAdapter implements Connect
return attributes;
}
@Override
public Connection getConnectionRaw() {
return conn;
}
@Override
public Properties getProperties() {
return multiDataSource.getProperties();
@@ -29,11 +29,11 @@ public class MultiDataSourceStatement extends WrapperAdapter implements Statemen
conn.checkConnection(sql);
if (resultSetType != null && resultSetConcurrency != null && resultSetHoldability != null) {
stmt = conn.getConnectionRaw().createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
stmt = conn.getRawObject().createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
} else if (resultSetType != null && resultSetConcurrency != null) {
stmt = conn.getConnectionRaw().createStatement(resultSetType, resultSetConcurrency);
stmt = conn.getRawObject().createStatement(resultSetType, resultSetConcurrency);
} else {
stmt = conn.getConnectionRaw().createStatement();
stmt = conn.getRawObject().createStatement();
}
if (maxFieldSize != null) {
@@ -62,7 +62,7 @@ public class OracleValidConnectionChecker implements ValidConnectionChecker, Ser
}
if (conn instanceof ConnectionProxy) {
conn = ((ConnectionProxy) conn).getConnectionRaw();
conn = ((ConnectionProxy) conn).getRawObject();
}
int status = OracleUtils.pingDatabase(conn);
@@ -22,5 +22,5 @@ import java.sql.CallableStatement;
*/
public interface CallableStatementProxy extends CallableStatement, PreparedStatementProxy {
CallableStatement getRawCallableStatement();
CallableStatement getRawObject();
}
@@ -43,7 +43,7 @@ public class CallableStatementProxyImpl extends PreparedStatementProxyImpl imple
this.statement = statement;
}
public CallableStatement getRawCallableStatement() {
public CallableStatement getRawObject() {
return this.statement;
}
@@ -24,7 +24,7 @@ import java.util.Properties;
*/
public interface ConnectionProxy extends Connection, WrapperProxy {
Connection getConnectionRaw();
Connection getRawObject();
Properties getProperties();
@@ -71,6 +71,10 @@ public class ConnectionProxyImpl extends WrapperProxyImpl implements ConnectionP
public Connection getConnectionRaw() {
return connection;
}
public Connection getRawObject() {
return connection;
}
public DataSourceProxy getDirectDataSource() {
return this.dataSource;
@@ -24,5 +24,5 @@ public interface PreparedStatementProxy extends PreparedStatement, StatementProx
String getSql();
PreparedStatement getRawPreparedStatement();
PreparedStatement getRawObject();
}
@@ -54,7 +54,7 @@ public class PreparedStatementProxyImpl extends StatementProxyImpl implements Pr
return this.sql;
}
public PreparedStatement getRawPreparedStatement() {
public PreparedStatement getRawObject() {
return this.statement;
}
@@ -25,7 +25,7 @@ public interface StatementProxy extends Statement, WrapperProxy {
ConnectionProxy getConnectionProxy();
Statement getStatementRaw();
Statement getRawObject();
List<String> getBatchSqlList();
@@ -54,7 +54,7 @@ public class StatementProxyImpl extends WrapperProxyImpl implements StatementPro
return connection;
}
public Statement getStatementRaw() {
public Statement getRawObject() {
return this.statement;
}
@@ -1,7 +0,0 @@
package com.alibaba.druid.spring;
import org.springframework.jdbc.support.nativejdbc.Jdbc4NativeJdbcExtractor;
public class DruidJdbcExtractor extends Jdbc4NativeJdbcExtractor {
}
@@ -1,111 +1,7 @@
package com.alibaba.druid.support.spring;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.springframework.jdbc.support.nativejdbc.Jdbc4NativeJdbcExtractor;
import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor;
import com.alibaba.druid.pool.DruidPooledCallableStatement;
import com.alibaba.druid.pool.DruidPooledConnection;
import com.alibaba.druid.pool.DruidPooledPreparedStatement;
import com.alibaba.druid.pool.DruidPooledResultSet;
import com.alibaba.druid.pool.DruidPooledStatement;
import com.alibaba.druid.proxy.jdbc.CallableStatementProxy;
import com.alibaba.druid.proxy.jdbc.ConnectionProxy;
import com.alibaba.druid.proxy.jdbc.PreparedStatementProxy;
import com.alibaba.druid.proxy.jdbc.ResultSetProxy;
import com.alibaba.druid.proxy.jdbc.StatementProxy;
public class DruidNativeJdbcExtractor implements NativeJdbcExtractor {
@Override
public boolean isNativeConnectionNecessaryForNativeStatements() {
return true;
}
@Override
public boolean isNativeConnectionNecessaryForNativePreparedStatements() {
return true;
}
@Override
public boolean isNativeConnectionNecessaryForNativeCallableStatements() {
return true;
}
@Override
public Connection getNativeConnection(Connection conn) throws SQLException {
if (conn instanceof DruidPooledConnection) {
conn = ((DruidPooledConnection) conn).getConnection();
}
if (conn instanceof ConnectionProxy) {
conn = ((ConnectionProxy) conn).getConnectionRaw();
}
return conn;
}
@Override
public Connection getNativeConnectionFromStatement(Statement stmt) throws SQLException {
Connection conn = stmt.getConnection();
return getNativeConnection(conn);
}
@Override
public Statement getNativeStatement(Statement stmt) throws SQLException {
if (stmt instanceof DruidPooledStatement) {
stmt = ((DruidPooledStatement) stmt).getStatement();
}
if (stmt instanceof StatementProxy) {
stmt = ((StatementProxy) stmt).getStatementRaw();
}
return stmt;
}
@Override
public PreparedStatement getNativePreparedStatement(PreparedStatement stmt) throws SQLException {
if (stmt instanceof DruidPooledPreparedStatement) {
stmt = ((DruidPooledPreparedStatement) stmt).getRawPreparedStatement();
}
if (stmt instanceof PreparedStatementProxy) {
stmt = ((PreparedStatementProxy) stmt).getRawPreparedStatement();
}
return stmt;
}
@Override
public CallableStatement getNativeCallableStatement(CallableStatement stmt) throws SQLException {
if (stmt instanceof DruidPooledCallableStatement) {
stmt = ((DruidPooledCallableStatement) stmt).getCallableStatementRaw();
}
if (stmt instanceof CallableStatementProxy) {
stmt = ((CallableStatementProxy) stmt).getRawCallableStatement();
}
return stmt;
}
@Override
public ResultSet getNativeResultSet(ResultSet rs) throws SQLException {
if (rs instanceof DruidPooledResultSet) {
rs = ((DruidPooledResultSet) rs).getRawResultSet();
}
if (rs instanceof ResultSetProxy) {
rs = ((ResultSetProxy) rs).getResultSetRaw();
}
return rs;
}
public class DruidNativeJdbcExtractor extends Jdbc4NativeJdbcExtractor {
}