KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > jdbc > ClientConnection


1 /* JFox, the OpenSource J2EE Application Server
2  *
3  * Distributable under GNU LGPL license by gun.org
4  * more details please visit http://www.huihoo.org/jfox
5  */

6
7 package org.jfox.jdbc;
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 /**
20  * ClientConnection 拦截 close 调用,使其无效
21  * 对于 Oracle,是不能调用 close 方法的,否则事务无法提交
22  *
23  * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>
24  */

25
26 public class ClientConnection implements Connection JavaDoc {
27     private Connection JavaDoc conn = null;
28     private boolean isClosed = false;
29
30     public ClientConnection(Connection JavaDoc conn) {
31         if(conn == null) {
32             throw new RuntimeException JavaDoc("conn is null.");
33         }
34         try {
35             if(conn.isClosed()) {
36                 throw new RuntimeException JavaDoc("conn is closed.");
37             }
38         }
39         catch(SQLException JavaDoc e) {
40             throw new RuntimeException JavaDoc(e);
41         }
42         this.conn = conn;
43     }
44
45     public void rollback(Savepoint JavaDoc savepoint) throws SQLException JavaDoc {
46         checkClosed();
47         conn.rollback(savepoint);
48     }
49
50     public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql, String JavaDoc columnNames[]) throws SQLException JavaDoc {
51         checkClosed();
52         return new LoggablePreparedStatement(conn.prepareStatement(sql, columnNames), sql);
53     }
54
55     public CallableStatement JavaDoc prepareCall(String JavaDoc sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException JavaDoc {
56         checkClosed();
57         return conn.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
58     }
59
60     public void rollback() throws SQLException JavaDoc {
61         conn.rollback();
62     }
63
64     public DatabaseMetaData JavaDoc getMetaData() throws SQLException JavaDoc {
65         checkClosed();
66         return conn.getMetaData();
67     }
68
69     public SQLWarning JavaDoc getWarnings() throws SQLException JavaDoc {
70         checkClosed();
71         return conn.getWarnings();
72     }
73
74     public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql, int columnIndexes[]) throws SQLException JavaDoc {
75         checkClosed();
76         return new LoggablePreparedStatement(conn.prepareStatement(sql, columnIndexes), sql);
77     }
78
79     public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException JavaDoc {
80         checkClosed();
81         return new LoggablePreparedStatement(conn.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability), sql);
82     }
83
84     public boolean getAutoCommit() throws SQLException JavaDoc {
85         checkClosed();
86         return conn.getAutoCommit();
87     }
88
89     public String JavaDoc nativeSQL(String JavaDoc sql) throws SQLException JavaDoc {
90         checkClosed();
91         return conn.nativeSQL(sql);
92     }
93
94     public void setTransactionIsolation(int level) throws SQLException JavaDoc {
95         checkClosed();
96         conn.setTransactionIsolation(level);
97     }
98
99     public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql) throws SQLException JavaDoc {
100         checkClosed();
101         return new LoggablePreparedStatement(conn.prepareStatement(sql), sql);
102     }
103
104     public int getHoldability() throws SQLException JavaDoc {
105         checkClosed();
106         return conn.getHoldability();
107     }
108
109     public void clearWarnings() throws SQLException JavaDoc {
110         checkClosed();
111         conn.clearWarnings();
112     }
113
114     public Savepoint JavaDoc setSavepoint() throws SQLException JavaDoc {
115         checkClosed();
116         return conn.setSavepoint();
117     }
118
119     public Map JavaDoc getTypeMap() throws SQLException JavaDoc {
120         checkClosed();
121         return conn.getTypeMap();
122     }
123
124     public void setTypeMap(Map JavaDoc map) throws SQLException JavaDoc {
125         checkClosed();
126         conn.setTypeMap(map);
127     }
128
129     public void commit() throws SQLException JavaDoc {
130         conn.commit();
131     }
132
133     public void setCatalog(String JavaDoc catalog) throws SQLException JavaDoc {
134         checkClosed();
135         conn.setCatalog(catalog);
136     }
137
138     public boolean isClosed() throws SQLException JavaDoc {
139         return isClosed;
140     }
141
142     public void setHoldability(int holdability) throws SQLException JavaDoc {
143         checkClosed();
144         conn.setHoldability(holdability);
145     }
146
147     public String JavaDoc getCatalog() throws SQLException JavaDoc {
148         checkClosed();
149         return conn.getCatalog();
150     }
151
152     public void setReadOnly(boolean readOnly) throws SQLException JavaDoc {
153         checkClosed();
154         conn.setReadOnly(readOnly);
155     }
156
157     public Savepoint JavaDoc setSavepoint(String JavaDoc name) throws SQLException JavaDoc {
158         checkClosed();
159         return conn.setSavepoint(name);
160     }
161
162     public void releaseSavepoint(Savepoint JavaDoc savepoint) throws SQLException JavaDoc {
163         checkClosed();
164         conn.releaseSavepoint(savepoint);
165     }
166
167     public CallableStatement JavaDoc prepareCall(String JavaDoc sql) throws SQLException JavaDoc {
168         checkClosed();
169         return conn.prepareCall(sql);
170     }
171
172     public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql, int resultSetType, int resultSetConcurrency) throws SQLException JavaDoc {
173         checkClosed();
174         return new LoggablePreparedStatement(conn.prepareStatement(sql, resultSetType, resultSetConcurrency), sql);
175     }
176
177     public void close() throws SQLException JavaDoc {
178         checkClosed();
179 // System.out.println("Warning: call connection.close explicit");
180
isClosed = true;
181         // do nothing
182
}
183
184     public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql, int autoGeneratedKeys) throws SQLException JavaDoc {
185         checkClosed();
186         return new LoggablePreparedStatement(conn.prepareStatement(sql, autoGeneratedKeys), sql);
187     }
188
189     public int getTransactionIsolation() throws SQLException JavaDoc {
190         checkClosed();
191         return conn.getTransactionIsolation();
192     }
193
194     public CallableStatement JavaDoc prepareCall(String JavaDoc sql, int resultSetType, int resultSetConcurrency) throws SQLException JavaDoc {
195         checkClosed();
196         return conn.prepareCall(sql, resultSetType, resultSetConcurrency);
197     }
198
199     public boolean isReadOnly() throws SQLException JavaDoc {
200         checkClosed();
201         return conn.isReadOnly();
202     }
203
204     public Statement JavaDoc createStatement() throws SQLException JavaDoc {
205         checkClosed();
206         return conn.createStatement();
207     }
208
209     public void setAutoCommit(boolean autoCommit) throws SQLException JavaDoc {
210         checkClosed();
211         conn.setAutoCommit(autoCommit);
212     }
213
214     public Statement JavaDoc createStatement(int resultSetType, int resultSetConcurrency) throws SQLException JavaDoc {
215         checkClosed();
216         return conn.createStatement(resultSetType, resultSetConcurrency);
217     }
218
219     public Statement JavaDoc createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException JavaDoc {
220         checkClosed();
221         return conn.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
222     }
223
224     private void checkClosed() throws SQLException JavaDoc {
225         if(isClosed) {
226             throw new SQLException JavaDoc("connection closed");
227         }
228     }
229
230     public static void main(String JavaDoc[] args) {
231
232     }
233 }
234
235
Popular Tags