public class Importer extends Object implements ImpExLogFilter.LocationProvider
Importer class, this CSV-stream will be given using an CSVReader or an
ImpExImportReader. If you only want to specify the input stream use an CSVReader, the
Importer will instantiate an corresponding ImpExImportReader. The usage of an
ImpExImportReader is only preferred, if special settings while instantiation are needed (settings after
instantiation can be done using the getReader() method of the Importer instance).
CSVReader reader = new CSVReader( "input.csv", "utf-8" );
Importer importer = new Importer( reader );
or
Importer importer = new Importer( new ImpExImportReader( reader, new MyImportProcessor() ) );
ImpExImportReader using the getReader method. Here you can
configure several things about the reading of the input (skipValueLines, enableCodeExecution, ..) or item processing
( setRelaxedMode, .. ).DumpHandler for specifying the dump file handling.ErrorHandler to specify the process in case of an error.importNext which processes the input stream until an item was
processed (insert, update or remove). It returns the processed item.importAll method which calls the importNext method
until finishing of the input stream. While and after the import process you have several possibilities to get
information about the state (current pass, processed items .. ).
Item item = null;
do
{
item = importer.importNext();
System.out.println( "Processed items: " + getProcessedItemsCountOverall() );
}
while( item != null );
or
importer.importAll();
System.out.println( "Processed items: " + getProcessedItemsCountOverall() );
| Modifier and Type | Field and Description |
|---|---|
static long |
LOG_INTERVAL
Duration between two logs.
|
| Constructor and Description |
|---|
Importer(CSVReader source)
Instantiates a
Importer using given source as input for import. |
Importer(ImpExImportReader importReader)
Instantiates a
Importer using given importReader for reading input and item processing. |
| Modifier and Type | Method and Description |
|---|---|
void |
abortImport()
Aborts the import phase by closing all readers and writers, cleaning dump files and switching to finish state.
|
protected void |
activateLogFilter() |
protected void |
assureStates(de.hybris.platform.impex.jalo.Importer.STATE... states)
Assures that the instance is in one of given states.
|
void |
close()
Closes the used reader instance.
|
protected ImpExImportReader |
createImportReader(CSVReader csvReader)
Creates an
ImpExImportReader instance for processing given input. |
protected ImpExImportReader |
createImportReaderForNextPass()
Creates an
ImpExImportReader instance for next pass using dump handler for getting input stream and
dump stream. |
protected void |
deactivateLogFilter() |
protected Item |
doImport()
Performs the
readLine method on used ImpExImportReader instance and returns read item. |
protected void |
finishImport()
Finishes the import phase by closing all readers and writers, cleaning dump files and switching state.
|
HeaderDescriptor |
getCurrentHeader()
Gets the current header descriptor processed by input reader.
|
int |
getCurrentLineNumber()
Gets the current line number in input stream.
|
String |
getCurrentLocation()
Gets the current location within input stream as text representation.
|
int |
getCurrentPass()
Gets the number of the current pass, the import process performs.
|
int |
getDumpedLineCountOverall()
Returns the amount of lines written to the dump data file in all passes.
|
int |
getDumpedLineCountPerHeader()
Returns the amount of lines of current header written to the dump data file.
|
int |
getDumpedLineCountPerPass()
Returns the amount of lines written to the dump data file in current pass intended to be processed within a second
import run or more.
|
DumpHandler |
getDumpHandler()
Gets the used
DumpHandler instance for handling dump medias. |
ErrorHandler |
getErrorHandler()
Gets the used
ErrorHandler instance for handling exceptions while import. |
int |
getLastImportedItemLineNumber()
Gets the line number of last imported line at current input.
|
ImpExLogFilter |
getLogFilter() |
int |
getMaxPass()
Gets the configured amount of maximal passes the import will perform for unresolving value lines.
|
int |
getProcessedItemsCountOverall()
Returns the overall processed item count.
|
int |
getProcessedItemsCountPerHeader()
Returns the overall processed item count of current header.
|
int |
getProcessedItemsCountPerPass()
Returns the overall processed item count of current pass.
|
ImpExImportReader |
getReader()
Gets the used
ImpExImportReader instance. |
int |
getResolvedItemsCountOverall()
Returns the overall item count processed and not dumped (means all dependencies are resolved).
|
int |
getResolvedItemsCountPerPass()
Returns the item count processed and not dumped in current pass (means all dependencies are resolved).
|
int |
getValueLineCountPerPass()
Returns the overall value line count of current pass.
|
boolean |
hadError() |
boolean |
hasUnresolvedLines()
Checks if there are unresolved lines written to dump.
|
void |
importAll()
The import process will be performed from input stream given in constructor.
|
Item |
importNext()
Tries to import the next item from input stream.
|
protected Item |
importNextInternal() |
protected void |
init()
Initializes the instance and switches to running state.
|
boolean |
isAborted()
Checks if instance has finished reading from input (has finished import process).
|
boolean |
isFinished()
Checks if instance has finished reading from input (has finished import process).
|
boolean |
isRunning()
Checks if instance is in import phase currently.
|
protected void |
logProcess()
Logs current state to the log4j system.
|
protected boolean |
prepareNextPass()
After checking the need for a next pass, it prepares the next import cycle by calling
prepareNextPass
of used DumpHandler and setting old dump file as input. |
void |
setDumpHandler(DumpHandler handler)
Sets the
DumpHandler to use while import process. |
void |
setErrorHandler(ErrorHandler handler)
Sets the
ErrorHandler to use while import. |
void |
setLogFilter(ImpExLogFilter filter)
Sets the logging filter to use while import.
|
void |
setMaxPass(int maxPass)
Sets the maximal amount of passes the import process will perform.
|
protected void |
switchToState(de.hybris.platform.impex.jalo.Importer.STATE newState)
Sets the
curSteate flag to given state. |
public static final long LOG_INTERVAL
public Importer(CSVReader source)
Importer using given source as input for import.source - encapsulated CSV-streampublic Importer(ImpExImportReader importReader)
Importer using given importReader for reading input and item processing.importReader - reader used for input reading and item processingprotected void init()
throws ImpExException
ImpExException - error while dump file creationprotected void switchToState(de.hybris.platform.impex.jalo.Importer.STATE newState)
curSteate flag to given state.newState - new state to which the current state will be setprotected void logProcess()
protected Item doImport() throws ImpExException
readLine method on used ImpExImportReader instance and returns read item.
If set ErrorHandler evaluated an error to ignore, the next item will be read.ImpExException - error while reading from input or item processingprotected boolean prepareNextPass()
throws ImpExException
prepareNextPass
of used DumpHandler and setting old dump file as input.ImpExException - error while preparing dump filesprotected void finishImport()
public void abortImport()
protected void assureStates(de.hybris.platform.impex.jalo.Importer.STATE... states)
IllegalStateException if instance is not in
one of given states currently.states - states to check forprotected ImpExImportReader createImportReader(CSVReader csvReader)
ImpExImportReader instance for processing given input.csvReader - reader covering input streamprotected ImpExImportReader createImportReaderForNextPass()
ImpExImportReader instance for next pass using dump handler for getting input stream and
dump stream.public boolean isRunning()
public boolean isFinished()
public boolean isAborted()
public int getMaxPass()
public int getCurrentPass()
public ImpExImportReader getReader()
ImpExImportReader instance.public DumpHandler getDumpHandler()
DumpHandler instance for handling dump medias.public ErrorHandler getErrorHandler()
ErrorHandler instance for handling exceptions while import.public boolean hasUnresolvedLines()
public int getValueLineCountPerPass()
public int getProcessedItemsCountPerHeader()
public int getProcessedItemsCountPerPass()
getValueCountPerPass without skipped
and discarded value lines.public int getProcessedItemsCountOverall()
public int getDumpedLineCountPerHeader()
public int getResolvedItemsCountPerPass()
public int getResolvedItemsCountOverall()
public int getDumpedLineCountPerPass()
public int getDumpedLineCountOverall()
public int getCurrentLineNumber()
CSVReader.getCurrentLineNumber()public int getLastImportedItemLineNumber()
public String getCurrentLocation()
getCurrentLocation in interface ImpExLogFilter.LocationProviderImpExReader.getCurrentLocation()public HeaderDescriptor getCurrentHeader()
ImpExReader.getCurrentHeader()public void importAll()
throws ImpExException
DumpHandler, the ErrorHandler and the maximal amount of passes. The call
will automatically perform the whole import process including the dumped line processing (if maximal passes are a
positive number). You can call the importNext method too for importing item based. This method is
only a convenience kind which calls the importNext method until it returns null.ImpExException - an error is occurred while import processing (reasoned by input stream errors, dump file handling or
item processing)public final Item importNext() throws ImpExException
set..
methods anymore. If the input stream ends and there are unresolved lines, the call will automatically start the
next pass by using the dump file as new input stream.ImpExException - ImpExException an error is occurred while import processing (reasoned by input stream errors, dump file
handling or item processing)protected Item importNextInternal() throws ImpExException
ImpExExceptionprotected void activateLogFilter()
protected void deactivateLogFilter()
public void close()
isFinished() returns true).public void setMaxPass(int maxPass)
maxPass - new amount of maximal passespublic void setDumpHandler(DumpHandler handler)
DumpHandler to use while import process.handler - new dump handler instancepublic void setErrorHandler(ErrorHandler handler)
ErrorHandler to use while import.handler - new error handler instancepublic void setLogFilter(ImpExLogFilter filter)
filter - new error handler instancepublic ImpExLogFilter getLogFilter()
public boolean hadError()
Copyright © 2017 SAP SE. All Rights Reserved.