• 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.07
/src/main/java/com/ibatis/sqlmap/engine/mapping/result/loader/EnhancedLazyResultLoader.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.common.beans.ClassInfo;
19
import com.ibatis.sqlmap.engine.impl.SqlMapClientImpl;
20
import com.ibatis.sqlmap.engine.type.DomTypeMarker;
21

22
import java.sql.SQLException;
23
import java.util.Collection;
24
import java.util.List;
25
import java.util.Set;
26

27
import net.sf.cglib.proxy.Enhancer;
28
import net.sf.cglib.proxy.LazyLoader;
29
import net.sf.cglib.proxy.NoOp;
30

31
/**
32
 * Class to lazily load results into objects (uses CGLib to improve performance).
33
 */
34
public class EnhancedLazyResultLoader {
35

36
  /** The Constant SET_INTERFACES. */
37
  private static final Class[] SET_INTERFACES = { Set.class };
1✔
38

39
  /** The Constant LIST_INTERFACES. */
40
  private static final Class[] LIST_INTERFACES = { List.class };
1✔
41

42
  /** The loader. */
43
  private Object loader;
44

45
  /**
46
   * Constructor for an enhanced lazy list loader.
47
   *
48
   * @param client
49
   *          - the client that is creating the lazy list
50
   * @param statementName
51
   *          - the statement to be used to build the list
52
   * @param parameterObject
53
   *          - the parameter object to be used to build the list
54
   * @param targetType
55
   *          - the type we are putting data into
56
   */
57
  public EnhancedLazyResultLoader(SqlMapClientImpl client, String statementName, Object parameterObject,
58
      Class targetType) {
1✔
59
    loader = new EnhancedLazyResultLoaderImpl(client, statementName, parameterObject, targetType);
1✔
60
  }
1✔
61

62
  /**
63
   * Loads the result.
64
   *
65
   * @return the results - a list or object
66
   *
67
   * @throws SQLException
68
   *           if there is a problem
69
   */
70
  public Object loadResult() throws SQLException {
71
    return ((EnhancedLazyResultLoaderImpl) loader).loadResult();
1✔
72
  }
73

74
  /**
75
   * The Class EnhancedLazyResultLoaderImpl.
76
   */
77
  private static class EnhancedLazyResultLoaderImpl implements LazyLoader {
78

79
    /** The client. */
80
    protected SqlMapClientImpl client;
81

82
    /** The statement name. */
83
    protected String statementName;
84

85
    /** The parameter object. */
86
    protected Object parameterObject;
87

88
    /** The target type. */
89
    protected Class targetType;
90

91
    /**
92
     * Constructor for an enhanced lazy list loader implementation.
93
     *
94
     * @param client
95
     *          - the client that is creating the lazy list
96
     * @param statementName
97
     *          - the statement to be used to build the list
98
     * @param parameterObject
99
     *          - the parameter object to be used to build the list
100
     * @param targetType
101
     *          - the type we are putting data into
102
     */
103
    public EnhancedLazyResultLoaderImpl(SqlMapClientImpl client, String statementName, Object parameterObject,
104
        Class targetType) {
1✔
105
      this.client = client;
1✔
106
      this.statementName = statementName;
1✔
107
      this.parameterObject = parameterObject;
1✔
108
      this.targetType = targetType;
1✔
109
    }
1✔
110

111
    /**
112
     * Loads the result.
113
     *
114
     * @return the results - a list or object
115
     *
116
     * @throws SQLException
117
     *           if there is a problem
118
     */
119
    public Object loadResult() throws SQLException {
120
      if (DomTypeMarker.class.isAssignableFrom(targetType)) {
1!
121
        return ResultLoader.getResult(client, statementName, parameterObject, targetType);
×
122
      }
123
      if (Collection.class.isAssignableFrom(targetType)) {
1!
124
        if (Set.class.isAssignableFrom(targetType)) {
×
125
          return Enhancer.create(Object.class, SET_INTERFACES, this);
×
126
        }
127
        return Enhancer.create(Object.class, LIST_INTERFACES, this);
×
128
      }
129
      if (targetType.isArray() || ClassInfo.isKnownType(targetType)) {
1!
130
        return ResultLoader.getResult(client, statementName, parameterObject, targetType);
×
131
      }
132
      return Enhancer.create(targetType, this);
1✔
133
    }
134

135
    @Override
136
    public Object loadObject() throws Exception {
137
      try {
138
        Object result = ResultLoader.getResult(client, statementName, parameterObject, targetType);
1✔
139
        if (result == null) {
1✔
140
          // if no result is available return a proxy with a default object is returned
141
          // because the loadObject() method must not return null
142
          result = Enhancer.create(targetType, NoOp.INSTANCE);
1✔
143
        }
144
        return result;
1✔
145
      } catch (SQLException e) {
×
146
        throw new RuntimeException("Error lazy loading result. Cause: " + e, e);
×
147
      }
148
    }
149
  }
150

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