Skip to content

Commit

Permalink
fix: when property mapping is not configured, value-to-key mapping is…
Browse files Browse the repository at this point in the history
… used by default (GitHub #190)
  • Loading branch information
Createsequence committed Jan 17, 2024
1 parent 184e213 commit 988a64e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public Cache<Object, Object> getCache(Long expireTime, TimeUnit timeUnit) {
* @author huangchengxing
* @since 2.4.0
*/
private static class GuavaCacheObject<K> extends AbstractCacheObject<K> {
protected static class GuavaCacheObject<K> extends AbstractCacheObject<K> {

private final Cache<Object, Object> cache;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected <K> MapCacheObject<K> doCreateCache(String name, Long expireTime, Time
* @author huangchengxing
* @since 2.4.0
*/
private static class MapCacheObject<K> extends AbstractCacheObject<K> {
protected static class MapCacheObject<K> extends AbstractCacheObject<K> {

private final Map<K, Object> map;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;

/**
Expand All @@ -27,18 +27,18 @@ public class AsyncBeanOperationExecutor extends DisorderedBeanOperationExecutor
/**
* thread pool used to perform operations.
*/
private final ExecutorService executorService;
private final Executor executor;

/**
* Create an instance of {@link AsyncBeanOperationExecutor}.
*
* @param containerManager container manager
* @param executorService thread pool used to perform operations
* @param executor thread pool used to perform operations
*/
public AsyncBeanOperationExecutor(
ContainerManager containerManager, ExecutorService executorService) {
ContainerManager containerManager, Executor executor) {
super(containerManager);
this.executorService = executorService;
this.executor = executor;
}

/**
Expand All @@ -65,7 +65,7 @@ public AsyncBeanOperationExecutor(
protected void executeOperations(List<AssembleExecution> executions, Options options) throws OperationExecuteException {
CompletableFuture<Void>[] tasks = executions.stream()
.map(execution -> (Runnable)() -> doExecuteOperations(execution))
.map(task -> CompletableFuture.runAsync(task, executorService))
.map(task -> CompletableFuture.runAsync(task, executor))
.toArray(CompletableFuture[]::new);
try {
CompletableFuture.allOf(tasks).join();
Expand All @@ -90,7 +90,7 @@ protected void doExecuteOperations(Map<Container<?>, Map<AssembleOperationHandle
executionGroups.forEach((c, he) ->
he.forEach((h, es) -> tasks.add(() -> h.process(c, es))));
tasks.stream()
.map(t -> CompletableFuture.runAsync(t, executorService))
.map(t -> CompletableFuture.runAsync(t, executor))
.collect(Collectors.collectingAndThen(
Collectors.toList(), ts -> CompletableFuture.allOf(ts.toArray(new CompletableFuture[0]))
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import cn.crane4j.core.parser.BeanOperationParser;
import cn.crane4j.core.parser.BeanOperations;
import cn.crane4j.core.parser.PropertyMapping;
import cn.crane4j.core.parser.SimplePropertyMapping;
import cn.crane4j.core.parser.handler.strategy.OverwriteNotNullMappingStrategy;
import cn.crane4j.core.parser.handler.strategy.PropertyMappingStrategy;
import cn.crane4j.core.parser.handler.strategy.PropertyMappingStrategyManager;
Expand Down Expand Up @@ -35,6 +36,7 @@
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
import java.util.Comparator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -180,6 +182,11 @@ protected AssembleOperation createAssembleOperation(
Class<?> keyType = parseKeyType(standardAnnotation, annotation);
AssembleOperationHandler assembleOperationHandler = parseAssembleOperationHandler(element, standardAnnotation);
Set<PropertyMapping> propertyMappings = parsePropertyMappings(element, standardAnnotation, key);
// fix https://github.com/opengoofy/crane4j/issues/190
// if no property mapping is specified, the default property mapping is the key itself
propertyMappings = propertyMappings.isEmpty() ?
CollectionUtils.newCollection(LinkedHashSet::new, new SimplePropertyMapping("", key)) : propertyMappings;

int sort = parseSort(element, standardAnnotation);
Set<String> groups = parseGroups(element, standardAnnotation);
PropertyMappingStrategy propertyMappingStrategy = parserPropertyMappingStrategy(standardAnnotation, annotation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
@Slf4j
public class DefaultMethodContainerFactory implements MethodContainerFactory {

public static final int ORDER = Integer.MAX_VALUE;
protected final MethodInvokerContainerCreator methodInvokerContainerCreator;
protected final AnnotationFinder annotationFinder;

Expand Down Expand Up @@ -82,10 +81,9 @@ public List<Container<Object>> get(
}

private Container<Object> createContainer(Object source, Method method, ContainerMethod annotation) {
MethodInvokerContainer container = methodInvokerContainerCreator.createContainer(
return methodInvokerContainerCreator.createContainer(
source, method, annotation.type(), annotation.namespace(),
annotation.resultType(), annotation.resultKey(), annotation.duplicateStrategy()
);
return container;
}
}

0 comments on commit 988a64e

Please sign in to comment.