poolmanconnectionhandle.java
来自「Java Database connection pool」· Java 代码 · 共 200 行
JAVA
200 行
/* * PoolMan Java Object Pooling and Caching Library * Copyright (C) 1999-2001 The Code Studio * * 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 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. * * The full license is located at the root of this distribution * in the LICENSE file. */package com.codestudio.sql;import java.io.Serializable;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.Statement;/** * Caller-side Connection object. */public class PoolManConnectionHandle implements Connection, Serializable { private PoolManConnection pcon; public PoolManConnectionHandle(PoolManConnection c) { this.pcon = c; } void clearConnection() { this.pcon = null; } void assertConnectionExists() throws SQLException { if (this.pcon == null) throw new SQLException("Either you have already closed this Connection or it has timed out, " + "and in either case it has returned to its pool. You must re-acquire the Connection."); } public void close() throws SQLException { assertConnectionExists(); pcon.sendCloseEvent(); } public Connection getPhysicalConnection() throws SQLException { assertConnectionExists(); return pcon.getPhysicalConnection(); } public Connection getNativeConnection() throws SQLException { assertConnectionExists(); return getPhysicalConnection(); } public PoolManConnection getPoolManConnection() throws SQLException { assertConnectionExists(); return pcon; } public Statement createStatement() throws SQLException { assertConnectionExists(); return pcon.createStatement(); } public PreparedStatement prepareStatement(String sql) throws SQLException { assertConnectionExists(); return pcon.prepareStatement(sql); } public CallableStatement prepareCall(String sql) throws SQLException { assertConnectionExists(); return pcon.prepareCall(sql); } public String nativeSQL(String sql) throws SQLException { assertConnectionExists(); return pcon.nativeSQL(sql); } public void setAutoCommit(boolean autoCommit) throws SQLException { assertConnectionExists(); pcon.setAutoCommit(autoCommit); } public boolean getAutoCommit() throws SQLException { assertConnectionExists(); return pcon.getAutoCommit(); } public void commit() throws SQLException { assertConnectionExists(); pcon.commit(); } public void rollback() throws SQLException { assertConnectionExists(); this.pcon.rollback(); } public boolean isClosed() throws SQLException { if (pcon != null) return false; return true; } public DatabaseMetaData getMetaData() throws SQLException { assertConnectionExists(); return pcon.getMetaData(); } public void setReadOnly(boolean readOnly) throws SQLException { assertConnectionExists(); pcon.setReadOnly(readOnly); } public boolean isReadOnly() throws SQLException { assertConnectionExists(); return pcon.isReadOnly(); } public void setCatalog(String catalog) throws SQLException { assertConnectionExists(); pcon.setCatalog(catalog); } public String getCatalog() throws SQLException { assertConnectionExists(); return pcon.getCatalog(); } public void setTransactionIsolation(int level) throws SQLException { assertConnectionExists(); pcon.setTransactionIsolation(level); } public int getTransactionIsolation() throws SQLException { assertConnectionExists(); return pcon.getTransactionIsolation(); } public SQLWarning getWarnings() throws SQLException { assertConnectionExists(); return pcon.getWarnings(); } public void clearWarnings() throws SQLException { assertConnectionExists(); pcon.clearWarnings(); } public Statement createStatement(int resultSetType, int resultSetPconcurrency) throws SQLException { assertConnectionExists(); return pcon.createStatement(resultSetType, resultSetPconcurrency); } public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetPconcurrency) throws SQLException { assertConnectionExists(); return pcon.prepareStatement(sql, resultSetType, resultSetPconcurrency); } public CallableStatement prepareCall(String sql, int resultSetType, int resultSetPconcurrency) throws SQLException { assertConnectionExists(); return pcon.prepareCall(sql, resultSetType, resultSetPconcurrency); } public java.util.Map getTypeMap() throws SQLException { assertConnectionExists(); return pcon.getTypeMap(); } public void setTypeMap(java.util.Map map) throws SQLException { assertConnectionExists(); pcon.setTypeMap(map); } /* OBJECT METHODS */ public String toString() { return "PoolManConnectionHandle-" + pcon.toString(); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?