|
15 | 15 | */
|
16 | 16 | package org.apache.ibatis.builder;
|
17 | 17 |
|
18 |
| -import java.lang.reflect.Constructor; |
19 | 18 | import java.sql.ResultSet;
|
20 | 19 | import java.util.ArrayList;
|
21 |
| -import java.util.Arrays; |
22 | 20 | import java.util.Collections;
|
23 | 21 | import java.util.HashMap;
|
24 | 22 | import java.util.HashSet;
|
|
27 | 25 | import java.util.Properties;
|
28 | 26 | import java.util.Set;
|
29 | 27 | import java.util.StringTokenizer;
|
30 |
| -import java.util.stream.Collectors; |
31 | 28 |
|
32 | 29 | import org.apache.ibatis.cache.Cache;
|
33 | 30 | import org.apache.ibatis.cache.decorators.LruCache;
|
@@ -469,75 +466,4 @@ private Class<?> resolveParameterJavaType(Class<?> resultType, String property,
|
469 | 466 | }
|
470 | 467 | return javaType;
|
471 | 468 | }
|
472 |
| - |
473 |
| - /** |
474 |
| - * Attempts to assign a {@code javaType} to result mappings when it has been omitted, this is done based on matching |
475 |
| - * constructors of the specified {@code resultType} |
476 |
| - * |
477 |
| - * @param resultType |
478 |
| - * the result type of the object to be built |
479 |
| - * @param resultMappings |
480 |
| - * the current mappings |
481 |
| - * |
482 |
| - * @return null if there are no missing javaType mappings, or if no suitable mapping could be determined |
483 |
| - * |
484 |
| - * @see <a href="https://github.com/mybatis/mybatis-3/issues/2618">#2618</a> |
485 |
| - */ |
486 |
| - public List<ResultMapping> autoTypeResultMappingsForUnknownJavaTypes(Class<?> resultType, |
487 |
| - List<ResultMapping> resultMappings) { |
488 |
| - final List<Class<?>> typesToMatch = resultMappings.stream().map(ResultMapping::getJavaType) |
489 |
| - .collect(Collectors.toList()); |
490 |
| - |
491 |
| - // check if we have any undefined java types present, and try to set them automatically |
492 |
| - if (typesToMatch.stream().noneMatch(type -> type == null || Object.class.equals(type))) { |
493 |
| - return null; |
494 |
| - } |
495 |
| - |
496 |
| - final List<List<Class<?>>> matchingConstructors = Arrays.stream(resultType.getDeclaredConstructors()) |
497 |
| - .map(Constructor::getParameterTypes).filter(parameters -> parameters.length == resultMappings.size()) |
498 |
| - .map(Arrays::asList).collect(Collectors.toList()); |
499 |
| - |
500 |
| - List<Class<?>> matchingTypes = null; |
501 |
| - for (List<Class<?>> actualTypes : matchingConstructors) { |
502 |
| - boolean matchesType = true; |
503 |
| - for (int j = 0; j < typesToMatch.size(); j++) { |
504 |
| - final Class<?> type = typesToMatch.get(j); |
505 |
| - |
506 |
| - // pre-filled a type, check if it matches the constructor |
507 |
| - if (type != null && !Object.class.equals(type) && !type.equals(actualTypes.get(j))) { |
508 |
| - matchesType = false; |
509 |
| - break; |
510 |
| - } |
511 |
| - } |
512 |
| - |
513 |
| - if (!matchesType) { |
514 |
| - continue; |
515 |
| - } |
516 |
| - |
517 |
| - if (matchingTypes != null) { |
518 |
| - // multiple matches found, abort as we cannot reliably guess the correct one. |
519 |
| - matchingTypes = null; |
520 |
| - break; |
521 |
| - } |
522 |
| - |
523 |
| - matchingTypes = actualTypes; |
524 |
| - } |
525 |
| - |
526 |
| - if (matchingTypes == null) { |
527 |
| - return null; |
528 |
| - } |
529 |
| - |
530 |
| - final List<ResultMapping> adjustedAutoTypeResultMappings = new ArrayList<>(); |
531 |
| - for (int i = 0; i < resultMappings.size(); i++) { |
532 |
| - ResultMapping otherMapping = resultMappings.get(i); |
533 |
| - Class<?> identifiedMatchingJavaType = matchingTypes.get(i); |
534 |
| - |
535 |
| - // given that we selected a new java type, overwrite the currently |
536 |
| - // selected type handler so it can get retrieved again from the registry |
537 |
| - adjustedAutoTypeResultMappings |
538 |
| - .add(new ResultMapping.Builder(otherMapping).javaType(identifiedMatchingJavaType).typeHandler(null).build()); |
539 |
| - } |
540 |
| - |
541 |
| - return adjustedAutoTypeResultMappings; |
542 |
| - } |
543 | 469 | }
|
0 commit comments