org.objectweb.telosys.common.data
Class DataSet

java.lang.Object
  extended byorg.objectweb.telosys.common.TelosysObject
      extended byorg.objectweb.telosys.common.data.DataSet
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
UpdatableDataSet

public abstract class DataSet
extends TelosysObject
implements java.io.Serializable

The abstract DataSet class

A DataSet is set of DataRows whith the same number of cells in each row
It's a kind of grid that can be accessed by row or by cell coordinates (X,Y)
A DataSet can be sorted by column

Implemented by SQLDataSet, MemDataSet, ...

See Also:
Serialized Form

Constructor Summary
DataSet()
          Constructs a new void DataSet
 
Method Summary
protected  int addRow()
          Adds a new void DataRow at the end of the DataSet
protected  int addRow(DataRow dataRow)
          Adds a DataRow at the end of the DataSet
 boolean getBoolean(int iRow, int iCol)
          Returns the boolean value located at the given cell coordinates
 byte getByte(int iRow, int iCol)
          Returns the byte value located at the given cell coordinates
 DataRow getDataRow(int iRow)
          Returns the DataRow located at the given index
 java.util.Date getDate(int iRow, int iCol)
          Returns the java.util.Date located at the given cell coordinates
 double getDouble(int iRow, int iCol)
          Returns the double value located at the given cell coordinates
 float getFloat(int iRow, int iCol)
          Returns the float value located at the given cell coordinates
 int getInt(int iRow, int iCol)
          Returns the int value located at the given cell coordinates
 long getLong(int iRow, int iCol)
          Returns the long value located at the given cell coordinates
 java.lang.Object getObject(int iRow, int iCol)
          Returns the object located at the given cell coordinates
 int getRowCount()
          Returns the number of rows
 short getShort(int iRow, int iCol)
          Returns the short value located at the given cell coordinates
 int getSortColumn()
          Returns the column used as current sort criteria
 java.sql.Date getSqlDate(int iRow, int iCol)
          Returns the java.sql.Date located at the given cell coordinates
 java.lang.String getString(int iRow, int iCol)
          Returns the String located at the given cell coordinates
 java.lang.String getString(int iRow, int iCol, java.lang.String sNullValue)
          Returns the String located at the given cell coordinates with a default value
protected  void initBeforeLoad()
          Data set initialization, must be called by subclasses before each load
 boolean isEmpty()
          Returns 'true' if the DataSet is empty.
 boolean isSortedBy(int iCol)
          Returns true if the DataSet is currently sorted by the given column
 boolean isSortedInAscendingOrder()
          Returns true if the DataSet is currently sorted in ascending order
 boolean isSortedInDescendingOrder()
          Returns true if the DataSet is currently sorted in descending order
 java.util.Iterator iterator()
          Returns an iterator over the 'datarows' in this DataSet
abstract  int load()
          Loads the DataSet using its definition
abstract  int load(java.lang.Object obj)
          Loads the DataSet using its definition and the given object
protected  DataRow replaceRow(int iRow, DataRow dataRow)
          Replaces the DataRow at the given position by a new one
 void sort(int iCol)
          Sort the DataSet using the given column as criteria (case sensitive) in ascending order
 void sort(int iCol, java.lang.String sOrder)
          Sort the DataSet using the given column as criteria (case sensitive) and the specified order ( ascending or descending )
 void sortIgnoreCase(int iCol)
          Sort the DataSet using the given column as criteria ( ignoring case ) in ascending order
 void sortIgnoreCase(int iCol, java.lang.String sOrder)
          Sort the DataSet using the given field as criteria ( ignoring case )
and the specified order ( ascending or descending )
 
Methods inherited from class org.objectweb.telosys.common.TelosysObject
error, error, error, getFlagTrace, info, setFlagTrace, trace, warn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataSet

public DataSet()
Constructs a new void DataSet

Method Detail

initBeforeLoad

protected void initBeforeLoad()
Data set initialization, must be called by subclasses before each load


replaceRow

protected DataRow replaceRow(int iRow,
                             DataRow dataRow)
Replaces the DataRow at the given position by a new one

Parameters:
iRow - index of row to replace ( 1 to N )
dataRow - the DataRow to be stored at the specified position
Returns:
the DataRow previously at the specified position

addRow

protected int addRow(DataRow dataRow)
Adds a DataRow at the end of the DataSet

Parameters:
dataRow - the DataRow to add
Returns:

addRow

protected int addRow()
Adds a new void DataRow at the end of the DataSet

Returns:

load

public abstract int load()
                  throws java.lang.Exception
Loads the DataSet using its definition

Returns:
Throws:
java.lang.Exception

load

public abstract int load(java.lang.Object obj)
                  throws java.lang.Exception
Loads the DataSet using its definition and the given object

Parameters:
obj - useful parameter for the load operation ( cannot be null )
e.g. with SQLDataSet : Connection, DatabaseSession, ...
Returns:
Throws:
java.lang.Exception

getRowCount

public int getRowCount()
Returns the number of rows

Returns:

isEmpty

public boolean isEmpty()
Returns 'true' if the DataSet is empty.

