Skip to content

Commit d460df9

Browse files
authored
Merge pull request #3563 from jeffgbutler/type-handler-failure
Failing test for Type Handler Parsing
2 parents 9a604b3 + 164a96c commit d460df9

File tree

7 files changed

+30
-11
lines changed

7 files changed

+30
-11
lines changed

src/main/java/org/apache/ibatis/builder/BaseBuilder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,15 @@ protected <T> Class<? extends T> resolveClass(String alias) {
107107

108108
@Deprecated(since = "3.6.0", forRemoval = true)
109109
protected TypeHandler<?> resolveTypeHandler(Class<?> javaType, String typeHandlerAlias) {
110-
return resolveTypeHandler(null, javaType, null, typeHandlerAlias);
110+
return resolveTypeHandler(javaType, null, typeHandlerAlias);
111111
}
112112

113113
@Deprecated(since = "3.6.0", forRemoval = true)
114114
protected TypeHandler<?> resolveTypeHandler(Class<?> javaType, Class<? extends TypeHandler<?>> typeHandlerType) {
115115
return resolveTypeHandler(javaType, null, typeHandlerType);
116116
}
117117

118-
protected TypeHandler<?> resolveTypeHandler(Class<?> parameterType, Type propertyType, JdbcType jdbcType,
119-
String typeHandlerAlias) {
118+
protected TypeHandler<?> resolveTypeHandler(Type propertyType, JdbcType jdbcType, String typeHandlerAlias) {
120119
Class<? extends TypeHandler<?>> typeHandlerType = null;
121120
typeHandlerType = resolveClass(typeHandlerAlias);
122121
if (typeHandlerType != null && !TypeHandler.class.isAssignableFrom(typeHandlerType)) {

src/main/java/org/apache/ibatis/builder/ParameterMappingTokenHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ private ParameterMapping buildParameterMapping(String content) {
9595
if (genericType == null) {
9696
genericType = javaType;
9797
}
98-
if ((typeHandler == null || typeHandlerAlias != null) && genericType != null && genericType != Object.class) {
99-
typeHandler = resolveTypeHandler(parameterType, genericType, jdbcType, typeHandlerAlias);
98+
if (typeHandler == null || typeHandlerAlias != null) {
99+
typeHandler = resolveTypeHandler(genericType, jdbcType, typeHandlerAlias);
100100
}
101101
builder.typeHandler(typeHandler);
102102

src/test/java/org/apache/ibatis/builder/XmlMapperBuilderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void resolveTypeHandlerTypeHandlerAliasIsNull() {
153153
{
154154
}
155155
};
156-
TypeHandler<?> typeHandler = builder.resolveTypeHandler(String.class, null, null, (String) null);
156+
TypeHandler<?> typeHandler = builder.resolveTypeHandler(null, null, (String) null);
157157
assertThat(typeHandler).isNull();
158158
}
159159

@@ -163,7 +163,7 @@ void resolveTypeHandlerNoAssignable() {
163163
{
164164
}
165165
};
166-
when(() -> builder.resolveTypeHandler(String.class, null, null, "integer"));
166+
when(() -> builder.resolveTypeHandler(null, null, "integer"));
167167
then(caughtException()).isInstanceOf(BuilderException.class).hasMessage(
168168
"Type java.lang.Integer is not a valid TypeHandler because it does not implement TypeHandler interface");
169169
}

src/test/java/org/apache/ibatis/submitted/language/VelocitySqlSourceBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private ParameterMapping buildParameterMapping(String content) {
134134
}
135135
}
136136
if (typeHandlerAlias != null) {
137-
builder.typeHandler(resolveTypeHandler(javaType, propertyType, jdbcType, typeHandlerAlias));
137+
builder.typeHandler(resolveTypeHandler(propertyType, jdbcType, typeHandlerAlias));
138138
}
139139
return builder.build();
140140
}

src/test/java/org/apache/ibatis/submitted/typebasedtypehandlerresolution/LocallySpecifiedTypeHandlerResolutionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ void specifyHandlerInXmlParameterWithoutParameterType() {
309309
// There is no way to obtain info about type parameters.
310310
assertThatExceptionOfType(PersistenceException.class).isThrownBy(() -> sqlSession.insert(
311311
"org.apache.ibatis.submitted.typebasedtypehandlerresolution.LocallySpecifiedHandlerMapper.insertXmlWithoutParameterType",
312-
user)).withMessageContaining("FuzzyBean cannot be cast to class java.lang.String");
312+
user)).withMessageContaining("Unknown rawType : class java.lang.Object");
313313
}
314314
}
315315
}

src/test/java/org/apache/ibatis/submitted/uuid_test/Mapper.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2022 the original author or authors.
2+
* Copyright 2009-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,12 +15,17 @@
1515
*/
1616
package org.apache.ibatis.submitted.uuid_test;
1717

18+
import java.util.Map;
1819
import java.util.UUID;
1920

21+
import org.apache.ibatis.annotations.Insert;
22+
2023
public interface Mapper {
2124

2225
User getUser(UUID id);
2326

2427
void insertUser(User user);
2528

29+
@Insert("${sql}")
30+
int insertDynamicUser(String sql, Map<String, Object> parameters);
2631
}

src/test/java/org/apache/ibatis/submitted/uuid_test/UUIDTest.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2024 the original author or authors.
2+
* Copyright 2009-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616
package org.apache.ibatis.submitted.uuid_test;
1717

1818
import java.io.Reader;
19+
import java.util.Map;
1920
import java.util.UUID;
2021

2122
import org.apache.ibatis.BaseDataTest;
@@ -64,4 +65,18 @@ void shouldInsertAUser() {
6465
}
6566
}
6667

68+
@Test
69+
void shouldInsertAUserFullyDynamic() {
70+
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
71+
Mapper mapper = sqlSession.getMapper(Mapper.class);
72+
Map<String, Object> parameters = Map.of("p1", UUID.randomUUID(), "p2", "User3");
73+
String sql = "insert into users values("
74+
+ "#{parameters.p1,typeHandler=org.apache.ibatis.submitted.uuid_test.UUIDTypeHandler}, "
75+
+ "#{parameters.p2})";
76+
77+
int rows = mapper.insertDynamicUser(sql, parameters);
78+
Assertions.assertEquals(1, rows);
79+
}
80+
}
81+
6782
}

0 commit comments

Comments
 (0)