📄 dbconnection.java
字号:
/* ===========================================================
* JDBMonitor : a flexiable JDBC Monitor for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2006-2006, by yang zhongke
*
* Project Info: http://www.cownew.com
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library 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 Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* ---------------
* DBConnection.java
* ---------------
* (C) Copyright 2006-2006, by yang zhongke
*
* Original Author: yang zhongke;
*
* Changes
* -------
*
*/
package com.cownew.JDBMonitor.jdbc;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Savepoint;
import java.sql.Statement;
import java.util.Map;
import com.cownew.JDBMonitor.common.DBListenerInfo;
import com.cownew.JDBMonitor.common.DBLogger;
import com.cownew.JDBMonitor.common.LoggerException;
import com.cownew.JDBMonitor.common.SQLInfo;
import com.cownew.JDBMonitor.common.SQLTypeEnum;
/**
* the JDBC Connection of DBMonitor
* @author yang zhongke
*/
public class DBConnection implements Connection
{
private Connection conn;
private DBListenerInfo[] dbListenerInfos;
public void logSql(SQLInfo info)
throws LoggerException, SQLException
{
DBLogger.getLogger(dbListenerInfos).logSQL(info);
}
public DBConnection(Connection conn,DBListenerInfo[] dbListenerInfos)
{
super();
this.conn = conn;
this.dbListenerInfos = dbListenerInfos;
}
public void clearWarnings() throws SQLException
{
conn.clearWarnings();
}
public void close() throws SQLException
{
conn.close();
}
public void commit() throws SQLException
{
conn.commit();
}
public Statement createStatement() throws SQLException
{
return new DBStatement(conn.createStatement(), this);
}
public Statement createStatement(int resultSetType, int resultSetConcurrency)
throws SQLException
{
return new DBStatement(conn.createStatement(resultSetType,
resultSetConcurrency), this);
}
public boolean getAutoCommit() throws SQLException
{
return conn.getAutoCommit();
}
public String getCatalog() throws SQLException
{
return conn.getCatalog();
}
public DatabaseMetaData getMetaData() throws SQLException
{
return conn.getMetaData();
}
public int getTransactionIsolation() throws SQLException
{
return conn.getTransactionIsolation();
}
public Map getTypeMap() throws SQLException
{
return conn.getTypeMap();
}
public SQLWarning getWarnings() throws SQLException
{
return conn.getWarnings();
}
public boolean isClosed() throws SQLException
{
return conn.isClosed();
}
public boolean isReadOnly() throws SQLException
{
return conn.isReadOnly();
}
public String nativeSQL(String sql) throws SQLException
{
return conn.nativeSQL(sql);
}
public CallableStatement prepareCall(String sql) throws SQLException
{
return conn.prepareCall(sql);
}
public CallableStatement prepareCall(String sql, int resultSetType,
int resultSetConcurrency) throws SQLException
{
return conn.prepareCall(sql, resultSetType, resultSetConcurrency);
}
public PreparedStatement prepareStatement(String sql) throws SQLException
{
return new DBPreparedStatement(conn.prepareStatement(sql),this,sql);
}
public PreparedStatement prepareStatement(String sql, int resultSetType,
int resultSetConcurrency) throws SQLException
{
return new DBPreparedStatement(conn.prepareStatement(sql,resultSetType,
resultSetConcurrency),this,sql);
}
public void rollback() throws SQLException
{
try
{
SQLInfo info = new SQLInfo();
info.setSql("");
info.setSqlType(SQLTypeEnum.rollback);
info.setBeginTime(JdbcUtils.getTimeStamp());
conn.rollback();
info.setEndTime(JdbcUtils.getTimeStamp());
logSql(info);
} catch (LoggerException e)
{
throw JdbcUtils.toSQLException(e);
}
}
public void setAutoCommit(boolean autoCommit) throws SQLException
{
conn.setAutoCommit(autoCommit);
}
public void setCatalog(String catalog) throws SQLException
{
conn.setCatalog(catalog);
}
public void setReadOnly(boolean readOnly) throws SQLException
{
conn.setReadOnly(readOnly);
}
public void setTransactionIsolation(int level) throws SQLException
{
conn.setTransactionIsolation(level);
}
public void setTypeMap(Map map) throws SQLException
{
conn.setTypeMap(map);
}
public Statement createStatement(int resultSetType,
int resultSetConcurrency, int resultSetHoldability)
throws SQLException
{
Statement stmt = conn.createStatement(resultSetType,
resultSetConcurrency, resultSetHoldability);
return new DBStatement(stmt, this);
}
public int getHoldability() throws SQLException
{
return conn.getHoldability();
}
public CallableStatement prepareCall(String sql, int resultSetType,
int resultSetConcurrency, int resultSetHoldability)
throws SQLException
{
CallableStatement stmt = conn.prepareCall(sql, resultSetType,
resultSetConcurrency, resultSetHoldability);
return stmt;
}
public PreparedStatement prepareStatement(String sql, int resultSetType,
int resultSetConcurrency, int resultSetHoldability)
throws SQLException
{
PreparedStatement stmt = conn.prepareStatement(sql, resultSetType,
resultSetConcurrency, resultSetHoldability);
return new DBPreparedStatement(stmt, this, sql);
}
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
throws SQLException
{
PreparedStatement stmt = conn.prepareStatement(sql, autoGeneratedKeys);
return new DBPreparedStatement(stmt, this, sql);
}
public PreparedStatement prepareStatement(String sql, int[] columnIndexes)
throws SQLException
{
PreparedStatement stmt = conn.prepareStatement(sql, columnIndexes);
return new DBPreparedStatement(stmt, this, sql);
}
public PreparedStatement prepareStatement(String sql, String[] columnNames)
throws SQLException
{
PreparedStatement stmt = conn.prepareStatement(sql, columnNames);
return new DBPreparedStatement(stmt, this, sql);
}
public void releaseSavepoint(Savepoint savepoint) throws SQLException
{
conn.releaseSavepoint(savepoint);
}
public void rollback(Savepoint savepoint) throws SQLException
{
try
{
SQLInfo info = new SQLInfo();
info.setSql("");
info.setSqlType(SQLTypeEnum.rollback);
info.setBeginTime(JdbcUtils.getTimeStamp());
conn.rollback(savepoint);
info.setEndTime(JdbcUtils.getTimeStamp());
logSql(info);
} catch (LoggerException e)
{
throw JdbcUtils.toSQLException(e);
}
}
public void setHoldability(int holdability) throws SQLException
{
conn.setHoldability(holdability);
}
public Savepoint setSavepoint() throws SQLException
{
return conn.setSavepoint();
}
public Savepoint setSavepoint(String name) throws SQLException
{
return conn.setSavepoint(name);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -