Class PartitionedTask<I,O,X,Y>
java.lang.Object
ch.tocco.nice2.persist.core.api.exec.PartitionedTask<I,O,X,Y>
- Type Parameters:
I- parameter type of thePartitionedTaskO- return type of thePartitionedTaskX- parameter type of the nested taskY- return type of the nested task
- All Implemented Interfaces:
PersistTask<Iterable<I>, Iterable<O>>, PersistTaskIterable<Iterable<I>, O>
A
PersistTaskIterable that takes an Iterable of parameters.
The nested task is executed once for each partition (and given an Iterable of parameters).
For each partition a new context (and transaction) is created to limit
the size of the context.
As Entity instances can only be used with the Context they are associated to, they
should typically not be used as parameter or return types of the outer PersistTaskIterable (I, O)
(use PrimaryKey or EntityId instead!). In addition this would defeat the purpose of
using multiple contexts to save memory.
The inner task can use Entity as parameter or return type though. A converter function that has to be
passed to the constructor will convert the parameters and return values of the outer task to inner task and vice versa.
(see entityToPrimaryKey() for example).-
Constructor Summary
ConstructorsConstructorDescriptionPartitionedTask(AbstractPartitionedPersistTask<X, Y, ?> task, BiFunction<Iterable<I>, PersistenceService, Iterable<X>> inputConverter, Function<Iterable<Y>, Iterable<O>> outputConverter, int batchSize, boolean transactional) -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> BiFunction<Iterable<T>, PersistenceService, Iterable<T>> emptyBiFunction(Class<T> clazz) Does not do anything - can be used for parameters that are independent of theContext.emptyFunction(Class<T> clazz) Does not do anything - can be used for parameters that are independent of theContext.static Function<Iterable<Entity>, Iterable<PrimaryKey>> Converts anEntityto aPrimaryKey.static Function<Iterable<Entity>, Iterable<SimpleEntityId>> static BiFunction<Iterable<EntityId>, PersistenceService, Iterable<Entity>> static BiFunction<Iterable<PrimaryKey>, PersistenceService, Iterable<Entity>> loadEntities(EntityModel entityModel, boolean keepOrder) static BiFunction<Iterable<PrimaryKey>, PersistenceService, Iterable<Entity>> loadEntities(String entityModel) Loads entities based on a list of private keys.run(Optional<Iterable<I>> args, CommandContext commandContext) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface PersistTask
andThenDo, compose, compose2, composeWhen, discardResult, expand, expand, getDescription, ifElse, orWhen, orWhenNot, passWhen, passWhenNot, skipErrors, unwrapMethods inherited from interface PersistTaskIterable
filter, find, flatMap, forEach, get, get, get, getOnlyElement, getOnlyElement, getOnlyElement, map
-
Constructor Details
-
PartitionedTask
public PartitionedTask(AbstractPartitionedPersistTask<X, Y, ?> task, BiFunction<Iterable<I>, PersistenceService, Iterable<X>> inputConverter, Function<Iterable<Y>, Iterable<O>> outputConverter, int batchSize, boolean transactional)
-
-
Method Details
-
run
-
entityToPrimaryKey
Converts anEntityto aPrimaryKey. -
entityToEntityId
-
entityToSimpleEntityId
-
emptyFunction
-
emptyBiFunction
public static <T> BiFunction<Iterable<T>, PersistenceService, Iterable<T>> emptyBiFunction(Class<T> clazz) Does not do anything - can be used for parameters that are independent of theContext. -
loadEntities
public static BiFunction<Iterable<PrimaryKey>, PersistenceService, Iterable<Entity>> loadEntities(String entityModel) Loads entities based on a list of private keys. -
loadEntities
public static BiFunction<Iterable<PrimaryKey>, PersistenceService, Iterable<Entity>> loadEntities(EntityModel entityModel, boolean keepOrder) -
loadEntities
-