Search in sources :

Example 11 with MockResultSet

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

the class JdbcUtilsTest method test_print.

public void test_print() throws Exception {
    final AtomicInteger nextCount = new AtomicInteger(2);
    final MockResultSetMetaData rsMeta = new MockResultSetMetaData() {

        private int[] types = new int[] { Types.DATE, Types.BIT, Types.BOOLEAN, Types.TINYINT, Types.SMALLINT, Types.INTEGER, Types.CLOB, Types.LONGVARCHAR, Types.OTHER, Types.VARCHAR, Types.CHAR, Types.NVARCHAR, Types.NCHAR };

        @Override
        public int getColumnCount() throws SQLException {
            return types.length;
        }

        @Override
        public int getColumnType(int column) throws SQLException {
            return types[column - 1];
        }

        @Override
        public String getColumnName(int column) throws SQLException {
            return "C" + column;
        }
    };
    MockResultSet rs = new MockResultSet(null) {

        @Override
        public boolean next() throws SQLException {
            return nextCount.getAndDecrement() > 0;
        }

        @Override
        public ResultSetMetaData getMetaData() throws SQLException {
            return rsMeta;
        }

        @Override
        public java.sql.Date getDate(int columnIndex) throws SQLException {
            return new java.sql.Date(System.currentTimeMillis());
        }

        @Override
        public boolean wasNull() throws SQLException {
            if (nextCount.get() == 1) {
                return true;
            }
            return false;
        }

        public Object getObject(int columnIndex) throws SQLException {
            return null;
        }
    };
    JdbcUtils.printResultSet(rs);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MockResultSetMetaData(com.alibaba.druid.mock.MockResultSetMetaData) MockResultSet(com.alibaba.druid.mock.MockResultSet)

Example 12 with MockResultSet

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

the class JdbcUtilsTest method test_close.

public void test_close() throws Exception {
    JdbcUtils.close((Connection) null);
    JdbcUtils.close((Statement) null);
    JdbcUtils.close((ResultSet) null);
    JdbcUtils.close(new MockConnection() {

        @Override
        public void close() throws SQLException {
            throw new SQLException();
        }
    });
    JdbcUtils.close(new MockStatement(null) {

        @Override
        public void close() throws SQLException {
            throw new SQLException();
        }
    });
    JdbcUtils.close(new MockResultSet(null) {

        @Override
        public void close() throws SQLException {
            throw new SQLException();
        }
    });
    JdbcUtils.close(new Closeable() {

        @Override
        public void close() throws IOException {
            throw new IOException();
        }
    });
    JdbcUtils.close(new Closeable() {

        @Override
        public void close() throws IOException {
        }
    });
    JdbcUtils.close((Closeable) null);
    new JdbcUtils();
}
Also used : JdbcUtils(com.alibaba.druid.util.JdbcUtils) SQLException(java.sql.SQLException) Closeable(java.io.Closeable) MockStatement(com.alibaba.druid.mock.MockStatement) MockResultSet(com.alibaba.druid.mock.MockResultSet) IOException(java.io.IOException) MockConnection(com.alibaba.druid.mock.MockConnection)

Example 13 with MockResultSet

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

the class DruidLobHandlerTest method test_0.

public void test_0() throws Exception {
    DruidLobHandler handler = new DruidLobHandler();
    List<Object[]> rows = new ArrayList<Object[]>();
    rows.add(new Object[] { null, new MockBlob(), new MockClob() });
    MockResultSet rs = new MockResultSet(null, rows);
    rs.next();
    handler.getBlobAsBinaryStream(rs, 1);
    handler.getBlobAsBinaryStream(rs, "1");
    handler.getBlobAsBytes(rs, 1);
    handler.getBlobAsBytes(rs, "1");
    handler.getBlobAsBinaryStream(rs, 2);
    handler.getBlobAsBinaryStream(rs, "2");
    handler.getBlobAsBytes(rs, 2);
    handler.getBlobAsBytes(rs, "2");
    handler.getClobAsAsciiStream(rs, 1);
    handler.getClobAsAsciiStream(rs, "1");
    handler.getClobAsCharacterStream(rs, 1);
    handler.getClobAsCharacterStream(rs, "1");
    handler.getClobAsString(rs, 1);
    handler.getClobAsString(rs, "1");
    handler.getClobAsAsciiStream(rs, 3);
    handler.getClobAsAsciiStream(rs, "3");
    handler.getClobAsCharacterStream(rs, 3);
    handler.getClobAsCharacterStream(rs, "3");
    handler.getClobAsString(rs, 3);
    handler.getClobAsString(rs, "3");
    handler.getLobCreator();
}
Also used : MockBlob(com.alibaba.druid.mock.MockBlob) MockClob(com.alibaba.druid.mock.MockClob) ArrayList(java.util.ArrayList) MockResultSet(com.alibaba.druid.mock.MockResultSet) DruidLobHandler(com.alibaba.druid.support.spring.DruidLobHandler)

Example 14 with MockResultSet

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

the class MySqlMockExecuteHandlerImpl method showStatus.

public ResultSet showStatus(MockStatementBase statement) throws SQLException {
    MockResultSet rs = new MockResultSet(statement);
    MockResultSetMetaData metaData = rs.getMockMetaData();
    Object[] row = new Object[] { "on" };
    ColumnMetaData column = new ColumnMetaData();
    column.setColumnType(Types.NVARCHAR);
    metaData.getColumns().add(column);
    rs.getRows().add(row);
    return rs;
}
Also used : MockResultSetMetaData(com.alibaba.druid.mock.MockResultSetMetaData) MockResultSet(com.alibaba.druid.mock.MockResultSet) ColumnMetaData(com.alibaba.druid.util.jdbc.ResultSetMetaDataBase.ColumnMetaData)

Example 15 with MockResultSet

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

the class ResultSetTest2 method test_closeError.

public void test_closeError() throws Exception {
    MockResultSet mock = new MockResultSet(null) {

        public void close() throws SQLException {
            throw new SQLException();
        }
    };
    DruidPooledResultSet rs = new DruidPooledResultSet(stmt, mock);
    SQLException error = null;
    try {
        rs.close();
    } catch (SQLException ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
Also used : SQLException(java.sql.SQLException) MockResultSet(com.alibaba.druid.mock.MockResultSet) DruidPooledResultSet(com.alibaba.druid.pool.DruidPooledResultSet)

Aggregations

MockResultSet (com.alibaba.druid.mock.MockResultSet)22 SQLException (java.sql.SQLException)11 ResultSet (java.sql.ResultSet)7 ResultSetProxyImpl (com.alibaba.druid.proxy.jdbc.ResultSetProxyImpl)6 FilterChainImpl (com.alibaba.druid.filter.FilterChainImpl)5 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)5 ResultSetProxy (com.alibaba.druid.proxy.jdbc.ResultSetProxy)5 MockResultSetMetaData (com.alibaba.druid.mock.MockResultSetMetaData)4 DruidPooledResultSet (com.alibaba.druid.pool.DruidPooledResultSet)4 StatementProxyImpl (com.alibaba.druid.proxy.jdbc.StatementProxyImpl)4 Properties (java.util.Properties)4 DruidPooledStatement (com.alibaba.druid.pool.DruidPooledStatement)3 ConnectionProxyImpl (com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl)3 Connection (java.sql.Connection)3 MockCallableStatement (com.alibaba.druid.mock.MockCallableStatement)2 MockClob (com.alibaba.druid.mock.MockClob)2 MockConnection (com.alibaba.druid.mock.MockConnection)2 MockStatement (com.alibaba.druid.mock.MockStatement)2 StatementProxy (com.alibaba.druid.proxy.jdbc.StatementProxy)2 ColumnMetaData (com.alibaba.druid.util.jdbc.ResultSetMetaDataBase.ColumnMetaData)2