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

mybatis / ibatis-2 / 678

27 Dec 2025 01:13AM UTC coverage: 65.584% (+0.05%) from 65.532%
678

push

github

hazendaz
Merge remote-tracking branch 'upstream/master' into support-javax

1606 of 2810 branches covered (57.15%)

167 of 305 new or added lines in 90 files covered. (54.75%)

6 existing lines in 4 files now uncovered.

5067 of 7726 relevant lines covered (65.58%)

0.66 hits per line

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

54.05
/src/main/java/com/ibatis/sqlmap/engine/exchange/ListDataExchange.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.ProbeFactory;
19
import com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap;
20
import com.ibatis.sqlmap.engine.mapping.parameter.ParameterMapping;
21
import com.ibatis.sqlmap.engine.mapping.result.ResultMap;
22
import com.ibatis.sqlmap.engine.mapping.result.ResultMapping;
23
import com.ibatis.sqlmap.engine.scope.StatementScope;
24

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

29
/**
30
 * DataExchange implementation for List objects.
31
 */
32
public class ListDataExchange extends BaseDataExchange implements DataExchange {
33

34
  /**
35
   * Instantiates a new list data exchange.
36
   *
37
   * @param dataExchangeFactory
38
   *          the data exchange factory
39
   */
40
  protected ListDataExchange(DataExchangeFactory dataExchangeFactory) {
41
    super(dataExchangeFactory);
1✔
42
  }
1✔
43

44
  @Override
45
  public void initialize(Map properties) {
46
  }
1✔
47

48
  @Override
49
  public Object[] getData(StatementScope statementScope, ParameterMap parameterMap, Object parameterObject) {
50
    ParameterMapping[] mappings = parameterMap.getParameterMappings();
1✔
51
    Object[] data = new Object[mappings.length];
1✔
52
    for (int i = 0; i < mappings.length; i++) {
1✔
53
      String propName = mappings[i].getPropertyName();
1✔
54

55
      // parse on the '.' notation and get nested properties
56
      String[] propertyArray = propName.split("\\.");
1✔
57

58
      if (propertyArray.length > 0) {
1!
59
        // iterate list of properties to discover values
60

61
        Object tempData = parameterObject;
1✔
62

63
        for (int x = 0; x < propertyArray.length; x++) {
1✔
64

65
          // is property an array reference
66
          int arrayStartIndex = propertyArray[x].indexOf('[');
1✔
67

68
          if (arrayStartIndex == -1) {
1✔
69

70
            // is a normal property
71
            tempData = ProbeFactory.getProbe().getObject(tempData, propertyArray[x]);
1✔
72

73
          } else {
74

75
            int index = Integer
1✔
76
                .parseInt(propertyArray[x].substring(arrayStartIndex + 1, propertyArray[x].length() - 1));
1✔
77
            tempData = ((List) tempData).get(index);
1✔
78

79
          }
80

81
        }
82

83
        data[i] = tempData;
1✔
84

85
      } else {
1✔
86

87
        int index = Integer.parseInt((propName.substring(propName.indexOf('[') + 1, propName.length() - 1)));
×
88
        data[i] = ((List) parameterObject).get(index);
×
89

90
      }
91

92
    }
93
    return data;
1✔
94
  }
95

96
  @Override
97
  public Object setData(StatementScope statementScope, ResultMap resultMap, Object resultObject, Object[] values) {
98
    ResultMapping[] mappings = resultMap.getResultMappings();
×
NEW
99
    List data = new ArrayList<>();
×
100
    for (int i = 0; i < mappings.length; i++) {
×
101
      String propName = mappings[i].getPropertyName();
×
102
      int index = Integer.parseInt((propName.substring(1, propName.length() - 1)));
×
103
      data.set(index, values[i]);
×
104
    }
105
    return data;
×
106
  }
107

108
  @Override
109
  public Object setData(StatementScope statementScope, ParameterMap parameterMap, Object parameterObject,
110
      Object[] values) {
111
    ParameterMapping[] mappings = parameterMap.getParameterMappings();
×
NEW
112
    List data = new ArrayList<>();
×
113
    for (int i = 0; i < mappings.length; i++) {
×
114
      if (mappings[i].isOutputAllowed()) {
×
115
        String propName = mappings[i].getPropertyName();
×
116
        int index = Integer.parseInt((propName.substring(1, propName.length() - 1)));
×
117
        data.set(index, values[i]);
×
118
      }
119
    }
120

121
    return data;
×
122
  }
123

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