KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdbc > VersantClientJDBCConnection


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdbc;
13
14 import com.versant.core.common.BindingSupportImpl;
15
16 import java.sql.*;
17
18 /**
19  * This is a JDBC Connection proxy for local PersistenceManager use. It is
20  * wrapped by this proxy so that we can disconnect the client and the pooled
21  * connection if he misbehaves.
22  */

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