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

mybatis / ibatis-2 / 586

26 May 2025 08:47PM UTC coverage: 65.53% (+0.02%) from 65.509%
586

push

github

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

Minor code cleanup

1606 of 2810 branches covered (57.15%)

15 of 24 new or added lines in 13 files covered. (62.5%)

5072 of 7740 relevant lines covered (65.53%)

0.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.7
/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.*;
24

25
/**
26
 * Class to load results into objects.
27
 */
28
public class ResultLoader {
29

30
  /**
31
   * Instantiates a new result loader.
32
   */
33
  private ResultLoader() {
34
  }
35

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

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

70
    return value;
1✔
71
  }
72

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

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

131
  }
132

133
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc