Search in sources :

Example 1 with DruidPooledCallableStatement

use of com.alibaba.druid.pool.DruidPooledCallableStatement in project druid by alibaba.

the class PoolableCallableStatementTest method setUp.

protected void setUp() throws Exception {
    MockConnection mockConn = new MockConnection();
    DruidConnectionHolder connHolder = new DruidConnectionHolder(dataSource, mockConn, 0);
    conn = new DruidPooledConnection(connHolder);
    raw = new MockCallableStatement(null, null);
    stmt = new DruidPooledCallableStatement(conn, new PreparedStatementHolder(new PreparedStatementKey("", null, null, 0, 0, 0), raw)) {

        protected SQLException checkException(Throwable error) throws SQLException {
            if (error instanceof SQLException) {
                return (SQLException) error;
            }
            return new SQLException(error);
        }
    };
    Assert.assertEquals(0, raw.getOutParameters().size());
    stmt.registerOutParameter(1, Types.INTEGER);
    Assert.assertEquals(1, raw.getOutParameters().size());
    stmt.registerOutParameter(2, Types.DECIMAL, 10);
    Assert.assertEquals(2, raw.getOutParameters().size());
}
Also used : MockCallableStatement(com.alibaba.druid.mock.MockCallableStatement) PreparedStatementHolder(com.alibaba.druid.pool.PreparedStatementHolder) DruidPooledCallableStatement(com.alibaba.druid.pool.DruidPooledCallableStatement) DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection) DruidConnectionHolder(com.alibaba.druid.pool.DruidConnectionHolder) PreparedStatementKey(com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey) MockConnection(com.alibaba.druid.mock.MockConnection)

Example 2 with DruidPooledCallableStatement

use of com.alibaba.druid.pool.DruidPooledCallableStatement in project druid by alibaba.

the class DruidPooledCallableStatementTest method test_getObject_1.

public void test_getObject_1() throws Exception {
    Connection conn = dataSource.getConnection();
    DruidPooledCallableStatement stmt = (DruidPooledCallableStatement) conn.prepareCall("select 1");
    stmt.execute();
    Assert.assertEquals(0, dataSource.getErrorCount());
    Exception error = null;
    try {
        stmt.getObject("1", String.class);
    } catch (SQLFeatureNotSupportedException e) {
        error = e;
    }
    Assert.assertNotNull(error);
    Assert.assertEquals(0, dataSource.getErrorCount());
    stmt.close();
    conn.close();
    Assert.assertEquals(1, dataSource.getPoolingCount());
}
Also used : DruidPooledCallableStatement(com.alibaba.druid.pool.DruidPooledCallableStatement) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) Connection(java.sql.Connection) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) SQLException(java.sql.SQLException)

Example 3 with DruidPooledCallableStatement

use of com.alibaba.druid.pool.DruidPooledCallableStatement in project druid by alibaba.

the class DruidPooledCallableStatementTest method test_getObject.

public void test_getObject() throws Exception {
    Connection conn = dataSource.getConnection();
    DruidPooledCallableStatement stmt = (DruidPooledCallableStatement) conn.prepareCall("select 1");
    stmt.execute();
    Assert.assertEquals(0, dataSource.getErrorCount());
    Exception error = null;
    try {
        stmt.getObject(1, String.class);
    } catch (SQLFeatureNotSupportedException e) {
        error = e;
    }
    Assert.assertNotNull(error);
    Assert.assertEquals(0, dataSource.getErrorCount());
    stmt.close();
    conn.close();
    Assert.assertEquals(1, dataSource.getPoolingCount());
}
Also used : DruidPooledCallableStatement(com.alibaba.druid.pool.DruidPooledCallableStatement) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) Connection(java.sql.Connection) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) SQLException(java.sql.SQLException)

Aggregations

DruidPooledCallableStatement (com.alibaba.druid.pool.DruidPooledCallableStatement)3 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)2 MockCallableStatement (com.alibaba.druid.mock.MockCallableStatement)1 MockConnection (com.alibaba.druid.mock.MockConnection)1 DruidConnectionHolder (com.alibaba.druid.pool.DruidConnectionHolder)1 DruidPooledConnection (com.alibaba.druid.pool.DruidPooledConnection)1 PreparedStatementKey (com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey)1 PreparedStatementHolder (com.alibaba.druid.pool.PreparedStatementHolder)1