public abstract class AbstractSimpleImporterProcessor extends Object implements IImporterProcessor
| Modifier and Type | Field and Description |
|---|---|
protected String |
COMMENT_START
Lines starting with this prefix are considered as comments
|
protected File |
currentFile
The current processed file
|
protected ImporterConfig |
importerConfig |
protected BufferedReader |
in
The bufferReader for the current read Geonames file
|
protected IInternationalisationService |
internationalisationService |
protected static org.slf4j.Logger |
logger
The logger
|
protected int |
readFileLine |
protected ImporterStatus |
status |
protected String |
statusMessage |
protected int |
totalReadLine |
protected org.springframework.transaction.PlatformTransactionManager |
transactionManager
The transaction manager
|
protected org.springframework.transaction.support.DefaultTransactionDefinition |
txDefinition |
protected org.springframework.transaction.TransactionStatus |
txStatus |
| Constructor and Description |
|---|
AbstractSimpleImporterProcessor()
Default constructor
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
checkNumberOfColumn(String[] fields)
Utility method which throw an exception if the number of fields is not
the one expected (retrieved by
getNumberOfColumns()) |
protected void |
commit() |
protected int |
countLines(File[] files) |
protected int |
decrementReadedFileLine(int decrement) |
protected static String |
dumpFields(String[] fields) |
protected abstract void |
flushAndClear()
Should flush and clear all the Daos that are used by the processor.
|
String |
getCurrentFileName() |
protected abstract File[] |
getFiles() |
protected int |
getMaxInsertsBeforeFlush() |
protected abstract int |
getNumberOfColumns() |
long |
getNumberOfLinesToProcess() |
long |
getReadFileLine()
The number of read line for the current processed file
|
ImporterStatus |
getStatus() |
String |
getStatusMessage() |
long |
getTotalReadLine()
The number of read line for all the processed file
|
protected int |
incrementReadedFileLine(int increment) |
protected static boolean |
isEmptyField(String[] fields,
int position,
boolean required)
Check that the array is not null, and the fields of the specified
position is not empty (after been trimed)
|
protected boolean |
isEndOfDocument() |
protected boolean |
needCommit() |
protected void |
onFileProcessed(File file)
hook to do when the file has been processed without error
|
void |
process()
Manage the transaction, flush Daos, and process all files to be processed
|
protected abstract void |
processData(String line)
Process a read line of the geonames file, must be implemented by the
concrete class
|
protected void |
processError(Exception e)
Method called when there is an exception.
|
int |
readLineAndProcessData()
Process the line if needed (is not a comment, should ignore first line,
is end of document,...)
|
void |
resetStatus()
Reset status fields, it should be done when the import has been canceled
|
protected void |
rollbackTransaction() |
protected abstract void |
setCommitFlushMode()
Will flush after every commit
|
void |
setImporterConfig(ImporterConfig importerConfig) |
void |
setInternationalisationService(IInternationalisationService internationalisationService) |
void |
setTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager) |
protected void |
setup()
Template method that can be override.
|
boolean |
shouldBeSkipped() |
protected abstract boolean |
shouldIgnoreComments()
Whether the filter should ignore the comments (i.e. lines starting with #)
|
protected abstract boolean |
shouldIgnoreFirstLine()
Template Method : Whether the processor should ignore the first line of
the input
|
protected void |
startTransaction() |
protected void |
tearDown()
Template method that can be override.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitrollbackprotected int totalReadLine
protected int readFileLine
protected String statusMessage
protected ImporterStatus status
@Autowired protected IInternationalisationService internationalisationService
protected ImporterConfig importerConfig
protected static final org.slf4j.Logger logger
protected String COMMENT_START
protected BufferedReader in
protected org.springframework.transaction.PlatformTransactionManager transactionManager
protected org.springframework.transaction.TransactionStatus txStatus
protected org.springframework.transaction.support.DefaultTransactionDefinition txDefinition
protected File currentFile
public AbstractSimpleImporterProcessor()
protected abstract boolean shouldIgnoreFirstLine()
protected abstract void flushAndClear()
protected abstract void setCommitFlushMode()
flushAndClear()protected abstract int getNumberOfColumns()
protected abstract boolean shouldIgnoreComments()
COMMENT_STARTprotected void setup()
protected abstract File[] getFiles()
ImporterHelperpublic String getCurrentFileName()
getCurrentFileName in interface IImporterProcessorpublic int readLineAndProcessData()
throws ImporterException
ImporterException - if an error occurredprotected abstract void processData(String line) throws ImporterException
line - the line to processImporterExceptionpublic void process()
process in interface IImporterProcessorprotected void processError(Exception e)
e - public boolean shouldBeSkipped()
shouldBeSkipped in interface IImporterProcessorprotected int incrementReadedFileLine(int increment)
protected int decrementReadedFileLine(int decrement)
protected void rollbackTransaction()
protected boolean needCommit()
protected void startTransaction()
protected void tearDown()
protected void onFileProcessed(File file)
file - protected void commit()
protected static boolean isEmptyField(String[] fields, int position, boolean required)
fields - The array to testposition - the position of the field to test in the arrayrequired - if an exception should be thrown if the field is emptyMissingRequiredFieldException - if the fields is empty and required is trueprotected static String dumpFields(String[] fields)
fields - The array to processprotected void checkNumberOfColumn(String[] fields)
getNumberOfColumns())fields - The array to checkgetNumberOfColumns()protected boolean isEndOfDocument()
public long getReadFileLine()
IImporterProcessorgetReadFileLine in interface IImporterProcessorIImporterProcessor.getTotalReadLine()public long getTotalReadLine()
IImporterProcessorgetTotalReadLine in interface IImporterProcessorIImporterProcessor.getReadFileLine()public void setTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager)
public void setImporterConfig(ImporterConfig importerConfig)
protected int countLines(File[] files)
public long getNumberOfLinesToProcess()
getNumberOfLinesToProcess in interface IImporterProcessorpublic ImporterStatus getStatus()
getStatus in interface IImporterProcessorprotected int getMaxInsertsBeforeFlush()
ImporterConfig.setMaxInsertsBeforeFlush(int)public void resetStatus()
IImporterProcessorresetStatus in interface IImporterProcessorpublic String getStatusMessage()
getStatusMessage in interface IImporterProcessorpublic void setInternationalisationService(IInternationalisationService internationalisationService)
Copyright © 2015. All rights reserved.