mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
支持Spring和ibatis
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@426 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -259,7 +259,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
PoolableConnection poolalbeConnection = getConnectionInternal();
|
||||
|
||||
if (isTestOnBorrow()) {
|
||||
boolean validate = testConnection(poolalbeConnection.getRawConnection());
|
||||
boolean validate = testConnection(poolalbeConnection.getConnection());
|
||||
if (!validate) {
|
||||
LOG.debug("skip not validate connection.");
|
||||
Connection realConnection = poolalbeConnection.getConnection();
|
||||
|
||||
@@ -41,6 +41,10 @@ public class PoolableCallableStatement extends PoolablePreparedStatement impleme
|
||||
this.stmt = stmt;
|
||||
}
|
||||
|
||||
public CallableStatement getCallableStatementRaw() {
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException {
|
||||
try {
|
||||
|
||||
@@ -104,10 +104,6 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
this.holder.getStatementPool().put(stmt);
|
||||
}
|
||||
|
||||
public Connection getRawConnection() {
|
||||
return conn;
|
||||
}
|
||||
|
||||
public ConnectionHolder getConnectionHolder() {
|
||||
return holder;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
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.NativeJdbcExtractor;
|
||||
|
||||
import com.alibaba.druid.pool.PoolableCallableStatement;
|
||||
import com.alibaba.druid.pool.PoolableConnection;
|
||||
import com.alibaba.druid.pool.PoolablePreparedStatement;
|
||||
import com.alibaba.druid.pool.PoolableResultSet;
|
||||
import com.alibaba.druid.pool.PoolableStatement;
|
||||
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 PoolableConnection) {
|
||||
conn = ((PoolableConnection) 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 PoolableStatement) {
|
||||
stmt = ((PoolableStatement) stmt).getStatement();
|
||||
}
|
||||
|
||||
if (stmt instanceof StatementProxy) {
|
||||
stmt = ((StatementProxy) stmt).getStatementRaw();
|
||||
}
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement getNativePreparedStatement(PreparedStatement stmt) throws SQLException {
|
||||
if (stmt instanceof PoolablePreparedStatement) {
|
||||
stmt = ((PoolablePreparedStatement) stmt).getRawPreparedStatement();
|
||||
}
|
||||
|
||||
if (stmt instanceof PreparedStatementProxy) {
|
||||
stmt = ((PreparedStatementProxy) stmt).getRawPreparedStatement();
|
||||
}
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallableStatement getNativeCallableStatement(CallableStatement stmt) throws SQLException {
|
||||
if (stmt instanceof PoolableCallableStatement) {
|
||||
stmt = ((PoolableCallableStatement) stmt).getCallableStatementRaw();
|
||||
}
|
||||
|
||||
if (stmt instanceof CallableStatementProxy) {
|
||||
stmt = ((CallableStatementProxy) stmt).getRawCallableStatement();
|
||||
}
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet getNativeResultSet(ResultSet rs) throws SQLException {
|
||||
if (rs instanceof PoolableResultSet) {
|
||||
rs = ((PoolableResultSet) rs).getRawResultSet();
|
||||
}
|
||||
|
||||
if (rs instanceof ResultSetProxy) {
|
||||
rs = ((ResultSetProxy) rs).getResultSetRaw();
|
||||
}
|
||||
|
||||
return rs;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user