gov.sns.tools.data
Class DataTable

java.lang.Object
  |
  +--gov.sns.tools.data.DataTable

public class DataTable
extends java.lang.Object

DataTable is internal storage resembling a database table. An instance of DataTable consists of an associated schema and a number of records. Each record must be of the same class and have the same keys.


Nested Class Summary
 class DataTable.AddRecordException
          Exception thrown when attempting to add a record which causes an inconsistency.
static class DataTable.NonUniqueRecordException
          This exception is thrown when attempting to fetch a single record with bindings and more than one record matches the criteria.
 class DataTable.Schema
          This class represents the schema of the table which specifies the attributes belonging to the table.
static interface DataTable.TableMessage
          Interface for notifying listeners of changes to the table
 
Field Summary
static java.lang.String nodeKey
           
 
Constructor Summary
DataTable(DataAdaptor adaptor)
           
DataTable(java.lang.String aName, java.util.Collection attributes)
          Creates new RecordSet
DataTable(java.lang.String aName, java.util.Collection attributes, java.lang.Class aRecordClass)
           
 
Method Summary
 void add(GenericRecord record)
          Add the record to the table.
 void addListener(DataTable.TableMessage listener)
           
 java.util.Collection attributes()
          Return the attributes of this table from the table's schema.
 DataListener dataHandler()
          Handle reading and writing from a data adaptor
 java.lang.Class getRecordClass()
          convienience method for user to detect record class
 java.util.List getRecords(java.util.Map bindings, SortOrdering ordering)
          Fetch the records with matching key/value pair bindings and sort them according to the sort ordering.
 java.util.List getRecords(SortOrdering ordering)
          Fetch all records held in the table and sort them according to the sort ordering.
 java.util.List getRecords(java.lang.String key, java.lang.Object value, SortOrdering ordering)
          Fetch the records with a matching key/value pair binding and sort them according to the sort ordering.
 java.util.Collection getUniquePrimaryKeyValues(java.lang.String key)
          Get the unique values of the specified primary key column.
 boolean hasRecord(GenericRecord record)
          Determine if this table contains the specified record
 java.util.Collection keys()
          Get all keys for this table.
 java.lang.String name()
          Get the name of this table.
 java.util.List orderRecords(java.util.Collection records, SortOrdering ordering)
          Order the records according to the specified sort ordering.
 java.util.Collection primaryKeys()
          Get the primary keys for the table.
 GenericRecord record(java.util.Map bindings)
          Fetch the record with matching key/value pair bindings.
 GenericRecord record(java.lang.String key, java.lang.Object value)
          Fetch the record with a matching key/value pair binding.
 GenericRecord recordForNode(java.lang.String nodeId)
          Fetch the record with a matching nodeId.
 java.util.Collection records()
          Fetch all records held in the table
 java.util.Collection records(java.util.Map bindings)
          Fetch the records with matching key/value pair bindings.
 java.util.Collection records(java.lang.String key, java.lang.Object value)
          Fetch the records with a matching key/value pair binding.
 java.util.Collection recordsForNode(java.lang.String nodeId)
          Fetch the records with a matching nodeId.
 void remove(GenericRecord record)
          Remove the specified record from this table.
 void removeListener(DataTable.TableMessage listener)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nodeKey

public static final java.lang.String nodeKey
See Also:
Constant Field Values
Constructor Detail

DataTable

public DataTable(java.lang.String aName,
                 java.util.Collection attributes)
Creates new RecordSet


DataTable

public DataTable(java.lang.String aName,
                 java.util.Collection attributes,
                 java.lang.Class aRecordClass)

DataTable

public DataTable(DataAdaptor adaptor)
Method Detail

addListener

public void addListener(DataTable.TableMessage listener)

removeListener

public void removeListener(DataTable.TableMessage listener)

getRecordClass

public java.lang.Class getRecordClass()
convienience method for user to detect record class


dataHandler

public DataListener dataHandler()
                         throws MissingPrimaryKeyException
