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

mybatis / ibatis-2 / #363

04 Nov 2023 06:48PM UTC coverage: 64.938%. Remained the same
#363

push

github

web-flow
Merge pull request #193 from hazendaz/master

Update GHA and prepare for new site distribution

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

95.45
/src/main/java/com/ibatis/sqlmap/engine/builder/xml/SqlStatementParser.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.builder.xml;
17

18
import com.ibatis.common.resources.Resources;
19
import com.ibatis.common.xml.NodeletUtils;
20
import com.ibatis.sqlmap.client.SqlMapException;
21
import com.ibatis.sqlmap.engine.config.MappedStatementConfig;
22
import com.ibatis.sqlmap.engine.mapping.statement.MappedStatement;
23

24
import java.util.Properties;
25

26
import org.w3c.dom.CharacterData;
27
import org.w3c.dom.Node;
28
import org.w3c.dom.NodeList;
29

30
/**
31
 * The Class SqlStatementParser.
32
 */
33
public class SqlStatementParser {
34

35
  /** The state. */
36
  private XmlParserState state;
37

38
  /**
39
   * Instantiates a new sql statement parser.
40
   *
41
   * @param config
42
   *          the config
43
   */
44
  public SqlStatementParser(XmlParserState config) {
1✔
45
    this.state = config;
1✔
46
  }
1✔
47

48
  /**
49
   * Parses the general statement.
50
   *
51
   * @param node
52
   *          the node
53
   * @param statement
54
   *          the statement
55
   */
56
  public void parseGeneralStatement(Node node, MappedStatement statement) {
57

58
    // get attributes
59
    Properties attributes = NodeletUtils.parseAttributes(node, state.getGlobalProps());
1✔
60
    String id = attributes.getProperty("id");
1✔
61
    String parameterMapName = state.applyNamespace(attributes.getProperty("parameterMap"));
1✔
62
    String parameterClassName = attributes.getProperty("parameterClass");
1✔
63
    String resultMapName = attributes.getProperty("resultMap");
1✔
64
    String resultClassName = attributes.getProperty("resultClass");
1✔
65
    String cacheModelName = state.applyNamespace(attributes.getProperty("cacheModel"));
1✔
66
    String xmlResultName = attributes.getProperty("xmlResultName");
1✔
67
    String resultSetType = attributes.getProperty("resultSetType");
1✔
68
    String fetchSize = attributes.getProperty("fetchSize");
1✔
69
    String allowRemapping = attributes.getProperty("remapResults");
1✔
70
    String timeout = attributes.getProperty("timeout");
1✔
71

72
    if (state.isUseStatementNamespaces()) {
1✔
73
      id = state.applyNamespace(id);
×
74
    }
75
    String[] additionalResultMapNames = null;
1✔
76
    if (resultMapName != null) {
1✔
77
      additionalResultMapNames = state.getAllButFirstToken(resultMapName);
1✔
78
      resultMapName = state.getFirstToken(resultMapName);
1✔
79
      resultMapName = state.applyNamespace(resultMapName);
1✔
80
      for (int i = 0; i < additionalResultMapNames.length; i++) {
1✔
81
        additionalResultMapNames[i] = state.applyNamespace(additionalResultMapNames[i]);
1✔
82
      }
83
    }
84

85
    String[] additionalResultClassNames = null;
1✔
86
    if (resultClassName != null) {
1✔
87
      additionalResultClassNames = state.getAllButFirstToken(resultClassName);
1✔
88
      resultClassName = state.getFirstToken(resultClassName);
1✔
89
    }
90
    Class[] additionalResultClasses = null;
1✔
91
    if (additionalResultClassNames != null) {
1✔
92
      additionalResultClasses = new Class[additionalResultClassNames.length];
1✔
93
      for (int i = 0; i < additionalResultClassNames.length; i++) {
1✔
94
        additionalResultClasses[i] = resolveClass(additionalResultClassNames[i]);
1✔
95
      }
96
    }
97

98
    state.getConfig().getErrorContext().setMoreInfo("Check the parameter class.");
1✔
99
    Class parameterClass = resolveClass(parameterClassName);
1✔
100

101
    state.getConfig().getErrorContext().setMoreInfo("Check the result class.");
1✔
102
    Class resultClass = resolveClass(resultClassName);
1✔
103

104
    Integer timeoutInt = timeout == null ? null : Integer.valueOf(timeout);
1✔
105
    Integer fetchSizeInt = fetchSize == null ? null : Integer.valueOf(fetchSize);
1✔
106
    boolean allowRemappingBool = "true".equals(allowRemapping);
1✔
107

108
    MappedStatementConfig statementConf = state.getConfig().newMappedStatementConfig(id, statement,
1✔
109
        new XMLSqlSource(state, node), parameterMapName, parameterClass, resultMapName, additionalResultMapNames,
110
        resultClass, additionalResultClasses, resultSetType, fetchSizeInt, allowRemappingBool, timeoutInt,
111
        cacheModelName, xmlResultName);
112

113
    findAndParseSelectKey(node, statementConf);
1✔
114
  }
1✔
115

116
  /**
117
   * Resolve class.
118
   *
119
   * @param resultClassName
120
   *          the result class name
121
   *
122
   * @return the class
123
   */
124
  private Class resolveClass(String resultClassName) {
125
    try {
126
      if (resultClassName != null) {
1✔
127
        return Resources.classForName(state.getConfig().getTypeHandlerFactory().resolveAlias(resultClassName));
1✔
128
      } else {
129
        return null;
1✔
130
      }
131
    } catch (ClassNotFoundException e) {
×
132
      throw new SqlMapException("Error.  Could not initialize class.  Cause: " + e, e);
×
133
    }
134
  }
135

136
  /**
137
   * Find and parse select key.
138
   *
139
   * @param node
140
   *          the node
141
   * @param config
142
   *          the config
143
   */
144
  private void findAndParseSelectKey(Node node, MappedStatementConfig config) {
145
    state.getConfig().getErrorContext().setActivity("parsing select key tags");
1✔
146
    boolean foundSQLFirst = false;
1✔
147
    NodeList children = node.getChildNodes();
1✔
148
    for (int i = 0; i < children.getLength(); i++) {
1✔
149
      Node child = children.item(i);
1✔
150
      if (child.getNodeType() == Node.CDATA_SECTION_NODE || child.getNodeType() == Node.TEXT_NODE) {
1✔
151
        String data = ((CharacterData) child).getData();
1✔
152
        if (data.trim().length() > 0) {
1✔
153
          foundSQLFirst = true;
1✔
154
        }
155
      } else if (child.getNodeType() == Node.ELEMENT_NODE && "selectKey".equals(child.getNodeName())) {
1✔
156
        Properties attributes = NodeletUtils.parseAttributes(child, state.getGlobalProps());
1✔
157
        String keyPropName = attributes.getProperty("keyProperty");
1✔
158
        String resultClassName = attributes.getProperty("resultClass");
1✔
159
        String type = attributes.getProperty("type");
1✔
160
        config.setSelectKeyStatement(new XMLSqlSource(state, child), resultClassName, keyPropName, foundSQLFirst, type);
1✔
161
        break;
1✔
162
      }
163
    }
164
    state.getConfig().getErrorContext().setMoreInfo(null);
1✔
165

166
  }
1✔
167

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