SQLResultSet implements IPentahoResultSet, IPeekable { public int getRowCount() { if ( !isScrollable() ) { return -1; } if ( rowCount != SQLResultSet.COUNT_NEVER_OBTAINED ) { return rowCount; } if ( nativeResultSet == null ) { return 0; } try { int curRow = nativeResultSet.getRow(); try { if ( nativeResultSet.last() ) { rowCount = nativeResultSet.getRow(); if ( rowCount <= 0 ) { rowCount = 0; } } else { rowCount = 0; } } finally { if ( curRow == 0 ) { nativeResultSet.beforeFirst(); } else { nativeResultSet.absolute( curRow ); } } } catch ( SQLException sqle ) { SQLResultSet.log.error( Messages.getInstance().getErrorString( "SQLResultSet.ERROR_0001_OBTAINING_ROWCOUNT" ), sqle ); rowCount = 0; } return rowCount; } SQLResultSet( final ResultSet nativeResultSet, final SQLConnection nativeConnection ); void setMetaData( final IPentahoMetaData metadata ); IPentahoMetaData getMetaData(); Object[] peek(); Object[] next(); void closeConnection(); void close(); void dispose(); boolean isScrollable(); int getColumnCount(); int getRowCount(); Object getValueAt( final int row, final int column ); IPentahoResultSet memoryCopy(); void beforeFirst(); Object[] getDataColumn( final int column ); Object[] getDataRow( final int row );  }
@Test public void testGetRowCount() { SQLResultSet resultSet = new SQLResultSet( nativeResultSet, nativeConnection ); assertEquals( 0, resultSet.getRowCount() ); }
@Test public void testGetRowCountResultSetReturn0() throws SQLException { int rowCount = 0; when( nativeResultSet.getRow() ).thenReturn( rowCount ); when( nativeResultSet.last() ).thenReturn( true ); SQLResultSet resultSet = new SQLResultSet( nativeResultSet, nativeConnection ); assertEquals( rowCount, resultSet.getRowCount() ); }
@Test public void testGetRowCountResultSetReturnRow() throws SQLException { int rowCount = 1; when( nativeResultSet.getRow() ).thenReturn( rowCount ); when( nativeResultSet.last() ).thenReturn( true ); SQLResultSet resultSet = new SQLResultSet( nativeResultSet, nativeConnection ); assertEquals( rowCount, resultSet.getRowCount() ); }
@Test public void testGetRowCountNonScrolableNullResultSet() { SQLResultSet resultSet = new SQLResultSet( null, nativeConnection ); assertEquals( -1, resultSet.getRowCount() ); }