001: /*
002: * $Header: /cvsroot/mvnforum/myvietnam/src/net/myvietnam/mvncore/db/ConnectionWrapper.java,v 1.6 2007/09/26 04:11:07 minhnn Exp $
003: * $Author: minhnn $
004: * $Revision: 1.6 $
005: * $Date: 2007/09/26 04:11:07 $
006: *
007: * ====================================================================
008: *
009: * Copyright (C) 2002-2007 by MyVietnam.net
010: *
011: * All copyright notices regarding MyVietnam and MyVietnam CoreLib
012: * MUST remain intact in the scripts and source code.
013: *
014: * This library is free software; you can redistribute it and/or
015: * modify it under the terms of the GNU Lesser General Public
016: * License as published by the Free Software Foundation; either
017: * version 2.1 of the License, or (at your option) any later version.
018: *
019: * This library is distributed in the hope that it will be useful,
020: * but WITHOUT ANY WARRANTY; without even the implied warranty of
021: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
022: * Lesser General Public License for more details.
023: *
024: * You should have received a copy of the GNU Lesser General Public
025: * License along with this library; if not, write to the Free Software
026: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
027: *
028: * Correspondence and Marketing Questions can be sent to:
029: * info at MyVietnam net
030: *
031: * @author: Minh Nguyen
032: */
033: package net.myvietnam.mvncore.db;
034:
035: import java.sql.*;
036: import java.util.Map;
037: import java.util.Properties;
038:
039: import org.apache.commons.lang.NotImplementedException;
040:
041: public class ConnectionWrapper implements Connection {
042:
043: private DBConnectionManager connectionManager = null;
044:
045: private static int outsideConnection = 0;
046:
047: Connection delegate = null;
048:
049: ConnectionWrapper(Connection original,
050: DBConnectionManager conManager) {
051: if (original == null) {
052: throw new IllegalArgumentException(
053: "Cannot accept the connection is null.");
054: }
055: if (conManager == null) {
056: throw new IllegalArgumentException(
057: "Cannot accept the DBConnectionManager is null.");
058: }
059: delegate = original;
060: connectionManager = conManager;
061: outsideConnection++;
062: }
063:
064: private void makeSureNotClose() {
065: if (delegate == null) {
066: throw new IllegalStateException(
067: "Connection has been closed (delegate == null).");
068: }
069: }
070:
071: public void close() throws SQLException {
072: //delegate.close();
073: if (delegate != null) {
074: connectionManager.freeConnection(delegate);
075: delegate = null;
076: outsideConnection--;
077: }
078: }
079:
080: public void clearWarnings() throws SQLException {
081: makeSureNotClose();
082: delegate.clearWarnings();
083: }
084:
085: public void commit() throws SQLException {
086: makeSureNotClose();
087: delegate.commit();
088: }
089:
090: public Statement createStatement() throws SQLException {
091: makeSureNotClose();
092: return delegate.createStatement();
093: }
094:
095: public Statement createStatement(int resultSetType,
096: int resultSetConcurrency, int resultSetHoldability)
097: throws SQLException {
098: makeSureNotClose();
099: return delegate.createStatement(resultSetType,
100: resultSetConcurrency, resultSetHoldability);
101: }
102:
103: public Statement createStatement(int resultSetType,
104: int resultSetConcurrency) throws SQLException {
105: makeSureNotClose();
106: return delegate.createStatement(resultSetType,
107: resultSetConcurrency);
108: }
109:
110: public boolean getAutoCommit() throws SQLException {
111: makeSureNotClose();
112: return delegate.getAutoCommit();
113: }
114:
115: public String getCatalog() throws SQLException {
116: makeSureNotClose();
117: return delegate.getCatalog();
118: }
119:
120: public int getHoldability() throws SQLException {
121: makeSureNotClose();
122: return delegate.getHoldability();
123: }
124:
125: public DatabaseMetaData getMetaData() throws SQLException {
126: makeSureNotClose();
127: return delegate.getMetaData();
128: }
129:
130: public int getTransactionIsolation() throws SQLException {
131: makeSureNotClose();
132: return delegate.getTransactionIsolation();
133: }
134:
135: public Map getTypeMap() throws SQLException {
136: makeSureNotClose();
137: return delegate.getTypeMap();
138: }
139:
140: public SQLWarning getWarnings() throws SQLException {
141: makeSureNotClose();
142: return delegate.getWarnings();
143: }
144:
145: public boolean isClosed() throws SQLException {
146: makeSureNotClose();
147: return delegate.isClosed();
148: }
149:
150: public boolean isReadOnly() throws SQLException {
151: makeSureNotClose();
152: return delegate.isReadOnly();
153: }
154:
155: public String nativeSQL(String sql) throws SQLException {
156: makeSureNotClose();
157: return delegate.nativeSQL(sql);
158: }
159:
160: public CallableStatement prepareCall(String sql, int resultSetType,
161: int resultSetConcurrency, int resultSetHoldability)
162: throws SQLException {
163: makeSureNotClose();
164: return delegate.prepareCall(sql, resultSetType,
165: resultSetConcurrency, resultSetHoldability);
166: }
167:
168: public CallableStatement prepareCall(String sql, int resultSetType,
169: int resultSetConcurrency) throws SQLException {
170: makeSureNotClose();
171: return delegate.prepareCall(sql, resultSetType,
172: resultSetConcurrency);
173: }
174:
175: public CallableStatement prepareCall(String sql)
176: throws SQLException {
177: makeSureNotClose();
178: return delegate.prepareCall(sql);
179: }
180:
181: public PreparedStatement prepareStatement(String sql,
182: int resultSetType, int resultSetConcurrency,
183: int resultSetHoldability) throws SQLException {
184: makeSureNotClose();
185: return delegate.prepareStatement(sql, resultSetType,
186: resultSetConcurrency, resultSetHoldability);
187: }
188:
189: public PreparedStatement prepareStatement(String sql,
190: int resultSetType, int resultSetConcurrency)
191: throws SQLException {
192: makeSureNotClose();
193: return delegate.prepareStatement(sql, resultSetType,
194: resultSetConcurrency);
195: }
196:
197: public PreparedStatement prepareStatement(String sql,
198: int autoGeneratedKeys) throws SQLException {
199: makeSureNotClose();
200: return delegate.prepareStatement(sql, autoGeneratedKeys);
201: }
202:
203: public PreparedStatement prepareStatement(String sql,
204: int[] columnIndexes) throws SQLException {
205: makeSureNotClose();
206: return delegate.prepareStatement(sql, columnIndexes);
207: }
208:
209: public PreparedStatement prepareStatement(String sql,
210: String[] columnNames) throws SQLException {
211: makeSureNotClose();
212: return delegate.prepareStatement(sql, columnNames);
213: }
214:
215: public PreparedStatement prepareStatement(String sql)
216: throws SQLException {
217: makeSureNotClose();
218: return delegate.prepareStatement(sql);
219: }
220:
221: public void releaseSavepoint(Savepoint savepoint)
222: throws SQLException {
223: makeSureNotClose();
224: delegate.releaseSavepoint(savepoint);
225: }
226:
227: public void rollback() throws SQLException {
228: makeSureNotClose();
229: delegate.rollback();
230: }
231:
232: public void rollback(Savepoint savepoint) throws SQLException {
233: makeSureNotClose();
234: delegate.rollback(savepoint);
235: }
236:
237: public void setAutoCommit(boolean autoCommit) throws SQLException {
238: makeSureNotClose();
239: delegate.setAutoCommit(autoCommit);
240: }
241:
242: public void setCatalog(String catalog) throws SQLException {
243: makeSureNotClose();
244: delegate.setCatalog(catalog);
245: }
246:
247: public void setHoldability(int holdability) throws SQLException {
248: makeSureNotClose();
249: delegate.setHoldability(holdability);
250: }
251:
252: public void setReadOnly(boolean readOnly) throws SQLException {
253: makeSureNotClose();
254: delegate.setReadOnly(readOnly);
255: }
256:
257: public Savepoint setSavepoint() throws SQLException {
258: makeSureNotClose();
259: return delegate.setSavepoint();
260: }
261:
262: public Savepoint setSavepoint(String name) throws SQLException {
263: makeSureNotClose();
264: return delegate.setSavepoint(name);
265: }
266:
267: public void setTransactionIsolation(int level) throws SQLException {
268: makeSureNotClose();
269: delegate.setTransactionIsolation(level);
270: }
271:
272: public void setTypeMap(Map map) throws SQLException {
273: makeSureNotClose();
274: delegate.setTypeMap(map);
275: }
276:
277: public Array createArrayOf(String typeName, Object[] elements)
278: throws SQLException {
279: throw new NotImplementedException("createArrayOf");
280: }
281:
282: public Blob createBlob() throws SQLException {
283: throw new NotImplementedException("createBlob");
284: }
285:
286: public Clob createClob() throws SQLException {
287: throw new NotImplementedException("createClob");
288: }
289:
290: public NClob createNClob() throws SQLException {
291: throw new NotImplementedException("createNClob");
292: }
293:
294: public SQLXML createSQLXML() throws SQLException {
295: throw new NotImplementedException("createSQLXML");
296: }
297:
298: public Struct createStruct(String typeName, Object[] attributes)
299: throws SQLException {
300: throw new NotImplementedException("createStruct");
301: }
302:
303: public Properties getClientInfo() throws SQLException {
304: throw new NotImplementedException("getClientInfo");
305: }
306:
307: public String getClientInfo(String name) throws SQLException {
308: throw new NotImplementedException("getClientInfo");
309: }
310:
311: public boolean isValid(int timeout) throws SQLException {
312: throw new NotImplementedException("isValid");
313: }
314:
315: public void setClientInfo(Properties properties)
316: throws SQLClientInfoException {
317: throw new NotImplementedException("setClientInfo");
318: }
319:
320: public void setClientInfo(String name, String value)
321: throws SQLClientInfoException {
322: throw new NotImplementedException("setClientInfo");
323: }
324:
325: public boolean isWrapperFor(Class iface) throws SQLException {
326: throw new NotImplementedException("isWrapperFor");
327: }
328:
329: public Object unwrap(Class iface) throws SQLException {
330: throw new NotImplementedException("unwrap");
331: }
332: }
|