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 intm_BatchSizethe batch size.protected ColumnNameConversionm_ColumnNameConversionthe column name conversion.protected String[]m_ColumnNamesthe column names (shortened, disambiguated).protected Cell.ContentType[]m_ContentTypesthe type used for the table.protected intm_MaxColumnLengththe maximum length for column names.protected intm_MaxStringLengththe maximum length for strings.protected SpreadSheetm_Sheetthe underlying spreadm_Sheet.protected booleanm_Stoppedwhether the last action was stopped.protected Stringm_StringColumnSQLthe SQL type for string columns.protected Stringm_Tablethe table to write the data to.protected AbstractTypeMapperm_TypeMapperthe type mapper to use.static StringPLACEHOLDER_MAXthe 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 StringcreateTable(SQLIntf sql)Creates the table.protected StringfixColumnName(String s)Fixes the column name.protected voidgenerate()Generates the table setup.ColumnNameConversiongetColumnNameConversion()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.StringgetCreateStatement()Generates the CREATE TABLE statement.StringgetInsertStatement()Generates a statement for an insert statement.intgetMaxStringLength()Returns the maximum length for strings.StringgetStringColumnSQL()Returns the SQL type for string columns for the CREATE statement.StringgetTable()Returns the table to write the data to.AbstractTypeMappergetTypeMapper()Returns the type mapper in use.voidsetLoggingLevel(LoggingLevel value)Sets the logging level.voidstopExecution()Stops the execution.StringwriteData(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:
stopExecutionin interfaceStoppable
-
-