Handle reading and writing from a data adaptor

MissingPrimaryKeyException

name

public java.lang.String name()
Get the name of this table.


keys

public java.util.Collection keys()
Get all keys for this table.


primaryKeys

public java.util.Collection primaryKeys()
Get the primary keys for the table.


hasRecord

public boolean hasRecord(GenericRecord record)
Determine if this table contains the specified record

Parameters:
record - The record to test for membership in this table
Returns:
true if this table contains the record and false if not

add

public void add(GenericRecord record)
         throws DataTable.AddRecordException
Add the record to the table.

DataTable.AddRecordException

remove

public void remove(GenericRecord record)
Remove the specified record from this table.


attributes

public java.util.Collection attributes()
Return the attributes of this table from the table's schema.


orderRecords

public java.util.List orderRecords(java.util.Collection records,
                                   SortOrdering ordering)
Order the records according to the specified sort ordering.

Parameters:
ordering - The sort ordering used to sort the record.
Returns:
The records sorted by the sort ordering.

records

public java.util.Collection records()
Fetch all records held in the table


getRecords

public java.util.List getRecords(SortOrdering ordering)
Fetch all records held in the table and sort them according to the sort ordering.

Parameters:
ordering - The sort ordering used to sort the records.
Returns:
All of the records ordered according to the sort ordering.

record

public GenericRecord record(java.util.Map bindings)
                     throws DataTable.NonUniqueRecordException
Fetch the record with matching key/value pair bindings. The keys must be one or more of the primary keys. If the record is not unique, an exception will be thrown.

DataTable.NonUniqueRecordException

record

public GenericRecord record(java.lang.String key,
                            java.lang.Object value)
                     throws DataTable.NonUniqueRecordException
Fetch the record with a matching key/value pair binding. The key must be a primary key. If the record is not unique, an exception will be thrown.

DataTable.NonUniqueRecordException

records

public java.util.Collection records(java.util.Map bindings)
Fetch the records with matching key/value pair bindings. The keys must be one or more of the primary keys.

Parameters:
bindings - The map of key/value pairs where the keys correspond to a subset of primary keys and the values are the ones we want to match.
Returns:
The matching records.

getRecords

public java.util.List getRecords(java.util.Map bindings,
                                 SortOrdering ordering)
Fetch the records with matching key/value pair bindings and sort them according to the sort ordering. The keys must be one or more of the primary keys.

Parameters:
bindings - The map of key/value pairs where the keys correspond to a subset of primary keys and the values are the ones we want to match.
ordering - The sort ordering used to sort the records.
Returns:
The matching records sorted according to the ordering.

records

public java.util.Collection records(java.lang.String key,
                                    java.lang.Object value)
Fetch the records with a matching key/value pair binding. The key must be a primary key.

Parameters:
key - A primary key to fetch against.
value - The value of the primary key to match.
Returns:
the matching records.

getRecords

public java.util.List getRecords(java.lang.String key,
                                 java.lang.Object value,
                                 SortOrdering ordering)
Fetch the records with a matching key/value pair binding and sort them according to the sort ordering. The key must be a primary key.

Parameters:
key - A primary key to fetch against.
value - The value of the primary key to match.
ordering - The sort ordering used to sort the records.
Returns:
The matching records sorted according to the ordering.

recordForNode

public GenericRecord recordForNode(java.lang.String nodeId)
                            throws DataTable.NonUniqueRecordException
Fetch the record with a matching nodeId. One of the primary keys must be "nodeId". If the record is not unique, an exception will be thrown.

DataTable.NonUniqueRecordException

recordsForNode

public java.util.Collection recordsForNode(java.lang.String nodeId)
Fetch the records with a matching nodeId. One of the primary keys must be "nodeId".


getUniquePrimaryKeyValues

public final java.util.Collection getUniquePrimaryKeyValues(java.lang.String key)
Get the unique values of the specified primary key column.

Parameters:
key - The primary key column whose unique values we want to fetch.
Returns:
the unique values of the specified column.