001: /*
002: * Copyright (c) 1998 - 2005 Versant Corporation
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * Versant Corporation - initial API and implementation
010: */
011: package com.versant.core.jdbc;
012:
013: import com.versant.core.common.BindingSupportImpl;
014:
015: import java.sql.*;
016:
017: /**
018: * This is a JDBC Connection proxy for local PersistenceManager use. It is
019: * wrapped by this proxy so that we can disconnect the client and the pooled
020: * connection if he misbehaves.
021: */
022: public final class VersantClientJDBCConnection implements Connection {
023:
024: private JdbcStorageManager owner;
025: private Connection realConnection;
026:
027: public VersantClientJDBCConnection(JdbcStorageManager owner,
028: Connection realConnection) {
029: this .owner = owner;
030: this .realConnection = realConnection;
031: }
032:
033: public Connection getRealConnection() {
034: return realConnection;
035: }
036:
037: private void checkClosed() {
038: if (realConnection == null) {
039: throw BindingSupportImpl.getInstance().invalidOperation(
040: "The connection has been closed");
041: }
042: }
043:
044: public Statement createStatement() throws SQLException {
045: checkClosed();
046: return realConnection.createStatement();
047: }
048:
049: public PreparedStatement prepareStatement(String sql)
050: throws SQLException {
051: checkClosed();
052: return realConnection.prepareStatement(sql);
053: }
054:
055: public CallableStatement prepareCall(String sql)
056: throws SQLException {
057: checkClosed();
058: return realConnection.prepareCall(sql);
059: }
060:
061: public String nativeSQL(String sql) throws SQLException {
062: checkClosed();
063: return realConnection.nativeSQL(sql);
064: }
065:
066: public void setAutoCommit(boolean autoCommit) {
067: checkClosed();
068: throw BindingSupportImpl
069: .getInstance()
070: .invalidOperation(
071: "This is not allowed. This connection is managed by JDO.");
072: }
073:
074: public boolean getAutoCommit() throws SQLException {
075: checkClosed();
076: return realConnection.getAutoCommit();
077: }
078:
079: public void commit() {
080: checkClosed();
081: throw BindingSupportImpl
082: .getInstance()
083: .invalidOperation(
084: "This is not allowed. Commit must be done via PersistenceManager.");
085: }
086:
087: public void rollback() {
088: checkClosed();
089: throw BindingSupportImpl
090: .getInstance()
091: .invalidOperation(
092: "This is not allowed. Rollback must be done via PersistenceManager.");
093: }
094:
095: public void close() throws SQLException {
096: if (isClosed())
097: return;
098: closeImp();
099: }
100:
101: public void closeImp() {
102: realConnection = null;
103: owner.clientConClosed();
104: }
105:
106: public boolean isClosed() throws SQLException {
107: return realConnection == null || realConnection.isClosed();
108: }
109:
110: public DatabaseMetaData getMetaData() throws SQLException {
111: checkClosed();
112: return realConnection.getMetaData();
113: }
114:
115: public void setReadOnly(boolean readOnly) throws SQLException {
116: checkClosed();
117: realConnection.setReadOnly(readOnly);
118: }
119:
120: public boolean isReadOnly() throws SQLException {
121: checkClosed();
122: return realConnection.isReadOnly();
123: }
124:
125: public void setCatalog(String catalog) throws SQLException {
126: checkClosed();
127: realConnection.setCatalog(catalog);
128: }
129:
130: public String getCatalog() throws SQLException {
131: checkClosed();
132: return realConnection.getCatalog();
133: }
134:
135: public void setTransactionIsolation(int level) throws SQLException {
136: checkClosed();
137: realConnection.setTransactionIsolation(level);
138: }
139:
140: public int getTransactionIsolation() throws SQLException {
141: checkClosed();
142: return realConnection.getTransactionIsolation();
143: }
144:
145: public SQLWarning getWarnings() throws SQLException {
146: checkClosed();
147: return realConnection.getWarnings();
148: }
149:
150: public void clearWarnings() throws SQLException {
151: checkClosed();
152: realConnection.clearWarnings();
153: }
154:
155: public Statement createStatement(int resultSetType,
156: int resultSetConcurrency) throws SQLException {
157: checkClosed();
158: return realConnection.createStatement(resultSetType,
159: resultSetConcurrency);
160: }
161:
162: public PreparedStatement prepareStatement(String sql,
163: int resultSetType, int resultSetConcurrency)
164: throws SQLException {
165: checkClosed();
166: return realConnection.prepareStatement(sql, resultSetType,
167: resultSetConcurrency);
168: }
169:
170: public CallableStatement prepareCall(String sql, int resultSetType,
171: int resultSetConcurrency) throws SQLException {
172: checkClosed();
173: return realConnection.prepareCall(sql, resultSetType,
174: resultSetConcurrency);
175: }
176:
177: public java.util.Map getTypeMap() throws SQLException {
178: checkClosed();
179: return realConnection.getTypeMap();
180: }
181:
182: public void setTypeMap(java.util.Map map) throws SQLException {
183: checkClosed();
184: realConnection.setTypeMap(map);
185: }
186:
187: public void setHoldability(int holdability) throws SQLException {
188: checkClosed();
189: realConnection.setHoldability(holdability);
190: }
191:
192: public int getHoldability() throws SQLException {
193: checkClosed();
194: return realConnection.getHoldability();
195: }
196:
197: public Savepoint setSavepoint() throws SQLException {
198: checkClosed();
199: return realConnection.setSavepoint();
200: }
201:
202: public Savepoint setSavepoint(String name) throws SQLException {
203: checkClosed();
204: return realConnection.setSavepoint(name);
205: }
206:
207: public void rollback(Savepoint savepoint) throws SQLException {
208: checkClosed();
209: realConnection.rollback(savepoint);
210: }
211:
212: public void releaseSavepoint(Savepoint savepoint)
213: throws SQLException {
214: checkClosed();
215: realConnection.releaseSavepoint(savepoint);
216: }
217:
218: public Statement createStatement(int resultSetType,
219: int resultSetConcurrency, int resultSetHoldability)
220: throws SQLException {
221: checkClosed();
222: return realConnection.createStatement(resultSetType,
223: resultSetConcurrency, resultSetHoldability);
224: }
225:
226: public PreparedStatement prepareStatement(String sql,
227: int resultSetType, int resultSetConcurrency,
228: int resultSetHoldability) throws SQLException {
229: checkClosed();
230: return realConnection.prepareStatement(sql, resultSetType,
231: resultSetConcurrency, resultSetHoldability);
232: }
233:
234: public CallableStatement prepareCall(String sql, int resultSetType,
235: int resultSetConcurrency, int resultSetHoldability)
236: throws SQLException {
237: checkClosed();
238: return realConnection.prepareCall(sql, resultSetType,
239: resultSetConcurrency, resultSetHoldability);
240: }
241:
242: public PreparedStatement prepareStatement(String sql,
243: int autoGeneratedKeys) throws SQLException {
244: checkClosed();
245: return realConnection.prepareStatement(sql, autoGeneratedKeys);
246: }
247:
248: public PreparedStatement prepareStatement(String sql,
249: int columnIndexes[]) throws SQLException {
250: checkClosed();
251: return realConnection.prepareStatement(sql, columnIndexes);
252: }
253:
254: public PreparedStatement prepareStatement(String sql,
255: String columnNames[]) throws SQLException {
256: checkClosed();
257: return realConnection.prepareStatement(sql, columnNames);
258: }
259: }
|