uk.ac.ed.inf.utils.database
Class TableWriter

java.lang.Object
  extended by uk.ac.ed.inf.utils.database.DbManaged
      extended by uk.ac.ed.inf.utils.database.TableManaged
          extended by uk.ac.ed.inf.utils.database.TableWriter

public class TableWriter
extends TableManaged

A TableWriter object contains all the information to create, fill and delete a database table.

Version:
24-Mar-2007 TODO create hierarchy?: table > table from file
Author:
Luna De Ferrari

Constructor Summary
TableWriter(TableManager tableManager)
          Constructor 2: takes the table name and a list of fields
 
Method Summary
 java.lang.String getInsertSql(TableRow row)
          Returns the sql "insert into" statement for the row
 java.lang.String getLoadDataInfileSql(java.lang.String fileName, java.lang.String fieldTerminator, java.lang.String lineTerminator, int numberOfInitialLinesToIgnore, java.lang.String commaSeparatedListOfColumns)
           
 java.lang.Integer insertReturnsKey(TableRow row)
          Executes an sql 'insert into' operation.
 boolean writeFileToTable(java.lang.String fileName, java.lang.String fieldTerminator, java.lang.String lineTerminator, int numberOfInitialLinesToIgnore, java.lang.String commaSeparatedListOfColumns)
          Writes a data file to table using LOAD DATA LOCAL INFILE return true if the statement was executed
 java.lang.Integer writeRowToTable(TableRow row)
          Insert the row values into the appropriate database table
 
Methods inherited from class uk.ac.ed.inf.utils.database.TableManaged
getTableManager
 
Methods inherited from class uk.ac.ed.inf.utils.database.DbManaged
getDbConnection, getDbManager
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TableWriter

public TableWriter(TableManager tableManager)
Constructor 2: takes the table name and a list of fields

Parameters:
tableManager - the table manager
Method Detail

getInsertSql

public java.lang.String getInsertSql(TableRow row)
Returns the sql "insert into" statement for the row

Parameters:
row -
Returns:
the sql "insert into" statement for the row

getLoadDataInfileSql

public java.lang.String getLoadDataInfileSql(java.lang.String fileName,
                                             java.lang.String fieldTerminator,
                                             java.lang.String lineTerminator,
                                             int numberOfInitialLinesToIgnore,
                                             java.lang.String commaSeparatedListOfColumns)

insertReturnsKey

public java.lang.Integer insertReturnsKey(TableRow row)
Executes an sql 'insert into' operation. And returns the auto-generated key for the inserted row.

Parameters:
row - a table row (columns + values)
Returns:
the auto-generated key for the inserted row.

writeFileToTable

public boolean writeFileToTable(java.lang.String fileName,
                                java.lang.String fieldTerminator,
                                java.lang.String lineTerminator,
                                int numberOfInitialLinesToIgnore,
                                java.lang.String commaSeparatedListOfColumns)
Writes a data file to table using LOAD DATA LOCAL INFILE return true if the statement was executed


writeRowToTable

public java.lang.Integer writeRowToTable(TableRow row)
Insert the row values into the appropriate database table

Returns:
the table auto-generated key for the inserted row (or null if the row was not inserted)