spypreparedstatement.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 744 行 · 第 1/2 页

JAVA
744
字号
/* * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved * * This file is part of Resin(R) Open Source * * Each copy or derived work must preserve the copyright notice and this * notice unmodified. * * Resin Open Source 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; either version 2 of the License, or * (at your option) any later version. * * Resin Open Source 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, or any warranty * of NON-INFRINGEMENT.  See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License * along with Resin Open Source; if not, write to the *   Free SoftwareFoundation, Inc. *   59 Temple Place, Suite 330 *   Boston, MA 02111-1307  USA * * @author Scott Ferguson */package com.caucho.sql.spy;import com.caucho.log.Log;import com.caucho.sql.SQLExceptionWrapper;import com.caucho.util.L10N;import java.io.InputStream;import java.io.Reader;import java.math.BigDecimal;import java.net.URL;import java.sql.*;import java.util.Calendar;import java.util.logging.*;/** * Spying on a statement; */public class SpyPreparedStatement extends SpyStatement  implements java.sql.PreparedStatement {  protected final static Logger log = Log.open(SpyPreparedStatement.class);  protected static L10N L = new L10N(SpyPreparedStatement.class);  private String _sql;  protected PreparedStatement _pstmt;  SpyPreparedStatement(String id, SpyConnection conn,                       PreparedStatement stmt, String sql)  {    super(id, conn, stmt);    _pstmt = stmt;    _sql = sql;  }  public java.sql.ResultSet executeQuery()    throws SQLException  {    try {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":executeQuery(" + _sql + ")");      ResultSet rs = _pstmt.executeQuery();      return rs;    } catch (Throwable e) {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":exn-executeQuery(" + e + ")");      throw SQLExceptionWrapper.create(e);    }  }  public int executeUpdate()    throws SQLException  {    try {      int result = _pstmt.executeUpdate();      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":executeUpdate(" + _sql + ") -> " + result);      return result;    } catch (Throwable e) {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":exn-executeUpdate(" + e + ")");      throw SQLExceptionWrapper.create(e);    }  }  public boolean execute()    throws SQLException  {    try {      boolean result = _pstmt.execute();      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":execute(" + _sql + ") -> " + result);      return result;    } catch (Throwable e) {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":exn-execute(" + e + ")");      throw SQLExceptionWrapper.create(e);    }  }  public void addBatch()    throws SQLException  {    try {      _pstmt.addBatch();      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":addBatch()");    } catch (Throwable e) {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":exn-addBatch(" + e + ")");      throw SQLExceptionWrapper.create(e);    }  }  public void clearParameters()    throws SQLException  {    try {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":clearParameters()");      _pstmt.clearParameters();    } catch (Throwable e) {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":exn-clearParameters(" + e + ")");      throw SQLExceptionWrapper.create(e);    }  }  public ResultSetMetaData getMetaData()    throws SQLException  {    try {      ResultSetMetaData result = _pstmt.getMetaData();      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":getMetaData() -> " + result);      return result;    } catch (Throwable e) {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":exn-getMetaData(" + e + ")");      throw SQLExceptionWrapper.create(e);    }  }  public ParameterMetaData getParameterMetaData()    throws SQLException  {    return _pstmt.getParameterMetaData();  }  public void setNull(int parameterIndex, int sqlType)    throws SQLException  {    try {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":setNull(" + parameterIndex + ",type=" + sqlType + ")");      _pstmt.setNull(parameterIndex, sqlType);    } catch (Throwable e) {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":exn-setNull(" + e + ")");      throw SQLExceptionWrapper.create(e);    }  }  public void setNull(int parameterIndex, int sqlType, String typeName)    throws SQLException  {    try {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":setNull(" + parameterIndex + ",type=" + sqlType +              ",typeName=" + typeName + ")");      _pstmt.setNull(parameterIndex, sqlType, typeName);    } catch (Throwable e) {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":exn-setNull(" + e + ")");      throw SQLExceptionWrapper.create(e);    }  }  public void setBoolean(int index, boolean value)    throws SQLException  {    try {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":setBoolean(" + index + "," + value + ")");      _pstmt.setBoolean(index, value);    } catch (Throwable e) {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":exn-setBoolean(" + e + ")");      throw SQLExceptionWrapper.create(e);    }  }  public void setByte(int index, byte value)    throws SQLException  {    try {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":setByte(" + index + "," + value + ")");      _pstmt.setByte(index, value);    } catch (Throwable e) {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":exn-setByte(" + e + ")");      throw SQLExceptionWrapper.create(e);    }  }  public void setShort(int index, short value)    throws SQLException  {    try {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":setShort(" + index + "," + value + ")");      _pstmt.setShort(index, value);    } catch (Throwable e) {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":exn-setShort(" + e + ")");      throw SQLExceptionWrapper.create(e);    }  }  public void setInt(int index, int value)    throws SQLException  {    try {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":setInt(" + index + "," + value + ")");      _pstmt.setInt(index, value);    } catch (Throwable e) {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":exn-setInt(" + e + ")");      throw SQLExceptionWrapper.create(e);    }  }  public void setLong(int index, long value)    throws SQLException  {    try {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":setLong(" + index + "," + value + ")");      _pstmt.setLong(index, value);    } catch (Throwable e) {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":exn-setLong(" + e + ")");      throw SQLExceptionWrapper.create(e);    }  }  public void setFloat(int index, float value)    throws SQLException  {    try {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":setFloat(" + index + "," + value + ")");      _pstmt.setFloat(index, value);    } catch (Throwable e) {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":exn-setFloat(" + e + ")");      throw SQLExceptionWrapper.create(e);    }  }  public void setDouble(int index, double value)    throws SQLException  {    try {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":setDouble(" + index + "," + value + ")");      _pstmt.setDouble(index, value);    } catch (Throwable e) {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":exn-setDouble(" + e + ")");      throw SQLExceptionWrapper.create(e);    }  }  public void setBigDecimal(int index, BigDecimal value)    throws SQLException  {    try {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":setBigDecimal(" + index + "," + value + ")");      _pstmt.setBigDecimal(index, value);    } catch (Throwable e) {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":exn-setBigDecimal(" + e + ")");      throw SQLExceptionWrapper.create(e);    }  }  public void setString(int index, String value)    throws SQLException  {    try {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":setString(" + index + "," + value + ")");      _pstmt.setString(index, value);    } catch (Throwable e) {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":exn-setString(" + e + ")");      throw SQLExceptionWrapper.create(e);    }  }  public void setBytes(int index, byte []value)    throws SQLException  {    try {      if (value != null)        if (log.isLoggable(Level.FINE))	  log.fine(getId() + ":setBytes(" + index + ",len=" + value.length + ")");      else        if (log.isLoggable(Level.FINE))	  log.fine(getId() + ":setBytes(" + index + ",null");      _pstmt.setBytes(index, value);    } catch (Throwable e) {      if (log.isLoggable(Level.FINE))	log.fine(getId() + ":exn-setBytes(" + e + ")");      throw SQLExceptionWrapper.create(e);    }  }  public void setDate(int index, Date value)    throws SQLException  {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?