Search in sources :

Example 6 with MockPreparedStatement

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

the class TestPoolPreparedStatement method test_removeAbandoned.

public void test_removeAbandoned() throws Exception {
    MockPreparedStatement raw;
    {
        Connection conn = dataSource.getConnection();
        PreparedStatement stmt = conn.prepareStatement("SELECT ?");
        raw = stmt.unwrap(MockPreparedStatement.class);
        stmt.execute();
        stmt.close();
        conn.close();
    }
    {
        Connection conn = dataSource.getConnection();
        PreparedStatement stmt = conn.prepareStatement("SELECT ?");
        Assert.assertTrue(raw == stmt.unwrap(MockPreparedStatement.class));
        stmt.execute();
        stmt.close();
        conn.close();
    }
    Assert.assertEquals(0, dataSource.getActiveCount());
    Assert.assertEquals(1, dataSource.getPoolingCount());
}
Also used : Connection(java.sql.Connection) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement) PreparedStatement(java.sql.PreparedStatement) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement)

Example 7 with MockPreparedStatement

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

the class TestGetUpdateCount method setUp.

protected void setUp() throws Exception {
    driver = new MockDriver() {

        @Override
        public MockPreparedStatement createMockPreparedStatement(MockConnection conn, String sql) {
            return new MyPreparedStatement(conn, sql);
        }
    };
    // /////////////////////////////
    dataSource = new DruidDataSource();
    dataSource.setDriver(driver);
    dataSource.setUrl("jdbc:mock:xx");
    dataSource.setFilters("stat");
    dataSource.setMaxOpenPreparedStatements(30);
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement) MockConnection(com.alibaba.druid.mock.MockConnection) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 8 with MockPreparedStatement

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

the class ConnectionTest4 method test_prepareStatement_3.

public void test_prepareStatement_3() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
    MockPreparedStatement raw = null;
    {
        PreparedStatement stmt = conn.prepareStatement("SELECT 1", new String[0]);
        raw = stmt.unwrap(MockPreparedStatement.class);
        stmt.close();
    }
    {
        PreparedStatement stmt = conn.prepareStatement("SELECT 1", new String[0]);
        Assert.assertEquals(raw, stmt.unwrap(MockPreparedStatement.class));
        stmt.close();
    }
    conn.close();
}
Also used : DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement) PreparedStatement(java.sql.PreparedStatement) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement)

Example 9 with MockPreparedStatement

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

the class ConnectionTest4 method test_prepareStatement_4.

public void test_prepareStatement_4() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
    MockPreparedStatement raw = null;
    {
        PreparedStatement stmt = conn.prepareStatement("SELECT 1", 0);
        raw = stmt.unwrap(MockPreparedStatement.class);
        stmt.close();
    }
    {
        PreparedStatement stmt = conn.prepareStatement("SELECT 1", 0);
        Assert.assertEquals(raw, stmt.unwrap(MockPreparedStatement.class));
        stmt.close();
    }
    conn.close();
}
Also used : DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement) PreparedStatement(java.sql.PreparedStatement) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement)

Example 10 with MockPreparedStatement

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

the class ConnectionTest4 method test_prepareStatement_1.

public void test_prepareStatement_1() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
    MockPreparedStatement raw = null;
    {
        PreparedStatement stmt = conn.prepareStatement("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
        raw = stmt.unwrap(MockPreparedStatement.class);
        stmt.close();
    }
    {
        PreparedStatement stmt = conn.prepareStatement("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
        Assert.assertSame(raw, stmt.unwrap(MockPreparedStatement.class));
        stmt.close();
    }
    conn.close();
}
Also used : DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement) PreparedStatement(java.sql.PreparedStatement) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement)

Aggregations

MockPreparedStatement (com.alibaba.druid.mock.MockPreparedStatement)24 PreparedStatement (java.sql.PreparedStatement)14 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)10 DruidPooledConnection (com.alibaba.druid.pool.DruidPooledConnection)9 Connection (java.sql.Connection)8 MockConnection (com.alibaba.druid.mock.MockConnection)6 MockDriver (com.alibaba.druid.mock.MockDriver)5 ResultSet (java.sql.ResultSet)5 SQLException (java.sql.SQLException)5 MockResultSet (com.alibaba.druid.mock.MockResultSet)4 MockStatement (com.alibaba.druid.mock.MockStatement)4 Statement (java.sql.Statement)4 MockCallableStatement (com.alibaba.druid.mock.MockCallableStatement)2 MockStatementBase (com.alibaba.druid.mock.MockStatementBase)2 DruidConnectionHolder (com.alibaba.druid.pool.DruidConnectionHolder)2 PreparedStatementKey (com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey)2 PreparedStatementHolder (com.alibaba.druid.pool.PreparedStatementHolder)2 DruidNativeJdbcExtractor (com.alibaba.druid.support.spring.DruidNativeJdbcExtractor)2 EncodingConvertFilter (com.alibaba.druid.filter.encoding.EncodingConvertFilter)1 MockResultSetMetaData (com.alibaba.druid.mock.MockResultSetMetaData)1