|
3 | 3 | import pl.wavesoftware.lang.TriConsumer; |
4 | 4 |
|
5 | 5 | /** |
6 | | - * @author <a href="krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszyński</a> |
| 6 | + * An abstract class that can be extended to provide logic in how to apply data from |
| 7 | + * {@link I} input object to an target {@link O} output object. It uses {@link CompositeContext} |
| 8 | + * as a MapStruct context. |
| 9 | + * |
| 10 | + * <p> |
| 11 | + * It's designed to be used easily with |
| 12 | + * <a href="http://mapstruct.org/documentation/stable/reference/html/#updating-bean-instances"> |
| 13 | + * MapStruct update methods</a>. |
| 14 | + * <pre> |
| 15 | + * @Service |
| 16 | + * @RequiredArgsConstructor |
| 17 | + * final class PetCompositeContextMapping extends AbstractCompositeContextMapping<Pet,PetData> { |
| 18 | + * private final PetMapper petMapper; |
| 19 | + * @Override |
| 20 | + * public void accept(Pet pet, PetData data, CompositeContext context) { |
| 21 | + * petMapper.updateFromPet(pet, data, context); |
| 22 | + * } |
| 23 | + * } |
| 24 | + * </pre> |
| 25 | + * |
| 26 | + * There is also a convenience method {@link #mappingFor(Class, Class, TriConsumer)} which can be |
| 27 | + * used to create mapping easily with {@link AbstractJpaContextProvider}: |
| 28 | + * |
| 29 | + * <br> |
| 30 | + * <pre> |
| 31 | + * @RequiredArgsConstructor |
| 32 | + * final class OwnerMappingProvider implements MappingProvider<Owner, OwnerJPA, CompositeContext> { |
| 33 | + * private final OwnerMapper ownerMapper; |
| 34 | + * |
| 35 | + * @Override |
| 36 | + * public Mapping<Owner, OwnerJPA, CompositeContext> provide() { |
| 37 | + * return AbstractCompositeContextMapping.mappingFor( |
| 38 | + * Owner.class, OwnerJPA.class, |
| 39 | + * ownerMapper::updateFromOwner |
| 40 | + * ); |
| 41 | + * } |
| 42 | + * } |
| 43 | + * </pre> |
| 44 | + * |
| 45 | + * @param <I> a type of input object to map from |
| 46 | + * @param <O> a type of output object to map to |
| 47 | + * @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszyński</a> |
7 | 48 | * @since 2018-05-02 |
8 | 49 | */ |
9 | | -public abstract class AbstractCompositeContextMapping<I, O> extends AbstractMapping<I, O, CompositeContext> { |
| 50 | +public abstract class AbstractCompositeContextMapping<I, O> |
| 51 | + extends AbstractMapping<I, O, CompositeContext> { |
| 52 | + |
10 | 53 | protected AbstractCompositeContextMapping(Class<I> sourceClass, |
11 | 54 | Class<O> targetClass) { |
12 | 55 | super(sourceClass, targetClass, CompositeContext.class); |
13 | 56 | } |
14 | 57 |
|
15 | | - public static <I, O> AbstractCompositeContextMapping<I, O> mapperFor( |
| 58 | + /** |
| 59 | + * A convenience method which can be used to create mapping easily with |
| 60 | + * {@link AbstractJpaContextProvider}. |
| 61 | + * |
| 62 | + * @param inputClass a class of an input object |
| 63 | + * @param outputClass a class of an output object |
| 64 | + * @param consumer a consumer of 3 values: input object, output object |
| 65 | + * and {@link CompositeContext} object |
| 66 | + * @param <I> a type of input object to map from |
| 67 | + * @param <O> a type of output object to map to |
| 68 | + * @return a mapping for given values |
| 69 | + */ |
| 70 | + public static <I, O> Mapping<I, O, CompositeContext> mappingFor( |
16 | 71 | Class<I> inputClass, |
17 | 72 | Class<O> outputClass, |
18 | 73 | TriConsumer<I, O, CompositeContext> consumer) { |
|
0 commit comments