• 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

71.88
/src/main/java/com/ibatis/sqlmap/engine/exchange/DomDataExchange.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.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
  public void initialize(Map properties) {
50
  }
1✔
51

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

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

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

62
    return values;
1✔
63
  }
64

65
  public Object setData(StatementScope statementScope, ResultMap resultMap, Object resultObject, Object[] values) {
66

67
    String name = ((ResultMap) resultMap).getXmlName();
1✔
68
    if (name == null) {
1✔
69
      name = "result";
1✔
70
    }
71

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

82
    Probe probe = ProbeFactory.getProbe(resultObject);
1✔
83

84
    ResultMapping[] mappings = resultMap.getResultMappings();
1✔
85

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

92
    return resultObject;
1✔
93
  }
94

95
  public Object setData(StatementScope statementScope, ParameterMap parameterMap, Object parameterObject,
96
      Object[] values) {
97
    Probe probe = ProbeFactory.getProbe(parameterObject);
×
98

99
    ParameterMapping[] mappings = parameterMap.getParameterMappings();
×
100

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

109
    return parameterObject;
×
110
  }
111

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