• 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

60.78
/src/main/java/com/ibatis/sqlmap/engine/mapping/statement/CachingStatement.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.statement;
17

18
import com.ibatis.sqlmap.client.event.RowHandler;
19
import com.ibatis.sqlmap.engine.cache.CacheKey;
20
import com.ibatis.sqlmap.engine.cache.CacheModel;
21
import com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap;
22
import com.ibatis.sqlmap.engine.mapping.result.ResultMap;
23
import com.ibatis.sqlmap.engine.mapping.sql.Sql;
24
import com.ibatis.sqlmap.engine.scope.StatementScope;
25
import com.ibatis.sqlmap.engine.transaction.Transaction;
26

27
import java.sql.SQLException;
28
import java.util.List;
29

30
/**
31
 * The Class CachingStatement.
32
 */
33
public class CachingStatement extends MappedStatement {
34

35
  /** The statement. */
36
  private MappedStatement statement;
37

38
  /** The cache model. */
39
  private CacheModel cacheModel;
40

41
  /**
42
   * Instantiates a new caching statement.
43
   *
44
   * @param statement
45
   *          the statement
46
   * @param cacheModel
47
   *          the cache model
48
   */
49
  public CachingStatement(MappedStatement statement, CacheModel cacheModel) {
1✔
50
    this.statement = statement;
1✔
51
    this.cacheModel = cacheModel;
1✔
52
  }
1✔
53

54
  @Override
55
  public String getId() {
56
    return statement.getId();
1✔
57
  }
58

59
  @Override
60
  public StatementType getStatementType() {
61
    return statement.getStatementType();
×
62
  }
63

64
  @Override
65
  public Integer getResultSetType() {
66
    return statement.getResultSetType();
×
67
  }
68

69
  @Override
70
  public Integer getFetchSize() {
71
    return statement.getFetchSize();
×
72
  }
73

74
  @Override
75
  public ParameterMap getParameterMap() {
76
    return statement.getParameterMap();
×
77
  }
78

79
  @Override
80
  public ResultMap getResultMap() {
81
    return statement.getResultMap();
×
82
  }
83

84
  @Override
85
  public int executeUpdate(StatementScope statementScope, Transaction trans, Object parameterObject)
86
      throws SQLException {
87
    return statement.executeUpdate(statementScope, trans, parameterObject);
×
88
  }
89

90
  @Override
91
  public Object executeQueryForObject(StatementScope statementScope, Transaction trans, Object parameterObject,
92
      Object resultObject) throws SQLException {
93
    CacheKey cacheKey = getCacheKey(statementScope, parameterObject);
1✔
94
    cacheKey.update("executeQueryForObject");
1✔
95
    Object object = cacheModel.getObject(cacheKey);
1✔
96
    if (object == CacheModel.NULL_OBJECT) {
1!
97
      // This was cached, but null
98
      object = null;
×
99
    } else if (object == null) {
1!
100
      object = statement.executeQueryForObject(statementScope, trans, parameterObject, resultObject);
1✔
101
      cacheModel.putObject(cacheKey, object);
1✔
102
    }
103
    return object;
1✔
104
  }
105

106
  @Override
107
  public List executeQueryForList(StatementScope statementScope, Transaction trans, Object parameterObject,
108
      int skipResults, int maxResults) throws SQLException {
109
    CacheKey cacheKey = getCacheKey(statementScope, parameterObject);
1✔
110
    cacheKey.update("executeQueryForList");
1✔
111
    cacheKey.update(skipResults);
1✔
112
    cacheKey.update(maxResults);
1✔
113
    Object listAsObject = cacheModel.getObject(cacheKey);
1✔
114
    List list;
115
    if (listAsObject == CacheModel.NULL_OBJECT) {
1!
116
      // The cached object was null
117
      list = null;
×
118
    } else if (listAsObject == null) {
1✔
119
      list = statement.executeQueryForList(statementScope, trans, parameterObject, skipResults, maxResults);
1✔
120
      cacheModel.putObject(cacheKey, list);
1✔
121
    } else {
122
      list = (List) listAsObject;
1✔
123
    }
124
    return list;
1✔
125
  }
126

127
  @Override
128
  public void executeQueryWithRowHandler(StatementScope statementScope, Transaction trans, Object parameterObject,
129
      RowHandler rowHandler) throws SQLException {
130
    statement.executeQueryWithRowHandler(statementScope, trans, parameterObject, rowHandler);
×
131
  }
×
132

133
  @Override
134
  public CacheKey getCacheKey(StatementScope statementScope, Object parameterObject) {
135
    CacheKey key = statement.getCacheKey(statementScope, parameterObject);
1✔
136
    if (!cacheModel.isReadOnly() && !cacheModel.isSerialize()) {
1!
137
      key.update(statementScope.getSession());
×
138
    }
139
    return key;
1✔
140
  }
141

142
  @Override
143
  public void setBaseCacheKey(int base) {
144
    statement.setBaseCacheKey(base);
1✔
145
  }
1✔
146

147
  @Override
148
  public void addExecuteListener(ExecuteListener listener) {
149
    statement.addExecuteListener(listener);
×
150
  }
×
151

152
  @Override
153
  public void notifyListeners() {
154
    statement.notifyListeners();
×
155
  }
×
156

157
  @Override
158
  public void initRequest(StatementScope statementScope) {
159
    statement.initRequest(statementScope);
1✔
160
  }
1✔
161

162
  @Override
163
  public Sql getSql() {
164
    return statement.getSql();
×
165
  }
166

167
  @Override
168
  public Class getParameterClass() {
169
    return statement.getParameterClass();
×
170
  }
171

172
  @Override
173
  public Integer getTimeout() {
174
    return statement.getTimeout();
×
175
  }
176

177
  @Override
178
  public boolean hasMultipleResultMaps() {
179
    return statement.hasMultipleResultMaps();
×
180
  }
181

182
  @Override
183
  public ResultMap[] getAdditionalResultMaps() {
184
    return statement.getAdditionalResultMaps();
×
185
  }
186

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