|
16 | 16 | package org.mybatis.spring.boot.autoconfigure;
|
17 | 17 |
|
18 | 18 | import java.math.BigInteger;
|
| 19 | +import java.sql.CallableStatement; |
| 20 | +import java.sql.PreparedStatement; |
| 21 | +import java.sql.ResultSet; |
| 22 | +import java.sql.SQLException; |
19 | 23 | import java.util.Map;
|
20 | 24 | import java.util.Properties;
|
| 25 | +import java.util.UUID; |
21 | 26 |
|
22 | 27 | import javax.sql.DataSource;
|
23 | 28 |
|
|
32 | 37 | import org.apache.ibatis.session.ExecutorType;
|
33 | 38 | import org.apache.ibatis.session.SqlSessionFactory;
|
34 | 39 | import org.apache.ibatis.session.defaults.DefaultSqlSessionFactory;
|
| 40 | +import org.apache.ibatis.type.BaseTypeHandler; |
| 41 | +import org.apache.ibatis.type.JdbcType; |
35 | 42 | import org.apache.ibatis.type.TypeHandlerRegistry;
|
36 | 43 | import org.junit.jupiter.api.AfterEach;
|
37 | 44 | import org.junit.jupiter.api.BeforeEach;
|
@@ -238,6 +245,20 @@ void testWithInterceptors() {
|
238 | 245 | this.context.close();
|
239 | 246 | }
|
240 | 247 |
|
| 248 | + @Test |
| 249 | + void testWithTypeHandlers() { |
| 250 | + this.context.register(EmbeddedDataSourceConfiguration.class, |
| 251 | + MybatisTypeHandlerConfiguration.class, |
| 252 | + MybatisAutoConfiguration.class, |
| 253 | + PropertyPlaceholderAutoConfiguration.class); |
| 254 | + this.context.refresh(); |
| 255 | + assertThat(this.context.getBeanNamesForType(SqlSessionFactory.class)).hasSize(1); |
| 256 | + assertThat(this.context.getBeanNamesForType(SqlSessionTemplate.class)).hasSize(1); |
| 257 | + assertThat(this.context.getBean(SqlSessionFactory.class).getConfiguration().getTypeHandlerRegistry() |
| 258 | + .getTypeHandler(UUID.class)).isInstanceOf(MyTypeHandler.class); |
| 259 | + this.context.close(); |
| 260 | + } |
| 261 | + |
241 | 262 | @Test
|
242 | 263 | void testWithDatabaseIdProvider() {
|
243 | 264 | this.context.register(EmbeddedDataSourceConfiguration.class,
|
@@ -600,6 +621,17 @@ public MyInterceptor myInterceptor() {
|
600 | 621 |
|
601 | 622 | }
|
602 | 623 |
|
| 624 | + @Configuration |
| 625 | + @EnableAutoConfiguration |
| 626 | + static class MybatisTypeHandlerConfiguration { |
| 627 | + |
| 628 | + @Bean |
| 629 | + public MyTypeHandler myTypeHandler() { |
| 630 | + return new MyTypeHandler(); |
| 631 | + } |
| 632 | + |
| 633 | + } |
| 634 | + |
603 | 635 | @Configuration
|
604 | 636 | @EnableAutoConfiguration
|
605 | 637 | static class MybatisPropertiesConfigurationCustomizer {
|
@@ -719,4 +751,28 @@ static class MySqlSessionTemplate extends SqlSessionTemplate {
|
719 | 751 | }
|
720 | 752 | }
|
721 | 753 |
|
| 754 | + static class MyTypeHandler extends BaseTypeHandler<UUID> { |
| 755 | + |
| 756 | + @Override |
| 757 | + public void setNonNullParameter(PreparedStatement ps, int i, UUID parameter, JdbcType jdbcType) throws SQLException { |
| 758 | + |
| 759 | + } |
| 760 | + |
| 761 | + @Override |
| 762 | + public UUID getNullableResult(ResultSet rs, String columnName) throws SQLException { |
| 763 | + return null; |
| 764 | + } |
| 765 | + |
| 766 | + @Override |
| 767 | + public UUID getNullableResult(ResultSet rs, int columnIndex) throws SQLException { |
| 768 | + return null; |
| 769 | + } |
| 770 | + |
| 771 | + @Override |
| 772 | + public UUID getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { |
| 773 | + return null; |
| 774 | + } |
| 775 | + |
| 776 | + } |
| 777 | + |
722 | 778 | }
|
0 commit comments