• 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

74.19
/src/main/java/com/ibatis/sqlmap/engine/exchange/DomDataExchange.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.client.SqlMapException;
21
import com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap;
22
import com.ibatis.sqlmap.engine.mapping.parameter.ParameterMapping;
23
import com.ibatis.sqlmap.engine.mapping.result.ResultMap;
24
import com.ibatis.sqlmap.engine.mapping.result.ResultMapping;
25
import com.ibatis.sqlmap.engine.scope.StatementScope;
26

27
import java.util.Map;
28

29
import javax.xml.parsers.DocumentBuilderFactory;
30
import javax.xml.parsers.ParserConfigurationException;
31

32
import org.w3c.dom.Document;
33

34
/**
35
 * A DataExchange implemtation for working with DOM objects.
36
 */
37
public class DomDataExchange extends BaseDataExchange implements DataExchange {
38

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

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

53
  @Override
54
  public Object[] getData(StatementScope statementScope, ParameterMap parameterMap, Object parameterObject) {
55
    Probe probe = ProbeFactory.getProbe(parameterObject);
1✔
56

57
    ParameterMapping[] mappings = parameterMap.getParameterMappings();
1✔
58
    Object[] values = new Object[mappings.length];
1✔
59

60
    for (int i = 0; i < mappings.length; i++) {
1✔
61
      values[i] = probe.getObject(parameterObject, mappings[i].getPropertyName());
1✔
62
    }
63

64
    return values;
1✔
65
  }
66

67
  @Override
68
  public Object setData(StatementScope statementScope, ResultMap resultMap, Object resultObject, Object[] values) {
69

70
    String name = resultMap.getXmlName();
1✔
71
    if (name == null) {
1✔
72
      name = "result";
1✔
73
    }
74

75
    if (resultObject == null) {
1!
76
      try {
77
        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
1✔
78
        doc.appendChild(doc.createElement(name));
1✔
79
        resultObject = doc;
1✔
80
      } catch (ParserConfigurationException e) {
×
81
        throw new SqlMapException("Error creating new Document for DOM result.  Cause: " + e, e);
×
82
      }
1✔
83
    }
84

85
    Probe probe = ProbeFactory.getProbe(resultObject);
1✔
86

87
    ResultMapping[] mappings = resultMap.getResultMappings();
1✔
88

89
    for (int i = 0; i < mappings.length; i++) {
1✔
90
      if (values[i] != null) {
1✔
91
        probe.setObject(resultObject, mappings[i].getPropertyName(), values[i]);
1✔
92
      }
93
    }
94

95
    return resultObject;
1✔
96
  }
97

98
  @Override
99
  public Object setData(StatementScope statementScope, ParameterMap parameterMap, Object parameterObject,
100
      Object[] values) {
101
    Probe probe = ProbeFactory.getProbe(parameterObject);
×
102

103
    ParameterMapping[] mappings = parameterMap.getParameterMappings();
×
104

105
    for (int i = 0; i < mappings.length; i++) {
×
106
      if (values[i] != null && mappings[i].isOutputAllowed()) {
×
107
        probe.setObject(parameterObject, mappings[i].getPropertyName(), values[i]);
×
108
      }
109
    }
110

111
    return parameterObject;
×
112
  }
113

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