001: /*
002: * Copyright 2003-2006 Rick Knowles <winstone-devel at lists sourceforge net>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: */
007: package winstone.jndi.resourceFactories;
008:
009: import java.sql.CallableStatement;
010: import java.sql.Connection;
011: import java.sql.DatabaseMetaData;
012: import java.sql.PreparedStatement;
013: import java.sql.SQLException;
014: import java.sql.SQLWarning;
015: import java.sql.Savepoint;
016: import java.sql.Statement;
017: import java.util.Map;
018:
019: import winstone.Logger;
020:
021: /**
022: * JDBC Connection wrapper for use in the pooling datasource. This just suppresses
023: * the close() call, and releases the connection.
024: *
025: * @author <a href="mailto:rick_knowles@hotmail.com">Rick Knowles</a>
026: * @version $Id: WinstoneConnection.java,v 1.3 2006/02/28 07:32:48 rickknowles Exp $
027: */
028: public class WinstoneConnection implements Connection {
029: private Connection realConnection;
030: private WinstoneDataSource datasource;
031:
032: /**
033: * Constructor - this sets the real connection and the link back to the pool
034: */
035: public WinstoneConnection(Connection connection,
036: WinstoneDataSource datasource) {
037: this .realConnection = connection;
038: this .datasource = datasource;
039: }
040:
041: public void close() throws SQLException {
042: if ((this .datasource != null)
043: && (this .datasource.getLogWriter() != null)) {
044: this .datasource
045: .getLogWriter()
046: .println(
047: WinstoneDataSource.DS_RESOURCES
048: .getString("WinstoneConnection.ReleaseRollback"));
049: } else {
050: Logger.log(Logger.FULL_DEBUG,
051: WinstoneDataSource.DS_RESOURCES,
052: "WinstoneConnection.ReleaseRollback");
053: }
054:
055: Connection realConnectionHolder = null;
056: try {
057: if (this .realConnection != null) {
058: realConnectionHolder = this .realConnection;
059: this .realConnection = null;
060:
061: if (!realConnectionHolder.getAutoCommit())
062: realConnectionHolder.rollback();
063: }
064: } finally {
065: if ((this .datasource != null)
066: && (realConnectionHolder != null)) {
067: this .datasource.releaseConnection(this ,
068: realConnectionHolder);
069: this .datasource = null;
070: }
071: }
072: }
073:
074: public boolean isClosed() throws SQLException {
075: return (this .realConnection == null);
076: }
077:
078: public void commit() throws SQLException {
079: this .realConnection.commit();
080: }
081:
082: public void rollback() throws SQLException {
083: this .realConnection.rollback();
084: }
085:
086: public void rollback(Savepoint sp) throws SQLException {
087: this .realConnection.rollback(sp);
088: }
089:
090: public boolean getAutoCommit() throws SQLException {
091: return this .realConnection.getAutoCommit();
092: }
093:
094: public void setAutoCommit(boolean autoCommit) throws SQLException {
095: this .realConnection.setAutoCommit(autoCommit);
096: }
097:
098: public int getHoldability() throws SQLException {
099: return this .realConnection.getHoldability();
100: }
101:
102: public void setHoldability(int hold) throws SQLException {
103: this .realConnection.setHoldability(hold);
104: }
105:
106: public int getTransactionIsolation() throws SQLException {
107: return this .realConnection.getTransactionIsolation();
108: }
109:
110: public void setTransactionIsolation(int level) throws SQLException {
111: this .realConnection.setTransactionIsolation(level);
112: }
113:
114: public void clearWarnings() throws SQLException {
115: this .realConnection.clearWarnings();
116: }
117:
118: public SQLWarning getWarnings() throws SQLException {
119: return this .realConnection.getWarnings();
120: }
121:
122: public boolean isReadOnly() throws SQLException {
123: return this .realConnection.isReadOnly();
124: }
125:
126: public void setReadOnly(boolean ro) throws SQLException {
127: this .realConnection.setReadOnly(ro);
128: }
129:
130: public String getCatalog() throws SQLException {
131: return this .realConnection.getCatalog();
132: }
133:
134: public void setCatalog(String catalog) throws SQLException {
135: this .realConnection.setCatalog(catalog);
136: }
137:
138: public DatabaseMetaData getMetaData() throws SQLException {
139: return this .realConnection.getMetaData();
140: }
141:
142: public Savepoint setSavepoint() throws SQLException {
143: return this .realConnection.setSavepoint();
144: }
145:
146: public Savepoint setSavepoint(String name) throws SQLException {
147: return this .realConnection.setSavepoint(name);
148: }
149:
150: public void releaseSavepoint(Savepoint sp) throws SQLException {
151: this .realConnection.releaseSavepoint(sp);
152: }
153:
154: public Map getTypeMap() throws SQLException {
155: return this .realConnection.getTypeMap();
156: }
157:
158: public void setTypeMap(Map map) throws SQLException {
159: this .realConnection.setTypeMap(map);
160: }
161:
162: public String nativeSQL(String sql) throws SQLException {
163: return this .realConnection.nativeSQL(sql);
164: }
165:
166: public CallableStatement prepareCall(String sql)
167: throws SQLException {
168: return this .realConnection.prepareCall(sql);
169: }
170:
171: public CallableStatement prepareCall(String sql, int resultSetType,
172: int resultSetConcurrency) throws SQLException {
173: return this .realConnection.prepareCall(sql, resultSetType,
174: resultSetConcurrency);
175: }
176:
177: public CallableStatement prepareCall(String sql, int resultSetType,
178: int resultSetConcurrency, int resultSetHoldability)
179: throws SQLException {
180: return this .realConnection.prepareCall(sql, resultSetType,
181: resultSetConcurrency, resultSetHoldability);
182: }
183:
184: public Statement createStatement() throws SQLException {
185: return this .realConnection.createStatement();
186: }
187:
188: public Statement createStatement(int resultSetType,
189: int resultSetConcurrency) throws SQLException {
190: return this .realConnection.createStatement(resultSetType,
191: resultSetConcurrency);
192: }
193:
194: public Statement createStatement(int resultSetType,
195: int resultSetConcurrency, int resultSetHoldability)
196: throws SQLException {
197: return this .realConnection.createStatement(resultSetType,
198: resultSetConcurrency, resultSetHoldability);
199: }
200:
201: public PreparedStatement prepareStatement(String sql)
202: throws SQLException {
203: return this .realConnection.prepareStatement(sql);
204: }
205:
206: public PreparedStatement prepareStatement(String sql,
207: int autogeneratedKeys) throws SQLException {
208: return this .realConnection.prepareStatement(sql,
209: autogeneratedKeys);
210: }
211:
212: public PreparedStatement prepareStatement(String sql,
213: int resultSetType, int resultSetConcurrency)
214: throws SQLException {
215: return this .realConnection.prepareStatement(sql, resultSetType,
216: resultSetConcurrency);
217: }
218:
219: public PreparedStatement prepareStatement(String sql,
220: int resultSetType, int resultSetConcurrency,
221: int resultSetHoldability) throws SQLException {
222: return this .realConnection.prepareStatement(sql, resultSetType,
223: resultSetConcurrency, resultSetHoldability);
224: }
225:
226: public PreparedStatement prepareStatement(String sql,
227: int[] columnIndexes) throws SQLException {
228: return this .realConnection.prepareStatement(sql, columnIndexes);
229: }
230:
231: public PreparedStatement prepareStatement(String sql,
232: String[] columnNames) throws SQLException {
233: return this.realConnection.prepareStatement(sql, columnNames);
234: }
235: }
|