KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > jdbc > DjStatement


1 /*
2  * Copyright (c) 2001-2005 by Genimen BV (www.genimen.com) All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, is permitted provided that the following conditions are met: -
6  * Redistributions of source code must retain the above copyright notice, this
7  * list of conditions and the following disclaimer. - Redistributions in binary
8  * form must reproduce the above copyright notice, this list of conditions and
9  * the following disclaimer in the documentation and/or other materials
10  * provided with the distribution. - All advertising materials mentioning
11  * features or use of this software must display the following acknowledgment:
12  * "This product includes Djeneric." - Products derived from this software may
13  * not be called "Djeneric" nor may "Djeneric" appear in their names without
14  * prior written permission of Genimen BV. - Redistributions of any form
15  * whatsoever must retain the following acknowledgment: "This product includes
16  * Djeneric."
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL GENIMEN BV, DJENERIC.ORG, OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */

30
31 package com.genimen.djeneric.jdbc;
32
33 import java.sql.Connection JavaDoc;
34 import java.sql.DriverManager JavaDoc;
35 import java.sql.ResultSet JavaDoc;
36 import java.sql.SQLException JavaDoc;
37 import java.sql.SQLWarning JavaDoc;
38 import java.sql.Statement JavaDoc;
39
40 import com.genimen.djeneric.repository.exceptions.DjenericException;
41 import com.genimen.djeneric.repository.rdbms.RdbmsSession;
42 import com.genimen.djeneric.repository.rdbms.SqlStatement;
43
44 /**
45  * @author Gert Rijs
46  * @version 1.0
47  */

