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

mybatis / ibatis-2 / 730

28 Dec 2025 10:16PM UTC coverage: 65.615% (+0.5%) from 65.146%
730

push

github

web-flow
Update README.md

1602 of 2802 branches covered (57.17%)

5053 of 7701 relevant lines covered (65.61%)

0.66 hits per line

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

80.0
/src/main/java/com/ibatis/sqlmap/engine/exchange/ComplexDataExchange.java
1
/*
2
 * Copyright 2004-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 com.ibatis.sqlmap.engine.exchange;
17

18
import com.ibatis.common.beans.Probe;
19
import com.ibatis.common.beans.ProbeFactory;
20
import com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap;
21
import com.ibatis.sqlmap.engine.mapping.parameter.ParameterMapping;
22
import com.ibatis.sqlmap.engine.mapping.result.ResultMap;
23
import com.ibatis.sqlmap.engine.mapping.result.ResultMapping;
24
import com.ibatis.sqlmap.engine.mapping.result.ResultObjectFactoryUtil;
25
import com.ibatis.sqlmap.engine.scope.StatementScope;
26
import com.ibatis.sqlmap.engine.type.TypeHandlerFactory;
27

28
import java.util.Map;
29

30
/**
31
 * A DataExchange implemtation for working with beans.
32
 */
33
public class ComplexDataExchange extends BaseDataExchange implements DataExchange {
34

35
  /** The Constant PROBE. */
36
  private static final Probe PROBE = ProbeFactory.getProbe();
1✔
37

38
  /**
39
   * Constructor for the factory.
40
   *
41
   * @param dataExchangeFactory
42
   *          - the factory
43
   */
44
  public ComplexDataExchange(DataExchangeFactory dataExchangeFactory) {
45
    super(dataExchangeFactory);
1✔
46
  }
1✔
47

48
  @Override
49
  public void initialize(Map properties) {
50
  }
1✔
51

52
  @Override
53
  public Object[] getData(StatementScope statementScope, ParameterMap parameterMap, Object parameterObject) {
54
    TypeHandlerFactory typeHandlerFactory = getDataExchangeFactory().getTypeHandlerFactory();
1✔
55
    if (parameterObject == null) {
1✔
56
      return new Object[1];
1✔
57
    }
58
    if (typeHandlerFactory.hasTypeHandler(parameterObject.getClass())) {
1✔
59
      ParameterMapping[] mappings = parameterMap.getParameterMappings();
1✔
60
      Object[] data = new Object[mappings.length];
1✔
61
      for (int i = 0; i < mappings.length; i++) {
1✔
62
        data[i] = parameterObject;
1✔
63
      }
64
      return data;
1✔
65
    }
66
    Object[] data = new Object[parameterMap.getParameterMappings().length];
1✔
67
    ParameterMapping[] mappings = parameterMap.getParameterMappings();
1✔
68
    for (int i = 0; i < mappings.length; i++) {
1✔
69
      data[i] = PROBE.getObject(parameterObject, mappings[i].getPropertyName());
1✔
70
    }
71
    return data;
1✔
72
  }
73

74
  @Override
75
  public Object setData(StatementScope statementScope, ResultMap resultMap, Object resultObject, Object[] values) {
76
    TypeHandlerFactory typeHandlerFactory = getDataExchangeFactory().getTypeHandlerFactory();
1✔
77
    if (typeHandlerFactory.hasTypeHandler(resultMap.getResultClass())) {
1!
78
      return values[0];
×
79
    }
80
    Object object = resultObject;
1✔
81
    if (object == null) {
1!
82
      try {
83
        object = ResultObjectFactoryUtil.createObjectThroughFactory(resultMap.getResultClass());
1✔
84
      } catch (Exception e) {
×
85
        throw new RuntimeException("JavaBeansDataExchange could not instantiate result class.  Cause: " + e, e);
×
86
      }
1✔
87
    }
88
    ResultMapping[] mappings = resultMap.getResultMappings();
1✔
89
    for (int i = 0; i < mappings.length; i++) {
1✔
90
      PROBE.setObject(object, mappings[i].getPropertyName(), values[i]);
1✔
91
    }
92
    return object;
1✔
93
  }
94

95
  @Override
96
  public Object setData(StatementScope statementScope, ParameterMap parameterMap, Object parameterObject,
97
      Object[] values) {
98
    TypeHandlerFactory typeHandlerFactory = getDataExchangeFactory().getTypeHandlerFactory();
1✔
99
    if (typeHandlerFactory.hasTypeHandler(parameterMap.getParameterClass())) {
1!
100
      return values[0];
×
101
    }
102
    Object object = parameterObject;
1✔
103
    if (object == null) {
1!
104
      try {
105
        object = ResultObjectFactoryUtil.createObjectThroughFactory(parameterMap.getParameterClass());
×
106
      } catch (Exception e) {
×
107
        throw new RuntimeException("JavaBeansDataExchange could not instantiate result class.  Cause: " + e, e);
×
108
      }
×
109
    }
110
    ParameterMapping[] mappings = parameterMap.getParameterMappings();
1✔
111
    for (int i = 0; i < mappings.length; i++) {
1✔
112
      if (mappings[i].isOutputAllowed()) {
1!
113
        PROBE.setObject(object, mappings[i].getPropertyName(), values[i]);
×
114
      }
115
    }
116
    return object;
1✔
117
  }
118

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