001: /**
002: * Speedo: an implementation of JDO compliant personality on top of JORM generic
003: * I/O sub-system.
004: * Copyright (C) 2001-2005 France Telecom R&D
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: *
021: *
022: * Contact: speedo@objectweb.org
023: *
024: * Authors: S. Chassande-Barrioz
025: *
026: */package org.objectweb.speedo.pm.jdo.lib;
027:
028: import java.sql.CallableStatement;
029: import java.sql.Connection;
030: import java.sql.DatabaseMetaData;
031: import java.sql.PreparedStatement;
032: import java.sql.SQLException;
033: import java.sql.SQLWarning;
034: import java.sql.Savepoint;
035: import java.sql.Statement;
036: import java.util.Map;
037:
038: import javax.jdo.JDOUserException;
039:
040: /**
041: * This class implements the java.sql.Connection and delegates call to an inner
042: * connection. But some calls are forbidden by the JDO 2 specification (12.16).
043: *
044: * @author S.Chassande-Barrioz
045: */
046: public class DSConnectionFilter implements Connection {
047:
048: Connection inner;
049:
050: /**
051: * indicates if the inner connection must be closed or simply forgotten.
052: */
053: boolean reallyClose;
054:
055: /**
056: * @param inner
057: * @param reallyClose
058: */
059: public DSConnectionFilter(Object inner, boolean reallyClose) {
060: super ();
061: this .inner = (Connection) inner;
062: this .reallyClose = reallyClose;
063: }
064:
065: public void clearWarnings() throws SQLException {
066: throw new JDOUserException("Action forbidden on JDO connection");
067: }
068:
069: public void close() throws SQLException {
070: if (reallyClose) {
071: inner.close();
072: }
073: inner = null;
074: }
075:
076: public void commit() throws SQLException {
077: throw new JDOUserException("Action forbidden on JDO connection");
078: }
079:
080: public Statement createStatement() throws SQLException {
081: return inner.createStatement();
082: }
083:
084: public Statement createStatement(int resultSetType,
085: int resultSetConcurrency, int resultSetHoldability)
086: throws SQLException {
087: return inner.createStatement(resultSetType,
088: resultSetConcurrency, resultSetHoldability);
089: }
090:
091: public Statement createStatement(int resultSetType,
092: int resultSetConcurrency) throws SQLException {
093: return inner.createStatement(resultSetType,
094: resultSetConcurrency);
095: }
096:
097: public boolean getAutoCommit() throws SQLException {
098: return inner.getAutoCommit();
099: }
100:
101: public String getCatalog() throws SQLException {
102: return inner.getCatalog();
103: }
104:
105: public int getHoldability() throws SQLException {
106: return inner.getHoldability();
107: }
108:
109: public DatabaseMetaData getMetaData() throws SQLException {
110: throw new JDOUserException("Action forbidden on JDO connection");
111: }
112:
113: public int getTransactionIsolation() throws SQLException {
114: return inner.getTransactionIsolation();
115: }
116:
117: public Map getTypeMap() throws SQLException {
118: return inner.getTypeMap();
119: }
120:
121: public SQLWarning getWarnings() throws SQLException {
122: return inner.getWarnings();
123: }
124:
125: public boolean isClosed() throws SQLException {
126: return inner.isClosed();
127: }
128:
129: public boolean isReadOnly() throws SQLException {
130: return inner.isReadOnly();
131: }
132:
133: public String nativeSQL(String sql) throws SQLException {
134: return inner.nativeSQL(sql);
135: }
136:
137: public CallableStatement prepareCall(String sql, int resultSetType,
138: int resultSetConcurrency, int resultSetHoldability)
139: throws SQLException {
140: return inner.prepareCall(sql, resultSetType,
141: resultSetConcurrency, resultSetHoldability);
142: }
143:
144: public CallableStatement prepareCall(String sql, int resultSetType,
145: int resultSetConcurrency) throws SQLException {
146: return inner.prepareCall(sql, resultSetType,
147: resultSetConcurrency);
148: }
149:
150: public CallableStatement prepareCall(String sql)
151: throws SQLException {
152: return inner.prepareCall(sql);
153: }
154:
155: public PreparedStatement prepareStatement(String sql,
156: int resultSetType, int resultSetConcurrency,
157: int resultSetHoldability) throws SQLException {
158: return inner.prepareStatement(sql, resultSetType,
159: resultSetConcurrency, resultSetHoldability);
160: }
161:
162: public PreparedStatement prepareStatement(String sql,
163: int resultSetType, int resultSetConcurrency)
164: throws SQLException {
165: return inner.prepareStatement(sql, resultSetType,
166: resultSetConcurrency);
167: }
168:
169: public PreparedStatement prepareStatement(String sql,
170: int autoGeneratedKeys) throws SQLException {
171: return inner.prepareStatement(sql, autoGeneratedKeys);
172: }
173:
174: public PreparedStatement prepareStatement(String sql,
175: int[] columnIndexes) throws SQLException {
176: return inner.prepareStatement(sql, columnIndexes);
177: }
178:
179: public PreparedStatement prepareStatement(String sql,
180: String[] columnNames) throws SQLException {
181: return inner.prepareStatement(sql, columnNames);
182: }
183:
184: public PreparedStatement prepareStatement(String sql)
185: throws SQLException {
186: return inner.prepareStatement(sql);
187: }
188:
189: public void releaseSavepoint(Savepoint savepoint)
190: throws SQLException {
191: throw new JDOUserException("Action forbidden on JDO connection");
192: }
193:
194: public void rollback() throws SQLException {
195: throw new JDOUserException("Action forbidden on JDO connection");
196: }
197:
198: public void rollback(Savepoint savepoint) throws SQLException {
199: throw new JDOUserException("Action forbidden on JDO connection");
200: }
201:
202: public void setAutoCommit(boolean autoCommit) throws SQLException {
203: throw new JDOUserException("Action forbidden on JDO connection");
204: }
205:
206: public void setCatalog(String catalog) throws SQLException {
207: throw new JDOUserException("Action forbidden on JDO connection");
208: }
209:
210: public void setHoldability(int holdability) throws SQLException {
211: throw new JDOUserException("Action forbidden on JDO connection");
212: }
213:
214: public void setReadOnly(boolean readOnly) throws SQLException {
215: throw new JDOUserException("Action forbidden on JDO connection");
216: }
217:
218: public Savepoint setSavepoint() throws SQLException {
219: throw new JDOUserException("Action forbidden on JDO connection");
220: }
221:
222: public Savepoint setSavepoint(String name) throws SQLException {
223: throw new JDOUserException("Action forbidden on JDO connection");
224: }
225:
226: public void setTransactionIsolation(int level) throws SQLException {
227: throw new JDOUserException("Action forbidden on JDO connection");
228: }
229:
230: public void setTypeMap(Map map) throws SQLException {
231: throw new JDOUserException("Action forbidden on JDO connection");
232: }
233: }
|