Package adams.data.io.output
Class AccessSpreadSheetWriter
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.data.io.output.AbstractSpreadSheetWriter
-
- adams.data.io.output.AccessSpreadSheetWriter
-
- All Implemented Interfaces:
AdditionalInformationHandler,Destroyable,GlobalInfoSupporter,EncodingSupporter,LoggingLevelHandler,LoggingSupporter,OptionHandler,SizeOfHandler,Stoppable,StoppableWithFeedback,AppendableSpreadSheetWriter,IncrementalSpreadSheetWriter,SpreadSheetWriter,Serializable
public class AccessSpreadSheetWriter extends AbstractSpreadSheetWriter implements AppendableSpreadSheetWriter, IncrementalSpreadSheetWriter
Writes spreadsheet data to a MS Access database.
-logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel) The logging level for outputting errors and debugging output. default: WARNING
-file-format <V1997 [VERSION_3]|V2000 [VERSION_4]|V2003 [VERSION_4]|V2007 [VERSION_12]|V2010 [VERSION_14]|MSISAM [MSISAM]> (property: fileFormat) The MS Access file format to use when creating a new database. default: V2010 [VERSION_14]
-appending <boolean> (property: appending) If enabled, multiple spreadsheets with the same structure can be written to the same file. default: false
-keep-existing <boolean> (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). default: false
- 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_Appendingwhether to append spreadsheets.protected HashMap<Integer,com.healthmarketscience.jackcess.DataType>m_ColumnTypesthe column types.protected com.healthmarketscience.jackcess.Databasem_Databasethe database object to use.protected booleanm_FileExistswhether the file already exists.protected com.healthmarketscience.jackcess.Database.FileFormatm_FileFormatthe file format to use.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 com.healthmarketscience.jackcess.Tablem_Tablethe table object to use.protected Stringm_TableNamethe table name to use.-
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 AccessSpreadSheetWriter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringappendingTipText()Returns the tip text for this property.booleancanAppend(SpreadSheet sheet)Checks whether we can append the specified spreadsheet to the existing file.voiddefineOptions()Adds options to the internal list of options.protected StringdetermineTableName(SpreadSheet sheet)Determines the name for the table.protected booleandoWrite(Row content, String filename)Performs the actual writing.protected booleandoWrite(SpreadSheet content, String filename)Performs the actual writing.protected booleandoWriteHeader(Row header, String filename)Writes the header.StringfileFormatTipText()Returns the tip text for this property.SpreadSheetReadergetCorrespondingReader()Returns, if available, the corresponding reader.booleangetFileExists()Returns whether the output file already exists.com.healthmarketscience.jackcess.Database.FileFormatgetFileFormat()Returns the file format in use when creating a database.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.protected AbstractSpreadSheetWriter.OutputTypegetOutputType()Returns how the data is written.StringgetTableName()Returns the table name to use.StringglobalInfo()Returns a string describing the object.protected voidinitialize()Initializes the members.booleanisAppending()Returns whether the next spreadsheet will get appended.booleanisIncremental()Returns whether the writer can write data incrementally.StringkeepExistingTipText()Returns the tip text for this property.voidreset()Resets the writer.voidsetAppending(boolean value)Sets whether the next write call is to append the data to the existing file.voidsetFileExists(boolean value)Sets whether the output file already exists.voidsetFileFormat(com.healthmarketscience.jackcess.Database.FileFormat value)Sets the file format to use when creating a database.voidsetKeepExisting(boolean value)Sets whether to keep any existing file on first execution.voidsetTableName(String value)Sets the table name to use.StringtableNameTipText()Returns the tip text for this property.booleanwrite(Row content, File file)Writes the given content to the specified file.booleanwrite(Row content, OutputStream stream)Writes the spreadsheet to the given output stream.booleanwrite(Row content, Writer writer)Writes the spreadsheet to the given writer.booleanwrite(Row content, String filename)Writes the spreadsheet to the given file.protected booleanwriteHeader(Row header, String filename)Writes the header, if necessary.-
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
-
Methods inherited from interface adams.data.io.output.SpreadSheetWriter
write, write, write, write
-
Methods inherited from interface adams.core.Stoppable
stopExecution
-
Methods inherited from interface adams.core.StoppableWithFeedback
isStopped
-
-
-
-
Field Detail
-
m_FileFormat
protected com.healthmarketscience.jackcess.Database.FileFormat m_FileFormat
the file format to use.
-
m_TableName
protected String m_TableName
the table name 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_Database
protected transient com.healthmarketscience.jackcess.Database m_Database
the database object to use.
-
m_Table
protected transient com.healthmarketscience.jackcess.Table m_Table
the table object to use.
-
-
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
-
setFileFormat
public void setFileFormat(com.healthmarketscience.jackcess.Database.FileFormat value)
Sets the file format to use when creating a database.- Parameters:
value- the file format
-
getFileFormat
public com.healthmarketscience.jackcess.Database.FileFormat getFileFormat()
Returns the file format in use when creating a database.- Returns:
- the file format
-
fileFormatTipText
public String fileFormatTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setTableName
public void setTableName(String value)
Sets the table name to use. If empty the spreadsheet's name is used.- Parameters:
value- the table name
-
getTableName
public String getTableName()
Returns the table name to use. If empty the spreadsheet's name is used.- Returns:
- the table name
-
tableNameTipText
public String tableNameTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
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
-
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.
-
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
-
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
-
getOutputType
protected AbstractSpreadSheetWriter.OutputType getOutputType()
Returns how the data is written.- Specified by:
getOutputTypein classAbstractSpreadSheetWriter- Returns:
- the type
-
determineTableName
protected String determineTableName(SpreadSheet sheet)
Determines the name for the table. Uses the project name if sheet has no name set and no table is set.- Parameters:
sheet- the sheet to determine the name for- Returns:
- the name for the table
- See Also:
getTableName()
-
doWriteHeader
protected boolean doWriteHeader(Row header, String filename)
Writes the header.- Parameters:
header- the header row to writefilename- the file to write the header to
-
writeHeader
protected boolean writeHeader(Row header, String filename)
Writes the header, if necessary.- Parameters:
header- the header row to writefilename- the file to write the header to
-
doWrite
protected boolean doWrite(Row content, String filename)
Performs the actual writing. The caller must ensure that the writer gets closed.- Parameters:
content- the row to writefilename- the file to write the spreadsheet to- Returns:
- true if successfully written
-
doWrite
protected boolean doWrite(SpreadSheet content, String filename)
Performs the actual writing. The caller must ensure that the writer gets closed.
Default implementation returns always false.- Overrides:
doWritein classAbstractSpreadSheetWriter- Parameters:
content- the spreadsheet to writefilename- the file to write the spreadsheet to- Returns:
- true if successfully written
-
isIncremental
public boolean isIncremental()
Returns whether the writer can write data incrementally.- Specified by:
isIncrementalin interfaceIncrementalSpreadSheetWriter- Returns:
- true if data can be written incrementally
-
write
public boolean write(Row content, File file)
Writes the given content to the specified file.- Specified by:
writein interfaceIncrementalSpreadSheetWriter- Parameters:
content- the content to writefile- the file to write to- Returns:
- true if successfully written
-
write
public boolean write(Row content, String filename)
Writes the spreadsheet to the given file.- Specified by:
writein interfaceIncrementalSpreadSheetWriter- Parameters:
content- the spreadsheet to writefilename- the file to write the spreadsheet to- Returns:
- true if successfully written
-
write
public boolean write(Row content, OutputStream stream)
Writes the spreadsheet to the given output stream. The caller must ensure that the stream gets closed.- Specified by:
writein interfaceIncrementalSpreadSheetWriter- Parameters:
content- the spreadsheet to writestream- the output stream to write the spreadsheet to- Returns:
- always false
- See Also:
write(adams.data.spreadsheet.Row, String)
-
write
public boolean write(Row content, Writer writer)
Writes the spreadsheet to the given writer. The caller must ensure that the writer gets closed.- Specified by:
writein interfaceIncrementalSpreadSheetWriter- Parameters:
content- the spreadsheet to writewriter- the writer to write the spreadsheet to- Returns:
- always false
- See Also:
write(adams.data.spreadsheet.Row, String)
-
-