Search in sources :

Example 1 with DruidNativeJdbcExtractor

use of com.alibaba.druid.support.spring.DruidNativeJdbcExtractor in project druid by alibaba.

the class DruidJdbcExtractorTest method test_spring.

public void test_spring() throws Exception {
    DruidDataSource dataSource = new DruidDataSource();
    try {
        DruidNativeJdbcExtractor extractor = new DruidNativeJdbcExtractor();
        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);
        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();
    }
}
Also used : MockCallableStatement(com.alibaba.druid.mock.MockCallableStatement) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement) MockStatement(com.alibaba.druid.mock.MockStatement) MockCallableStatement(com.alibaba.druid.mock.MockCallableStatement) Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) Connection(java.sql.Connection) MockConnection(com.alibaba.druid.mock.MockConnection) MockStatement(com.alibaba.druid.mock.MockStatement) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement) PreparedStatement(java.sql.PreparedStatement) DruidNativeJdbcExtractor(com.alibaba.druid.support.spring.DruidNativeJdbcExtractor) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) MockConnection(com.alibaba.druid.mock.MockConnection)

Example 2 with DruidNativeJdbcExtractor

use of com.alibaba.druid.support.spring.DruidNativeJdbcExtractor in project druid by alibaba.

the class DruidJdbcExtractorTest method test_spring_filter.

public void test_spring_filter() throws Exception {
    DruidDataSource dataSource = new DruidDataSource();
    try {
        DruidNativeJdbcExtractor extractor = new DruidNativeJdbcExtractor();
        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);
        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();
    }
}
Also used : MockCallableStatement(com.alibaba.druid.mock.MockCallableStatement) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement) MockStatement(com.alibaba.druid.mock.MockStatement) MockCallableStatement(com.alibaba.druid.mock.MockCallableStatement) Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) Connection(java.sql.Connection) MockConnection(com.alibaba.druid.mock.MockConnection) MockStatement(com.alibaba.druid.mock.MockStatement) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement) PreparedStatement(java.sql.PreparedStatement) DruidNativeJdbcExtractor(com.alibaba.druid.support.spring.DruidNativeJdbcExtractor) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) MockConnection(com.alibaba.druid.mock.MockConnection)

Aggregations

MockCallableStatement (com.alibaba.druid.mock.MockCallableStatement)2 MockConnection (com.alibaba.druid.mock.MockConnection)2 MockPreparedStatement (com.alibaba.druid.mock.MockPreparedStatement)2 MockStatement (com.alibaba.druid.mock.MockStatement)2 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)2 DruidNativeJdbcExtractor (com.alibaba.druid.support.spring.DruidNativeJdbcExtractor)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 Statement (java.sql.Statement)2