mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
support spring Jdbc4NativeJdbcExtractor
This commit is contained in:
@@ -14,6 +14,7 @@ import com.alibaba.druid.mock.MockDriver;
|
||||
import com.alibaba.druid.mock.MockPreparedStatement;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
import com.alibaba.druid.proxy.jdbc.ConnectionProxy;
|
||||
import com.alibaba.druid.stat.DruidDataSourceStatManager;
|
||||
import com.alibaba.druid.stat.JdbcStatContext;
|
||||
import com.alibaba.druid.stat.JdbcStatManager;
|
||||
@@ -60,7 +61,7 @@ public class ConnectionTest4 extends TestCase {
|
||||
|
||||
Assert.assertEquals(null, conn.unwrap(Date.class));
|
||||
Assert.assertEquals(null, conn.unwrap(null));
|
||||
Assert.assertEquals(conn, conn.unwrap(Connection.class));
|
||||
Assert.assertEquals(((ConnectionProxy) conn.getConnection()).getRawObject(), conn.unwrap(Connection.class));
|
||||
|
||||
Assert.assertEquals(false, conn.isWrapperFor(null));
|
||||
Assert.assertEquals(true, conn.isWrapperFor(DruidPooledConnection.class));
|
||||
|
||||
@@ -7,6 +7,9 @@ import java.sql.Statement;
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.jdbc.support.nativejdbc.Jdbc4NativeJdbcExtractor;
|
||||
|
||||
import com.alibaba.druid.mock.MockCallableStatement;
|
||||
import com.alibaba.druid.mock.MockConnection;
|
||||
import com.alibaba.druid.mock.MockPreparedStatement;
|
||||
import com.alibaba.druid.mock.MockStatement;
|
||||
@@ -37,6 +40,12 @@ public class DruidJdbcExtractorTest extends TestCase {
|
||||
Assert.assertEquals(true, extractor.getNativePreparedStatement(preStmt) instanceof MockPreparedStatement);
|
||||
preStmt.close();
|
||||
|
||||
PreparedStatement callStmt = conn.prepareCall("select 1");
|
||||
Assert.assertEquals(true, extractor.getNativeConnectionFromStatement(callStmt) instanceof MockConnection);
|
||||
Assert.assertEquals(true, extractor.getNativeStatement(callStmt) instanceof MockCallableStatement);
|
||||
Assert.assertEquals(true, extractor.getNativePreparedStatement(callStmt) instanceof MockCallableStatement);
|
||||
callStmt.close();
|
||||
|
||||
conn.close();
|
||||
} finally {
|
||||
dataSource.close();
|
||||
@@ -47,7 +56,7 @@ public class DruidJdbcExtractorTest extends TestCase {
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
|
||||
try {
|
||||
DruidJdbcExtractor extractor = new DruidJdbcExtractor();
|
||||
Jdbc4NativeJdbcExtractor extractor = new Jdbc4NativeJdbcExtractor();
|
||||
|
||||
dataSource.setUrl("jdbc:mock:xx1");
|
||||
dataSource.setFilters("stat");
|
||||
@@ -66,6 +75,12 @@ public class DruidJdbcExtractorTest extends TestCase {
|
||||
Assert.assertEquals(true, extractor.getNativePreparedStatement(preStmt) instanceof MockPreparedStatement);
|
||||
preStmt.close();
|
||||
|
||||
PreparedStatement callStmt = conn.prepareCall("select 1");
|
||||
Assert.assertEquals(true, extractor.getNativeConnectionFromStatement(callStmt) instanceof MockConnection);
|
||||
Assert.assertEquals(true, extractor.getNativeStatement(callStmt) instanceof MockCallableStatement);
|
||||
Assert.assertEquals(true, extractor.getNativePreparedStatement(callStmt) instanceof MockCallableStatement);
|
||||
callStmt.close();
|
||||
|
||||
conn.close();
|
||||
} finally {
|
||||
dataSource.close();
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.alibaba.druid.bvt.spring;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.jdbc.support.nativejdbc.Jdbc4NativeJdbcExtractor;
|
||||
|
||||
import com.alibaba.druid.mock.MockCallableStatement;
|
||||
import com.alibaba.druid.mock.MockConnection;
|
||||
import com.alibaba.druid.mock.MockPreparedStatement;
|
||||
import com.alibaba.druid.mock.MockResultSet;
|
||||
import com.alibaba.druid.mock.MockStatement;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.spring.DruidJdbcExtractor;
|
||||
|
||||
public class Jdbc4ExtractorTest extends TestCase {
|
||||
|
||||
public void test_spring() throws Exception {
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
|
||||
try {
|
||||
Jdbc4NativeJdbcExtractor extractor = new Jdbc4NativeJdbcExtractor();
|
||||
|
||||
dataSource.setUrl("jdbc:mock:xx1");
|
||||
Connection conn = dataSource.getConnection();
|
||||
Assert.assertEquals(true, extractor.getNativeConnection(conn) instanceof MockConnection);
|
||||
|
||||
Statement stmt = conn.createStatement();
|
||||
Assert.assertEquals(true, extractor.getNativeConnectionFromStatement(stmt) instanceof MockConnection);
|
||||
Assert.assertEquals(true, extractor.getNativeStatement(stmt) instanceof MockStatement);
|
||||
|
||||
stmt.close();
|
||||
|
||||
PreparedStatement preStmt = conn.prepareStatement("select 1");
|
||||
Assert.assertEquals(true, extractor.getNativeConnectionFromStatement(preStmt) instanceof MockConnection);
|
||||
Assert.assertEquals(true, extractor.getNativeStatement(preStmt) instanceof MockPreparedStatement);
|
||||
Assert.assertEquals(true, extractor.getNativePreparedStatement(preStmt) instanceof MockPreparedStatement);
|
||||
ResultSet rs = preStmt.executeQuery();
|
||||
Assert.assertEquals(true, extractor.getNativeResultSet(rs) instanceof MockResultSet);
|
||||
rs.close();
|
||||
|
||||
preStmt.close();
|
||||
|
||||
PreparedStatement callStmt = conn.prepareCall("select 1");
|
||||
Assert.assertEquals(true, extractor.getNativeConnectionFromStatement(callStmt) instanceof MockConnection);
|
||||
Assert.assertEquals(true, extractor.getNativeStatement(callStmt) instanceof MockCallableStatement);
|
||||
Assert.assertEquals(true, extractor.getNativePreparedStatement(callStmt) instanceof MockCallableStatement);
|
||||
callStmt.close();
|
||||
|
||||
conn.close();
|
||||
} finally {
|
||||
dataSource.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void test_spring_filter() throws Exception {
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
|
||||
try {
|
||||
DruidJdbcExtractor extractor = new DruidJdbcExtractor();
|
||||
|
||||
dataSource.setUrl("jdbc:mock:xx1");
|
||||
dataSource.setFilters("stat");
|
||||
Connection conn = dataSource.getConnection();
|
||||
Assert.assertEquals(true, extractor.getNativeConnection(conn) instanceof MockConnection);
|
||||
|
||||
Statement stmt = conn.createStatement();
|
||||
Assert.assertEquals(true, extractor.getNativeConnectionFromStatement(stmt) instanceof MockConnection);
|
||||
Assert.assertEquals(true, extractor.getNativeStatement(stmt) instanceof MockStatement);
|
||||
|
||||
stmt.close();
|
||||
|
||||
PreparedStatement preStmt = conn.prepareStatement("select 1");
|
||||
Assert.assertEquals(true, extractor.getNativeConnectionFromStatement(preStmt) instanceof MockConnection);
|
||||
Assert.assertEquals(true, extractor.getNativeStatement(preStmt) instanceof MockPreparedStatement);
|
||||
Assert.assertEquals(true, extractor.getNativePreparedStatement(preStmt) instanceof MockPreparedStatement);
|
||||
ResultSet rs = preStmt.executeQuery();
|
||||
Assert.assertEquals(true, extractor.getNativeResultSet(rs) instanceof MockResultSet);
|
||||
rs.close();
|
||||
|
||||
preStmt.close();
|
||||
|
||||
PreparedStatement callStmt = conn.prepareCall("select 1");
|
||||
Assert.assertEquals(true, extractor.getNativeConnectionFromStatement(callStmt) instanceof MockConnection);
|
||||
Assert.assertEquals(true, extractor.getNativeStatement(callStmt) instanceof MockCallableStatement);
|
||||
Assert.assertEquals(true, extractor.getNativePreparedStatement(callStmt) instanceof MockCallableStatement);
|
||||
callStmt.close();
|
||||
|
||||
conn.close();
|
||||
} finally {
|
||||
dataSource.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user