• 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

67.65
/src/main/java/com/ibatis/sqlmap/engine/mapping/result/loader/ResultLoader.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.mapping.result.loader;
17

18
import com.ibatis.sqlmap.engine.impl.SqlMapClientImpl;
19
import com.ibatis.sqlmap.engine.type.DomCollectionTypeMarker;
20

21
import java.lang.reflect.Array;
22
import java.sql.SQLException;
23
import java.util.Collection;
24
import java.util.HashSet;
25
import java.util.Iterator;
26
import java.util.List;
27
import java.util.Set;
28

29
/**
30
 * Class to load results into objects.
31
 */
32
public class ResultLoader {
33

34
  /**
35
   * Instantiates a new result loader.
36
   */
37
  private ResultLoader() {
38
  }
39

40
  /**
41
   * Loads a result lazily.
42
   *
43
   * @param client
44
   *          - the client creating the object
45
   * @param statementName
46
   *          - the name of the statement to be used
47
   * @param parameterObject
48
   *          - the parameters for the statement
49
   * @param targetType
50
   *          - the target type of the result
51
   *
52
   * @return the loaded result
53
   *
54
   * @throws SQLException
55
   *           the SQL exception
56
   */
57
  public static Object loadResult(SqlMapClientImpl client, String statementName, Object parameterObject,
58
      Class targetType) throws SQLException {
59
    Object value = null;
1✔
60

61
    if (client.isLazyLoadingEnabled()) {
1!
62
      if (client.isEnhancementEnabled()) {
1!
63
        EnhancedLazyResultLoader lazy = new EnhancedLazyResultLoader(client, statementName, parameterObject,
×
64
            targetType);
65
        value = lazy.loadResult();
×
66
      } else {
×
67
        LazyResultLoader lazy = new LazyResultLoader(client, statementName, parameterObject, targetType);
1✔
68
        value = lazy.loadResult();
1✔
69
      }
1✔
70
    } else {
71
      value = getResult(client, statementName, parameterObject, targetType);
×
72
    }
73

74
    return value;
1✔
75
  }
76

77
  /**
78
   * Gets the result.
79
   *
80
   * @param client
81
   *          the client
82
   * @param statementName
83
   *          the statement name
84
   * @param parameterObject
85
   *          the parameter object
86
   * @param targetType
87
   *          the target type
88
   *
89
   * @return the result
90
   *
91
   * @throws SQLException
92
   *           the SQL exception
93
   */
94
  protected static Object getResult(SqlMapClientImpl client, String statementName, Object parameterObject,
95
      Class targetType) throws SQLException {
96
    Object value = null;
1✔
97
    if (DomCollectionTypeMarker.class.isAssignableFrom(targetType)) {
1✔
98
      value = client.queryForList(statementName, parameterObject);
1✔
99
    } else if (Set.class.isAssignableFrom(targetType)) {
1!
100
      value = new HashSet<>(client.queryForList(statementName, parameterObject));
×
101
    } else if (Collection.class.isAssignableFrom(targetType)) {
1✔
102
      value = client.queryForList(statementName, parameterObject);
1✔
103
    } else if (targetType.isArray()) {
1✔
104
      List list = client.queryForList(statementName, parameterObject);
1✔
105
      value = listToArray(list, targetType.getComponentType());
1✔
106
    } else {
1✔
107
      value = client.queryForObject(statementName, parameterObject);
1✔
108
    }
109
    return value;
1✔
110
  }
111

112
  /**
113
   * List to array.
114
   *
115
   * @param list
116
   *          the list
117
   * @param type
118
   *          the type
119
   *
120
   * @return the object
121
   */
122
  private static Object listToArray(List list, Class type) {
123
    Object array = java.lang.reflect.Array.newInstance(type, list.size());
1✔
124
    if (type.isPrimitive()) {
1!
125
      Iterator iter = list.iterator();
×
126
      int index = 0;
×
127
      while (iter.hasNext()) {
×
128
        Array.set(array, index, iter.next());
×
129
        index++;
×
130
      }
131
    } else {
×
132
      array = list.toArray((Object[]) array);
1✔
133
    }
134
    return array;
1✔
135

136
  }
137

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