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 boolean
m_Appending
whether to append spreadsheets.protected HashMap<Integer,com.healthmarketscience.jackcess.DataType>
m_ColumnTypes
the column types.protected com.healthmarketscience.jackcess.Database
m_Database
the database object to use.protected boolean
m_FileExists
whether the file already exists.protected com.healthmarketscience.jackcess.Database.FileFormat
m_FileFormat
the file format to use.protected SpreadSheet
m_Header
the header of the first spreadsheet written to file, if appending is active.protected boolean
m_KeepExisting
whether to keep existing files the first time the writer is called.protected com.healthmarketscience.jackcess.Table
m_Table
the table object to use.protected String
m_TableName
the 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 String
appendingTipText()
Returns the tip text for this property.boolean
canAppend(SpreadSheet sheet)
Checks whether we can append the specified spreadsheet to the existing file.void
defineOptions()
Adds options to the internal list of options.protected String
determineTableName(SpreadSheet sheet)
Determines the name for the table.protected boolean
doWrite(Row content, String filename)
Performs the actual writing.protected boolean
doWrite(SpreadSheet content, String filename)
Performs the actual writing.protected boolean
doWriteHeader(Row header, String filename)
Writes the header.String
fileFormatTipText()
Returns the tip text for this property.SpreadSheetReader
getCorrespondingReader()
Returns, if available, the corresponding reader.boolean
getFileExists()
Returns whether the output file already exists.com.healthmarketscience.jackcess.Database.FileFormat
getFileFormat()
Returns the file format in use when creating a database.String
getFormatDescription()
Returns a string describing the format (used in the file chooser).String[]
getFormatExtensions()
Returns the extension(s) of the format.boolean
getKeepExisting()
Returns whether any existing file is kept on first execution.protected AbstractSpreadSheetWriter.OutputType
getOutputType()
Returns how the data is written.String
getTableName()
Returns the table name to use.String
globalInfo()
Returns a string describing the object.protected void
initialize()
Initializes the members.boolean
isAppending()
Returns whether the next spreadsheet will get appended.boolean
isIncremental()
Returns whether the writer can write data incrementally.String
keepExistingTipText()
Returns the tip text for this property.void
reset()
Resets the writer.void
setAppending(boolean value)
Sets whether the next write call is to append the data to the existing file.void
setFileExists(boolean value)
Sets whether the output file already exists.void
setFileFormat(com.healthmarketscience.jackcess.Database.FileFormat value)
Sets the file format to use when creating a database.void
setKeepExisting(boolean value)
Sets whether to keep any existing file on first execution.void
setTableName(String value)
Sets the table name to use.String
tableNameTipText()
Returns the tip text for this property.boolean
write(Row content, File file)
Writes the given content to the specified file.boolean
write(Row content, OutputStream stream)
Writes the spreadsheet to the given output stream.boolean
write(Row content, Writer writer)
Writes the spreadsheet to the given writer.boolean
write(Row content, String filename)
Writes the spreadsheet to the given file.protected boolean
writeHeader(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:
globalInfo
in interfaceGlobalInfoSupporter
- Specified by:
globalInfo
in classAbstractOptionHandler
- Returns:
- a description suitable for displaying in the gui
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractOptionHandler
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in classAbstractSpreadSheetWriter
-
reset
public void reset()
Resets the writer.- Specified by:
reset
in interfaceSpreadSheetWriter
- Overrides:
reset
in 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:
canAppend
in 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:
setAppending
in interfaceAppendableSpreadSheetWriter
- Parameters:
value
- true if to append
-
isAppending
public boolean isAppending()
Returns whether the next spreadsheet will get appended.- Specified by:
isAppending
in interfaceAppendableSpreadSheetWriter
- Returns:
- true if append is active
-
appendingTipText
public String appendingTipText()
Returns the tip text for this property.- Specified by:
appendingTipText
in 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:
setKeepExisting
in 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:
getKeepExisting
in interfaceAppendableSpreadSheetWriter
- Returns:
- true if existing file is kept
-
keepExistingTipText
public String keepExistingTipText()
Returns the tip text for this property.- Specified by:
keepExistingTipText
in 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:
setFileExists
in interfaceAppendableSpreadSheetWriter
- Parameters:
value
- true if the output file already exists
-
getFileExists
public boolean getFileExists()
Returns whether the output file already exists.- Specified by:
getFileExists
in 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:
getFormatDescription
in interfaceSpreadSheetWriter
- Specified by:
getFormatDescription
in classAbstractSpreadSheetWriter
- Returns:
- a description suitable for displaying in the file chooser
-
getFormatExtensions
public String[] getFormatExtensions()
Returns the extension(s) of the format.- Specified by:
getFormatExtensions
in interfaceSpreadSheetWriter
- Specified by:
getFormatExtensions
in classAbstractSpreadSheetWriter
- Returns:
- the extension (without the dot!)
-
getCorrespondingReader
public SpreadSheetReader getCorrespondingReader()
Returns, if available, the corresponding reader.- Specified by:
getCorrespondingReader
in interfaceSpreadSheetWriter
- Returns:
- the reader, null if none available
-
getOutputType
protected AbstractSpreadSheetWriter.OutputType getOutputType()
Returns how the data is written.- Specified by:
getOutputType
in 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:
doWrite
in 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:
isIncremental
in 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:
write
in 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:
write
in 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:
write
in 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:
write
in 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)
-
-