org.afcs.warts.db
Class DataSet

java.lang.Object
  extended byorg.afcs.warts.db.DataSet
All Implemented Interfaces:
TabularData

public final class DataSet
extends java.lang.Object
implements TabularData

The DataSet class is responsible for loading and presenting the data associated with some database table. Various static load...Data() methods are available for creating an instance of this class with all or some subset of the data in the table.

The data is maintained internally as a map of primary key values to non-primary values, where each set of values is stored in a java.util.List instance.

LICENSE: This code is released to the public domain and may be used for any purpose whatsoever without permission or acknowledgment.

Version:
Last Modified 18 September 2003
Author:
Warren Hedley ( whedley at sdsc dot edu )

Method Summary
 java.util.Map getData()
          Returns an unmodifiable mapping between the primary key values and non-primary key values available in the current dataset.
 java.lang.Object[][] getNormalisedData()
          Returns a normalised array of the data in the current dataset with the rows sorted in key order.
 int getNumRows()
          Returns the number of rows that were loaded.
 java.util.List getSortedKeys()
          Returns an unmodifiable list containing the primary key lists for this dataset sorted in primary key order.
 TableDescription getTableDescription()
          Returns the table that this data was loaded for.
 java.lang.Object getValueAt(int rowIndex, int columnIndex)
          Returns the value at the specified row and column from the dataset analysed by this instance, where the row is an index into the sorted keys.
static DataSet loadCharacterData(TableDescription tableDescription)
          Returns a DataSet instance containing just the character data column values from the specified table.
static DataSet loadCharacterData(TableDescription tableDescription, int maxRowsToLoad)
          Returns a DataSet instance containing up to maxRowsToLoad of character data from the specified table, where the rows that will be returned are the first rows found when sorting in ascending order by the primary key columns.
static DataSet loadData(TableDescription tableDescription)
          Returns a DataSet instance containing all of the data from the specified table.
static DataSet loadData(TableDescription tableDescription, int maxRowsToLoad)
          Returns a DataSet instance containing up to maxRowsToLoad of data from the specified table, where the rows that will be returned are the first rows found when sorting in ascending order by the primary key columns.
static void multiThreadedLoading()
          This changes the loading mechanism to use the multi-threaded loading system.
 java.lang.String toString()
          Returns a text description of the current instance that can be used for debugging purposes.
static boolean usingMultiThreadedLoading()
          Returns true if we're using multi-threaded loading.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getData

public java.util.Map getData()
Returns an unmodifiable mapping between the primary key values and non-primary key values available in the current dataset. The keys and values in the map are both unmodifiable java.util.List instances. Note that getSortedKeys() returns the keys from this map in key order.

Returns:
An unmodifiable mapping between the primary key values and non-primary key values available in the current dataset.

getNormalisedData

public java.lang.Object[][] getNormalisedData()
Returns a normalised array of the data in the current dataset with the rows sorted in key order.

Returns:
A normalised array of the data in the current dataset.

getNumRows

public int getNumRows()
Returns the number of rows that were loaded. (This may not be the number of rows in the table depending on the method used to load the data.)

Specified by:
getNumRows in interface TabularData
Returns:
The number of rows that were loaded.

getSortedKeys

public java.util.List getSortedKeys()
Returns an unmodifiable list containing the primary key lists for this dataset sorted in primary key order. Each entry in the list returned is a java.util.List instance containing the primary key column values. Each primary key list is also unmodifiable.

Returns:
An unmodifiable list containing the primary key lists for this dataset sorted in primary key order.

getTableDescription

public TableDescription getTableDescription()
Returns the table that this data was loaded for.

Specified by:
getTableDescription in interface TabularData
Returns:
The table that this data was loaded for.

getValueAt

public java.lang.Object getValueAt(int rowIndex,
                                   int columnIndex)
Returns the value at the specified row and column from the dataset analysed by this instance, where the row is an index into the sorted keys.

Specified by:
getValueAt in interface TabularData
Parameters:
rowIndex - The row to retrieve the data from.
columnIndex - The column to retrieve the data from.
Returns:
The value at the specified row and column from the dataset analysed by this instance.
Throws:
java.lang.IllegalArgumentException - If either argument is out of bounds.

loadData

public static DataSet loadData(TableDescription tableDescription)
Returns a DataSet instance containing all of the data from the specified table.

Parameters:
tableDescription - The table to load data from.
Returns:
A DataSet instance containing all of the data from the specified table.
Throws:
java.lang.NullPointerException - If tableDescription is null.

loadData

public static DataSet loadData(TableDescription tableDescription,
                               int maxRowsToLoad)
Returns a DataSet instance containing up to maxRowsToLoad of data from the specified table, where the rows that will be returned are the first rows found when sorting in ascending order by the primary key columns.

Parameters:
tableDescription - The table to load data from.
maxRowsToLoad - The maximum number of rows to load.
Returns:
A DataSet instance containing up to maxRowsToLoad of character data from the specified table.
Throws:
java.lang.NullPointerException - If tableDescription is null.
java.lang.IllegalArgumentException - If maxRowsToLoad is less than 1.

loadCharacterData

public static DataSet loadCharacterData(TableDescription tableDescription)
Returns a DataSet instance containing just the character data column values from the specified table. For each row, data from all of the primary key columns, and any non-primary columns containing character data will be loaded.

Parameters:
tableDescription - The table to load data from.
Returns:
A DataSet instance containing just the character data column values from the specified table.
Throws:
java.lang.NullPointerException - If tableDescription is null.

loadCharacterData

public static DataSet loadCharacterData(TableDescription tableDescription,
                                        int maxRowsToLoad)
Returns a DataSet instance containing up to maxRowsToLoad of character data from the specified table, where the rows that will be returned are the first rows found when sorting in ascending order by the primary key columns. For each row, data from all of the primary key columns, and any non-primary columns containing character data will be loaded.

Parameters:
tableDescription - The table to load data from.
maxRowsToLoad - The maximum number of rows to load.
Returns:
A DataSet instance containing up to maxRowsToLoad of character data from the specified table.
Throws:
java.lang.NullPointerException - If tableDescription is null.
java.lang.IllegalArgumentException - If maxRowsToLoad is less than 1.

multiThreadedLoading

public static void multiThreadedLoading()
This changes the loading mechanism to use the multi-threaded loading system. By default the loading mechanism loads all data with a single query. Typically this would be caused during an early configuration phase.


usingMultiThreadedLoading

public static boolean usingMultiThreadedLoading()
Returns true if we're using multi-threaded loading.

Returns:
True if we're using multi-threaded loading.

toString

public java.lang.String toString()
Returns a text description of the current instance that can be used for debugging purposes.

Returns:
A text description of the current instance that can be used for debugging purposes.