com.martiansoftware.trivialpersist
Class Table

java.lang.Object
  extended bycom.martiansoftware.trivialpersist.Table

public class Table
extends Object

A collection of records that share a schema. Analogous to a table in a relational database.

Author:
Marty Lamb

Method Summary
 Iterator comparatorNames()
          Returns an Iterator over all comparator names available
 Record create()
          Creates a new, writeable Record in this Table.
 Record createCopy(Record record)
          Creates a new, writeable Record in this Table with all fields (except its Key) copied from the specified Record.
 void declareField(String fieldName, String fieldType)
          Declares a field (name and type) for this Table
 Iterator filterNames()
          Returns an Iterator over all filter names available
 Record getByKey(martianutils.io.MaildirID key)
          Returns the record associated with the specified Key, or null if no such record exists.
 Comparator getComparator(String comparatorName)
          Returns the requested comparator.
 RecordFilter getFilter(String filterName)
          Returns the requested RecordFilter, or null if no such filter is defined.
 String getName()
          Returns the name of this Table
 void init(File schemaFile)
          Initializes the table with the schema contained within the specified file
 SortedSet select(RecordFilter recordFilter, Comparator comparator)
          Returns a SortedSet of Records that pass the specified RecordFilter, sorted by the specified Comparator.
 SortedSet select(String filterName, String comparatorName)
           
 SortedSet selectAll()
          Returns a set of all records, sorted by key.
 void setRecordInitializer(RecordInitializer recordInitializer)
          Sets the RecordInitializer for this Table.
 int size()
          Returns the number of Records in this Table
 void storeComparator(String comparatorName, Comparator comparator)
          Stores a comparator by name
 void storeFilter(String filterName, RecordFilter filter)
          Stores a filter by name
 String toString()
          Returns a String representatino of this Table.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getName

public String getName()
Returns the name of this Table

Returns:
the name of this Table

init

public void init(File schemaFile)
          throws TrivialPersistException
Initializes the table with the schema contained within the specified file

Parameters:
schemaFile - the file containing the schema
Throws:
TrivialPersistException

declareField

public void declareField(String fieldName,
                         String fieldType)
                  throws TrivialPersistException
Declares a field (name and type) for this Table

Parameters:
fieldName - the name of the field to declare
fieldType - the data type of the field
Throws:
TrivialPersistException - if the declaration fails for any reason (e.g., duplicate fieldname, invalid type, etc.)

size

public int size()
Returns the number of Records in this Table

Returns:
the number of Records in this Table

selectAll

public SortedSet selectAll()
Returns a set of all records, sorted by key. This is the same result one would obtain by calling select(null, null).

Returns:
a set of all records, sorted by key.

select

public SortedSet select(String filterName,
                        String comparatorName)

select

public SortedSet select(RecordFilter recordFilter,
                        Comparator comparator)
Returns a SortedSet of Records that pass the specified RecordFilter, sorted by the specified Comparator.

Parameters:
recordFilter - the filter to use in selecting Records. If null, all Records will be included in the result.
comparator - the Comparator to use in sorting Records. If null, Records will be sorted according to their keys.
Returns:
a SortedSet of Records that pass the specified RecordFilter, sorted by the specified Comparator.

create

public Record create()
              throws TrivialPersistException
Creates a new, writeable Record in this Table.

Returns:
the newly created Record
Throws:
TrivialPersistException - if the Record could not be created

createCopy

public Record createCopy(Record record)
                  throws TrivialPersistException
Creates a new, writeable Record in this Table with all fields (except its Key) copied from the specified Record. This Record must be save()d before it will be returned by any queries against this Table.

If this Table has a RecordInitializer set, it will not be run on the new copy.

Parameters:
record - the Record to copy
Returns:
a new, writeable Record with all fields copied from the specified Record
Throws:
TrivialPersistException - if the record could not be copied

getByKey

public Record getByKey(martianutils.io.MaildirID key)
Returns the record associated with the specified Key, or null if no such record exists.

Parameters:
key - the Key to use for the lookup.
Returns:
the associated record, or null if no such record exists.

toString

public String toString()
Returns a String representatino of this Table.

Returns:
a String representatino of this Table.

setRecordInitializer

public void setRecordInitializer(RecordInitializer recordInitializer)
Sets the RecordInitializer for this Table.

Parameters:
recordInitializer - the RecordInitializer to use. If null, no RecordInitializer will be used.

storeFilter

public void storeFilter(String filterName,
                        RecordFilter filter)
Stores a filter by name

Parameters:
filterName - the name to give the filter
filter - the filter to store

filterNames

public Iterator filterNames()
Returns an Iterator over all filter names available

Returns:
an Iterator over all filter names available

getFilter

public RecordFilter getFilter(String filterName)
Returns the requested RecordFilter, or null if no such filter is defined.

Parameters:
filterName - the name of the filter to retrieve
Returns:
the requested RecordFilter, or null if no such filter is defined.

storeComparator

public void storeComparator(String comparatorName,
                            Comparator comparator)
Stores a comparator by name

Parameters:
comparatorName - the name to give the comparator
comparator - the comparator to store

comparatorNames

public Iterator comparatorNames()
Returns an Iterator over all comparator names available

Returns:
an Iterator over all comparator names available

getComparator

public Comparator getComparator(String comparatorName)
Returns the requested comparator. If no such comparator exist, AND the name supplied is the name of a field, then a FieldComparator or null if no such comparator is defined.

Parameters:
comparatorName - the name of the comparator to retrieve
Returns:
the requested comparator, or null if no such comparator is defined.


Copyright © 2004, Martian Software, Inc.. All Rights Reserved.
For the latest version and documentation, please visit http://www.martiansoftware.com/trivialpersist