48
49 public class DjStatement implements Statement JavaDoc
50 {
51   private static final String JavaDoc CLASSNAME = DjStatement.class.getName();
52   private DjConnection _connection = null;
53   // private Statement _underlyingSqlStatement = null;
54
private RdbmsSession _session;
55
56   private String JavaDoc _originalSqlStatement = null; // select * from supplyers
57
private String JavaDoc _polymorphStatement = null; // select * from polymorph where
58

59   // table_type = 'supp'
60

61   public DjStatement(DjConnection p_con) throws SQLException JavaDoc
62   {
63     this(p_con, 0, ResultSet.CONCUR_READ_ONLY);
64   }
65
66   public DjStatement(DjConnection p_con, int resultSetType, int resultSetConcurrency) throws SQLException JavaDoc
67   {
68     if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) throw new SQLException JavaDoc(
69         "djeneric jdbc-driver can only handle SELECT statements");
70     _connection = p_con;
71     try
72     {
73       _session = (RdbmsSession) _connection.getPersistenceManager().createSession();
74     }
75     catch (DjenericException ex)
76     {
77       throw new SQLException JavaDoc(ex.getMessage());
78     }
79   }
80
81   public ResultSet JavaDoc executeQuery(String JavaDoc sql) throws SQLException JavaDoc
82   {
83     _originalSqlStatement = sql;
84     _polymorphStatement = _connection.translateSqlToPolymorph(sql);
85     DriverManager.println("original sql : " + _originalSqlStatement);
86     DriverManager.println("translated to sql: " + _polymorphStatement);
87     if (_polymorphStatement.toLowerCase().trim().startsWith("select ") == false) throw new SQLException JavaDoc(
88         "djeneric jdbc-driver can only handle SELECT statements");
89
90     try
91     {
92       SqlStatement stat = _session.getInternalSqlStatement(_polymorphStatement);
93       ResultSet JavaDoc rs = stat.executeQuery();
94       ResultSet JavaDoc rv = DjResultSet.createFromResultSet(rs);
95       stat.close();
96       return rv;
97     }
98     catch (SQLException JavaDoc e)
99     {
100       throw e;
101     }
102     catch (Exception JavaDoc ee_)
103     {
104       throw new SQLException JavaDoc(ee_.toString());
105     }
106   }
107
108   public int executeUpdate(String JavaDoc sql) throws SQLException JavaDoc
109   {
110     throw new SQLException JavaDoc("djeneric jdbc-driver can only handle SELECT statements");
111   }
112
113   public void close() throws SQLException JavaDoc
114   {
115     _connection.close(this);
116   }
117
118   protected void finalize()
119   {
120     try
121     {
122       super.finalize();
123       close();
124     }
125     catch (Throwable JavaDoc e)
126     {
127     }
128   }
129
130   public int getMaxFieldSize() throws SQLException JavaDoc
131   {
132     throw new java.lang.UnsupportedOperationException JavaDoc("Method getMaxFieldSize() not yet implemented.");
133   }
134
135   public void setMaxFieldSize(int max) throws SQLException JavaDoc
136   {
137     throw new java.lang.UnsupportedOperationException JavaDoc("Method setMaxFieldSize() not yet implemented.");
138   }
139
140   public int getMaxRows() throws SQLException JavaDoc
141   {
142     throw new java.lang.UnsupportedOperationException JavaDoc("Method getMaxRows() not yet implemented.");
143   }
144
145   public void setMaxRows(int max) throws SQLException JavaDoc
146   {
147     throw new java.lang.UnsupportedOperationException JavaDoc("Method setMaxRows() not yet implemented.");
148   }
149
150   public void setEscapeProcessing(boolean enable) throws SQLException JavaDoc
151   {
152     throw new java.lang.UnsupportedOperationException JavaDoc("Method setEscapeProcessing() not yet implemented.");
153   }
154
155   public int getQueryTimeout() throws SQLException JavaDoc
156   {
157     throw new java.lang.UnsupportedOperationException JavaDoc("Method getQueryTimeout() not yet implemented.");
158   }
159
160   public void setQueryTimeout(int seconds) throws SQLException JavaDoc
161   {
162     throw new java.lang.UnsupportedOperationException JavaDoc("Method setQueryTimeout() not yet implemented.");
163   }
164
165   public void cancel() throws SQLException JavaDoc
166   {
167     throw new java.lang.UnsupportedOperationException JavaDoc("Method cancel() not yet implemented.");
168   }
169
170   public SQLWarning JavaDoc getWarnings() throws SQLException JavaDoc
171   {
172     throw new java.lang.UnsupportedOperationException JavaDoc("Method getWarnings() not yet implemented.");
173   }
174
175   public void clearWarnings() throws SQLException JavaDoc
176   {
177     throw new java.lang.UnsupportedOperationException JavaDoc("Method clearWarnings() not yet implemented.");
178   }
179
180   public void setCursorName(String JavaDoc name) throws SQLException JavaDoc
181   {
182     throw new java.lang.UnsupportedOperationException JavaDoc("Method setCursorName() not yet implemented.");
183   }
184
185   public boolean execute(String JavaDoc sql) throws SQLException JavaDoc
186   {
187     throw new java.lang.UnsupportedOperationException JavaDoc("Method execute() not yet implemented.");
188   }
189
190   public ResultSet JavaDoc getResultSet() throws SQLException JavaDoc
191   {
192     throw new java.lang.UnsupportedOperationException JavaDoc("Method getResultSet() not yet implemented.");
193   }
194
195   public int getUpdateCount() throws SQLException JavaDoc
196   {
197     throw new java.lang.UnsupportedOperationException JavaDoc("Method getUpdateCount() not yet implemented.");
198   }
199
200   public boolean getMoreResults() throws SQLException JavaDoc
201   {
202     throw new java.lang.UnsupportedOperationException JavaDoc("Method getMoreResults() not yet implemented.");
203   }
204
205   public void setFetchDirection(int direction) throws SQLException JavaDoc
206   {
207     throw new java.lang.UnsupportedOperationException JavaDoc("Method setFetchDirection() not yet implemented.");
208   }
209
210   public int getFetchDirection() throws SQLException JavaDoc
211   {
212     throw new java.lang.UnsupportedOperationException JavaDoc("Method getFetchDirection() not yet implemented.");
213   }
214
215   public void setFetchSize(int rows) throws SQLException JavaDoc
216   {
217     throw new java.lang.UnsupportedOperationException JavaDoc("Method setFetchSize() not yet implemented.");
218   }
219
220   public int getFetchSize() throws SQLException JavaDoc
221   {
222     throw new java.lang.UnsupportedOperationException JavaDoc("Method getFetchSize() not yet implemented.");
223   }
224
225   public int getResultSetConcurrency() throws SQLException JavaDoc
226   {
227     /** @todo: Implement this java.sql.Statement method */
228     throw new java.lang.UnsupportedOperationException JavaDoc("Method getResultSetConcurrency() not yet implemented.");
229   }
230
231   public int getResultSetType() throws SQLException JavaDoc
232   {
233     /** @todo: Implement this java.sql.Statement method */
234     throw new java.lang.UnsupportedOperationException JavaDoc("Method getResultSetType() not yet implemented.");
235   }
236
237   public void addBatch(String JavaDoc sql) throws SQLException JavaDoc
238   {
239     /** @todo: Implement this java.sql.Statement method */
240     throw new java.lang.UnsupportedOperationException JavaDoc("Method addBatch() not yet implemented.");
241   }
242
243   public void clearBatch() throws SQLException JavaDoc
244   {
245     /** @todo: Implement this java.sql.Statement method */
246     throw new java.lang.UnsupportedOperationException JavaDoc("Method clearBatch() not yet implemented.");
247   }
248
249   public int[] executeBatch() throws SQLException JavaDoc
250   {
251     /** @todo: Implement this java.sql.Statement method */
252     throw new java.lang.UnsupportedOperationException JavaDoc("Method executeBatch() not yet implemented.");
253   }
254
255   public Connection JavaDoc getConnection() throws SQLException JavaDoc
256   {
257     /** @todo: Implement this java.sql.Statement method */
258     throw new java.lang.UnsupportedOperationException JavaDoc("Method getConnection() not yet implemented.");
259   }
260
261   /*
262    * (non-Javadoc)
263    *
264    * @see java.sql.Statement#execute(java.lang.String, int)
265    */

