com.zimbra.cs.db.DebugConnection.java Source code

Java tutorial

Introduction

Here is the source code for com.zimbra.cs.db.DebugConnection.java

Source

/*
 * ***** BEGIN LICENSE BLOCK *****
 * Zimbra Collaboration Suite Server
 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013, 2014, 2016 Synacor, Inc.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software Foundation,
 * version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License along with this program.
 * If not, see <https://www.gnu.org/licenses/>.
 * ***** END LICENSE BLOCK *****
 */
package com.zimbra.cs.db;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.zimbra.common.util.ZimbraLog;
import org.apache.commons.dbcp.DelegatingConnection;

class DebugConnection extends DelegatingConnection {
    protected final Connection mConn;

    DebugConnection(Connection conn) {
        super(conn);
        mConn = conn;
    }

    Connection getConnection() {
        return mConn;
    }

    public PreparedStatement prepareStatement(String sql) throws SQLException {
        return new DebugPreparedStatement(this, mConn.prepareStatement(sql), sql);
    }

    public void commit() throws SQLException {
        ZimbraLog.sqltrace.debug("commit, conn=" + mConn.hashCode());
        mConn.commit();
    }

    public void rollback() throws SQLException {
        ZimbraLog.sqltrace.debug("rollback, conn=" + mConn.hashCode());
        mConn.rollback();
    }

    public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
            throws SQLException {
        return new DebugPreparedStatement(this, mConn.prepareStatement(sql, resultSetType, resultSetConcurrency),
                sql);
    }

    public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
            int resultSetHoldability) throws SQLException {
        return new DebugPreparedStatement(this,
                mConn.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability), sql);
    }

    public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
        return new DebugPreparedStatement(this, mConn.prepareStatement(sql, autoGeneratedKeys), sql);
    }

    public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
        return new DebugPreparedStatement(this, mConn.prepareStatement(sql, columnIndexes), sql);
    }

    public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
        return new DebugPreparedStatement(this, mConn.prepareStatement(sql, columnNames), sql);
    }
}