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

mybatis / mybatis-3 / 2686

01 Feb 2025 09:55PM UTC coverage: 87.093% (-0.1%) from 87.217%
2686

Pull #3379

github

web-flow
Merge c97c5c598 into 3d71c862a
Pull Request #3379: Resolve type handler based on `java.lang.reflect.Type` instead of `Class` and respect runtime JDBC type

3825 of 4663 branches covered (82.03%)

515 of 579 new or added lines in 36 files covered. (88.95%)

28 existing lines in 6 files now uncovered.

9912 of 11381 relevant lines covered (87.09%)

0.87 hits per line

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

90.63
/src/main/java/org/apache/ibatis/mapping/ParameterMapping.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.mapping;
17

18
import java.sql.ResultSet;
19

20
import org.apache.ibatis.session.Configuration;
21
import org.apache.ibatis.type.JdbcType;
22
import org.apache.ibatis.type.TypeHandler;
23

24
/**
25
 * @author Clinton Begin
26
 */
27
public class ParameterMapping {
28

29
  private static final Object UNSET = new Object();
1✔
30
  private Configuration configuration;
31

32
  private String property;
33
  private ParameterMode mode;
34
  private Class<?> javaType = Object.class;
1✔
35
  private JdbcType jdbcType;
36
  private Integer numericScale;
37
  private TypeHandler<?> typeHandler;
38
  private String resultMapId;
39
  private String jdbcTypeName;
40
  private String expression;
41
  private Object value = UNSET;
1✔
42

43
  private ParameterMapping() {
1✔
44
  }
1✔
45

46
  public static class Builder {
47
    private final ParameterMapping parameterMapping = new ParameterMapping();
1✔
48

49
    public Builder(Configuration configuration, String property, TypeHandler<?> typeHandler) {
1✔
50
      parameterMapping.configuration = configuration;
1✔
51
      parameterMapping.property = property;
1✔
52
      parameterMapping.typeHandler = typeHandler;
1✔
53
      parameterMapping.mode = ParameterMode.IN;
1✔
54
    }
1✔
55

56
    public Builder(Configuration configuration, String property, Class<?> javaType) {
1✔
57
      parameterMapping.configuration = configuration;
1✔
58
      parameterMapping.property = property;
1✔
59
      parameterMapping.javaType = javaType;
1✔
60
      parameterMapping.mode = ParameterMode.IN;
1✔
61
    }
1✔
62

63
    public Builder mode(ParameterMode mode) {
64
      parameterMapping.mode = mode;
1✔
65
      return this;
1✔
66
    }
67

68
    public Builder javaType(Class<?> javaType) {
69
      parameterMapping.javaType = javaType;
1✔
70
      return this;
1✔
71
    }
72

73
    public Builder jdbcType(JdbcType jdbcType) {
74
      parameterMapping.jdbcType = jdbcType;
1✔
75
      return this;
1✔
76
    }
77

78
    public Builder numericScale(Integer numericScale) {
79
      parameterMapping.numericScale = numericScale;
1✔
80
      return this;
1✔
81
    }
82

83
    public Builder resultMapId(String resultMapId) {
84
      parameterMapping.resultMapId = resultMapId;
1✔
85
      return this;
1✔
86
    }
87

88
    public Builder typeHandler(TypeHandler<?> typeHandler) {
89
      parameterMapping.typeHandler = typeHandler;
1✔
90
      return this;
1✔
91
    }
92

93
    public Builder jdbcTypeName(String jdbcTypeName) {
94
      parameterMapping.jdbcTypeName = jdbcTypeName;
×
95
      return this;
×
96
    }
97

98
    public Builder expression(String expression) {
99
      parameterMapping.expression = expression;
×
100
      return this;
×
101
    }
102

103
    public Builder value(Object value) {
104
      parameterMapping.value = value;
1✔
105
      return this;
1✔
106
    }
107

108
    public ParameterMapping build() {
109
      validate();
1✔
110
      return parameterMapping;
1✔
111
    }
112

113
    private void validate() {
114
      if (ResultSet.class.equals(parameterMapping.javaType) && parameterMapping.resultMapId == null) {
1!
NEW
115
        throw new IllegalStateException("Missing resultmap in property '" + parameterMapping.property + "'.  "
×
116
            + "Parameters of type java.sql.ResultSet require a resultmap.");
117
      }
118
    }
1✔
119
  }
120

121
  public String getProperty() {
122
    return property;
1✔
123
  }
124

125
  /**
126
   * Used for handling output of callable statements.
127
   *
128
   * @return the mode
129
   */
130
  public ParameterMode getMode() {
131
    return mode;
1✔
132
  }
133

134
  /**
135
   * Used for handling output of callable statements.
136
   *
137
   * @return the java type
138
   */
139
  public Class<?> getJavaType() {
140
    return javaType;
1✔
141
  }
142

143
  /**
144
   * Used in the UnknownTypeHandler in case there is no handler for the property type.
145
   *
146
   * @return the jdbc type
147
   */
148
  public JdbcType getJdbcType() {
149
    return jdbcType;
1✔
150
  }
151

152
  /**
153
   * Used for handling output of callable statements.
154
   *
155
   * @return the numeric scale
156
   */
157
  public Integer getNumericScale() {
158
    return numericScale;
1✔
159
  }
160

161
  /**
162
   * Used when setting parameters to the PreparedStatement.
163
   *
164
   * @return the type handler
165
   */
166
  public TypeHandler<?> getTypeHandler() {
167
    return typeHandler;
1✔
168
  }
169

170
  /**
171
   * Used for handling output of callable statements.
172
   *
173
   * @return the result map id
174
   */
175
  public String getResultMapId() {
176
    return resultMapId;
1✔
177
  }
178

179
  /**
180
   * Used for handling output of callable statements.
181
   *
182
   * @return the jdbc type name
183
   */
184
  public String getJdbcTypeName() {
185
    return jdbcTypeName;
1✔
186
  }
187

188
  /**
189
   * Expression 'Not used'.
190
   *
191
   * @return the expression
192
   */
193
  public String getExpression() {
194
    return expression;
×
195
  }
196

197
  public Object getValue() {
198
    return value;
1✔
199
  }
200

201
  public boolean hasValue() {
202
    return value != UNSET;
1✔
203
  }
204

205
  @Override
206
  public String toString() {
207
    final StringBuilder sb = new StringBuilder("ParameterMapping{");
1✔
208
    // sb.append("configuration=").append(configuration); // configuration doesn't have a useful .toString()
209
    sb.append("property='").append(property).append('\'');
1✔
210
    sb.append(", mode=").append(mode);
1✔
211
    sb.append(", javaType=").append(javaType);
1✔
212
    sb.append(", jdbcType=").append(jdbcType);
1✔
213
    sb.append(", numericScale=").append(numericScale);
1✔
214
    // sb.append(", typeHandler=").append(typeHandler); // typeHandler also doesn't have a useful .toString()
215
    sb.append(", resultMapId='").append(resultMapId).append('\'');
1✔
216
    sb.append(", jdbcTypeName='").append(jdbcTypeName).append('\'');
1✔
217
    sb.append(", expression='").append(expression).append('\'');
1✔
218
    sb.append(", value='").append(value).append('\'');
1✔
219
    sb.append('}');
1✔
220
    return sb.toString();
1✔
221
  }
222
}
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

© 2025 Coveralls, Inc