KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > winstone > jndi > resourceFactories > WinstoneConnection


1 /*
2  * Copyright 2003-2006 Rick Knowles <winstone-devel at lists sourceforge net>
3  * Distributed under the terms of either:
4  * - the common development and distribution license (CDDL), v1.0; or
5  * - the GNU Lesser General Public License, v2.1 or later
6  */

7 package winstone.jndi.resourceFactories;
8
9 import java.sql.CallableStatement JavaDoc;
10 import java.sql.Connection JavaDoc;
11 import java.sql.DatabaseMetaData JavaDoc;
12 import java.sql.PreparedStatement JavaDoc;
13 import java.sql.SQLException JavaDoc;
14 import java.sql.SQLWarning JavaDoc;
15 import java.sql.Savepoint JavaDoc;
16 import java.sql.Statement JavaDoc;
17 import java.util.Map JavaDoc;
18
19 import winstone.Logger;
20
21 /**
22  * JDBC Connection wrapper for use in the pooling datasource. This just suppresses
23  * the close() call, and releases the connection.
24  *
25  * @author <a HREF="mailto:rick_knowles@hotmail.com">Rick Knowles</a>
26  * @version $Id: WinstoneConnection.java,v 1.3 2006/02/28 07:32:48 rickknowles Exp $
27  */

