Package adams.data.io.output
Class SqlDumpSpreadSheetWriter
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.data.io.output.AbstractSpreadSheetWriter
-
- adams.data.io.output.SqlDumpSpreadSheetWriter
-
- All Implemented Interfaces:
AdditionalInformationHandler,Destroyable,GlobalInfoSupporter,EncodingSupporter,LoggingLevelHandler,LoggingSupporter,OptionHandler,SizeOfHandler,Stoppable,StoppableWithFeedback,AppendableSpreadSheetWriter,SpreadSheetWriter,Serializable
public class SqlDumpSpreadSheetWriter extends AbstractSpreadSheetWriter implements AppendableSpreadSheetWriter
Generates an SQL dump from the spreadsheet, which can be imported into a database.
Valid options are:
-D <int> (property: debugLevel) The greater the number the more additional info the scheme may output to the console (0 = off). default: 0 minimum: 0
-appending (property: appending) If enabled, multiple spreadsheets with the same structure can be written to the same file.
-keep-existing (property: keepExisting) If enabled, any output file that exists when the writer is executed for the first time won't get replaced with the current header; useful when outputting data in multiple locations in the flow, but one needs to be cautious as to not stored mixed content (eg varying number of columns, etc).
-table <java.lang.String> (property: table) The name of the table. default: blah
-column-name-conversion <AS_IS|LOWER_CASE|UPPER_CASE> (property: columnNameConversion) How to convert the column headers into SQL table column names. default: UPPER_CASE
-max-string-length <int> (property: maxStringLength) The maximum length for strings to enforce; can be used as @MAX in the 'stringColumnsSQL' property. default: 50 minimum: 1
-string-column-sql <java.lang.String> (property: stringColumnSQL) The SQL type to use for STRING columns in the CREATE statement; you can use the @MAX placeholder to tie the type to the 'naxStringLength' property; see also: http://en.wikipedia.org/wiki/SQL default: VARCHAR(@MAX)
-add-create-table (property: addCreateTable) If enabled, a CREATE TABLE statement is output as well.
-use-backslashes (property: useBackslashes) If enabled, backslashes are used to escape single quotes, rather than doubling up the single quotes.
- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class adams.data.io.output.AbstractSpreadSheetWriter
AbstractSpreadSheetWriter.OutputType
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanm_AddCreateTablewhether to add a CREATE TABLE statement.protected booleanm_Appendingwhether to append spreadsheets.protected ColumnNameConversionm_ColumnNameConversionthe column name conversion.protected String[]m_ColumnNamesthe column names (shortened, disambiguated).protected booleanm_FileExistswhether the file already exists.protected SpreadSheetm_Headerthe header of the first spreadsheet written to file, if appending is active.protected booleanm_KeepExistingwhether to keep existing files the first time the writer is called.protected intm_MaxStringLengththe maximum length for strings.protected Stringm_StringColumnSQLthe SQL type for string columns.protected Stringm_Tablethe name of the table.protected AbstractTypeMapperm_TypeMapperthe type mapper to use.protected Cell.ContentType[]m_Typesthe type used for the table.protected booleanm_UseBackslasheswhether to use backslashes for escaping.-
Fields inherited from class adams.data.io.output.AbstractSpreadSheetWriter
m_Encoding, m_Stopped
-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description SqlDumpSpreadSheetWriter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringaddCreateTableTipText()Returns the tip text for this property.StringappendingTipText()Returns the tip text for this property.booleancanAppend(SpreadSheet sheet)Checks whether we can append the specified spreadsheet to the existing file.StringcolumnNameConversionTipText()Returns the tip text for this property.voiddefineOptions()Adds options to the internal list of options.protected booleandoWrite(SpreadSheet content, Writer writer)Performs the actual writing.protected Stringformat(double value)Formats the number according to the format and returns the generated textual representation.booleangetAddCreateTable()Returns whether a CREATE TABLE statement is output.ColumnNameConversiongetColumnNameConversion()Returns how to convert the column headers into SQL table column names.SpreadSheetReadergetCorrespondingReader()Returns, if available, the corresponding reader.booleangetFileExists()Returns whether the output file already exists.StringgetFormatDescription()Returns a string describing the format (used in the file chooser).String[]getFormatExtensions()Returns the extension(s) of the format.booleangetKeepExisting()Returns whether any existing file is kept on first execution.intgetMaxStringLength()Returns the maximum length for strings.protected AbstractSpreadSheetWriter.OutputTypegetOutputType()Returns how the data is written.StringgetStringColumnSQL()Returns the SQL type for string columns for the CREATE statement.StringgetTable()Returns the name of the table.AbstractTypeMappergetTypeMapper()Returns the type mapper in use.booleangetUseBackslashes()Returns whether to use backslashes for escaping quotes rather than doubling them.StringglobalInfo()Returns a string describing the object.protected voidinitialize()Initializes the members.booleanisAppending()Returns whether the next spreadsheet will get appended.StringkeepExistingTipText()Returns the tip text for this property.StringmaxStringLengthTipText()Returns the tip text for this property.protected StringquoteString(String s)Quotes the string if necessary.voidreset()Resets the writer.voidsetAddCreateTable(boolean value)Sets whether to add a CREATE TABLE statement.voidsetAppending(boolean value)Sets whether the next write call is to append the data to the existing file.voidsetColumnNameConversion(ColumnNameConversion value)Sets how to convert the column headers into SQL table column names.voidsetFileExists(boolean value)Sets whether the output file already exists.voidsetKeepExisting(boolean value)Sets whether to keep any existing file on first execution.voidsetMaxStringLength(int value)Sets the maximum length for strings.voidsetStringColumnSQL(String value)Sets the SQL type for string columns for the CREATE statement.voidsetTable(String value)Sets the name of the table.voidsetTypeMapper(AbstractTypeMapper value)Sets the type mapper to use.voidsetUseBackslashes(boolean value)Sets whether to use backslashes for escaping quotes rather than doubling them.StringstringColumnSQLTipText()Returns the tip text for this property.StringtableTipText()Returns the tip text for this property.StringtypeMapperTipText()Returns the tip text for this property.StringuseBackslashesTipText()Returns the tip text for this property.-
Methods inherited from class adams.data.io.output.AbstractSpreadSheetWriter
canCompress, doWrite, doWrite, encodingTipText, getAdditionalInformation, getDefaultFormatExtension, getEncoding, getWriters, isStopped, preWriteFile, setEncoding, stopExecution, supportsCompressedOutput, write, write, write, write
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, loggingLevelTipText, newOptionManager, setLoggingLevel, toCommandLine, toString
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.Destroyable
destroy
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
Methods inherited from interface adams.core.option.OptionHandler
cleanUpOptions, getOptionManager, toCommandLine
-
-
-
-
Field Detail
-
m_TypeMapper
protected AbstractTypeMapper m_TypeMapper
the type mapper to use.
-
m_Appending
protected boolean m_Appending
whether to append spreadsheets.
-
m_Header
protected SpreadSheet m_Header
the header of the first spreadsheet written to file, if appending is active.
-
m_KeepExisting
protected boolean m_KeepExisting
whether to keep existing files the first time the writer is called.
-
m_FileExists
protected boolean m_FileExists
whether the file already exists.
-
m_Table
protected String m_Table
the name of the table.
-
m_Types
protected Cell.ContentType[] m_Types
the type used for the table.
-
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_AddCreateTable
protected boolean m_AddCreateTable
whether to add a CREATE TABLE statement.
-
m_UseBackslashes
protected boolean m_UseBackslashes
whether to use backslashes for escaping.
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfoin interfaceGlobalInfoSupporter- Specified by:
globalInfoin classAbstractOptionHandler- Returns:
- a description suitable for displaying in the gui
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptionsin interfaceOptionHandler- Overrides:
defineOptionsin classAbstractOptionHandler
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initializein classAbstractSpreadSheetWriter
-
reset
public void reset()
Resets the writer.- Specified by:
resetin interfaceSpreadSheetWriter- Overrides:
resetin classAbstractSpreadSheetWriter
-
getFormatDescription
public String getFormatDescription()
Returns a string describing the format (used in the file chooser).- Specified by:
getFormatDescriptionin interfaceSpreadSheetWriter- Specified by:
getFormatDescriptionin classAbstractSpreadSheetWriter- Returns:
- a description suitable for displaying in the file chooser
-
getFormatExtensions
public String[] getFormatExtensions()
Returns the extension(s) of the format.- Specified by:
getFormatExtensionsin interfaceSpreadSheetWriter- Specified by:
getFormatExtensionsin classAbstractSpreadSheetWriter- Returns:
- the extension (without the dot!)
-
getCorrespondingReader
public SpreadSheetReader getCorrespondingReader()
Returns, if available, the corresponding reader.- Specified by:
getCorrespondingReaderin interfaceSpreadSheetWriter- Returns:
- the reader, null if none available
-
canAppend
public boolean canAppend(SpreadSheet sheet)
Checks whether we can append the specified spreadsheet to the existing file.- Specified by:
canAppendin interfaceAppendableSpreadSheetWriter- Parameters:
sheet- the spreadsheet to append to the existing one- Returns:
- true if appending is possible
-
setTypeMapper
public void setTypeMapper(AbstractTypeMapper value)
Sets the type mapper to use.- Parameters:
value- the mapper
-
getTypeMapper
public AbstractTypeMapper getTypeMapper()
Returns the type mapper in use.- Returns:
- the mapper
-
typeMapperTipText
public String typeMapperTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setAppending
public void setAppending(boolean value)
Sets whether the next write call is to append the data to the existing file.- Specified by:
setAppendingin interfaceAppendableSpreadSheetWriter- Parameters:
value- true if to append
-
isAppending
public boolean isAppending()
Returns whether the next spreadsheet will get appended.- Specified by:
isAppendingin interfaceAppendableSpreadSheetWriter- Returns:
- true if append is active
-
appendingTipText
public String appendingTipText()
Returns the tip text for this property.- Specified by:
appendingTipTextin interfaceAppendableSpreadSheetWriter- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setKeepExisting
public void setKeepExisting(boolean value)
Sets whether to keep any existing file on first execution.- Specified by:
setKeepExistingin interfaceAppendableSpreadSheetWriter- Parameters:
value- if true then existing file is kept
-
getKeepExisting
public boolean getKeepExisting()
Returns whether any existing file is kept on first execution.- Specified by:
getKeepExistingin interfaceAppendableSpreadSheetWriter- Returns:
- true if existing file is kept
-
keepExistingTipText
public String keepExistingTipText()
Returns the tip text for this property.- Specified by:
keepExistingTipTextin interfaceAppendableSpreadSheetWriter- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setTable
public void setTable(String value)
Sets the name of the table.- Parameters:
value- the name
-
getTable
public String getTable()
Returns the name of the table.- Returns:
- the name
-
tableTipText
public String tableTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setColumnNameConversion
public void setColumnNameConversion(ColumnNameConversion value)
Sets how to convert the column headers into SQL table column names.- Parameters:
value- the conversion
-
getColumnNameConversion
public ColumnNameConversion getColumnNameConversion()
Returns how to convert the column headers into SQL table column names.- Returns:
- the conversion
-
columnNameConversionTipText
public String columnNameConversionTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setMaxStringLength
public void setMaxStringLength(int value)
Sets the maximum length for strings.- Parameters:
value- the maximum
-
getMaxStringLength
public int getMaxStringLength()
Returns the maximum length for strings.- Returns:
- the maximum
-
maxStringLengthTipText
public String maxStringLengthTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setStringColumnSQL
public void setStringColumnSQL(String value)
Sets the SQL type for string columns for the CREATE statement.- Parameters:
value- the SQL type
-
getStringColumnSQL
public String getStringColumnSQL()
Returns the SQL type for string columns for the CREATE statement.- Returns:
- the SQL type
-
stringColumnSQLTipText
public String stringColumnSQLTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setAddCreateTable
public void setAddCreateTable(boolean value)
Sets whether to add a CREATE TABLE statement.- Parameters:
value- if true then a CREATE TABLE statement is output as well
-
getAddCreateTable
public boolean getAddCreateTable()
Returns whether a CREATE TABLE statement is output.- Returns:
- true if statement is output
-
addCreateTableTipText
public String addCreateTableTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setUseBackslashes
public void setUseBackslashes(boolean value)
Sets whether to use backslashes for escaping quotes rather than doubling them.- Parameters:
value- if true then backslashes are used
-
getUseBackslashes
public boolean getUseBackslashes()
Returns whether to use backslashes for escaping quotes rather than doubling them.- Returns:
- true if backslashes are used
-
useBackslashesTipText
public String useBackslashesTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setFileExists
public void setFileExists(boolean value)
Sets whether the output file already exists.- Specified by:
setFileExistsin interfaceAppendableSpreadSheetWriter- Parameters:
value- true if the output file already exists
-
getFileExists
public boolean getFileExists()
Returns whether the output file already exists.- Specified by:
getFileExistsin interfaceAppendableSpreadSheetWriter- Returns:
- true if the output file already exists
-
format
protected String format(double value)
Formats the number according to the format and returns the generated textual representation.- Parameters:
value- the double value to turn into a string- Returns:
- the generated string
-
quoteString
protected String quoteString(String s)
Quotes the string if necessary.- Parameters:
s- the string to quote, if necessary- Returns:
- the potentially quoted string
-
getOutputType
protected AbstractSpreadSheetWriter.OutputType getOutputType()
Returns how the data is written.- Specified by:
getOutputTypein classAbstractSpreadSheetWriter- Returns:
- the type
-
doWrite
protected boolean doWrite(SpreadSheet content, Writer writer)
Performs the actual writing. The caller must ensure that the writer gets closed.- Overrides:
doWritein classAbstractSpreadSheetWriter- Parameters:
content- the spreadsheet to writewriter- the writer to write the spreadsheet to- Returns:
- true if successfully written
-
-