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

mybatis / ibatis-2 / 692

27 Dec 2025 03:18AM UTC coverage: 65.607% (+0.04%) from 65.57%
692

push

github

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

Various cleanup

1602 of 2802 branches covered (57.17%)

70 of 95 new or added lines in 30 files covered. (73.68%)

6 existing lines in 5 files now uncovered.

5057 of 7708 relevant lines covered (65.61%)

0.66 hits per line

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

0.0
/src/main/java/com/ibatis/common/jdbc/logging/StatementLogProxy.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.common.jdbc.logging;
17

18
import com.ibatis.common.beans.ClassInfo;
19
import com.ibatis.common.logging.Log;
20
import com.ibatis.common.logging.LogFactory;
21

22
import java.lang.reflect.InvocationHandler;
23
import java.lang.reflect.Method;
24
import java.lang.reflect.Proxy;
25
import java.sql.ResultSet;
26
import java.sql.Statement;
27

28
/**
29
 * Statement proxy to add logging.
30
 */
31
public class StatementLogProxy extends BaseLogProxy implements InvocationHandler {
32

33
  /** The Constant log. */
34
  private static final Log log = LogFactory.getLog(Statement.class);
×
35

36
  /** The statement. */
37
  private Statement statement;
38

39
  /**
40
   * Instantiates a new statement log proxy.
41
   *
42
   * @param stmt
43
   *          the stmt
44
   */
45
  private StatementLogProxy(Statement stmt) {
46
    super();
×
47
    this.statement = stmt;
×
48
  }
×
49

50
  @Override
51
  public Object invoke(Object proxy, Method method, Object[] params) throws Throwable {
52
    try {
53
      if (EXECUTE_METHODS.contains(method.getName())) {
×
54
        if (log.isDebugEnabled()) {
×
55
          log.debug("{stmt-" + id + "} Statement: " + removeBreakingWhitespace((String) params[0]));
×
56
        }
57
        if ("executeQuery".equals(method.getName())) {
×
58
          ResultSet rs = (ResultSet) method.invoke(statement, params);
×
59
          if (rs != null) {
×
60
            return ResultSetLogProxy.newInstance(rs);
×
61
          } else {
62
            return null;
×
63
          }
64
        } else {
65
          return method.invoke(statement, params);
×
66
        }
67
      }
NEW
68
      if ("getResultSet".equals(method.getName())) {
×
69
        ResultSet rs = (ResultSet) method.invoke(statement, params);
×
70
        if (rs != null) {
×
71
          return ResultSetLogProxy.newInstance(rs);
×
72
        } else {
73
          return null;
×
74
        }
75
      } else if ("equals".equals(method.getName())) {
×
76
        Object ps = params[0];
×
77
        if (ps instanceof Proxy) {
×
78
          return Boolean.valueOf(proxy == ps);
×
79
        }
80
        return Boolean.valueOf(false);
×
81
      } else if ("hashCode".equals(method.getName())) {
×
82
        return Integer.valueOf(proxy.hashCode());
×
83
      } else {
84
        return method.invoke(statement, params);
×
85
      }
86
    } catch (Throwable t) {
×
87
      throw ClassInfo.unwrapThrowable(t);
×
88
    }
89
  }
90

91
  /**
92
   * Creates a logging version of a Statement.
93
   *
94
   * @param stmt
95
   *          - the statement
96
   *
97
   * @return - the proxy
98
   */
99
  public static Statement newInstance(Statement stmt) {
100
    InvocationHandler handler = new StatementLogProxy(stmt);
×
101
    ClassLoader cl = Statement.class.getClassLoader();
×
102
    return (Statement) Proxy.newProxyInstance(cl, new Class[] { Statement.class }, handler);
×
103
  }
104

105
  /**
106
   * return the wrapped statement.
107
   *
108
   * @return the statement
109
   */
110
  public Statement getStatement() {
111
    return statement;
×
112
  }
113

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

© 2026 Coveralls, Inc