28 public class WinstoneConnection implements Connection JavaDoc {
29     private Connection JavaDoc realConnection;
30     private WinstoneDataSource datasource;
31
32     /**
33      * Constructor - this sets the real connection and the link back to the pool
34      */

35     public WinstoneConnection(Connection JavaDoc connection,
36             WinstoneDataSource datasource) {
37         this.realConnection = connection;
38         this.datasource = datasource;
39     }
40
41     public void close() throws SQLException JavaDoc {
42         if ((this.datasource != null) && (this.datasource.getLogWriter() != null)) {
43             this.datasource.getLogWriter().println(
44                     WinstoneDataSource.DS_RESOURCES.getString(
45                             "WinstoneConnection.ReleaseRollback"));
46         } else {
47             Logger.log(Logger.FULL_DEBUG, WinstoneDataSource.DS_RESOURCES,
48                     "WinstoneConnection.ReleaseRollback");
49         }
50         
51         Connection JavaDoc realConnectionHolder = null;
52         try {
53             if (this.realConnection != null) {
54                 realConnectionHolder = this.realConnection;
55                 this.realConnection = null;
56                 
57                 if (!realConnectionHolder.getAutoCommit())
58                     realConnectionHolder.rollback();
59             }
60         } finally {
61             if ((this.datasource != null) && (realConnectionHolder != null)) {
62                 this.datasource.releaseConnection(this, realConnectionHolder);
63                 this.datasource = null;
64             }
65         }
66     }
67
68     public boolean isClosed() throws SQLException JavaDoc {
69         return (this.realConnection == null);
70     }
71
72     public void commit() throws SQLException JavaDoc {
73         this.realConnection.commit();
74     }
75
76     public void rollback() throws SQLException JavaDoc {
77         this.realConnection.rollback();
78     }
79
80     public void rollback(Savepoint JavaDoc sp) throws SQLException JavaDoc {
81         this.realConnection.rollback(sp);
82     }
83
84     public boolean getAutoCommit() throws SQLException JavaDoc {
85         return this.realConnection.getAutoCommit();
86     }
87
88     public void setAutoCommit(boolean autoCommit) throws SQLException JavaDoc {
89         this.realConnection.setAutoCommit(autoCommit);
90     }
91
92     public int getHoldability() throws SQLException JavaDoc {
93         return this.realConnection.getHoldability();
94     }
95
96     public void setHoldability(int hold) throws SQLException JavaDoc {
97         this.realConnection.setHoldability(hold);
98     }
99
100     public int getTransactionIsolation() throws SQLException JavaDoc {
101         return this.realConnection.getTransactionIsolation();
102     }
103
104     public void setTransactionIsolation(int level) throws SQLException JavaDoc {
105         this.realConnection.setTransactionIsolation(level);
106     }
107
108     public void clearWarnings() throws SQLException JavaDoc {
109         this.realConnection.clearWarnings();
110     }
111
112     public SQLWarning JavaDoc getWarnings() throws SQLException JavaDoc {
113         return this.realConnection.getWarnings();
114     }
115
116     public boolean isReadOnly() throws SQLException JavaDoc {
117         return this.realConnection.isReadOnly();
118     }
119
120     public void setReadOnly(boolean ro) throws SQLException JavaDoc {
121         this.realConnection.setReadOnly(ro);
122     }
123
124     public String JavaDoc getCatalog() throws SQLException JavaDoc {
125         return this.realConnection.getCatalog();
126     }
127
128     public void setCatalog(String JavaDoc catalog) throws SQLException JavaDoc {
129         this.realConnection.setCatalog(catalog);
130     }
131
132     public DatabaseMetaData JavaDoc getMetaData() throws SQLException JavaDoc {
133         return this.realConnection.getMetaData();
134     }
135
136     public Savepoint JavaDoc setSavepoint() throws SQLException JavaDoc {
137         return this.realConnection.setSavepoint();
138     }
139
140     public Savepoint JavaDoc setSavepoint(String JavaDoc name) throws SQLException JavaDoc {
141         return this.realConnection.setSavepoint(name);
142     }
143
144     public void releaseSavepoint(Savepoint JavaDoc sp) throws SQLException JavaDoc {
145         this.realConnection.releaseSavepoint(sp);
146     }
147
148     public Map JavaDoc getTypeMap() throws SQLException JavaDoc {
149         return this.realConnection.getTypeMap();
150     }
151
152     public void setTypeMap(Map JavaDoc map) throws SQLException JavaDoc {
153         this.realConnection.setTypeMap(map);
154     }
155
156     public String JavaDoc nativeSQL(String JavaDoc sql) throws SQLException JavaDoc {
157         return this.realConnection.nativeSQL(sql);
158     }
159
160     public CallableStatement JavaDoc prepareCall(String JavaDoc sql) throws SQLException JavaDoc {
161         return this.realConnection.prepareCall(sql);
162     }
163
164     public CallableStatement JavaDoc prepareCall(String JavaDoc sql, int resultSetType,
165             int resultSetConcurrency) throws SQLException JavaDoc {
166         return this.realConnection.prepareCall(sql, resultSetType,
167                 resultSetConcurrency);
168     }
169
170     public CallableStatement JavaDoc prepareCall(String JavaDoc sql, int resultSetType,
171             int resultSetConcurrency, int resultSetHoldability)
172             throws SQLException JavaDoc {
173         return this.realConnection.prepareCall(sql, resultSetType,
174                 resultSetConcurrency, resultSetHoldability);
175     }
176
177     public Statement JavaDoc createStatement() throws SQLException JavaDoc {
178         return this.realConnection.createStatement();
179     }
180
181     public Statement JavaDoc createStatement(int resultSetType, int resultSetConcurrency)
182             throws SQLException JavaDoc {
183         return this.realConnection.createStatement(resultSetType,
184                 resultSetConcurrency);
185     }
186
187     public Statement JavaDoc createStatement(int resultSetType,
188             int resultSetConcurrency, int resultSetHoldability)
189             throws SQLException JavaDoc {
190         return this.realConnection.createStatement(resultSetType,
191                 resultSetConcurrency, resultSetHoldability);
192     }
193
194     public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql) throws SQLException JavaDoc {
195         return this.realConnection.prepareStatement(sql);
196     }
197
198     public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql, int autogeneratedKeys)
199             throws SQLException JavaDoc {
200         return this.realConnection.prepareStatement(sql, autogeneratedKeys);
201     }
202
203     public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql, int resultSetType,
204             int resultSetConcurrency) throws SQLException JavaDoc {
205         return this.realConnection.prepareStatement(sql, resultSetType,
206                 resultSetConcurrency);
207     }
208
209     public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql, int resultSetType,
210             int resultSetConcurrency, int resultSetHoldability)
211             throws SQLException JavaDoc {
212         return this.realConnection.prepareStatement(sql, resultSetType,
213                 resultSetConcurrency, resultSetHoldability);
214     }
215
216     public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql, int[] columnIndexes)
217             throws SQLException JavaDoc {
218         return this.realConnection.prepareStatement(sql, columnIndexes);
219     }
220
221     public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql, String JavaDoc[] columnNames)
222             throws SQLException JavaDoc {
223         return this.realConnection.prepareStatement(sql, columnNames);
224     }
225 }
226
Popular Tags