org.dbunit.dataset
Class SortedTable

java.lang.Object
  extended by org.dbunit.dataset.AbstractTable
      extended by org.dbunit.dataset.SortedTable
All Implemented Interfaces:
ITable

public class SortedTable
extends AbstractTable

This is a ITable decorator that provide a sorted view of the decorated table. This implementation does not keep a separate copy of the decorated table data.

Since:
Feb 19, 2003
Version:
$Revision: 913 $ $Date: 2008-12-06 17:09:29 +0100 (Sat, 06 Dec 2008) $
Author:
Manuel Laflamme, Last changed by: $Author: gommma $

Nested Class Summary
protected static class SortedTable.AbstractRowComparator
          Abstract class for sorting the table rows of a given table in a specific order
protected static class SortedTable.RowComparator
          Compares the rows with each other in order to sort them in the correct order using the data type and the Comparable implementation the current column has.
protected static class SortedTable.RowComparatorByString
          Compares the rows with each other in order to sort them in the correct order using the string value of both values for the comparison.
 
Field Summary
 
Fields inherited from interface org.dbunit.dataset.ITable
NO_VALUE
 
Constructor Summary
SortedTable(ITable table)
          Sort the decorated table by its own columns order which is defined by ITable.getTableMetaData().
SortedTable(ITable table, Column[] columns)
          Sort the decorated table by specified columns order.
SortedTable(ITable table, ITableMetaData metaData)
          Sort the decorated table by specified metadata columns order.
SortedTable(ITable table, String[] columnNames)
          Sort the decorated table by specified columns order.
 
Method Summary
 int getRowCount()
          Returns this table row count.
 Column[] getSortColumns()
           
 ITableMetaData getTableMetaData()
          Returns this table metadata.
 Object getValue(int row, String columnName)
          Returns this table value for the specified row and column.
 void setRowComparator(SortedTable.AbstractRowComparator comparator)
          Sets the comparator to be used for sorting the table rows.
 void setUseComparable(boolean useComparable)
          Whether or not the comparable interface should be used of the compared columns instead of the plain strings Default value is false for backwards compatibility Set whether or not to use the Comparable implementation of the corresponding column DataType for comparing values or not.
 
Methods inherited from class org.dbunit.dataset.AbstractTable
assertValidColumn, assertValidRowIndex, assertValidRowIndex, getColumnIndex
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SortedTable

public SortedTable(ITable table,
                   Column[] columns)
            throws DataSetException
Sort the decorated table by specified columns order.

Parameters:
table - decorated table
columns - columns to be used for sorting
Throws:
DataSetException

SortedTable

public SortedTable(ITable table,
                   String[] columnNames)
            throws DataSetException
Sort the decorated table by specified columns order.

Parameters:
table - decorated table
columnNames - names of columns to be used for sorting
Throws:
DataSetException

SortedTable

public SortedTable(ITable table,
                   ITableMetaData metaData)
            throws DataSetException
Sort the decorated table by specified metadata columns order. All metadata columns will be used.

Parameters:
table - The decorated table
metaData - The metadata used to retrieve all columns which in turn are used for sorting the table
Throws:
DataSetException

SortedTable

public SortedTable(ITable table)
            throws DataSetException
Sort the decorated table by its own columns order which is defined by ITable.getTableMetaData(). All table columns will be used.

Parameters:
table - The decorated table
Throws:
DataSetException
Method Detail

getSortColumns

public Column[] getSortColumns()
Returns:
The columns that are used for sorting the table

setUseComparable

public void setUseComparable(boolean useComparable)
Whether or not the comparable interface should be used of the compared columns instead of the plain strings Default value is false for backwards compatibility Set whether or not to use the Comparable implementation of the corresponding column DataType for comparing values or not. Default value is false which means that the old string comparison is used.

Parameters:
useComparable -
Since:
2.3.0

setRowComparator

public void setRowComparator(SortedTable.AbstractRowComparator comparator)
Sets the comparator to be used for sorting the table rows.

Parameters:
comparator - sorts the table rows
Since:
2.4.2

getTableMetaData

public ITableMetaData getTableMetaData()
Description copied from interface: ITable
Returns this table metadata.


getRowCount

public int getRowCount()
Description copied from interface: ITable
Returns this table row count.


getValue

public Object getValue(int row,
                       String columnName)
                throws DataSetException
Description copied from interface: ITable
Returns this table value for the specified row and column.

Parameters:
row - The row index, starting with 0
columnName - The name of the column
Returns:
The value
Throws:
NoSuchColumnException - if specified column name do not exist in this table
RowOutOfBoundsException - if specified row is less than zero or equals or greater than getRowCount
DataSetException


Copyright © 2002-2012. All Rights Reserved.