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

mybatis / ibatis-2 / #341

08 Sep 2023 11:16PM UTC coverage: 64.938% (+0.03%) from 64.913%
#341

push

github

web-flow
Merge pull request #183 from hazendaz/master

fixes #174, update GHA, maven wrapper, fix EOL markers, do not use star imports

5047 of 7772 relevant lines covered (64.94%)

0.65 hits per line

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

92.31
/src/main/java/com/ibatis/sqlmap/engine/config/ParameterMapConfig.java
1
/*
2
 * Copyright 2004-2023 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 com.ibatis.sqlmap.engine.config;
17

18
import com.ibatis.sqlmap.client.extensions.TypeHandlerCallback;
19
import com.ibatis.sqlmap.engine.impl.SqlMapClientImpl;
20
import com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap;
21
import com.ibatis.sqlmap.engine.mapping.parameter.ParameterMapping;
22
import com.ibatis.sqlmap.engine.scope.ErrorContext;
23
import com.ibatis.sqlmap.engine.type.CustomTypeHandler;
24
import com.ibatis.sqlmap.engine.type.TypeHandler;
25

26
import java.util.ArrayList;
27
import java.util.List;
28

29
/**
30
 * The Class ParameterMapConfig.
31
 */
32
public class ParameterMapConfig {
33

34
  /** The Constant MODE_IN. */
35
  public static final String MODE_IN = "IN";
36

37
  /** The Constant MODE_OUT. */
38
  public static final String MODE_OUT = "OUT";
39

40
  /** The Constant MODE_INOUT. */
41
  public static final String MODE_INOUT = "INUOT";
42

43
  /** The config. */
44
  private SqlMapConfiguration config;
45

46
  /** The error context. */
47
  private ErrorContext errorContext;
48

49
  /** The client. */
50
  private SqlMapClientImpl client;
51

52
  /** The parameter map. */
53
  private ParameterMap parameterMap;
54

55
  /** The parameter mapping list. */
56
  private List parameterMappingList;
57

58
  /**
59
   * Instantiates a new parameter map config.
60
   *
61
   * @param config
62
   *          the config
63
   * @param id
64
   *          the id
65
   * @param parameterClass
66
   *          the parameter class
67
   */
68
  ParameterMapConfig(SqlMapConfiguration config, String id, Class parameterClass) {
1✔
69
    this.config = config;
1✔
70
    this.errorContext = config.getErrorContext();
1✔
71
    this.client = config.getClient();
1✔
72
    errorContext.setActivity("building a parameter map");
1✔
73
    parameterMap = new ParameterMap(client.getDelegate());
1✔
74
    parameterMap.setId(id);
1✔
75
    parameterMap.setResource(errorContext.getResource());
1✔
76
    errorContext.setObjectId(id + " parameter map");
1✔
77
    parameterMap.setParameterClass(parameterClass);
1✔
78
    errorContext.setMoreInfo("Check the parameter mappings.");
1✔
79
    this.parameterMappingList = new ArrayList();
1✔
80
    client.getDelegate().addParameterMap(parameterMap);
1✔
81
  }
1✔
82

83
  /**
84
   * Adds the parameter mapping.
85
   *
86
   * @param propertyName
87
   *          the property name
88
   * @param javaClass
89
   *          the java class
90
   * @param jdbcType
91
   *          the jdbc type
92
   * @param nullValue
93
   *          the null value
94
   * @param mode
95
   *          the mode
96
   * @param outParamType
97
   *          the out param type
98
   * @param numericScale
99
   *          the numeric scale
100
   * @param typeHandlerImpl
101
   *          the type handler impl
102
   * @param resultMap
103
   *          the result map
104
   */
105
  public void addParameterMapping(String propertyName, Class javaClass, String jdbcType, String nullValue, String mode,
106
      String outParamType, Integer numericScale, Object typeHandlerImpl, String resultMap) {
107
    errorContext.setObjectId(propertyName + " mapping of the " + parameterMap.getId() + " parameter map");
1✔
108
    TypeHandler handler;
109
    if (typeHandlerImpl != null) {
1✔
110
      errorContext.setMoreInfo("Check the parameter mapping typeHandler attribute '" + typeHandlerImpl
1✔
111
          + "' (must be a TypeHandler or TypeHandlerCallback implementation).");
112
      if (typeHandlerImpl instanceof TypeHandlerCallback) {
1✔
113
        handler = new CustomTypeHandler((TypeHandlerCallback) typeHandlerImpl);
1✔
114
      } else if (typeHandlerImpl instanceof TypeHandler) {
×
115
        handler = (TypeHandler) typeHandlerImpl;
×
116
      } else {
117
        throw new RuntimeException(
×
118
            "The class '" + typeHandlerImpl + "' is not a valid implementation of TypeHandler or TypeHandlerCallback");
119
      }
120
    } else {
121
      errorContext.setMoreInfo("Check the parameter mapping property type or name.");
1✔
122
      handler = config.resolveTypeHandler(client.getDelegate().getTypeHandlerFactory(),
1✔
123
          parameterMap.getParameterClass(), propertyName, javaClass, jdbcType);
1✔
124
    }
125
    ParameterMapping mapping = new ParameterMapping();
1✔
126
    mapping.setPropertyName(propertyName);
1✔
127
    mapping.setJdbcTypeName(jdbcType);
1✔
128
    mapping.setTypeName(outParamType);
1✔
129
    mapping.setResultMapName(resultMap);
1✔
130
    mapping.setNullValue(nullValue);
1✔
131
    if (mode != null && mode.length() > 0) {
1✔
132
      mapping.setMode(mode);
1✔
133
    }
134
    mapping.setTypeHandler(handler);
1✔
135
    mapping.setJavaType(javaClass);
1✔
136
    mapping.setNumericScale(numericScale);
1✔
137
    parameterMappingList.add(mapping);
1✔
138
    parameterMap.setParameterMappingList(parameterMappingList);
1✔
139
  }
1✔
140

141
}
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