TissueInfo API 20091124110011

edu.mssm.crover.tables
Class AddToTable

java.lang.Object
  extended by edu.mssm.crover.tables.AddToTable

public class AddToTable
extends Object

Adds to columns (and creates them if necessary) from an input file.


Field Summary
protected  Connection conn
          The connection to the database used by this instance.
 
Constructor Summary
protected AddToTable(String filename, String tablename, String[] heading, String index)
          Adds the data to the specified table.
 
Method Summary
 void addColumns(String tablename, String[] newHeadings, HashSet oldHeadings)
          Checks whether the columns to be added to already exist in the table.
 void addData(String filename, String tablename, String[] newHeadings, String index)
          Reads the input file (which should contain the same number of tab-delimited fields per line as columns you want to add to), and adds the information from each field in each line to the corresponding column.
 void begin()
          Notifies this class that a batch of interaction now begin.
 HashSet describeTable(String tablename)
          Uses SQL to describe the table, and puts the column headings into a HashSet.
 void end()
          Notifies this class that a batch of interaction now ends.
static String[] getHeading(String[] args)
          Returns the name of the headings in the table to which the data are to be added.
static String getIndexColumn(String[] args)
          Returns the name of the column to be used as an identifier.
static String getInputFile(String[] args)
          Returns the name of the input file.
static AddToTable getInstance(String filename, String tablename, String[] heading, String index)
          Gets an instance of this class.
static String getTableName(String[] args)
          Returns the name of the table to which the data are to be added.
protected  void initConnection()
          Makes sure a connection is available.
static void main(String[] args)
          Main method.
static void printHelp()
          Prints the help menu.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

conn

protected Connection conn
The connection to the database used by this instance.

Constructor Detail

AddToTable

protected AddToTable(String filename,
                     String tablename,
                     String[] heading,
                     String index)
              throws DatabaseErrorException
Adds the data to the specified table.

Parameters:
filename - The name of the input file containing the data.
tablename - The name of the table to be modified.
heading - The headings of the columns to which the data will be added.
index - The name of the identifier column.
Throws:
DatabaseErrorException - if there is a problem connecting to the database.
Method Detail

getInputFile

public static String getInputFile(String[] args)
Returns the name of the input file. Read from the command line, after "-i" flag. Each line contains tab-delimited data to be entered into different columns. This is a necessary parameter.

Parameters:
args - Thcommand line arguments.
Returns:
the name of the input file.

getTableName

public static String getTableName(String[] args)
Returns the name of the table to which the data are to be added. Read from the command line, after "-t" flag. This is a necessary parameter.

Parameters:
args - The command line arguments.
Returns:
the name of the table to be modified.

getHeading

public static String[] getHeading(String[] args)
Returns the name of the headings in the table to which the data are to be added. Read from the command line, after "-t" flag. This is a necessary parameter.

Parameters:
args - The command line arguments.
Returns:
the headings of the columns into which the data will be entered.

getIndexColumn

public static String getIndexColumn(String[] args)
Returns the name of the column to be used as an identifier. Read from the command line, after the "-index" flag. This is a necessary parameter.

Parameters:
args - The command line arguments.
Returns:
the heading of the identifier column.

printHelp

public static void printHelp()
Prints the help menu.


describeTable

public final HashSet describeTable(String tablename)
                            throws SQLException
Uses SQL to describe the table, and puts the column headings into a HashSet.

Parameters:
tablename - The name of the table to be described.
Returns:
the column names from the specified table.
Throws:
SQLException - if there is a problem querying the database.

addColumns

public final void addColumns(String tablename,
                             String[] newHeadings,
                             HashSet oldHeadings)
                      throws SQLException
Checks whether the columns to be added to already exist in the table. If not, they are added, and a default type of varchar2(80) is assigned to them.

Parameters:
tablename - The name of the table to be modified.
newHeadings - The headings of the columns to be added to the specified table.
oldHeadings - The headings of the columns already present in the specified table.
Throws:
SQLException - if there is a problem querying the database.

addData

public final void addData(String filename,
                          String tablename,
                          String[] newHeadings,
                          String index)
                   throws SQLException,
                          IOException,
                          DatabaseErrorException
Reads the input file (which should contain the same number of tab-delimited fields per line as columns you want to add to), and adds the information from each field in each line to the corresponding column. The input file should contain as a first field the values of the index column.

Parameters:
filename - The name of the input file containing the data.
tablename - The name of the table to be modified.
newHeadings - The headings of the columns to be added to the specified table (if they do not already exist).
index - The heading of the identifier column.
Throws:
SQLException - if there is a problem querying the database.
IOException - if there is a problem reading the input file.
DatabaseErrorException - if there is a problem connecting to the database.

begin

public final void begin()
                 throws DatabaseErrorException
Notifies this class that a batch of interaction now begin. Allows specific optimization to be performed.

Throws:
DatabaseErrorException - if there is a problem connecting to the database.

end

public final void end()
Notifies this class that a batch of interaction now ends. Allows specific optimization to be performed.


initConnection

protected final void initConnection()
                             throws DatabaseErrorException
Makes sure a connection is available.

Throws:
DatabaseErrorException - if there is a problem connecting to the database.

getInstance

public static AddToTable getInstance(String filename,
                                     String tablename,
                                     String[] heading,
                                     String index)
                              throws DatabaseErrorException
Gets an instance of this class.

Parameters:
filename - The name of the input file containing the data.
tablename - The name of the table to be modified.
heading - The headings of the columns to be added to the specified table (if they do not already exist).
index - The heading of the identifier column.
Returns:
an instance of this class.
Throws:
DatabaseErrorException - if there is a problem connecting to the database.

main

public static void main(String[] args)
Main method.

Parameters:
args - The command line arguments.

TissueInfo API 20091124110011

Copyright © 2001-2009 Institute for Computational Biomedicine, All Rights Reserved.