001: package com.quadcap.jdbc;
002:
003: /* Copyright 1999 - 2003 Quadcap Software. All rights reserved.
004: *
005: * This software is distributed under the Quadcap Free Software License.
006: * This software may be used or modified for any purpose, personal or
007: * commercial. Open Source redistributions are permitted. Commercial
008: * redistribution of larger works derived from, or works which bundle
009: * this software requires a "Commercial Redistribution License"; see
010: * http://www.quadcap.com/purchase.
011: *
012: * Redistributions qualify as "Open Source" under one of the following terms:
013: *
014: * Redistributions are made at no charge beyond the reasonable cost of
015: * materials and delivery.
016: *
017: * Redistributions are accompanied by a copy of the Source Code or by an
018: * irrevocable offer to provide a copy of the Source Code for up to three
019: * years at the cost of materials and delivery. Such redistributions
020: * must allow further use, modification, and redistribution of the Source
021: * Code under substantially the same terms as this license.
022: *
023: * Redistributions of source code must retain the copyright notices as they
024: * appear in each source code file, these license terms, and the
025: * disclaimer/limitation of liability set forth as paragraph 6 below.
026: *
027: * Redistributions in binary form must reproduce this Copyright Notice,
028: * these license terms, and the disclaimer/limitation of liability set
029: * forth as paragraph 6 below, in the documentation and/or other materials
030: * provided with the distribution.
031: *
032: * The Software is provided on an "AS IS" basis. No warranty is
033: * provided that the Software is free of defects, or fit for a
034: * particular purpose.
035: *
036: * Limitation of Liability. Quadcap Software shall not be liable
037: * for any damages suffered by the Licensee or any third party resulting
038: * from use of the Software.
039: */
040:
041: import java.io.IOException;
042:
043: import java.util.Map;
044:
045: import java.sql.CallableStatement;
046: import java.sql.ResultSet; //#ifdef JDK14
047: import java.sql.Savepoint; //#endif
048: import java.sql.SQLException;
049: import java.sql.SQLWarning;
050:
051: import com.quadcap.sql.Database;
052: import com.quadcap.sql.DbException;
053: import com.quadcap.sql.Session;
054:
055: import com.quadcap.util.ConfigNumber;
056: import com.quadcap.util.Debug;
057: import com.quadcap.util.Util;
058:
059: /**
060: * This class implements the <code>java.sql.Connection</code> interface,
061: * which provides facilities for executing SQL statements, performing
062: * transaction commit and rollback, and obtaining information about
063: * the database via <code>DatabaseMetaData</code>.
064: *
065: * @author Stan Bailes
066: */
067: public class Connection implements java.sql.Connection {
068: /*{com.quadcap.qed.Trace-vars.xml-1052}
069: * <config-var>
070: * <config-name>qed.trace.Connection</config-name>
071: * <config-dflt>0</config-dflt>
072: * <config-desc>
073: * <pre>
074: * bit 0: Connection lifecycle
075: * bit 1: Connection methods
076: * </pre>
077: * </config-desc>
078: * </config-var>
079: */
080:
081: //#ifdef DEBUG
082: static final ConfigNumber trace = ConfigNumber.find(
083: "qed.trace.Connection", "0");
084: //#endif
085:
086: Database db;
087: com.quadcap.sql.Connection qConn = null;
088: boolean closed = false;
089: Map typeMap = null;
090:
091: /**
092: * Construct a new connection object for the specified database
093: * and userid.
094: * @deprecated <i>Pay no attention to that man behind the curtains.</i>
095: *
096: * @param db the database
097: * @param auth the userid
098: * @param passwd the password
099: */
100: public Connection(Database db, String auth, String passwd)
101: throws SQLException {
102: this .db = db;
103: if (auth == null)
104: auth = "";
105: this .qConn = new com.quadcap.sql.Connection(db, auth
106: .toUpperCase(), passwd);
107: //#ifdef DEBUG
108: if (trace.bit(0)) {
109: Debug.println("Connection.init(" + qConn + ")");
110: }
111: //#endif
112: }
113:
114: /**
115: * Return the database to which this connection is bound.
116: * @deprecated <i>Pay no attention to that man behind the curtains.</i>
117: *
118: * @return the connection's database
119: */
120: public Database getDatabase() {
121: return db;
122: }
123:
124: /**
125: * Return the connection's session.
126: * @deprecated <i>Pay no attention to that man behind the curtains.</i>
127: *
128: * @return the connection's session
129: */
130: public final com.quadcap.sql.Connection getConnection() {
131: return qConn;
132: }
133:
134: //------------------------------------------------------------------
135: // java.sql.Connection implementation
136: //------------------------------------------------------------------
137:
138: /**
139: * Clears all warnings that have been reported on calls to this
140: * connection. QED doesn't currently throw any SQLWarnings,
141: * so this operation does nothing.
142: */
143: public void clearWarnings() {
144: }
145:
146: /**
147: * Close this connection, which implicitly ends (i.e., commits) any
148: * pending transactions for this connection, closes any
149: * <code>ResultSet</code>s opened on this connection, and marks
150: * the connection as closed. It is an error to attempt to use
151: * this connection after the close operation
152: *
153: * @exception SQLException may be thrown
154: */
155: public void close() throws SQLException {
156: //#ifdef DEBUG
157: if (trace.bit(0)) {
158: Debug.println("Connection[" + qConn + "].close()");
159: }
160: //#endif
161: closed = true;
162: try {
163: if (qConn != null)
164: qConn.close();
165: } catch (IOException e) {
166: throw DbException.wrapThrowable(e);
167: } finally {
168: qConn = null;
169: }
170: }
171:
172: /**
173: * Make sure the connection closes on gc...
174: */
175: public void finalize() throws Throwable {
176: if (!closed) {
177: try {
178: close();
179: } catch (Throwable t) {
180: }
181: }
182: super .finalize();
183: }
184:
185: /**
186: * Commit any pending changes for the current transaction. This
187: * ends the transaction; any further statements executed by this
188: * connection will cause a new transaction to be started. This
189: * method closes any <code>ResultSet</code>s opened on this connection.
190: *
191: * @exception SQLException may be thrown
192: */
193: public void commit() throws SQLException {
194: //#ifdef DEBUG
195: if (trace.bit(1)) {
196: Debug.println("Connection.commit()");
197: }
198: //#endif
199: if (closed)
200: throw new SQLException("Connection closed", "08003");
201: try {
202: qConn.endTransaction();
203: } catch (IOException e) {
204: throw DbException.wrapThrowable(e);
205: }
206: }
207:
208: /**
209: * Return a new <code>Statement</code> object that can be used to
210: * execute SQL statements on this connection
211: *
212: * @return a new <code>Statement</code> object
213: * @exception SQLException may be thrown
214: */
215: public java.sql.Statement createStatement() throws SQLException {
216: if (closed)
217: throw new SQLException("Connection closed", "08003");
218: try {
219: return new Statement(this );
220: } catch (IOException e) {
221: throw DbException.wrapThrowable(e);
222: }
223: }
224:
225: /**
226: * Return the current value for the <code>autoCommit</code> variable.
227: * By default, connections are created with <code>autoCommit</code>
228: * equal to <code>true</code>
229: *
230: * @return the current <code>autoCommit</code> state
231: */
232: public boolean getAutoCommit() throws SQLException {
233: if (closed)
234: throw new SQLException("Connection closed", "08003");
235: return qConn.getAutoCommit();
236: }
237:
238: /**
239: * QED doesn't support catalogs, so this function returns
240: * <code>null</code>
241: *
242: * @return null
243: */
244: public String getCatalog() {
245: return null;
246: }
247:
248: /**
249: * Return a <code>DatabaseMetaData</code> object that can be used
250: * to get information about the features supported by QED.
251: *
252: * @return a <code>DatabaseMetaData</code>
253: */
254: DatabaseMetaData dbm = null;
255:
256: public java.sql.DatabaseMetaData getMetaData() throws SQLException {
257: try {
258: if (dbm == null) {
259: dbm = new DatabaseMetaData(this );
260: }
261: } catch (IOException e) {
262: throw DbException.wrapThrowable(e);
263: }
264: return dbm;
265: }
266:
267: /**
268: * Return the current transaction isolation level -- QED currently
269: * only supports <code>TRANSACTION_SERIALIZABLE</code>
270: *
271: * @return <code>TRANSACTION_SERIALIZABLE</code>
272: */
273: public int getTransactionIsolation() {
274: return TRANSACTION_SERIALIZABLE;
275: }
276:
277: /**
278: * QED doesn't generate any <code>SQLWarning</code>s, so this function
279: * always returns <code>null</code>
280: *
281: * @return null
282: */
283: public SQLWarning getWarnings() {
284: return null;
285: }
286:
287: /**
288: * Return true if this connection has been closed.
289: *
290: * @return true if this connection has been closed.
291: */
292: public boolean isClosed() {
293: return closed;
294: }
295:
296: /**
297: * Return true if this connection is read only. QED doesn't currently
298: * support read-only connections, so this always returns
299: * false
300: *
301: * @return false
302: */
303: public boolean isReadOnly() {
304: return false;
305: }
306:
307: /**
308: * This function is supposed to translate the specified query into
309: * the native query language of the underlying DBMS. In QED, the
310: * native query language is SQL-92, and JDBC escapes are directly
311: * supported by the DBMS, so this translation is a no-op, and always
312: * returns the original string
313: *
314: * @param stmt an SQL statement
315: * @return the same SQL statement
316: */
317: public String nativeSQL(String stmt) {
318: return stmt;
319: }
320:
321: /**
322: * QED doesn't support stored procedures, so this method returns
323: * a "not implemented" exception
324: *
325: * @param sql the SQL statement
326: * @return never
327: * @exception SQLException "not implemented"
328: */
329: public CallableStatement prepareCall(String sql)
330: throws SQLException {
331: throw new SQLException("Not implemented");
332: }
333:
334: /**
335: * QED doesn't support stored procedures, so this method returns
336: * a "not implemented" exception
337: *
338: * @param sql the SQL statement
339: * @param resultType the desired <code>ResultSet</code> type
340: * @param resultSetConcurrency the desired <code>ResultSet</code>
341: * concurrency
342: * @return never
343: * @exception SQLException "not implemented"
344: */
345: public CallableStatement prepareCall(String sql, int resultType,
346: int resultSetConcurrency) throws SQLException {
347: throw new SQLException("Not implemented");
348: }
349:
350: /**
351: * Returns a new <code>PreparedStatement</code> statement, which is
352: * a pre-compiled representation of the statement <i>sql</i>, with
353: * place holders for parameters specified using the <code>'?'</code>
354: * character.
355: *
356: * @param sql the SQL statement
357: * @return the <code>PreparedStatement</code> statement that can be
358: * used to invoke the SQL statement, after the parameters
359: * represented by the <code>'?'</code> characters are
360: * supplied
361: * @exception SQLException may be thrown
362: */
363: public java.sql.PreparedStatement prepareStatement(String sql)
364: throws SQLException {
365: if (closed)
366: throw new SQLException("Connection closed", "08003");
367: try {
368: return new PreparedStatement(this , sql);
369: } catch (IOException e) {
370: throw DbException.wrapThrowable(e);
371: }
372: }
373:
374: /**
375: * Returns a new <code>PreparedStatement</code> statement, which is
376: * a pre-compiled representation of the statement <i>sql</i>, with
377: * place holders for parameters specified using the <code>'?'</code>
378: * character.
379: *
380: * @param sql the SQL statement
381: * @param resultType the desired <code>ResultSet</code> type
382: * @param resultSetConcurrency the desired <code>ResultSet</code>
383: * concurrency
384: * @return the <code>PreparedStatement</code> statement that can be
385: * used to invoke the SQL statement, after the parameters
386: * represented by the <code>'?'</code> characters are
387: * supplied
388: * @exception SQLException may be thrown
389: */
390: public java.sql.PreparedStatement prepareStatement(String sql,
391: int resultType, int resultSetConcurrency)
392: throws SQLException {
393: if (closed)
394: throw new SQLException("Connection closed", "08003");
395: try {
396: return new PreparedStatement(this , sql, resultType,
397: resultSetConcurrency);
398: } catch (IOException e) {
399: throw DbException.wrapThrowable(e);
400: }
401: }
402:
403: /**
404: * Roll back any pending changes for the current transaction. This
405: * ends the transaction; any further statements executed by this
406: * connection will cause a new transaction to be started. This
407: * method closes any <code>ResultSet</code>s opened on this connection.
408: *
409: * @exception SQLException may be thrown
410: */
411: public void rollback() throws SQLException {
412: //#ifdef DEBUG
413: if (trace.bit(1)) {
414: Debug.println("Connection.rollback()");
415: }
416: //#endif
417: if (closed) {
418: throw new SQLException("Connection closed", "08003");
419: }
420: try {
421: qConn.rollbackTransaction();
422: } catch (IOException e) {
423: throw DbException.wrapThrowable(e);
424: }
425: }
426:
427: /**
428: * Set the state of the <code>autoCommit</code> flag.
429: *
430: * @param autoCommit the new <code>autoCommit</code> state.
431: */
432: public void setAutoCommit(boolean autoCommit) throws SQLException {
433: //#ifdef DEBUG
434: if (trace.bit(1)) {
435: Debug.println("Connection.setAutoCommit(" + autoCommit
436: + ")");
437: }
438: //#endif
439: if (closed)
440: throw new SQLException("Connection closed", "08003");
441: qConn.setAutoCommit(autoCommit);
442: }
443:
444: /**
445: * QED doesn't support catalogs, so this function throws
446: * a "not implemented" exception
447: *
448: * @exception SQLException "not implemented"
449: */
450: public void setCatalog(String catalog) throws SQLException {
451: throw new SQLException("Not implemented");
452: }
453:
454: /**
455: * QED doesn't support read-only connections, so this function will
456: * throw a "not implemented" exception if it is called with
457: * <code>readOnly == true</code>
458: *
459: * @param readOnly had better be false
460: * @exception SQLException if it's not
461: */
462: public void setReadOnly(boolean readOnly) throws SQLException {
463: if (readOnly) {
464: throw new SQLException(
465: "Read-only connections not supported");
466: }
467: }
468:
469: /**
470: * QED only supports the <code>TRANSACTION_SERIALIZABLE</code>
471: * isolation level, so this function will
472: * throw a "not implemented" exception if it is called with
473: * any other value.
474: *
475: * @param readOnly had better be <code>TRANSACTION_SERIALIZABLE</code>
476: * @exception SQLException if it's not
477: */
478: public void setTransactionIsolation(int trans) throws SQLException {
479: if (trans != TRANSACTION_SERIALIZABLE) {
480: throw new SQLException("Transaction isolation " + trans
481: + " not supported");
482: }
483:
484: }
485:
486: //#ifndef JDK11
487: /**
488: * Set the type map to be used for custom type mapping of UDTS.
489: * In this release of QED, this call will succeed, but type mapping
490: * is not fully implemented in this release.
491: *
492: * @param map the new map
493: */
494: public void setTypeMap(Map map) throws SQLException {
495: this .typeMap = map;
496: }
497:
498: /**
499: * Return the current type map to be used for custom type mapping of UDTS.
500: * In this release of QED, this call will succeed, but type mapping
501: * is not fully implemented in this release.
502: *
503: * @return the curren type map
504: */
505: public Map getTypeMap() throws SQLException {
506: return typeMap;
507: }
508:
509: /**
510: * Return a new <code>Statement</code> object that can be used to
511: * execute SQL statements on this connection
512: *
513: * @param resultType the desired <code>ResultSet</code> type
514: * @param resultSetConcurrency the desired <code>ResultSet</code>
515: * concurrency
516: * @return a new <code>Statement</code> object
517: * @exception SQLException may be thrown
518: */
519: public java.sql.Statement createStatement(int resultType,
520: int resultSetConcurrency) throws SQLException {
521: if (closed)
522: throw new SQLException("Connection closed", "08003");
523: try {
524: return new Statement(this , resultType, resultSetConcurrency);
525: } catch (IOException e) {
526: throw DbException.wrapThrowable(e);
527: }
528: }
529:
530: //#endif
531:
532: //--------------------------JDBC 3.0-----------------------------
533:
534: //#ifdef JDK14
535: /**
536: * Changes the holdability of <code>ResultSet</code> objects
537: * created using this <code>Connection</code> object to the given
538: * holdability.
539: *
540: * <p>QED: <code>ResultSet</code>s are always closed on commit.</p>
541: *
542: * @param holdability a <code>ResultSet</code> holdability constant; one of
543: * <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
544: * <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
545: * @throws SQLException if a database access occurs, the given parameter
546: * is not a <code>ResultSet</code> constant indicating holdability,
547: * or the given holdability is not supported
548: * @see #getHoldability
549: * @see ResultSet
550: * @since 1.4
551: */
552: public void setHoldability(int holdability) throws SQLException {
553: if (holdability != ResultSet.CLOSE_CURSORS_AT_COMMIT) {
554: throw new SQLException("Not implemented");
555: }
556: }
557:
558: /**
559: * Retrieves the current holdability of <code>ResultSet</code> objects
560: * created using this <code>Connection</code> object.
561: *
562: * <p>QED: <code>ResultSet</code>s are always closed on commit.</p>
563: *
564: * @return the holdability, one of
565: * <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
566: * <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
567: * @throws SQLException if a database access occurs
568: * @see #setHoldability
569: * @see ResultSet
570: * @since 1.4
571: */
572: public int getHoldability() throws SQLException {
573: return ResultSet.CLOSE_CURSORS_AT_COMMIT;
574: }
575:
576: /**
577: * Creates an unnamed savepoint in the current transaction and
578: * returns the new <code>Savepoint</code> object that represents it.
579: *
580: * <p>QED: <code>Savepoint</code>s not supported.</p>
581: *
582: * @return the new <code>Savepoint</code> object
583: * @exception SQLException if a database access error occurs
584: * or this <code>Connection</code> object is currently in
585: * auto-commit mode
586: * @see Savepoint
587: * @since 1.4
588: */
589: public Savepoint setSavepoint() throws SQLException {
590: throw new SQLException("Not implemented");
591: }
592:
593: /**
594: * Creates a savepoint with the given name in the current transaction
595: * and returns the new <code>Savepoint</code> object that represents it.
596: *
597: * <p>QED: <code>Savepoint</code>s not supported.</p>
598: *
599: * @param name a <code>String</code> containing the name of the savepoint
600: * @return the new <code>Savepoint</code> object
601: * @exception SQLException if a database access error occurs
602: * or this <code>Connection</code> object is currently in
603: * auto-commit mode
604: * @see Savepoint
605: * @since 1.4
606: */
607: public Savepoint setSavepoint(String name) throws SQLException {
608: throw new SQLException("Not implemented");
609: }
610:
611: /**
612: * Undoes all changes made after the given <code>Savepoint</code> object
613: * was set.
614: * <P>
615: * This method should be used only when auto-commit has been disabled.
616: *
617: * <p>QED: <code>Savepoint</code>s not supported.</p>
618: *
619: * @param savepoint the <code>Savepoint</code> object to roll back to
620: * @exception SQLException if a database access error occurs,
621: * the <code>Savepoint</code> object is no longer valid,
622: * or this <code>Connection</code> object is currently in
623: * auto-commit mode
624: * @see Savepoint
625: * @see #rollback
626: * @since 1.4
627: */
628: public void rollback(Savepoint savepoint) throws SQLException {
629: throw new SQLException("Not implemented");
630: }
631:
632: /**
633: * Removes the given <code>Savepoint</code> object from the current
634: * transaction. Any reference to the savepoint after it have been removed
635: * will cause an <code>SQLException</code> to be thrown.
636: *
637: * <p>QED: <code>Savepoint</code>s not supported.</p>
638: *
639: * @param savepoint the <code>Savepoint</code> object to be removed
640: * @exception SQLException if a database access error occurs or
641: * the given <code>Savepoint</code> object is not a valid
642: * savepoint in the current transaction
643: * @since 1.4
644: */
645: public void releaseSavepoint(Savepoint savepoint)
646: throws SQLException {
647: throw new SQLException("Not implemented");
648: }
649:
650: /**
651: * Creates a <code>Statement</code> object that will generate
652: * <code>ResultSet</code> objects with the given type, concurrency,
653: * and holdability.
654: * This method is the same as the <code>createStatement</code> method
655: * above, but it allows the default result set
656: * type, concurrency, and holdability to be overridden.
657: *
658: * @param resultSetType one of the following <code>ResultSet</code>
659: * constants:
660: * <code>ResultSet.TYPE_FORWARD_ONLY</code>,
661: * <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
662: * <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
663: * @param resultSetConcurrency one of the following <code>ResultSet</code>
664: * constants:
665: * <code>ResultSet.CONCUR_READ_ONLY</code> or
666: * <code>ResultSet.CONCUR_UPDATABLE</code>
667: * @param resultSetHoldability one of the following <code>ResultSet</code>
668: * constants:
669: * <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
670: * <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
671: * @return a new <code>Statement</code> object that will generate
672: * <code>ResultSet</code> objects with the given type,
673: * concurrency, and holdability
674: * @exception SQLException if a database access error occurs
675: * or the given parameters are not <code>ResultSet</code>
676: * constants indicating type, concurrency, and holdability
677: * @see ResultSet
678: * @since 1.4
679: */
680: public java.sql.Statement createStatement(int resultSetType,
681: int resultSetConcurrency, int resultSetHoldability)
682: throws SQLException {
683: setHoldability(resultSetHoldability);
684: return createStatement(resultSetType, resultSetConcurrency);
685: }
686:
687: /**
688: * Creates a <code>PreparedStatement</code> object that will generate
689: * <code>ResultSet</code> objects with the given type, concurrency,
690: * and holdability.
691: * <P>
692: * This method is the same as the <code>prepareStatement</code> method
693: * above, but it allows the default result set
694: * type, concurrency, and holdability to be overridden.
695: *
696: * @param sql a <code>String</code> object that is the SQL statement to
697: * be sent to the database; may contain one or more ? IN
698: * parameters
699: * @param resultSetType one of the following <code>ResultSet</code>
700: * constants:
701: * <code>ResultSet.TYPE_FORWARD_ONLY</code>,
702: * <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
703: * <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
704: * @param resultSetConcurrency one of the following <code>ResultSet</code>
705: * constants:
706: * <code>ResultSet.CONCUR_READ_ONLY</code> or
707: * <code>ResultSet.CONCUR_UPDATABLE</code>
708: * @param resultSetHoldability one of the following <code>ResultSet</code>
709: * constants:
710: * <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
711: * <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
712: * @return a new <code>PreparedStatement</code> object, containing the
713: * pre-compiled SQL statement, that will generate
714: * <code>ResultSet</code> objects with the given type,
715: * concurrency, and holdability
716: * @exception SQLException if a database access error occurs
717: * or the given parameters are not <code>ResultSet</code>
718: * constants indicating type, concurrency, and holdability
719: * @see ResultSet
720: * @since 1.4
721: */
722: public java.sql.PreparedStatement prepareStatement(String sql,
723: int resultSetType, int resultSetConcurrency,
724: int resultSetHoldability) throws SQLException {
725: setHoldability(resultSetHoldability);
726: return prepareStatement(sql, resultSetType,
727: resultSetConcurrency);
728: }
729:
730: /**
731: * Creates a <code>CallableStatement</code> object that will generate
732: * <code>ResultSet</code> objects with the given type and concurrency.
733: * This method is the same as the <code>prepareCall</code> method
734: * above, but it allows the default result set
735: * type, result set concurrency type and holdability to be overridden.
736: *
737: * @param sql a <code>String</code> object that is the SQL statement to
738: * be sent to the database; may contain on or more ? parameters
739: * @param resultSetType one of the following <code>ResultSet</code>
740: * constants:
741: * <code>ResultSet.TYPE_FORWARD_ONLY</code>,
742: * <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
743: * <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
744: * @param resultSetConcurrency one of the following <code>ResultSet</code>
745: * constants:
746: * <code>ResultSet.CONCUR_READ_ONLY</code> or
747: * <code>ResultSet.CONCUR_UPDATABLE</code>
748: * @param resultSetHoldability one of the following <code>ResultSet</code>
749: * constants:
750: * <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
751: * <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
752: * @return a new <code>CallableStatement</code> object, containing the
753: * pre-compiled SQL statement, that will generate
754: * <code>ResultSet</code> objects with the given type,
755: * concurrency, and holdability
756: * @exception SQLException if a database access error occurs
757: * or the given parameters are not <code>ResultSet</code>
758: * constants indicating type, concurrency, and holdability
759: * @see ResultSet
760: * @since 1.4
761: */
762: public CallableStatement prepareCall(String sql, int resultSetType,
763: int resultSetConcurrency, int resultSetHoldability)
764: throws SQLException {
765: setHoldability(resultSetHoldability);
766: return prepareCall(sql, resultSetType, resultSetConcurrency);
767: }
768:
769: /**
770: * Creates a default <code>PreparedStatement</code> object that has
771: * the capability to retrieve auto-generated keys. The given constant
772: * tells the driver whether it should make auto-generated keys
773: * available for retrieval. This parameter is ignored if the SQL
774: * statement is not an <code>INSERT</code> statement.
775: * <P>
776: * <B>Note:</B> This method is optimized for handling
777: * parametric SQL statements that benefit from precompilation. If
778: * the driver supports precompilation,
779: * the method <code>prepareStatement</code> will send
780: * the statement to the database for precompilation. Some drivers
781: * may not support precompilation. In this case, the statement may
782: * not be sent to the database until the <code>PreparedStatement</code>
783: * object is executed. This has no direct effect on users; however, it does
784: * affect which methods throw certain SQLExceptions.
785: * <P>
786: * Result sets created using the returned <code>PreparedStatement</code>
787: * object will by default be type <code>TYPE_FORWARD_ONLY</code>
788: * and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
789: *
790: * @param sql an SQL statement that may contain one or more '?' IN
791: * parameter placeholders
792: * @param autoGeneratedKeys a flag indicating whether auto-generated keys
793: * should be returned; one of the following <code>Statement</code>
794: * constants:
795: * @param autoGeneratedKeys a flag indicating that auto-generated keys
796: * should be returned, one of
797: * <code>Statement.RETURN_GENERATED_KEYS</code> or
798: * <code>Statement.NO_GENERATED_KEYS</code>.
799: * @return a new <code>PreparedStatement</code> object, containing the
800: * pre-compiled SQL statement, that will have the capability of
801: * returning auto-generated keys
802: * @exception SQLException if a database access error occurs
803: * or the given parameter is not a <code>Statement</code>
804: * constant indicating whether auto-generated keys should be
805: * returned
806: * @since 1.4
807: */
808: public java.sql.PreparedStatement prepareStatement(String sql,
809: int autoGeneratedKeys) throws SQLException {
810: if (autoGeneratedKeys == Statement.RETURN_GENERATED_KEYS) {
811: throw new SQLException(
812: "RETURN_GENERATED_KEYS not implemented");
813: }
814: return prepareStatement(sql);
815: }
816:
817: /**
818: * Creates a default <code>PreparedStatement</code> object capable
819: * of returning the auto-generated keys designated by the given array.
820: * This array contains the indexes of the columns in the target
821: * table that contain the auto-generated keys that should be made
822: * available. This array is ignored if the SQL
823: * statement is not an <code>INSERT</code> statement.
824: * <P>
825: * An SQL statement with or without IN parameters can be
826: * pre-compiled and stored in a <code>PreparedStatement</code> object. This
827: * object can then be used to efficiently execute this statement
828: * multiple times.
829: * <P>
830: * <B>Note:</B> This method is optimized for handling
831: * parametric SQL statements that benefit from precompilation. If
832: * the driver supports precompilation,
833: * the method <code>prepareStatement</code> will send
834: * the statement to the database for precompilation. Some drivers
835: * may not support precompilation. In this case, the statement may
836: * not be sent to the database until the <code>PreparedStatement</code>
837: * object is executed. This has no direct effect on users; however, it does
838: * affect which methods throw certain SQLExceptions.
839: * <P>
840: * Result sets created using the returned <code>PreparedStatement</code>
841: * object will by default be type <code>TYPE_FORWARD_ONLY</code>
842: * and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
843: *
844: * @param sql an SQL statement that may contain one or more '?' IN
845: * parameter placeholders
846: * @param columnIndexes an array of column indexes indicating the columns
847: * that should be returned from the inserted row or rows
848: * @return a new <code>PreparedStatement</code> object, containing the
849: * pre-compiled statement, that is capable of returning the
850: * auto-generated keys designated by the given array of column
851: * indexes
852: * @exception SQLException if a database access error occurs
853: *
854: * @since 1.4
855: */
856: public java.sql.PreparedStatement prepareStatement(String sql,
857: int columnIndexes[]) throws SQLException {
858: throw new SQLException("RETURN_GENERATED_KEYS not implemented");
859: }
860:
861: /**
862: * Creates a default <code>PreparedStatement</code> object capable
863: * of returning the auto-generated keys designated by the given array.
864: * This array contains the names of the columns in the target
865: * table that contain the auto-generated keys that should be returned.
866: * This array is ignored if the SQL
867: * statement is not an <code>INSERT</code> statement.
868: * <P>
869: * An SQL statement with or without IN parameters can be
870: * pre-compiled and stored in a <code>PreparedStatement</code> object. This
871: * object can then be used to efficiently execute this statement
872: * multiple times.
873: * <P>
874: * <B>Note:</B> This method is optimized for handling
875: * parametric SQL statements that benefit from precompilation. If
876: * the driver supports precompilation,
877: * the method <code>prepareStatement</code> will send
878: * the statement to the database for precompilation. Some drivers
879: * may not support precompilation. In this case, the statement may
880: * not be sent to the database until the <code>PreparedStatement</code>
881: * object is executed. This has no direct effect on users; however, it does
882: * affect which methods throw certain SQLExceptions.
883: * <P>
884: * Result sets created using the returned <code>PreparedStatement</code>
885: * object will by default be type <code>TYPE_FORWARD_ONLY</code>
886: * and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
887: *
888: * @param sql an SQL statement that may contain one or more '?' IN
889: * parameter placeholders
890: * @param columnNames an array of column names indicating the columns
891: * that should be returned from the inserted row or rows
892: * @return a new <code>PreparedStatement</code> object, containing the
893: * pre-compiled statement, that is capable of returning the
894: * auto-generated keys designated by the given array of column
895: * names
896: * @exception SQLException if a database access error occurs
897: *
898: * @since 1.4
899: */
900: public java.sql.PreparedStatement prepareStatement(String sql,
901: String columnNames[]) throws SQLException {
902: throw new SQLException("RETURN_GENERATED_KEYS not implemented");
903: }
904: //#endif
905: }
|