Skip to content

Commit

Permalink
Merge pull request #3252 from mawen12/optimize-mapper-builder
Browse files Browse the repository at this point in the history
optimize mapper builder
  • Loading branch information
hazendaz authored Dec 28, 2024
2 parents a943a1b + 85bd9ba commit 1a02824
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private ResultMap resultMapElement(XNode resultMapNode, List<ResultMapping> addi
resultMappings.add(buildResultMappingFromContext(resultChild, typeClass, flags));
}
}
String id = resultMapNode.getStringAttribute("id", resultMapNode.getValueBasedIdentifier());
String id = resultMapNode.getStringAttribute("id", resultMapNode::getValueBasedIdentifier);
String extend = resultMapNode.getStringAttribute("extends");
Boolean autoMapping = resultMapNode.getBooleanAttribute("autoMapping");
ResultMapResolver resultMapResolver = new ResultMapResolver(builderAssistant, id, typeClass, extend, discriminator,
Expand Down Expand Up @@ -289,8 +289,7 @@ private Discriminator processDiscriminatorElement(XNode context, Class<?> result
Map<String, String> discriminatorMap = new HashMap<>();
for (XNode caseChild : context.getChildren()) {
String value = caseChild.getStringAttribute("value");
String resultMap = caseChild.getStringAttribute("resultMap",
processNestedResultMappings(caseChild, resultMappings, resultType));
String resultMap = caseChild.getStringAttribute("resultMap", () -> processNestedResultMappings(caseChild, resultMappings, resultType));
discriminatorMap.put(value, resultMap);
}
return builderAssistant.buildDiscriminator(resultType, column, javaTypeClass, jdbcTypeEnum, typeHandlerClass,
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/org/apache/ibatis/type/TypeAliasRegistryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.apache.ibatis.type;

import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -75,4 +76,21 @@ void shouldFetchCharType() {
assertEquals(char[].class, typeAliasRegistry.resolveAlias("_char[]"));
}

@Test
void shouldNotBeAbleToRegisterAliasWithEmptyString() {
TypeAliasRegistry typeAliasRegistry = new TypeAliasRegistry();

assertThatThrownBy(() -> typeAliasRegistry.registerAlias("foo", ""))
.isInstanceOf(TypeException.class)
.hasMessageContaining("Error registering type alias foo for");
}

@Test
void shouldNotBeAbleToResolveNotExistsAlias() {
TypeAliasRegistry typeAliasRegistry = new TypeAliasRegistry();

assertThatThrownBy(() -> typeAliasRegistry.resolveAlias("abc"))
.isInstanceOf(TypeException.class)
.hasMessageContaining("Could not resolve type alias 'abc'. Cause: java.lang.ClassNotFoundException: Cannot find class: abc");
}
}

0 comments on commit 1a02824

Please sign in to comment.