📄 connectionproxy.java
字号:
// jTDS JDBC Driver for Microsoft SQL Server and Sybase
// Copyright (C) 2004 The jTDS Project
//
// 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
package net.sourceforge.jtds.jdbcx.proxy;
import java.sql.*;
import java.util.Map;
import net.sourceforge.jtds.jdbc.*;
import net.sourceforge.jtds.jdbcx.*;
/**
* This class would be better implemented as a java.lang.reflect.Proxy. However, this
* feature was not added until 1.3 and reflection performance was not improved until 1.4.
* Since the driver still needs to be compatible with 1.2 and 1.3 this class is used
* to delegate the calls to the connection with minimal overhead.
*
* @version $Id: ConnectionProxy.java,v 1.7 2005/04/20 16:49:30 alin_sinpalean Exp $
*/
public class ConnectionProxy implements Connection {
private PooledConnection _pooledConnection;
private ConnectionJDBC2 _connection;
private boolean _closed;
/**
* Constructs a new connection proxy.
*/
public ConnectionProxy(PooledConnection pooledConnection,
Connection connection) {
_pooledConnection = pooledConnection;
_connection = (ConnectionJDBC2) connection;
}
/**
* Delgates calls to the connection; SQLExceptions thrown from the connection
* will cause an event to be fired on the connection pool listeners.
*
* @throws SQLException if an error occurs
*/
public void clearWarnings() throws SQLException {
validateConnection();
try {
_connection.clearWarnings();
} catch (SQLException sqlException) {
processSQLException(sqlException);
}
}
/**
* Delgates calls to the connection; SQLExceptions thrown from the connection
* will cause an event to be fired on the connection pool listeners.
*/
public void close() {
if (_closed) {
return;
}
_pooledConnection.fireConnectionEvent(true, null);
_closed = true;
}
/**
* Delgates calls to the connection; SQLExceptions thrown from the connection
* will cause an event to be fired on the connection pool listeners.
*
* @throws SQLException if an error occurs
*/
public void commit() throws SQLException {
validateConnection();
try {
_connection.commit();
} catch (SQLException sqlException) {
processSQLException(sqlException);
}
}
/**
* Delgates calls to the connection; SQLExceptions thrown from the connection
* will cause an event to be fired on the connection pool listeners.
*
* @throws SQLException if an error occurs
*/
public Statement createStatement() throws SQLException {
validateConnection();
try {
return new StatementProxy(this, (JtdsStatement) _connection.createStatement());
} catch (SQLException sqlException) {
processSQLException(sqlException);
}
return null;
}
/**
* Delgates calls to the connection; SQLExceptions thrown from the connection
* will cause an event to be fired on the connection pool listeners.
*
* @throws SQLException if an error occurs
*/
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
validateConnection();
try {
return new StatementProxy(this, (JtdsStatement) _connection.createStatement(resultSetType, resultSetConcurrency));
} catch (SQLException sqlException) {
processSQLException(sqlException);
}
return null;
}
/**
* Delgates calls to the connection; SQLExceptions thrown from the connection
* will cause an event to be fired on the connection pool listeners.
*
* @throws SQLException if an error occurs
*/
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
validateConnection();
try {
return new StatementProxy(this, (JtdsStatement) _connection.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability));
} catch (SQLException sqlException) {
processSQLException(sqlException);
}
return null;
}
/**
* Delgates calls to the connection; SQLExceptions thrown from the connection
* will cause an event to be fired on the connection pool listeners.
*
* @throws SQLException if an error occurs
*/
public boolean getAutoCommit() throws SQLException {
validateConnection();
try {
return _connection.getAutoCommit();
} catch (SQLException sqlException) {
processSQLException(sqlException);
}
return false;
}
/**
* Delgates calls to the connection; SQLExceptions thrown from the connection
* will cause an event to be fired on the connection pool listeners.
*
* @throws SQLException if an error occurs
*/
public String getCatalog() throws SQLException {
validateConnection();
try {
return _connection.getCatalog();
} catch (SQLException sqlException) {
processSQLException(sqlException);
}
return null;
}
/**
* Delgates calls to the connection; SQLExceptions thrown from the connection
* will cause an event to be fired on the connection pool listeners.
*
* @throws SQLException if an error occurs
*/
public int getHoldability() throws SQLException {
validateConnection();
try {
return _connection.getHoldability();
} catch (SQLException sqlException) {
processSQLException(sqlException);
}
return Integer.MIN_VALUE;
}
/**
* Delgates calls to the connection; SQLExceptions thrown from the connection
* will cause an event to be fired on the connection pool listeners.
*
* @throws SQLException if an error occurs
*/
public int getTransactionIsolation() throws SQLException {
validateConnection();
try {
return _connection.getTransactionIsolation();
} catch (SQLException sqlException) {
processSQLException(sqlException);
}
return Integer.MIN_VALUE;
}
/**
* Delgates calls to the connection; SQLExceptions thrown from the connection
* will cause an event to be fired on the connection pool listeners.
*
* @throws SQLException if an error occurs
*/
public Map getTypeMap() throws SQLException {
validateConnection();
try {
return _connection.getTypeMap();
} catch (SQLException sqlException) {
processSQLException(sqlException);
}
return null;
}
/**
* Delgates calls to the connection; SQLExceptions thrown from the connection
* will cause an event to be fired on the connection pool listeners.
*
* @throws SQLException if an error occurs
*/
public SQLWarning getWarnings() throws SQLException {
validateConnection();
try {
return _connection.getWarnings();
} catch (SQLException sqlException) {
processSQLException(sqlException);
}
return null;
}
/**
* Delgates calls to the connection; SQLExceptions thrown from the connection
* will cause an event to be fired on the connection pool listeners.
*
* @throws SQLException if an error occurs
*/
public DatabaseMetaData getMetaData() throws SQLException {
validateConnection();
try {
return _connection.getMetaData();
} catch (SQLException sqlException) {
processSQLException(sqlException);
}
return null;
}
/**
* Delgates calls to the connection; SQLExceptions thrown from the connection
* will cause an event to be fired on the connection pool listeners.
*
* @throws SQLException if an error occurs
*/
public boolean isClosed() throws SQLException {
if (_closed) {
return true;
}
try {
return _connection.isClosed();
} catch (SQLException sqlException) {
processSQLException(sqlException);
}
return _closed;
}
/**
* Delgates calls to the connection; SQLExceptions thrown from the connection
* will cause an event to be fired on the connection pool listeners.
*
* @throws SQLException if an error occurs
*/
public boolean isReadOnly() throws SQLException {
validateConnection();
try {
return _connection.isReadOnly();
} catch (SQLException sqlException) {
processSQLException(sqlException);
}
return false;
}
/**
* Delgates calls to the connection; SQLExceptions thrown from the connection
* will cause an event to be fired on the connection pool listeners.
*
* @throws SQLException if an error occurs
*/
public String nativeSQL(String sql) throws SQLException {
validateConnection();
try {
return _connection.nativeSQL(sql);
} catch (SQLException sqlException) {
processSQLException(sqlException);
}
return null;
}
/**
* Delgates calls to the connection; SQLExceptions thrown from the connection
* will cause an event to be fired on the connection pool listeners.
*
* @throws SQLException if an error occurs
*/
public CallableStatement prepareCall(String sql) throws SQLException {
validateConnection();
try {
return new CallableStatementProxy(this, (JtdsCallableStatement) _connection.prepareCall(sql));
} catch (SQLException sqlException) {
processSQLException(sqlException);
}
return null;
}
/**
* Delgates calls to the connection; SQLExceptions thrown from the connection
* will cause an event to be fired on the connection pool listeners.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -