Package adams.data.spreadsheet.sql
Class Writer
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.data.spreadsheet.sql.Writer
-
- All Implemented Interfaces:
LoggingSupporter
,SizeOfHandler
,Stoppable
,Serializable
public class Writer extends LoggingObject implements Stoppable
For writing data to a database.- Version:
- $Revision: 13404 $
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected int
m_BatchSize
the batch size.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.protected AbstractTypeMapper
m_TypeMapper
the type mapper to use.static String
PLACEHOLDER_MAX
the placeholder for the maximum length for string values.-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description Writer(SpreadSheet sheet, AbstractTypeMapper typeMapper, String table, int maxCol, ColumnNameConversion colName, String stringCol, int maxStr, int batchSize)
Initializes the object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
createTable(SQLIntf 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.AbstractTypeMapper
getTypeMapper()
Returns the type mapper in use.void
setLoggingLevel(LoggingLevel value)
Sets the logging level.void
stopExecution()
Stops the execution.String
writeData(SQLIntf sql)
Writes the data to the table.-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
-
-
-
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_TypeMapper
protected AbstractTypeMapper m_TypeMapper
the type mapper to use.
-
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_BatchSize
protected int m_BatchSize
the batch size.
-
m_Stopped
protected boolean m_Stopped
whether the last action was stopped.
-
-
Constructor Detail
-
Writer
public Writer(SpreadSheet sheet, AbstractTypeMapper typeMapper, String table, int maxCol, ColumnNameConversion colName, String stringCol, int maxStr, int batchSize)
Initializes the object.- Parameters:
sheet
- the underlying spreadm_SheettypeMapper
- the type mapper to usetable
- the table namemaxCol
- the maximum length for column namescolName
- the conversion for column namesstringCol
- the SQL type for string columnsmaxStr
- the maximum length for strings (get truncated)
-
-
Method Detail
-
generate
protected void generate()
Generates the table setup.
-
setLoggingLevel
public void setLoggingLevel(LoggingLevel value)
Sets the logging level.- Parameters:
value
- the level
-
getTypeMapper
public AbstractTypeMapper getTypeMapper()
Returns the type mapper in use.- Returns:
- the type mapper
-
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(SQLIntf sql)
Creates the table.- Parameters:
sql
- for executing queries- Returns:
- null if everything OK, otherwise error message
-
writeData
public String writeData(SQLIntf 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 interfaceStoppable
-
-