Returns:

iterator

public java.util.Iterator iterator()
Returns an iterator over the 'datarows' in this DataSet

Returns:

getDataRow

public DataRow getDataRow(int iRow)
Returns the DataRow located at the given index

Parameters:
iRow - the row index ( 1 to N )
Returns:
the DataRow found, or null if no row at this index

getObject

public java.lang.Object getObject(int iRow,
                                  int iCol)
Returns the object located at the given cell coordinates

Parameters:
iRow - row index ( 1 to N )
iCol - column index ( 1 to N )
Returns:
instance found or null
Throws:
TelosysRuntimeException - if invalid column index

getString

public java.lang.String getString(int iRow,
                                  int iCol)
Returns the String located at the given cell coordinates

Parameters:
iRow - row index ( 1 to N )
iCol - column index ( 1 to N )
Returns:
instance found or null
Throws:
TelosysRuntimeException - if invalid column index

getString

public java.lang.String getString(int iRow,
                                  int iCol,
                                  java.lang.String sNullValue)
Returns the String located at the given cell coordinates with a default value

Parameters:
iRow - row index ( 1 to N )
iCol - column index ( 1 to N )
sNullValue -
Returns:
instance found or default value
Throws:
TelosysRuntimeException - if invalid column index

getDate

public java.util.Date getDate(int iRow,
                              int iCol)
Returns the java.util.Date located at the given cell coordinates

Parameters:
iRow - iRow row index ( 1 to N )
iCol - iCol column index ( 1 to N )
Returns:
instance found or null
Throws:
TelosysRuntimeException - if invalid column index

getSqlDate

public java.sql.Date getSqlDate(int iRow,
                                int iCol)
Returns the java.sql.Date located at the given cell coordinates

Parameters:
iRow - iRow row index ( 1 to N )
iCol - iCol column index ( 1 to N )
Returns:
instance found or null
Throws:
TelosysRuntimeException - if invalid column index

getBoolean

public boolean getBoolean(int iRow,
                          int iCol)
Returns the boolean value located at the given cell coordinates

Parameters:
iRow - iRow row index ( 1 to N )
iCol - iCol column index ( 1 to N )
Returns:
the value found, or false if not found

getByte

public byte getByte(int iRow,
                    int iCol)
Returns the byte value located at the given cell coordinates

Parameters:
iRow - iRow row index ( 1 to N )
iCol - iCol column index ( 1 to N )
Returns:
the value found, or 0 if not found

getInt

public int getInt(int iRow,
                  int iCol)
Returns the int value located at the given cell coordinates

Parameters:
iRow - iRow row index ( 1 to N )
iCol - iCol column index ( 1 to N )
Returns:
the value found, or 0 if not found

getShort

public short getShort(int iRow,
                      int iCol)
Returns the short value located at the given cell coordinates

Parameters:
iRow - iRow row index ( 1 to N )
iCol - iCol column index ( 1 to N )
Returns:
the value found, or 0 if not found

getLong

public long getLong(int iRow,
                    int iCol)
Returns the long value located at the given cell coordinates

Parameters:
iRow - iRow row index ( 1 to N )
iCol - iCol column index ( 1 to N )
Returns:
the value found, or 0 if not found

getFloat

public float getFloat(int iRow,
                      int iCol)
Returns the float value located at the given cell coordinates

Parameters:
iRow - iRow row index ( 1 to N )
iCol - iCol column index ( 1 to N )
Returns:
the value found, or 0 if not found

getDouble

public double getDouble(int iRow,
                        int iCol)
Returns the double value located at the given cell coordinates

Parameters:
iRow - iRow row index ( 1 to N )
iCol - iCol column index ( 1 to N )
Returns:
the value found, or 0 if not found

getSortColumn

public int getSortColumn()
Returns the column used as current sort criteria

Returns:
: column number, or -1 if the DataSet is not sorted

isSortedBy

public boolean isSortedBy(int iCol)
Returns true if the DataSet is currently sorted by the given column

Parameters:
iCol -
Returns:

isSortedInAscendingOrder

public boolean isSortedInAscendingOrder()
Returns true if the DataSet is currently sorted in ascending order

Returns:

isSortedInDescendingOrder

public boolean isSortedInDescendingOrder()
Returns true if the DataSet is currently sorted in descending order

Returns:

sort

public void sort(int iCol)
Sort the DataSet using the given column as criteria (case sensitive) in ascending order

Parameters:
iCol -

sort

public void sort(int iCol,
                 java.lang.String sOrder)
Sort the DataSet using the given column as criteria (case sensitive) and the specified order ( ascending or descending )

Parameters:
iCol -
sOrder - ( "asc" or "desc" )

sortIgnoreCase

public void sortIgnoreCase(int iCol)
Sort the DataSet using the given column as criteria ( ignoring case ) in ascending order

Parameters:
iCol -

sortIgnoreCase

public void sortIgnoreCase(int iCol,
                           java.lang.String sOrder)
Sort the DataSet using the given field as criteria ( ignoring case )
and the specified order ( ascending or descending )

Parameters:
iCol -
sOrder - ( "asc" or "desc" )