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

mybatis / ibatis-2 / #341

08 Sep 2023 11:16PM UTC coverage: 64.938% (+0.03%) from 64.913%
#341

push

github

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

fixes #174, update GHA, maven wrapper, fix EOL markers, do not use star imports

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

80.82
/src/main/java/com/ibatis/sqlmap/engine/impl/SqlMapClientImpl.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.impl;
17

18
import com.ibatis.common.logging.Log;
19
import com.ibatis.common.logging.LogFactory;
20
import com.ibatis.common.util.PaginatedList;
21
import com.ibatis.sqlmap.client.SqlMapClient;
22
import com.ibatis.sqlmap.client.SqlMapException;
23
import com.ibatis.sqlmap.client.SqlMapSession;
24
import com.ibatis.sqlmap.client.event.RowHandler;
25
import com.ibatis.sqlmap.engine.execution.BatchException;
26
import com.ibatis.sqlmap.engine.execution.SqlExecutor;
27
import com.ibatis.sqlmap.engine.mapping.result.ResultObjectFactory;
28
import com.ibatis.sqlmap.engine.mapping.statement.MappedStatement;
29

30
import java.sql.Connection;
31
import java.sql.SQLException;
32
import java.util.List;
33
import java.util.Map;
34

35
import javax.sql.DataSource;
36

37
/**
38
 * Implementation of ExtendedSqlMapClient.
39
 */
