1 21 package org.dbunit.database; 22 23 import org.dbunit.dataset.Column; 24 import org.dbunit.dataset.DataSetException; 25 import org.dbunit.dataset.ITableMetaData; 26 import org.dbunit.dataset.RowOutOfBoundsException; 27 28 import java.sql.ResultSet ; 29 import java.sql.SQLException ; 30 31 36 public class ForwardOnlyResultSetTable extends AbstractResultSetTable 37 { 38 private int _lastRow = -1; 39 private boolean _eot = false; 41 public ForwardOnlyResultSetTable(ITableMetaData metaData, 42 ResultSet resultSet) throws SQLException , DataSetException 43 { 44 super(metaData, resultSet); 45 } 46 47 public ForwardOnlyResultSetTable(ITableMetaData metaData, 48 IDatabaseConnection connection) throws DataSetException, SQLException 49 { 50 super(metaData, connection); 51 } 52 53 public ForwardOnlyResultSetTable(String tableName, String selectStatement, 54 IDatabaseConnection connection) throws DataSetException, SQLException 55 { 56 super(tableName, selectStatement, connection); 57 } 58 59 62 public int getRowCount() 63 { 64 throw new UnsupportedOperationException (); 65 } 66 67 public Object getValue(int row, String columnName) throws DataSetException 68 { 69 try 70 { 71 while (!_eot && row > _lastRow) 73 { 74 _eot = !_resultSet.next(); 75 _lastRow++; 76 } 77 78 if (row < _lastRow) 79 { 80 throw new UnsupportedOperationException ("Cannot go backward!"); 81 } 82 83 if (_eot || row > _lastRow) 84 { 85 close(); 87 throw new RowOutOfBoundsException(row + " > " + _lastRow); 88 } 89 90 int columnIndex = getColumnIndex(columnName); 91 Column column = _metaData.getColumns()[columnIndex]; 92 return column.getDataType().getSqlValue(columnIndex + 1, _resultSet); 93 } 94 catch (SQLException e) 95 { 96 throw new DataSetException(e); 97 } 98 } 99 } 100 | Popular Tags |