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 thePersistTask
Y
- return type of thePersistTask
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionCreate a function that creates an instance of Z.protected Z
getTaskData
(Context context) Get or create the task data for the given context.partition
(int size) Creates aPersistTaskIterable
which uses a different context after every 'size' iterations.<I,
O> PersistTaskIterable <Iterable<I>, O> partition
(BiFunction<Iterable<I>, PersistenceService, Iterable<X>> inputConverter, Function<Iterable<Y>, Iterable<O>> outputConverter, int size) Creates aPersistTaskIterable
which uses a different context after every 'size' iterations.<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 aPersistTaskIterable
which uses a different context after every 'size' iterations.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface ch.tocco.nice2.persist.core.api.exec.PersistTask
andThenDo, compose, compose2, composeWhen, discardResult, expand, expand, getDescription, ifElse, orWhen, orWhenNot, passWhen, passWhenNot, run, skipErrors, unwrap
-
Constructor Details
-
AbstractPartitionedPersistTask
public AbstractPartitionedPersistTask()
-
-
Method Details
-
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 otherContext
related objects) which are used in every iteration. -
getTaskData
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 aPersistTaskIterable
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 aPersistTaskIterable
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 contexttransactional
- whether the task should run in a transaction that will be committed before each context is closed- See Also:
-
partition
Creates aPersistTaskIterable
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:
-