40
public class SqlMapClientImpl implements SqlMapClient, ExtendedSqlMapClient {
41

42
  /** The Constant log. */
43
  private static final Log log = LogFactory.getLog(SqlMapClientImpl.class);
1✔
44

45
  /** Delegate for SQL execution. */
46
  public SqlMapExecutorDelegate delegate;
47

48
  /** The local sql map session. */
49
  protected ThreadLocal<SqlMapSessionImpl> localSqlMapSession = new ThreadLocal<SqlMapSessionImpl>();
1✔
50

51
  /**
52
   * Constructor to supply a delegate.
53
   *
54
   * @param delegate
55
   *          - the delegate
56
   */
57
  public SqlMapClientImpl(SqlMapExecutorDelegate delegate) {
1✔
58
    this.delegate = delegate;
1✔
59
  }
1✔
60

61
  public Object insert(String id, Object param) throws SQLException {
62
    return getLocalSqlMapSession().insert(id, param);
1✔
63
  }
64

65
  public Object insert(String id) throws SQLException {
66
    return getLocalSqlMapSession().insert(id);
×
67
  }
68

69
  public int update(String id, Object param) throws SQLException {
70
    return getLocalSqlMapSession().update(id, param);
1✔
71
  }
72

73
  public int update(String id) throws SQLException {
74
    return getLocalSqlMapSession().update(id);
1✔
75
  }
76

77
  public int delete(String id, Object param) throws SQLException {
78
    return getLocalSqlMapSession().delete(id, param);
×
79
  }
80

81
  public int delete(String id) throws SQLException {
82
    return getLocalSqlMapSession().delete(id);
×
83
  }
84

85
  public Object queryForObject(String id, Object paramObject) throws SQLException {
86
    return getLocalSqlMapSession().queryForObject(id, paramObject);
1✔
87
  }
88

89
  public Object queryForObject(String id) throws SQLException {
90
    return getLocalSqlMapSession().queryForObject(id);
1✔
91
  }
92

93
  public Object queryForObject(String id, Object paramObject, Object resultObject) throws SQLException {
94
    return getLocalSqlMapSession().queryForObject(id, paramObject, resultObject);
1✔
95
  }
96

97
  public List queryForList(String id, Object paramObject) throws SQLException {
98
    return getLocalSqlMapSession().queryForList(id, paramObject);
1✔
99
  }
100

101
  public List queryForList(String id) throws SQLException {
102
    return getLocalSqlMapSession().queryForList(id);
1✔
103
  }
104

105
  public List queryForList(String id, Object paramObject, int skip, int max) throws SQLException {
106
    return getLocalSqlMapSession().queryForList(id, paramObject, skip, max);
1✔
107
  }
108

109
  public List queryForList(String id, int skip, int max) throws SQLException {
110
    return getLocalSqlMapSession().queryForList(id, skip, max);
×
111
  }
112

113
  /**
114
   * @deprecated All paginated list features have been deprecated
115
   */
116
  public PaginatedList queryForPaginatedList(String id, Object paramObject, int pageSize) throws SQLException {
117
    return getLocalSqlMapSession().queryForPaginatedList(id, paramObject, pageSize);
1✔
118
  }
119

120
  /**
121
   * @deprecated All paginated list features have been deprecated
122
   */
123
  public PaginatedList queryForPaginatedList(String id, int pageSize) throws SQLException {
124
    return getLocalSqlMapSession().queryForPaginatedList(id, pageSize);
1✔
125
  }
126

127
  public Map queryForMap(String id, Object paramObject, String keyProp) throws SQLException {
128
    return getLocalSqlMapSession().queryForMap(id, paramObject, keyProp);
1✔
129
  }
130

131
  public Map queryForMap(String id, Object paramObject, String keyProp, String valueProp) throws SQLException {
132
    return getLocalSqlMapSession().queryForMap(id, paramObject, keyProp, valueProp);
1✔
133
  }
134

135
  public void queryWithRowHandler(String id, Object paramObject, RowHandler rowHandler) throws SQLException {
136
    getLocalSqlMapSession().queryWithRowHandler(id, paramObject, rowHandler);
1✔
137
  }
1✔
138

139
  public void queryWithRowHandler(String id, RowHandler rowHandler) throws SQLException {
140
    getLocalSqlMapSession().queryWithRowHandler(id, rowHandler);
1✔
141
  }
1✔
142

143
  public void startTransaction() throws SQLException {
144
    getLocalSqlMapSession().startTransaction();
1✔
145
  }
1✔
146

147
  public void startTransaction(int transactionIsolation) throws SQLException {
148
    getLocalSqlMapSession().startTransaction(transactionIsolation);
×
149
  }
×
150

151
  public void commitTransaction() throws SQLException {
152
    getLocalSqlMapSession().commitTransaction();
1✔
153
  }
1✔
154

155
  public void endTransaction() throws SQLException {
156
    try {
157
      getLocalSqlMapSession().endTransaction();
1✔
158
    } finally {
159
      getLocalSqlMapSession().close();
1✔
160
      localSqlMapSession.remove();
1✔
161
    }
162
  }
1✔
163

164
  public void startBatch() throws SQLException {
165
    getLocalSqlMapSession().startBatch();
1✔
166
  }
1✔
167

168
  public int executeBatch() throws SQLException {
169
    return getLocalSqlMapSession().executeBatch();
1✔
170
  }
171

172
  public List executeBatchDetailed() throws SQLException, BatchException {
173
    return getLocalSqlMapSession().executeBatchDetailed();
1✔
174
  }
175

176
  public void setUserConnection(Connection connection) throws SQLException {
177
    try {
178
      getLocalSqlMapSession().setUserConnection(connection);
1✔
179
    } finally {
180
      if (connection == null) {
1✔
181
        getLocalSqlMapSession().close();
×
182
      }
183
    }
184
  }
1✔
185

186
  /**
187
   * TODO Deprecated.
188
   *
189
   * @return Current connection
190
   *
191
   * @throws SQLException
192
   *           the SQL exception
193
   *
194
   * @deprecated
195
   */
196
  public Connection getUserConnection() throws SQLException {
197
    return getCurrentConnection();
×
198
  }
199

200
  public Connection getCurrentConnection() throws SQLException {
201
    return getLocalSqlMapSession().getCurrentConnection();
1✔
202
  }
203

204
  public DataSource getDataSource() {
205
    return delegate.getDataSource();
1✔
206
  }
207

208
  public MappedStatement getMappedStatement(String id) {
209
    return delegate.getMappedStatement(id);
1✔
210
  }
211

212
  public boolean isLazyLoadingEnabled() {
213
    return delegate.isLazyLoadingEnabled();
1✔
214
  }
215

216
  public boolean isEnhancementEnabled() {
217
    return delegate.isEnhancementEnabled();
1✔
218
  }
219

220
  public SqlExecutor getSqlExecutor() {
221
    return delegate.getSqlExecutor();
1✔
222
  }
223

224
  public SqlMapExecutorDelegate getDelegate() {
225
    return delegate;
1✔
226
  }
227

228
  public SqlMapSession openSession() {
229
    SqlMapSessionImpl sqlMapSession = new SqlMapSessionImpl(this);
1✔
230
    sqlMapSession.open();
1✔
231
    return sqlMapSession;
1✔
232
  }
233

234
  public SqlMapSession openSession(Connection conn) {
235
    try {
236
      SqlMapSessionImpl sqlMapSession = new SqlMapSessionImpl(this);
1✔
237
      sqlMapSession.open();
1✔
238
      sqlMapSession.setUserConnection(conn);
1✔
239
      return sqlMapSession;
1✔
240
    } catch (SQLException e) {
×
241
      throw new SqlMapException("Error setting user provided connection.  Cause: " + e, e);
×
242
    }
243
  }
244

245
  /**
246
   * TODO : DEPRECATED
247
   *
248
   * @deprecated Use openSession()
249
   */
250
  public SqlMapSession getSession() {
251
    log.warn(
×
252
        "Use of a deprecated API detected.  SqlMapClient.getSession() is deprecated.  Use SqlMapClient.openSession() instead.");
253
    return openSession();
×
254
  }
255

256
  public void flushDataCache() {
257
    delegate.flushDataCache();
1✔
258
  }
1✔
259

260
  public void flushDataCache(String cacheId) {
261
    delegate.flushDataCache(cacheId);
×
262
  }
×
263

264
  /**
265
   * Gets the local sql map session.
266
   *
267
   * @return the local sql map session
268
   */
269
  protected SqlMapSessionImpl getLocalSqlMapSession() {
270
    SqlMapSessionImpl sqlMapSession = localSqlMapSession.get();
1✔
271
    if (sqlMapSession == null || sqlMapSession.isClosed()) {
1✔
272
      sqlMapSession = new SqlMapSessionImpl(this);
1✔
273
      localSqlMapSession.set(sqlMapSession);
1✔
274
    }
275
    return sqlMapSession;
1✔
276
  }
277

278
  public ResultObjectFactory getResultObjectFactory() {
279
    return delegate.getResultObjectFactory();
1✔
280
  }
281
}
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