266   public boolean execute(String JavaDoc arg0, int arg1) throws SQLException JavaDoc
267   {
268     return false;
269   }
270
271   /*
272    * (non-Javadoc)
273    *
274    * @see java.sql.Statement#execute(java.lang.String, int[])
275    */

276   public boolean execute(String JavaDoc arg0, int[] arg1) throws SQLException JavaDoc
277   {
278     return false;
279   }
280
281   /*
282    * (non-Javadoc)
283    *
284    * @see java.sql.Statement#execute(java.lang.String, java.lang.String[])
285    */

286   public boolean execute(String JavaDoc arg0, String JavaDoc[] arg1) throws SQLException JavaDoc
287   {
288     return false;
289   }
290
291   /*
292    * (non-Javadoc)
293    *
294    * @see java.sql.Statement#executeUpdate(java.lang.String, int)
295    */

296   public int executeUpdate(String JavaDoc arg0, int arg1) throws SQLException JavaDoc
297   {
298     return 0;
299   }
300
301   /*
302    * (non-Javadoc)
303    *
304    * @see java.sql.Statement#executeUpdate(java.lang.String, int[])
305    */

306   public int executeUpdate(String JavaDoc arg0, int[] arg1) throws SQLException JavaDoc
307   {
308     return 0;
309   }
310
311   /*
312    * (non-Javadoc)
313    *
314    * @see java.sql.Statement#executeUpdate(java.lang.String,
315    * java.lang.String[])
316    */

317   public int executeUpdate(String JavaDoc arg0, String JavaDoc[] arg1) throws SQLException JavaDoc
318   {
319     return 0;
320   }
321
322   /*
323    * (non-Javadoc)
324    *
325    * @see java.sql.Statement#getGeneratedKeys()
326    */

327   public ResultSet JavaDoc getGeneratedKeys() throws SQLException JavaDoc
328   {
329     return null;
330   }
331
332   /*
333    * (non-Javadoc)
334    *
335    * @see java.sql.Statement#getMoreResults(int)
336    */

337   public boolean getMoreResults(int arg0) throws SQLException JavaDoc
338   {
339     return false;
340   }
341
342   /*
343    * (non-Javadoc)
344    *
345    * @see java.sql.Statement#getResultSetHoldability()
346    */

347   public int getResultSetHoldability() throws SQLException JavaDoc
348   {
349     return 0;
350   }
351
352 }
Popular Tags