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 thePartitionedTask
O
- return type of thePartitionedTask
X
- 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
ConstructorDescriptionPartitionedTask
(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 anEntity
to 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 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, skipErrors, unwrap
Methods inherited from interface ch.tocco.nice2.persist.core.api.exec.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
@Nullable public @Nullable Iterable<O> run(Optional<Iterable<I>> args, CommandContext commandContext) throws Exception - Specified by:
run
in interfacePersistTask<I,
O> - Throws:
Exception
-
entityToPrimaryKey
Converts anEntity
to aPrimaryKey
. -
entityToEntityId
-
entityToSimpleEntityId
-
emptyFunction
Does not do anything - can be used for parameters that are independent of theContext
. -
emptyBiFunction
public static <T> BiFunction<Iterable<T>,PersistenceService, emptyBiFunctionIterable<T>> (Class<T> clazz) Does not do anything - can be used for parameters that are independent of theContext
. -
loadEntities
public static BiFunction<Iterable<PrimaryKey>,PersistenceService, loadEntitiesIterable<Entity>> (String entityModel) Loads entities based on a list of private keys. -
loadEntities
public static BiFunction<Iterable<PrimaryKey>,PersistenceService, loadEntitiesIterable<Entity>> (EntityModel entityModel, boolean keepOrder) -
loadEntities
-