⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connectionwrapper.java

📁 开发MySql数据库的最新JDBC驱动。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	/**	 * The physical connection is not actually closed. the physical connection	 * is closed when the application server calls	 * mysqlPooledConnection.close(). this object is de-referenced by the pooled	 * connection each time mysqlPooledConnection.getConnection() is called by	 * app server.	 * 	 * @throws SQLException	 *             if an error occurs	 */	public void close() throws SQLException {		close(true);	}	/**	 * Passes call to method on physical connection instance. Notifies listeners	 * of any caught exceptions before re-throwing to client.	 * 	 * @throws SQLException	 *             if an error occurs	 */	public void commit() throws SQLException {		checkClosed();				if (isInGlobalTx()) {			throw SQLError.createSQLException(					"Can't call commit() on an XAConnection associated with a global transaction",					SQLError.SQL_STATE_INVALID_TRANSACTION_TERMINATION, 					MysqlErrorNumbers.ER_XA_RMERR);		}		try {			this.mc.commit();		} catch (SQLException sqlException) {			checkAndFireConnectionError(sqlException);		}	}	/**	 * Passes call to method on physical connection instance. Notifies listeners	 * of any caught exceptions before re-throwing to client.	 * 	 * @see java.sql.Connection#createStatement()	 */	public java.sql.Statement createStatement() throws SQLException {		checkClosed();		try {			return new StatementWrapper(this, this.mpc, this.mc					.createStatement());		} catch (SQLException sqlException) {			checkAndFireConnectionError(sqlException);		}		return null; // we don't reach this code, compiler can't tell	}	/**	 * Passes call to method on physical connection instance. Notifies listeners	 * of any caught exceptions before re-throwing to client.	 * 	 * @see java.sql.Connection#createStatement()	 */	public java.sql.Statement createStatement(int resultSetType,			int resultSetConcurrency) throws SQLException {		checkClosed();		try {			return new StatementWrapper(this, this.mpc, this.mc					.createStatement(resultSetType, resultSetConcurrency));		} catch (SQLException sqlException) {			checkAndFireConnectionError(sqlException);		}		return null; // we don't reach this code, compiler can't tell	}	/**	 * @see Connection#createStatement(int, int, int)	 */	public java.sql.Statement createStatement(int arg0, int arg1, int arg2)			throws SQLException {		checkClosed();		try {			return new StatementWrapper(this, this.mpc, this.mc					.createStatement(arg0, arg1, arg2));		} catch (SQLException sqlException) {			checkAndFireConnectionError(sqlException);		}		return null; // we don't reach this code, compiler can't tell	}	/**	 * Passes call to method on physical connection instance. Notifies listeners	 * of any caught exceptions before re-throwing to client.	 * 	 * @see java.sql.Connection#nativeSQL()	 */	public String nativeSQL(String sql) throws SQLException {		checkClosed();		try {			return this.mc.nativeSQL(sql);		} catch (SQLException sqlException) {			checkAndFireConnectionError(sqlException);		}		return null; // we don't reach this code, compiler can't tell	}	/**	 * Passes call to method on physical connection instance. Notifies listeners	 * of any caught exceptions before re-throwing to client.	 * 	 * @see java.sql.Connection#prepareCall()	 */	public java.sql.CallableStatement prepareCall(String sql)			throws SQLException {		checkClosed();		try {			return new CallableStatementWrapper(this, this.mpc, this.mc					.prepareCall(sql));		} catch (SQLException sqlException) {			checkAndFireConnectionError(sqlException);		}		return null; // we don't reach this code, compiler can't tell	}	/**	 * Passes call to method on physical connection instance. Notifies listeners	 * of any caught exceptions before re-throwing to client.	 * 	 * @see java.sql.Connection#prepareCall()	 */	public java.sql.CallableStatement prepareCall(String sql,			int resultSetType, int resultSetConcurrency) throws SQLException {		checkClosed();		try {			return new CallableStatementWrapper(this, this.mpc, this.mc					.prepareCall(sql, resultSetType, resultSetConcurrency));		} catch (SQLException sqlException) {			checkAndFireConnectionError(sqlException);		}		return null; // we don't reach this code, compiler can't tell	}	/**	 * @see Connection#prepareCall(String, int, int, int)	 */	public java.sql.CallableStatement prepareCall(String arg0, int arg1,			int arg2, int arg3) throws SQLException {		checkClosed();		try {			return new CallableStatementWrapper(this, this.mpc, this.mc					.prepareCall(arg0, arg1, arg2, arg3));		} catch (SQLException sqlException) {			checkAndFireConnectionError(sqlException);		}		return null; // we don't reach this code, compiler can't tell	}	public java.sql.PreparedStatement clientPrepare(String sql) throws SQLException	{		checkClosed();		try {			return new PreparedStatementWrapper(this, this.mpc, 					this.mc.clientPrepareStatement(sql));		} catch (SQLException sqlException) {			checkAndFireConnectionError(sqlException);		}				return null;	}		public java.sql.PreparedStatement clientPrepare(String sql,			int resultSetType, int resultSetConcurrency) throws SQLException	{		checkClosed();		try {			return new PreparedStatementWrapper(this, this.mpc, 					this.mc.clientPrepareStatement(sql,							resultSetType, resultSetConcurrency));		} catch (SQLException sqlException) {			checkAndFireConnectionError(sqlException);		}				return null;	}		/**	 * Passes call to method on physical connection instance. Notifies listeners	 * of any caught exceptions before re-throwing to client.	 * 	 * @see java.sql.Connection#prepareStatement()	 */	public java.sql.PreparedStatement prepareStatement(String sql)			throws SQLException {		checkClosed();		try {			return new PreparedStatementWrapper(this, this.mpc, this.mc					.prepareStatement(sql));		} catch (SQLException sqlException) {			checkAndFireConnectionError(sqlException);		}		return null; // we don't reach this code, compiler can't tell	}	/**	 * Passes call to method on physical connection instance. Notifies listeners	 * of any caught exceptions before re-throwing to client.	 * 	 * @see java.sql.Connection#prepareStatement()	 */	public java.sql.PreparedStatement prepareStatement(String sql,			int resultSetType, int resultSetConcurrency) throws SQLException {		checkClosed();		try {			return new PreparedStatementWrapper(this, this.mpc, this.mc					.prepareStatement(sql, resultSetType, resultSetConcurrency));		} catch (SQLException sqlException) {			checkAndFireConnectionError(sqlException);		}		return null; // we don't reach this code, compiler can't tell	}	/**	 * @see Connection#prepareStatement(String, int, int, int)	 */	public java.sql.PreparedStatement prepareStatement(String arg0, int arg1,			int arg2, int arg3) throws SQLException {		checkClosed();		try {			return new PreparedStatementWrapper(this, this.mpc, this.mc					.prepareStatement(arg0, arg1, arg2, arg3));		} catch (SQLException sqlException) {			checkAndFireConnectionError(sqlException);		}		return null; // we don't reach this code, compiler can't tell	}	/**	 * @see Connection#prepareStatement(String, int)	 */	public java.sql.PreparedStatement prepareStatement(String arg0, int arg1)			throws SQLException {		checkClosed();		try {			return new PreparedStatementWrapper(this, this.mpc, this.mc					.prepareStatement(arg0, arg1));		} catch (SQLException sqlException) {			checkAndFireConnectionError(sqlException);		}		return null; // we don't reach this code, compiler can't tell	}	/**	 * @see Connection#prepareStatement(String, int[])	 */	public java.sql.PreparedStatement prepareStatement(String arg0, int[] arg1)			throws SQLException {		checkClosed();		try {			return new PreparedStatementWrapper(this, this.mpc, this.mc					.prepareStatement(arg0, arg1));		} catch (SQLException sqlException) {			checkAndFireConnectionError(sqlException);		}		return null; // we don't reach this code, compiler can't tell	}	/**	 * @see Connection#prepareStatement(String, String[])	 */	public java.sql.PreparedStatement prepareStatement(String arg0,			String[] arg1) throws SQLException {		checkClosed();		try {			return new PreparedStatementWrapper(this, this.mpc, this.mc					.prepareStatement(arg0, arg1));		} catch (SQLException sqlException) {			checkAndFireConnectionError(sqlException);		}		return null; // we don't reach this code, compiler can't tell	}	/**	 * @see Connection#releaseSavepoint(Savepoint)	 */	public void releaseSavepoint(Savepoint arg0) throws SQLException {		checkClosed();		try {			this.mc.releaseSavepoint(arg0);		} catch (SQLException sqlException) {			checkAndFireConnectionError(sqlException);		}	}	/**	 * Passes call to method on physical connection instance. Notifies listeners	 * of any caught exceptions before re-throwing to client.	 * 	 * @see java.sql.Connection#rollback()	 */	public void rollback() throws SQLException {		checkClosed();		if (isInGlobalTx()) {			throw SQLError.createSQLException("Can't call rollback() on an XAConnection associated with a global transaction",					SQLError.SQL_STATE_INVALID_TRANSACTION_TERMINATION, 					MysqlErrorNumbers.ER_XA_RMERR);		}				try {			this.mc.rollback();		} catch (SQLException sqlException) {			checkAndFireConnectionError(sqlException);		}	}	/**	 * @see Connection#rollback(Savepoint)	 */	public void rollback(Savepoint arg0) throws SQLException {		checkClosed();		if (isInGlobalTx()) {			throw SQLError.createSQLException("Can't call rollback() on an XAConnection associated with a global transaction",					SQLError.SQL_STATE_INVALID_TRANSACTION_TERMINATION, 					MysqlErrorNumbers.ER_XA_RMERR);		}				try {			this.mc.rollback(arg0);		} catch (SQLException sqlException) {			checkAndFireConnectionError(sqlException);		}	}	public boolean isSameResource(Connection c) {		if (c instanceof ConnectionWrapper) {			return this.mc.isSameResource(((ConnectionWrapper)c).mc);		} else if (c instanceof com.mysql.jdbc.Connection) {			return this.mc.isSameResource((com.mysql.jdbc.Connection)c);		}				return false;	}		protected void close(boolean fireClosedEvent) throws SQLException {		synchronized (this.mpc) {			if (this.closed) {				return;			}			if (!isInGlobalTx() 					&& this.mc.getRollbackOnPooledClose()					&& !this.getAutoCommit()) {				rollback();			}			if (fireClosedEvent) {				this.mpc.callListener(						MysqlPooledConnection.CONNECTION_CLOSED_EVENT, null);			}			// set closed status to true so that if application client tries to			// make additional			// calls a sqlException will be thrown. The physical connection is			// re-used by the pooled connection each time getConnection is			// called.			this.closed = true;		}	}	private void checkClosed() throws SQLException {		if (this.closed) {			throw SQLError.createSQLException(this.invalidHandleStr);		}	}	protected boolean isInGlobalTx() {		return this.mc.isInGlobalTx();	}	protected void setInGlobalTx(boolean flag) {		this.mc.setInGlobalTx(flag);	}		public void ping() throws SQLException {		if (this.mc != null) {			this.mc.ping();		}	}}

⌨️ 快捷键说明

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