org.melati.poem.csv
Class CSVTable

Package class diagram package CSVTable
java.lang.Object
  extended by org.melati.poem.csv.CSVTable

public class CSVTable
extends Object

A representation of a CSV file as a POEM Table.


Field Summary
protected  Hashtable columns
           
protected  Vector columnsInUploadOrder
           
protected  File data
           
protected  CSVFileParser parser
           
protected  CSVColumn primaryKey
           
protected  BufferedReader reader
           
protected  Vector records
           
protected  Table table
           
 
Constructor Summary
CSVTable(Table table, File data)
          Constructor.
 
Method Summary
 void addColumn(String csvName, String poemName)
          Add column definitions to this table.
 void addColumn(String csvName, String poemName, boolean isPrimaryKey)
          Add column definitions, perhaps Primary Keys, to this table.
 void addColumn(String csvName, String foreignPoemName, CSVTable foreignTable)
          Add column definitions for foreign keys to this table.
 void define()
          Process the first line to define columns.
 void emptyTable()
          Delete all Persistents from the Poem table.
 String getName()
          Used in debugging to display name of table being emptied.
protected  Persistent getRecordWithID(String csvValue)
          Lookup the Persistent corresponding to the CSV record with the given value for the CSV table's primary key.
 void load(boolean writeOnFly)
          Parse the CSV data file and store the data for saving later.
 CSVRecord parseRecord()
          Reads the file until is has seen an object's-worth of field values (ie until it sees an EOF or a line starting with '$') which it returns in a hashtable (null if there are no field values).
 void report(boolean recordDetails, boolean fieldDetails, Writer output)
          Return a string reporting on the data added to this table.
 void writeRecords()
          Write the records to the database, called if we are not writing each record to db as we go.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

table

protected Table table

data

protected File data

columns

protected Hashtable columns

columnsInUploadOrder

protected Vector columnsInUploadOrder

primaryKey

protected CSVColumn primaryKey

records

protected Vector records

reader

protected BufferedReader reader

parser

protected CSVFileParser parser
Constructor Detail

CSVTable

public CSVTable(Table table,
                File data)
Constructor.

Parameters:
table - POEM table to load data into
data - CSV file to read from
Method Detail

define

public void define()
            throws IOException
Process the first line to define columns. The first line contains the field names - this needs to be validated againsed expected values, and the order of the fields established.

Throws:
IOException

addColumn

public void addColumn(String csvName,
                      String poemName)
Add column definitions to this table.


addColumn

public void addColumn(String csvName,
                      String poemName,
                      boolean isPrimaryKey)
               throws CSVPrimaryKeyColumnAlreadySetException
Add column definitions, perhaps Primary Keys, to this table.

Throws:
CSVPrimaryKeyColumnAlreadySetException

addColumn

public void addColumn(String csvName,
                      String foreignPoemName,
                      CSVTable foreignTable)
Add column definitions for foreign keys to this table.


load

public void load(boolean writeOnFly)
          throws IOException,
                 CSVParseException,
                 NoPrimaryKeyInCSVTableException,
                 CSVWriteDownException
Parse the CSV data file and store the data for saving later.

Parameters:
writeOnFly - whether to commit each line to db as we go
Throws:
IOException - if there is a file system problem
CSVParseException - if the is a malformed field in the CSV
CSVWriteDownException
NoPrimaryKeyInCSVTableException

parseRecord

public CSVRecord parseRecord()
                      throws IOException,
                             CSVParseException
Reads the file until is has seen an object's-worth of field values (ie until it sees an EOF or a line starting with '$') which it returns in a hashtable (null if there are no field values).

Returns:
a new CSVRecord
Throws:
IOException - if there is a problem with the file system
CSVParseException - if there is a problem parsing the input

emptyTable

public void emptyTable()
Delete all Persistents from the Poem table.


writeRecords

public void writeRecords()
                  throws NoPrimaryKeyInCSVTableException,
                         CSVWriteDownException
Write the records to the database, called if we are not writing each record to db as we go.

Throws:
NoPrimaryKeyInCSVTableException
CSVWriteDownException

getRecordWithID

protected Persistent getRecordWithID(String csvValue)
                              throws NoPrimaryKeyInCSVTableException,
                                     CSVWriteDownException
Lookup the Persistent corresponding to the CSV record with the given value for the CSV table's primary key.

Throws:
NoPrimaryKeyInCSVTableException
CSVWriteDownException

report

public void report(boolean recordDetails,
                   boolean fieldDetails,
                   Writer output)
            throws IOException
Return a string reporting on the data added to this table.

Throws:
IOException

getName

public String getName()
Used in debugging to display name of table being emptied.

Returns:
the POEM Table's name


Copyright © 2000-2010 PanEris. All Rights Reserved.