KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > spi > persistence > support > sqlstore > connection > PreparedStatementImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * StatementImpl.java
26  *
27  * Create on March 3, 2000
28  */

29
30 package com.sun.jdo.spi.persistence.support.sqlstore.connection;
31
32 import java.math.BigDecimal JavaDoc;
33 import java.sql.*;
34
35
36 /**
37  * This class implements the <code>java.sql.PreparedStatement</code>
38  * interface, which is part of the JDBC API. You should use
39  * the <code>java.sql.PreparedStatement</code> interface as an object
40  * type instead of this class.
41  */

42 // CHANGES
43
// 23-Dec-1997
44
// Created (psb)
45
//
46

47 public class PreparedStatementImpl
48         extends StatementImpl
49         implements PreparedStatement {
50     //
51
// Create a new PreparedStatementImpl object.
52
//
53
public PreparedStatementImpl() {
54         super();
55         this.conn = null;
56         this.stmt = null;
57     }
58
59     //
60
// Create a new PreparedStatementImpl object and keep references to
61
// corresponding JDBC Connection and PreparedStatement objects.
62
//
63
// @param conn ConnectionImpl
64
// @param pstmt JDBC PreparedStatement
65
//
66
public PreparedStatementImpl(ConnectionImpl conn,
67                                  PreparedStatement pstmt) {
68         super();
69         this.conn = conn;
70         this.stmt = (Statement) pstmt;
71     }
72
73     //----------------------------------------------------------------------
74
// Wrapper methods for JDBC PreparedStatement:
75

76     public ResultSet executeQuery() throws SQLException {
77         PreparedStatement pstmt = (PreparedStatement) this.stmt;
78
79         try {
80             this.conn.checkXact();
81             return (pstmt.executeQuery());
82         } catch (SQLException se) {
83             throw se;
84         }
85     }
86
87     public int executeUpdate() throws SQLException {
88         PreparedStatement pstmt = (PreparedStatement) this.stmt;
89
90         try {
91             this.conn.checkXact();
92             return (pstmt.executeUpdate());
93         } catch (SQLException se) {
94             throw se;
95         }
96     }
97
98     public void setNull(int parameterIndex, int sqlType) throws SQLException {
99         PreparedStatement pstmt = (PreparedStatement) this.stmt;
100
101         try {
102             pstmt.setNull(parameterIndex, sqlType);
103         } catch (SQLException se) {
104             throw se;
105         }
106     }
107
108     public void setBoolean(int parameterIndex, boolean x) throws SQLException {
109         PreparedStatement pstmt = (PreparedStatement) this.stmt;
110
111         try {
112             pstmt.setBoolean(parameterIndex, x);
113         } catch (SQLException se) {
114             throw se;
115         }
116     }
117
118     public void setByte(int parameterIndex, byte x) throws SQLException {
119         PreparedStatement pstmt = (PreparedStatement) this.stmt;
120
121         try {
122             pstmt.setByte(parameterIndex, x);
123         } catch (SQLException se) {
124             throw se;
125         }
126     }
127
128     public void setShort(int parameterIndex, short x) throws SQLException {
129         PreparedStatement pstmt = (PreparedStatement) this.stmt;
130
131         try {
132             pstmt.setShort(parameterIndex, x);
133         } catch (SQLException se) {
134             throw se;
135         }
136     }
137
138     public void setInt(int parameterIndex, int x) throws SQLException {
139         PreparedStatement pstmt = (PreparedStatement) this.stmt;
140
141         try {
142             pstmt.setInt(parameterIndex, x);
143         } catch (SQLException se) {
144             throw se;
145         }
146     }
147
148     public void setLong(int parameterIndex, long x) throws SQLException {
149         PreparedStatement pstmt = (PreparedStatement) this.stmt;
150
151         try {
152             pstmt.setLong(parameterIndex, x);
153         } catch (SQLException se) {
154             throw se;
155         }
156     }
157
158     public void setFloat(int parameterIndex, float x) throws SQLException {
159         PreparedStatement pstmt = (PreparedStatement) this.stmt;
160
161         try {
162             pstmt.setFloat(parameterIndex, x);
163         } catch (SQLException se) {
164             throw se;
165         }
166     }
167
168     public void setDouble(int parameterIndex, double x) throws SQLException {
169         PreparedStatement pstmt = (PreparedStatement) this.stmt;
170
171         try {
172             pstmt.setDouble(parameterIndex, x);
173         } catch (SQLException se) {
174             throw se;
175         }
176     }
177
178     public void setBigDecimal(int parameterIndex, BigDecimal JavaDoc x)
179             throws SQLException {
180         PreparedStatement pstmt = (PreparedStatement) this.stmt;
181
182         try {
183             pstmt.setBigDecimal(parameterIndex, x);
184         } catch (SQLException se) {
185             throw se;
186         }
187     }
188
189     public void setString(int parameterIndex, String JavaDoc x) throws SQLException {
190         PreparedStatement pstmt = (PreparedStatement) this.stmt;
191
192         try {
193             pstmt.setString(parameterIndex, x);
194         } catch (SQLException se) {
195             throw se;
196         }
197     }
198
199     public void setBytes(int parameterIndex, byte x[]) throws SQLException {
200         PreparedStatement pstmt = (PreparedStatement) this.stmt;
201
202         try {
203             pstmt.setBytes(parameterIndex, x);
204         } catch (SQLException se) {
205             throw se;
206         }
207     }
208
209     public void setDate(int parameterIndex, java.sql.Date JavaDoc x)
210             throws SQLException {
211         PreparedStatement pstmt = (PreparedStatement) this.stmt;
212
213         try {
214             pstmt.setDate(parameterIndex, x);
215         } catch (SQLException se) {
216             throw se;
217         }
218     }
219
220     public void setTime(int parameterIndex, java.sql.Time JavaDoc x)
221             throws SQLException {
222         PreparedStatement pstmt = (PreparedStatement) this.stmt;
223
224         try {
225             pstmt.setTime(parameterIndex, x);
226         } catch (SQLException se) {
227             throw se;
228         }
229     }
230
231     public void setTimestamp(int parameterIndex, java.sql.Timestamp JavaDoc x)
232             throws SQLException {
233         PreparedStatement pstmt = (PreparedStatement) this.stmt;
234
235         try {
236             pstmt.setTimestamp(parameterIndex, x);
237         } catch (SQLException se) {
238             throw se;
239         }
240     }
241
242     public void setTimestamp(int parameterIndex, java.sql.Timestamp JavaDoc x,
243                              java.util.Calendar JavaDoc cal)
244             throws SQLException {
245         PreparedStatement pstmt = (PreparedStatement) this.stmt;
246
247         try {
248             pstmt.setTimestamp(parameterIndex, x);
249         } catch (SQLException se) {
250             throw se;
251         }
252     }
253
254     public void setTime(int parameterIndex, java.sql.Time JavaDoc x,
255                         java.util.Calendar JavaDoc cal)
256             throws SQLException {
257         PreparedStatement pstmt = (PreparedStatement) this.stmt;
258
259         try {
260             pstmt.setTime(parameterIndex, x);
261         } catch (SQLException se) {
262             throw se;
263         }
264     }
265
266     public void setArray(int i, Array x)
267             throws SQLException {
268     }
269
270     public void setClob(int i, Clob x)
271             throws SQLException {
272     }
273
274     public ResultSetMetaData getMetaData()
275             throws SQLException {
276         return (null);
277     }
278
279     public Clob getClob(int i)
280             throws SQLException {
281         return (null);
282     }
283
284     public void setDate(int parameterIndex, Date x,
285                         java.util.Calendar JavaDoc cal)
286             throws SQLException {
287     }
288
289     public Array getArray(int i)
290             throws SQLException {
291         return (null);
292     }
293
294     public Time getTime(int parameterIndex, java.util.Calendar JavaDoc cal)
295             throws SQLException {
296         return (null);
297     }
298
299     public Blob getBlob(int i)
300             throws SQLException {
301         return (null);
302     }
303
304     public void setBlob(int i, Blob x) throws SQLException {
305     }
306
307     public Date getDate(int parameterIndex, java.util.Calendar JavaDoc cal)
308             throws SQLException {
309         return (null);
310     }
311
312     public Timestamp getTimestamp(int parameterIndex,
313                                   java.util.Calendar JavaDoc cal)
314             throws SQLException {
315         return (null);
316     }
317
318     public void setAsciiStream(int parameterIndex,
319                                java.io.InputStream JavaDoc x,
320                                int length)
321             throws SQLException {
322         PreparedStatement pstmt = (PreparedStatement) this.stmt;
323
324         try {
325             pstmt.setAsciiStream(parameterIndex, x, length);
326         } catch (SQLException se) {
327             throw se;
328         }
329     }
330
331     /**
332      * @deprecated
333      */

334     public void setUnicodeStream(int parameterIndex,
335                                  java.io.InputStream JavaDoc x,
336                                  int length)
337             throws SQLException {
338         PreparedStatement pstmt = (PreparedStatement) this.stmt;
339
340         try {
341             pstmt.setUnicodeStream(parameterIndex, x, length);
342         } catch (SQLException se) {
343             throw se;
344         }
345     }
346
347     public void setBinaryStream(int parameterIndex,
348                                 java.io.InputStream JavaDoc x,
349                                 int length)
350             throws SQLException {
351         PreparedStatement pstmt = (PreparedStatement) this.stmt;
352
353         try {
354             pstmt.setBinaryStream(parameterIndex, x, length);
355         } catch (SQLException se) {
356             throw se;
357         }
358     }
359
360     public void clearParameters() throws SQLException {
361         PreparedStatement pstmt = (PreparedStatement) this.stmt;
362
363         try {
364             pstmt.clearParameters();
365         } catch (SQLException se) {
366             throw se;
367         }
368     }
369
370     //----------------------------------------------------------------------
371
// Advanced features:
372

373     public void setObject(int parameterIndex,
374                           Object JavaDoc x, int targetSqlType, int scale)
375             throws SQLException {
376         PreparedStatement pstmt = (PreparedStatement) this.stmt;
377
378         try {
379             pstmt.setObject(parameterIndex, x, targetSqlType, scale);
380         } catch (SQLException se) {
381             throw se;
382         }
383     }
384
385     public void setObject(int parameterIndex,
386                           Object JavaDoc x, int targetSqlType)
387             throws SQLException {
388         PreparedStatement pstmt = (PreparedStatement) this.stmt;
389
390         try {
391             pstmt.setObject(parameterIndex, x, targetSqlType);
392         } catch (SQLException se) {
393             throw se;
394         }
395     }
396
397     public void setObject(int parameterIndex, Object JavaDoc x) throws SQLException {
398         PreparedStatement pstmt = (PreparedStatement) this.stmt;
399
400         try {
401             pstmt.setObject(parameterIndex, x);
402         } catch (SQLException se) {
403             throw se;
404         }
405     }
406
407     public boolean execute() throws SQLException {
408         PreparedStatement pstmt = (PreparedStatement) this.stmt;
409
410         try {
411             this.conn.checkXact();
412             return (pstmt.execute());
413         } catch (SQLException se) {
414             throw se;
415         }
416     }
417
418     //--------------------------JDBC 2.0-----------------------------
419

420     public void addBatch() throws SQLException {
421         PreparedStatement pstmt = (PreparedStatement) this.stmt;
422
423         try {
424             pstmt.addBatch();
425         } catch (SQLException se) {
426             throw se;
427         }
428     }
429
430     public void setCharacterStream(int parameterIndex,
431                                    java.io.Reader JavaDoc reader,
432                                    int length) throws SQLException {
433         PreparedStatement pstmt = (PreparedStatement) this.stmt;
434
435         try {
436             pstmt.setCharacterStream(parameterIndex, reader, length);
437         } catch (SQLException se) {
438             throw se;
439         }
440     }
441
442     public void setRef(int i, Ref x) throws SQLException {
443         PreparedStatement pstmt = (PreparedStatement) this.stmt;
444
445         try {
446             pstmt.setRef(i, x);
447         } catch (SQLException se) {
448             throw se;
449         }
450     }
451
452 /* BETA3
453
454     public void setBlobLocator (int i, BlobLocator x) throws SQLException
455     {
456         PreparedStatement pstmt = (PreparedStatement)this.stmt;
457
458         try
459         {
460             pstmt.setBlobLocator(i, x);
461         }
462         catch (SQLException se)
463         {
464             throw se;
465         }
466     }
467
468     public void setClobLocator (int i, ClobLocator x) throws SQLException
469     {
470         PreparedStatement pstmt = (PreparedStatement)this.stmt;
471
472         try
473         {
474             pstmt.setClobLocator(i, x);
475         }
476         catch (SQLException se)
477         {
478             throw se;
479         }
480     }
481
482     public void setStructLocator (int i, StructLocator x) throws SQLException
483     {
484         PreparedStatement pstmt = (PreparedStatement)this.stmt;
485
486         try
487         {
488             pstmt.setStructLocator(i, x);
489         }
490         catch (SQLException se)
491         {
492             throw se;
493         }
494     }
495
496     public void setArrayLocator (int i, ArrayLocator x) throws SQLException
497     {
498         PreparedStatement pstmt = (PreparedStatement)this.stmt;
499
500         try
501         {
502             pstmt.setArrayLocator(i, x);
503         }
504         catch (SQLException se)
505         {
506             throw se;
507         }
508     }
509
510 BETA3 */

511
512 // JDK1.2FCS
513

514     public void setNull(int i, int j, String JavaDoc str) throws SQLException {
515         PreparedStatement pstmt = (PreparedStatement) this.stmt;
516
517         /* Comment out for now.
518         try
519         {
520             pstmt.setNull(i, j, str);
521         }
522         catch (SQLException se)
523         {
524             throw se;
525         }
526         */

527     }
528
529     //-------------Begin New methods added in JDBC 3.0 --------------
530
public void setURL(int parameterIndex,java.net.URL JavaDoc x) throws SQLException {
531         throw new UnsupportedOperationException JavaDoc();
532     }
533
534     public ParameterMetaData getParameterMetaData() throws SQLException {
535
536         throw new UnsupportedOperationException JavaDoc();
537     }
538
539     //-------------End New methods added in JDBC 3.0 --------------
540
}
541
Popular Tags