Search in sources :

Example 6 with MockCallableStatement

use of com.alibaba.druid.mock.MockCallableStatement 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 7 with MockCallableStatement

use of com.alibaba.druid.mock.MockCallableStatement 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)

Example 8 with MockCallableStatement

use of com.alibaba.druid.mock.MockCallableStatement in project druid by alibaba.

the class CallableStatmentTest method setUp.

protected void setUp() throws Exception {
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setTestOnBorrow(false);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setMaxOpenPreparedStatements(100);
    dataSource.setFilters("log4j");
    dataSource.setDriver(new MockDriver() {

        public MockCallableStatement createMockCallableStatement(MockConnection conn, String sql) {
            return new MyMockCallableStatement(conn, sql);
        }
    });
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) MockCallableStatement(com.alibaba.druid.mock.MockCallableStatement) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) MockConnection(com.alibaba.druid.mock.MockConnection)

Example 9 with MockCallableStatement

use of com.alibaba.druid.mock.MockCallableStatement in project druid by alibaba.

the class FilterChainTest_NClob_2 method setUp.

protected void setUp() throws Exception {
    dataSource = new DruidDataSource();
    MockCallableStatement mockStmt = new MockCallableStatement(null, "") {

        @Override
        public Object getObject(int parameterIndex) throws SQLException {
            invokeCount++;
            return new MockNClob();
        }
    };
    statement = new CallableStatementProxyImpl(new ConnectionProxyImpl(null, null, null, 0), mockStmt, "", 1);
}
Also used : MockCallableStatement(com.alibaba.druid.mock.MockCallableStatement) MockNClob(com.alibaba.druid.mock.MockNClob) ConnectionProxyImpl(com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl) CallableStatementProxyImpl(com.alibaba.druid.proxy.jdbc.CallableStatementProxyImpl) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Aggregations

MockCallableStatement (com.alibaba.druid.mock.MockCallableStatement)9 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)6 MockConnection (com.alibaba.druid.mock.MockConnection)5 MockResultSet (com.alibaba.druid.mock.MockResultSet)3 CallableStatementProxyImpl (com.alibaba.druid.proxy.jdbc.CallableStatementProxyImpl)3 ConnectionProxyImpl (com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl)3 Connection (java.sql.Connection)3 MockPreparedStatement (com.alibaba.druid.mock.MockPreparedStatement)2 MockStatement (com.alibaba.druid.mock.MockStatement)2 DruidPooledConnection (com.alibaba.druid.pool.DruidPooledConnection)2 DruidNativeJdbcExtractor (com.alibaba.druid.support.spring.DruidNativeJdbcExtractor)2 CallableStatement (java.sql.CallableStatement)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2 EncodingConvertFilter (com.alibaba.druid.filter.encoding.EncodingConvertFilter)1 MockClob (com.alibaba.druid.mock.MockClob)1 MockDriver (com.alibaba.druid.mock.MockDriver)1 MockNClob (com.alibaba.druid.mock.MockNClob)1 DruidConnectionHolder (com.alibaba.druid.pool.DruidConnectionHolder)1