Class AbstractPartitionedPersistTask<X,Y,Z>

java.lang.Object
ch.tocco.nice2.persist.core.api.exec.AbstractPartitionedPersistTask<X,Y,Z>
Type Parameters:
X - parameter type of the PersistTask
Y - return type of the PersistTask
Z - type of the 'task data' object
All Implemented Interfaces:
PersistTask<Iterable<X>,Iterable<Y>>
Direct Known Subclasses:
CreateOutputJobItemPersistTask, CreatePrincipalTask, NewLecturerBookingTask, NoTaskDataPartitionedPersistTask, RowImportTask, ZipEntryImportTask, ZipEntryImportTask

public abstract class AbstractPartitionedPersistTask<X,Y,Z> extends Object implements PersistTask<Iterable<X>,Iterable<Y>>
Base class for a 'partitioned' task. This is a task that can be expanded (similar to PersistTask.expand() and then will be executed once for every parameter. To avoid memory issues a new context is created for every 'n' iterations. Keep in mind that Entity instances cannot be shared between different contexts! Entities that are required for each iteration should be retrieved in createTaskData(). This method is called once for each context. This data can then be retrieved using getTaskData(Context).
  • Constructor Details

    • AbstractPartitionedPersistTask

      public AbstractPartitionedPersistTask()
  • Method Details

    • createTaskData

      protected abstract Function<Context,Z> createTaskData()
      Create a function that creates an instance of Z. This function is called once for each context and should be used to load entities (or other Context related objects) which are used in every iteration.
    • getTaskData

      protected Z getTaskData(Context context)
      Get or create the task data for the given context.
    • partition

      public <I, O> PersistTaskIterable<Iterable<I>,O> partition(BiFunction<Iterable<I>,PersistenceService,Iterable<X>> inputConverter, Function<Iterable<Y>,Iterable<O>> outputConverter, int size)
      Creates a PersistTaskIterable which uses a different context after every 'size' iterations. Input and output converter functions can be passed to this methods, which can be used to convert the parameters for the new context (for example conversion between PrimaryKey and Entity instances).
      Parameters:
      size - the number of iterations to execute before committing the transaction and creating a new context
      See Also:
    • partition

      public <I, O> PersistTaskIterable<Iterable<I>,O> partition(BiFunction<Iterable<I>,PersistenceService,Iterable<X>> inputConverter, Function<Iterable<Y>,Iterable<O>> outputConverter, int size, boolean transactional)
      Creates a PersistTaskIterable which uses a different context after every 'size' iterations. Input and output converter functions can be passed to this methods, which can be used to convert the parameters for the new context (for example conversion between PrimaryKey and Entity instances).
      Parameters:
      size - the number of iterations to execute before creating a new context
      transactional - whether the task should run in a transaction that will be committed before each context is closed
      See Also:
    • partition

      public PersistTaskIterable<Iterable<X>,Y> partition(int size)
      Creates a PersistTaskIterable which uses a different context after every 'size' iterations.
      Parameters:
      size - the number of iterations to execute before committing the transaction and creating a new context
      See Also: