Class ImpExImportJob

All Implemented Interfaces:
Serializable, Comparable
Direct Known Subclasses:
MultiThreadedImpExImportReaderIntegrationTest.TestImpExImportJob

public class ImpExImportJob extends GeneratedImpExImportJob
This job imports data given by jobMedia attribute of assigned cronjob using the ImpEx Importer. For dumping of unresolved lines, the CronJobDumpHandler is used, so the dump file will be hold transient while each pass and at the end of a pass stored to the unresolvedMedia flag of the cronjob. Additionally it will be performed a savepoint logic periodically which also stores the transient dump file and saves information about current state.
ATTENTION: Each default import cronjob uses the same instance of this job. So be assure while extending this job that no state dependent things are used, like member variables.
See Also:
  • Constructor Details

    • ImpExImportJob

      public ImpExImportJob()
  • Method Details

    • canUndo

      protected boolean canUndo(CronJob cronJob)
      Description copied from class: Job
      Returns true, if the specified CronJob can be undone. Overwrite this method of you want to undo your CronJob. Default value is false
      Overrides:
      canUndo in class Job
      Parameters:
      cronJob - the CronJob to undo changes for
      Returns:
      true if this Job is undoable, false otherwise.
    • isAbortable

      public boolean isAbortable(CronJob cronJob)
      Description copied from class: Job
      Tells whether this currently executed job is abortable. As default this method returns false. Override to implement abortable jobs.
      Overrides:
      isAbortable in class Job
      Parameters:
      cronJob - the current execution of this job.
      Returns:
      true if the cronjob is running and the job supports aborting via GeneratedCronJob.setRequestAbort(boolean)
    • isPerformable

      public boolean isPerformable(CronJob cronJob)
      Description copied from class: Job
      Tests whether the given CronJob instance can be performed. Internal the methods canPerform( final CronJob cronJob ) and canPerformInternal( final CronJob cronJob ) are called. Only if both methods returning true, this method also return true Returns true, if this Job can be performed using the specified Cronjob. Otherwise false is returned.
      Overrides:
      isPerformable in class Job
      Parameters:
      cronJob - which should be performed
      Returns:
      true, if this Job can be performed using the specified Cronjob. Otherwise false is returned
    • performCronJob

      public CronJob.CronJobResult performCronJob(CronJob cronJob) throws AbortCronJobException
      Description copied from class: Job
      You have to implement this method in your Job. Here you can execute the job. You have to return a CronJobResult that indicates whether the Job was successfully executed or not.
      Specified by:
      performCronJob in class Job
      Parameters:
      cronJob - the CronJob to execute
      Returns:
      a CronJobResult that indicates whether the Job was successfully executed or not.

      Throws:
      AbortCronJobException
      See Also:
    • cleanup

      protected void cleanup(ImpExImportCronJob importCronJob)
      Tries to remove all used medias which are marked as to remove.
      Parameters:
      importCronJob - cronjob instance for accessing the medias
    • performJob

      protected boolean performJob(ImpExImportCronJob cronJob) throws AbortCronJobException
      Instantiates and configures a Importer instance and performs the import using it. For instantiating the Importer, first a CSVReader holding the source data will be created and configured, second a ImportProcessor will be created and configured and third an ImpExImportReader will be instantiated and configured.
      Parameters:
      cronJob - cronjob instance performing this job
      Returns:
      true if import was successful, false otherwise
      Throws:
      AbortCronJobException - import job was aborted
    • getStatsInverval

      protected long getStatsInverval()
    • doImport

      protected boolean doImport(ImpExImportCronJob cronJob, Importer importer) throws AbortCronJobException
      Performs the import using given Importer instance. If a abort is requested, the import will be aborted.
      Parameters:
      cronJob - cronjob instance performing this job
      importer - configured importer instance to use for import
      Returns:
      true if import was successful, false otherwise
      Throws:
      AbortCronJobException - import job was aborted
    • createCSVReader

      protected CSVReader createCSVReader(ImpExImportCronJob cronJob)
      Creates the csv reader which gives the ImpExImportReader access to the source data. As source data the media of the jobMedia attribute of the cronjob is used. Furthermore the encoding attribute is used for defining the encoding of the stream to that media.
      Parameters:
      cronJob - current cronjob instance to get encoding and source data
      Returns:
      CSVReader created csv reader
    • createImportProcessor

      protected ImportProcessor createImportProcessor(ImpExImportCronJob cronJob)
      Creates the job specific ImportProcessor. This processor adds the cronjob code to the saved values message.
      Parameters:
      cronJob - cronjob instance to get further parameters
      Returns:
      created processor instance
    • createImportReader

      protected ImpExImportReader createImportReader(ImpExImportCronJob cronJob, CSVReader csvReader, ImportProcessor processor)
      Creates the import reader instance used by the Importer. Here a cronjob specific reader is used which uses the encoding specified at cronjob for external data medias and an specific ImportProcessor. Furthermore a specific ImportProcessor can be specified.
      Parameters:
      cronJob - current cronjob instance to get parameters like encoding
      csvReader - reader holding the source data used for instantiating the import reader
      processor - processor which will be set when instantiating the import reader
      Returns:
      ImpExImportReader import reader used by Importer
    • createImporter

      protected Importer createImporter(ImpExImportCronJob cronJob, ImpExImportReader reader)
      Creates the importer instance. This object performs the import item by item.
      Parameters:
      cronJob - current cronjob instance to get parameters for instantiation
      reader - import reader used for instantiating the importer
      Returns:
      created importer instance
    • adjustCSVReader

      protected CSVReader adjustCSVReader(CSVReader reader, ImpExImportCronJob cronJob)
      Adjusts the CSV reader to the cronjob specific requirements.
      Parameters:
      reader - reader instance to configure
      cronJob - cronjob instance to get further parameters
      Returns:
      adjusted reader
    • adjustImportProcessor

      protected ImportProcessor adjustImportProcessor(ImportProcessor processor, ImpExImportCronJob cronJob)
      Adjusts the processor to the cronjob specific requirements.
      Parameters:
      processor - processor instance to configure
      cronJob - cronjob instance to get further parameters
      Returns:
      adjusted processor
    • adjustImportReader

      protected ImpExImportReader adjustImportReader(ImpExImportReader reader, ImpExImportCronJob cronJob)
      Adjusts the import reader to the cronjob specific requirements.
      Parameters:
      reader - instance to configure
      cronJob - cronjob instance to get further parameters
      Returns:
      adjusted reader
    • adjustImporter

      protected Importer adjustImporter(Importer importer, ImpExImportCronJob cronJob)
      Adjusts the importer to the cronjob specific requirements.
      Parameters:
      importer - instance to configure
      cronJob - cronjob instance to get further parameters
      Returns:
      adjusted importer
    • prepareLocale

      protected Locale prepareLocale(ImpExImportCronJob cronJob)
      Gets the locale setting from the given cronjob and converts it to a real Locale object.
      Parameters:
      cronJob - cronjob holding the locale string
      Returns:
      locale string converted to Locale instance
    • prepareMedia

      protected ImpExMedia prepareMedia(ImpExImportCronJob cronJob) throws ImpExException
      Gets the media used as source data. Internally this method creates a work media (see GeneratedImpExImportCronJob.getWorkMedia()) and copies all data from actual impex media.
      Parameters:
      cronJob - the cronjob holding all settings
      Returns:
      media containing source data
      Throws:
      ImpExException - error while accessing data of medias
    • saveStats

      protected void saveStats(ImpExImportCronJob cronJob, Importer importer)
      Saves important statistics for error resolving.
      Parameters:
      cronJob - cronjob instance for getting further parameters
      importer - importer instance which has performed the import
    • abort

      protected void abort(CronJob cronJob) throws AbortCronJobException
      Aborts the job by throwing an exception.
      Parameters:
      cronJob - cronjob instance for getting further parameters
      Throws:
      AbortCronJobException - exception indicating the abort
    • getMaxThreads4Run

      protected int getMaxThreads4Run(ImpExImportCronJob cronjob)
    • setMaxThreads

      public void setMaxThreads(SessionContext ctx, Integer integer)
      Description copied from class: GeneratedImpExImportJob
      Generated method - Setter of the ImpExImportJob.maxThreads attribute.
      Overrides:
      setMaxThreads in class GeneratedImpExImportJob
      integer - the maxThreads
    • getMaxThreads

      public Integer getMaxThreads(SessionContext ctx)
      Description copied from class: GeneratedImpExImportJob
      Generated method - Getter of the ImpExImportJob.maxThreads attribute.
      Overrides:
      getMaxThreads in class GeneratedImpExImportJob
      Returns:
      the maxThreads
    • getDefaultMaxThreads

      public static int getDefaultMaxThreads(Tenant tenant)