• 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

52.78
/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 (String element : propertyArray) {
1✔
64

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

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

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

73
          } else {
74

75
            int index = Integer.parseInt(element.substring(arrayStartIndex + 1, element.length() - 1));
1✔
76
            tempData = ((List) tempData).get(index);
1✔
77

78
          }
79

80
        }
81

82
        data[i] = tempData;
1✔
83

84
      } else {
1✔
85

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

89
      }
90

91
    }
92
    return data;
1✔
93
  }
94

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

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

120
    return data;
×
121
  }
122

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