• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mybatis / mybatis-3 / 3031

11 Nov 2025 09:55AM UTC coverage: 87.38% (-0.009%) from 87.389%
3031

push

github

web-flow
Merge pull request #3563 from jeffgbutler/type-handler-failure

Failing test for Type Handler Parsing

3846 of 4659 branches covered (82.55%)

2 of 3 new or added lines in 2 files covered. (66.67%)

1 existing line in 1 file now uncovered.

9943 of 11379 relevant lines covered (87.38%)

0.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.74
/src/main/java/org/apache/ibatis/builder/BaseBuilder.java
1
/*
2
 *    Copyright 2009-2025 the original author or authors.
3
 *
4
 *    Licensed under the Apache License, Version 2.0 (the "License");
5
 *    you may not use this file except in compliance with the License.
6
 *    You may obtain a copy of the License at
7
 *
8
 *       https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *    Unless required by applicable law or agreed to in writing, software
11
 *    distributed under the License is distributed on an "AS IS" BASIS,
12
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *    See the License for the specific language governing permissions and
14
 *    limitations under the License.
15
 */
16
package org.apache.ibatis.builder;
17

18
import java.lang.reflect.Type;
19
import java.util.Arrays;
20
import java.util.HashSet;
21
import java.util.Set;
22
import java.util.regex.Pattern;
23

24
import org.apache.ibatis.mapping.ParameterMode;
25
import org.apache.ibatis.mapping.ResultSetType;
26
import org.apache.ibatis.session.Configuration;
27
import org.apache.ibatis.type.JdbcType;
28
import org.apache.ibatis.type.TypeAliasRegistry;
29
import org.apache.ibatis.type.TypeHandler;
30
import org.apache.ibatis.type.TypeHandlerRegistry;
31

32
/**
33
 * @author Clinton Begin
34
 */
35
public abstract class BaseBuilder {
36
  protected final Configuration configuration;
37
  protected final TypeAliasRegistry typeAliasRegistry;
38
  protected final TypeHandlerRegistry typeHandlerRegistry;
39

40
  public BaseBuilder(Configuration configuration) {
1✔
41
    this.configuration = configuration;
1✔
42
    this.typeAliasRegistry = this.configuration.getTypeAliasRegistry();
1✔
43
    this.typeHandlerRegistry = this.configuration.getTypeHandlerRegistry();
1✔
44
  }
1✔
45

46
  public Configuration getConfiguration() {
47
    return configuration;
1✔
48
  }
49

50
  protected Pattern parseExpression(String regex, String defaultValue) {
51
    return Pattern.compile(regex == null ? defaultValue : regex);
1✔
52
  }
53

54
  protected Boolean booleanValueOf(String value, Boolean defaultValue) {
55
    return value == null ? defaultValue : Boolean.valueOf(value);
1✔
56
  }
57

58
  protected Integer integerValueOf(String value, Integer defaultValue) {
59
    return value == null ? defaultValue : Integer.valueOf(value);
1✔
60
  }
61

62
  protected Set<String> stringSetValueOf(String value, String defaultValue) {
63
    value = value == null ? defaultValue : value;
1!
64
    return new HashSet<>(Arrays.asList(value.split(",")));
1✔
65
  }
66

67
  protected JdbcType resolveJdbcType(String alias) {
68
    try {
69
      return alias == null ? null : JdbcType.valueOf(alias);
1✔
70
    } catch (IllegalArgumentException e) {
1✔
71
      throw new BuilderException("Error resolving JdbcType. Cause: " + e, e);
1✔
72
    }
73
  }
74

75
  protected ResultSetType resolveResultSetType(String alias) {
76
    try {
77
      return alias == null ? null : ResultSetType.valueOf(alias);
1✔
78
    } catch (IllegalArgumentException e) {
1✔
79
      throw new BuilderException("Error resolving ResultSetType. Cause: " + e, e);
1✔
80
    }
81
  }
82

83
  protected ParameterMode resolveParameterMode(String alias) {
84
    try {
85
      return alias == null ? null : ParameterMode.valueOf(alias);
1✔
86
    } catch (IllegalArgumentException e) {
1✔
87
      throw new BuilderException("Error resolving ParameterMode. Cause: " + e, e);
1✔
88
    }
89
  }
90

91
  protected Object createInstance(String alias) {
92
    Class<?> clazz = resolveClass(alias);
1✔
93
    try {
94
      return clazz == null ? null : clazz.getDeclaredConstructor().newInstance();
1✔
95
    } catch (Exception e) {
1✔
96
      throw new BuilderException("Error creating instance. Cause: " + e, e);
1✔
97
    }
98
  }
99

100
  protected <T> Class<? extends T> resolveClass(String alias) {
101
    try {
102
      return alias == null ? null : resolveAlias(alias);
1✔
103
    } catch (Exception e) {
1✔
104
      throw new BuilderException("Error resolving class. Cause: " + e, e);
1✔
105
    }
106
  }
107

108
  @Deprecated(since = "3.6.0", forRemoval = true)
109
  protected TypeHandler<?> resolveTypeHandler(Class<?> javaType, String typeHandlerAlias) {
NEW
110
    return resolveTypeHandler(javaType, null, typeHandlerAlias);
×
111
  }
112

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

118
  protected TypeHandler<?> resolveTypeHandler(Type propertyType, JdbcType jdbcType, String typeHandlerAlias) {
119
    Class<? extends TypeHandler<?>> typeHandlerType = null;
1✔
120
    typeHandlerType = resolveClass(typeHandlerAlias);
1✔
121
    if (typeHandlerType != null && !TypeHandler.class.isAssignableFrom(typeHandlerType)) {
1✔
122
      throw new BuilderException("Type " + typeHandlerType.getName()
1✔
123
          + " is not a valid TypeHandler because it does not implement TypeHandler interface");
124
    }
125
    return resolveTypeHandler(propertyType, jdbcType, typeHandlerType);
1✔
126
  }
127

128
  protected TypeHandler<?> resolveTypeHandler(Type javaType, JdbcType jdbcType,
129
      Class<? extends TypeHandler<?>> typeHandlerType) {
130
    if (typeHandlerType == null && jdbcType == null) {
1✔
131
      return null;
1✔
132
    }
133
    return configuration.getTypeHandlerRegistry().getTypeHandler(javaType, jdbcType, typeHandlerType);
1✔
134
  }
135

136
  protected <T> Class<? extends T> resolveAlias(String alias) {
137
    return typeAliasRegistry.resolveAlias(alias);
1✔
138
  }
139
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc