Package com.jbstrap.core.data
Class DataExporter
java.lang.Object
com.jbstrap.core.data.DataExporter
- Direct Known Subclasses:
CSVExport
,ExcelExport
The data exporting parent class, that requires the implementation of the start, process end methods.
It also provides the methods, that can (or must be) used when exporting data.
- Since:
- 4.0
- Author:
- JBStrap
-
Field Summary
-
Constructor Summary
ConstructorDescriptionDataExporter
(Parameters params) Creates a DataExporter instance with the specified export settings (parameters). -
Method Summary
Modifier and TypeMethodDescriptionaddColumnMapping
(String columnName) addColumnMapping
(String columnName, String title) Adds a column mapping to the exporterabstract byte[]
end()
This method is to be called after completing the export process.Gets a map of the Column Mapping assigned.Gets the export file extension.abstract boolean
Processing records retrieved using lazy fetch and writing them into the export file.removeColumnMapping
(String columnName) Removes a column mapping from the exporterabstract boolean
start()
This method is to be called upon starting the export process.
-
Field Details
-
params
-
columnMap
The map containing the columns and their headers.
The Map key is the column name, and the value is the header.
-
-
Constructor Details
-
DataExporter
Creates a DataExporter instance with the specified export settings (parameters).- Parameters:
params
- Export parameters
-
-
Method Details
-
addColumnMapping
-
addColumnMapping
Adds a column mapping to the exporter- Parameters:
columnName
- The column nametitle
- The column header text- Returns:
- The data exporter class
-
removeColumnMapping
Removes a column mapping from the exporter- Parameters:
columnName
- The name of the column that has the mapping to be removed- Returns:
- The data exporter class
-
getColumnMapping
Gets a map of the Column Mapping assigned.- Returns:
- The column mappings in a map format. The map key is the column name, the value is the header text
-
start
public abstract boolean start()This method is to be called upon starting the export process. Necessary objects and the export file are initialized at this point.- Returns:
- Initialization success
-
process
Processing records retrieved using lazy fetch and writing them into the export file. This method is called every time the query is performed and the retrieved set of records is not empty.- Parameters:
data
- Records retrieved using lazy fetch- Returns:
- If an exception is thrown and more records cannot be written into the export file, then
false
, otherwisetrue
. Iftrue
, the export process continues, otherwise the end method is called.
-
end
This method is to be called after completing the export process. The method closes all the sources opened in the start method.- Returns:
- The exported file returned as a byte array
- Throws:
IOException
- An exception is thrown while handling a source
-
getExtension
Gets the export file extension. If no extension is specified, then the export file is created using the export.defaultExtension message source, which is an empty string by default- Returns:
- Export file extension
-