Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/main/java/org/apache/ibatis/builder/BaseBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,15 @@ protected <T> Class<? extends T> resolveClass(String alias) {

@Deprecated(since = "3.6.0", forRemoval = true)
protected TypeHandler<?> resolveTypeHandler(Class<?> javaType, String typeHandlerAlias) {
return resolveTypeHandler(null, javaType, null, typeHandlerAlias);
return resolveTypeHandler(javaType, null, typeHandlerAlias);
}

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

protected TypeHandler<?> resolveTypeHandler(Class<?> parameterType, Type propertyType, JdbcType jdbcType,
String typeHandlerAlias) {
protected TypeHandler<?> resolveTypeHandler(Type propertyType, JdbcType jdbcType, String typeHandlerAlias) {
Class<? extends TypeHandler<?>> typeHandlerType = null;
typeHandlerType = resolveClass(typeHandlerAlias);
if (typeHandlerType != null && !TypeHandler.class.isAssignableFrom(typeHandlerType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ private ParameterMapping buildParameterMapping(String content) {
if (genericType == null) {
genericType = javaType;
}
if ((typeHandler == null || typeHandlerAlias != null) && genericType != null && genericType != Object.class) {
typeHandler = resolveTypeHandler(parameterType, genericType, jdbcType, typeHandlerAlias);
if (typeHandler == null || typeHandlerAlias != null) {
typeHandler = resolveTypeHandler(genericType, jdbcType, typeHandlerAlias);
}
builder.typeHandler(typeHandler);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void resolveTypeHandlerTypeHandlerAliasIsNull() {
{
}
};
TypeHandler<?> typeHandler = builder.resolveTypeHandler(String.class, null, null, (String) null);
TypeHandler<?> typeHandler = builder.resolveTypeHandler(null, null, (String) null);
assertThat(typeHandler).isNull();
}

Expand All @@ -163,7 +163,7 @@ void resolveTypeHandlerNoAssignable() {
{
}
};
when(() -> builder.resolveTypeHandler(String.class, null, null, "integer"));
when(() -> builder.resolveTypeHandler(null, null, "integer"));
then(caughtException()).isInstanceOf(BuilderException.class).hasMessage(
"Type java.lang.Integer is not a valid TypeHandler because it does not implement TypeHandler interface");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private ParameterMapping buildParameterMapping(String content) {
}
}
if (typeHandlerAlias != null) {
builder.typeHandler(resolveTypeHandler(javaType, propertyType, jdbcType, typeHandlerAlias));
builder.typeHandler(resolveTypeHandler(propertyType, jdbcType, typeHandlerAlias));
}
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ void specifyHandlerInXmlParameterWithoutParameterType() {
// There is no way to obtain info about type parameters.
assertThatExceptionOfType(PersistenceException.class).isThrownBy(() -> sqlSession.insert(
"org.apache.ibatis.submitted.typebasedtypehandlerresolution.LocallySpecifiedHandlerMapper.insertXmlWithoutParameterType",
user)).withMessageContaining("FuzzyBean cannot be cast to class java.lang.String");
user)).withMessageContaining("Unknown rawType : class java.lang.Object");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2022 the original author or authors.
* Copyright 2009-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,12 +15,17 @@
*/
package org.apache.ibatis.submitted.uuid_test;

import java.util.Map;
import java.util.UUID;

import org.apache.ibatis.annotations.Insert;

public interface Mapper {

User getUser(UUID id);

void insertUser(User user);

@Insert("${sql}")
int insertDynamicUser(String sql, Map<String, Object> parameters);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2024 the original author or authors.
* Copyright 2009-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@
package org.apache.ibatis.submitted.uuid_test;

import java.io.Reader;
import java.util.Map;
import java.util.UUID;

import org.apache.ibatis.BaseDataTest;
Expand Down Expand Up @@ -64,4 +65,18 @@ void shouldInsertAUser() {
}
}

@Test
void shouldInsertAUserFullyDynamic() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
Mapper mapper = sqlSession.getMapper(Mapper.class);
Map<String, Object> parameters = Map.of("p1", UUID.randomUUID(), "p2", "User3");
String sql = "insert into users values("
+ "#{parameters.p1,typeHandler=org.apache.ibatis.submitted.uuid_test.UUIDTypeHandler}, "
+ "#{parameters.p2})";

int rows = mapper.insertDynamicUser(sql, parameters);
Assertions.assertEquals(1, rows);
}
}

}