adams.data.spreadsheet
Class SqlUtils.Writer

java.lang.Object
  extended by adams.core.ConsoleObject
      extended by adams.data.spreadsheet.SqlUtils.Writer
All Implemented Interfaces:
SizeOfHandler, Stoppable, Serializable
Enclosing class:
SqlUtils

public static class SqlUtils.Writer
extends ConsoleObject
implements Stoppable

For writing data to a database.

Version:
$Revision: 7087 $
Author:
fracpete (fracpete at waikato dot ac dot nz)
See Also:
Serialized Form

Field Summary
protected  ColumnNameConversion m_ColumnNameConversion
          the column name conversion.
protected  String[] m_ColumnNames
          the column names (shortened, disambiguated).
protected  Cell.ContentType[] m_ContentTypes
          the type used for the table.
protected  int m_MaxColumnLength
          the maximum length for column names.
protected  int m_MaxStringLength
          the maximum length for strings.
protected  SpreadSheet m_Sheet
          the underlying spreadm_Sheet.
protected  boolean m_Stopped
          whether the last action was stopped.
protected  String m_StringColumnSQL
          the SQL type for string columns.
protected  String m_Table
          the table to write the data to.
static String PLACEHOLDER_MAX
          the placeholder for the maximum length for string values.
 
Constructor Summary
SqlUtils.Writer(SpreadSheet sheet, String table, int maxCol, ColumnNameConversion colName, String stringCol, int maxStr)
          Initializes the object.
 
Method Summary
 String createTable(SQL sql)
          Creates the table.
protected  String fixColumnName(String s)
          Fixes the column name.
protected  void generate()
          Generates the table setup.
 ColumnNameConversion getColumnNameConversion()
          Returns how to convert the column headers into SQL table column names.
 String[] getColumnNames()
          Returns the generated column names.
 Cell.ContentType[] getContentTypes()
          Returns the content types of the columns.
 String getCreateStatement()
          Generates the CREATE TABLE statement.
 String getInsertStatement()
          Generates a statement for an insert statement.
 int getMaxStringLength()
          Returns the maximum length for strings.
 String getStringColumnSQL()
          Returns the SQL type for string columns for the CREATE statement.
 String getTable()
          Returns the table to write the data to.
 void stopExecution()
          Stops the execution.
 String writeData(SQL sql)
          Writes the data to the table.
 
Methods inherited from class adams.core.ConsoleObject
getDebugging, getSystemErr, getSystemOut, sizeOf
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PLACEHOLDER_MAX

public static final String PLACEHOLDER_MAX
the placeholder for the maximum length for string values.

See Also:
Constant Field Values

m_Sheet

protected SpreadSheet m_Sheet
the underlying spreadm_Sheet.


m_Table

protected String m_Table
the table to write the data to.


m_ContentTypes

protected Cell.ContentType[] m_ContentTypes
the type used for the table.


m_MaxColumnLength

protected int m_MaxColumnLength
the maximum length for column names.


m_ColumnNames

protected String[] m_ColumnNames
the column names (shortened, disambiguated).


m_ColumnNameConversion

protected ColumnNameConversion m_ColumnNameConversion
the column name conversion.


m_StringColumnSQL

protected String m_StringColumnSQL
the SQL type for string columns.


m_MaxStringLength

protected int m_MaxStringLength
the maximum length for strings.


m_Stopped

protected boolean m_Stopped
whether the last action was stopped.

Constructor Detail

SqlUtils.Writer

public SqlUtils.Writer(SpreadSheet sheet,
                       String table,
                       int maxCol,
                       ColumnNameConversion colName,
                       String stringCol,
                       int maxStr)
Initializes the object.

Parameters:
m_Sheet - the underlying spreadm_Sheet
table - the table name
maxCol - the maximum length for column names
colName - the conversion for column names
stringCol - the SQL type for string columns
maxStr - the maximum length for strings (get truncated)
Method Detail

generate

protected void generate()
Generates the table setup.


getTable

public String getTable()
Returns the table to write the data to.

Returns:
the table name

getColumnNameConversion

public ColumnNameConversion getColumnNameConversion()
Returns how to convert the column headers into SQL table column names.

Returns:
the conversion

getMaxStringLength

public int getMaxStringLength()
Returns the maximum length for strings.

Returns:
the maximum

getStringColumnSQL

public String getStringColumnSQL()
Returns the SQL type for string columns for the CREATE statement.

Returns:
the SQL type

fixColumnName

protected String fixColumnName(String s)
Fixes the column name.

Parameters:
s - the column name to fix
Returns:
the fixed name

getCreateStatement

public String getCreateStatement()
Generates the CREATE TABLE statement.

Returns:
the SQL statement

getInsertStatement

public String getInsertStatement()
Generates a statement for an insert statement.

Returns:
the insert statement

getColumnNames

public String[] getColumnNames()
Returns the generated column names.

Returns:
the column names

getContentTypes

public Cell.ContentType[] getContentTypes()
Returns the content types of the columns.

Returns:
the content types

createTable

public String createTable(SQL sql)
Creates the table.

Parameters:
sql - for executing queries
Returns:
null if everything OK, otherwise error message

writeData

public String writeData(SQL sql)
Writes the data to the table.

Parameters:
sql - for performing the writing
Returns:
null if everything OK, otherwise error message

stopExecution

public void stopExecution()
Stops the execution.

Specified by:
stopExecution in interface Stoppable


Copyright © 2013 University of Waikato, Hamilton, NZ. All Rights Reserved.