KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > client > am > DatabaseMetaData


1 /*
2
3    Derby - Class org.apache.derby.client.am.DatabaseMetaData
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20 */

21
22 package org.apache.derby.client.am;
23
24 import java.sql.SQLException JavaDoc;
25
26 import org.apache.derby.jdbc.ClientDataSource;
27 import org.apache.derby.shared.common.reference.SQLState;
28 import org.apache.derby.shared.common.reference.JDBC30Translation;
29
30 // Note:
31
// Tag members using the strictest visibility.
32
// Note:
33
// Mark methods synchronized if and only if they update object state and are public.
34
// Not yet done:
35
// Application heap data should be copied for shiraz.
36
// Save for future pass to avoid clutter during development.
37
// Not yet done:
38
// Apply meaning-preserving program transformations for performance,
39
// including the replacement of slow ADTs with faster unsynchronized ADTs.
40
// Save for future pass to avoid clutter during development.
41
// Not yet done:
42
// Assign an ErrorKey, ResourceKey, and Resource for each throw statement.
43
// Save for future pass to avoid maintenance during development.
44

45 public abstract class DatabaseMetaData implements java.sql.DatabaseMetaData JavaDoc {
46     //----------------------------- constants -----------------------------------
47

48     private final static short SQL_BEST_ROWID = 1;
49     private final static short SQL_ROWVER = 2;
50
51     private final static short SQL_INDEX_UNIQUE = 0;
52     private final static short SQL_INDEX_ALL = 1;
53
54     //---------------------navigational members-----------------------------------
55

56     protected Agent agent_;
57     protected Connection connection_;
58
59     //-----------------------------state------------------------------------------
60

61     private final static int numberOfMetaDataInfoMethods__ = 108;
62     private Object JavaDoc[] metaDataInfoCache_ = new Object JavaDoc[numberOfMetaDataInfoMethods__];
63     private boolean metaDataInfoIsCached_ = false;
64
65     public ProductLevel productLevel_;
66
67     /** The JDBC major version supported by the server. */
68     private final int serverJdbcMajorVersion;
69     /** The JDBC minor version supported by the server. */
70     private final int serverJdbcMinorVersion;
71
72     public boolean useServerXAState_ = true;
73
74     //---------------------constructors/finalizer---------------------------------
75

76     protected DatabaseMetaData(Agent agent, Connection connection, ProductLevel productLevel) {
77         agent_ = agent;
78         connection_ = connection;
79         productLevel_ = productLevel;
80         computeFeatureSet_();
81         if (connection.isXAConnection()) {
82             connection.xaHostVersion_ = productLevel_.versionLevel_;
83         }
84         if (productLevel_.lessThan(10, 2, 0)) {
85             serverJdbcMajorVersion = 3;
86             serverJdbcMinorVersion = 0;
87         } else {
88             serverJdbcMajorVersion = 4;
89             serverJdbcMinorVersion = 0;
90         }
91     }
92
93     // ---------------------------jdbc 1------------------------------------------
94

95     //----------------------------------------------------------------------
96
// First, a variety of minor information about the target database.
97

98     private final static int allProceduresAreCallable__ = 0;
99
100     public boolean allProceduresAreCallable() throws SQLException JavaDoc {
101         checkForClosedConnection();
102         return getMetaDataInfoBoolean(allProceduresAreCallable__);
103     }
104
105     private final static int allTablesAreSelectable__ = 1;
106
107     public boolean allTablesAreSelectable() throws SQLException JavaDoc {
108         checkForClosedConnection();
109         return getMetaDataInfoBoolean(allTablesAreSelectable__);
110     }
111
112     private final static int nullsAreSortedHigh__ = 2;
113
114     public boolean nullsAreSortedHigh() throws SQLException JavaDoc {
115         checkForClosedConnection();
116         return getMetaDataInfoBoolean(nullsAreSortedHigh__);
117     }
118
119     private final static int nullsAreSortedLow__ = 3;
120
121     public boolean nullsAreSortedLow() throws SQLException JavaDoc {
122         checkForClosedConnection();
123         return getMetaDataInfoBoolean(nullsAreSortedLow__);
124     }
125
126     private final static int nullsAreSortedAtStart__ = 4;
127
128     public boolean nullsAreSortedAtStart() throws SQLException JavaDoc {
129         checkForClosedConnection();
130         return getMetaDataInfoBoolean(nullsAreSortedAtStart__);
131     }
132
133     private final static int nullsAreSortedAtEnd__ = 5;
134
135     public boolean nullsAreSortedAtEnd() throws SQLException JavaDoc {
136         checkForClosedConnection();
137         return getMetaDataInfoBoolean(nullsAreSortedAtEnd__);
138     }
139
140     private final static int usesLocalFiles__ = 6;
141
142     public boolean usesLocalFiles() throws SQLException JavaDoc {
143         checkForClosedConnection();
144         return getMetaDataInfoBoolean(usesLocalFiles__);
145     }
146
147     private final static int usesLocalFilePerTable__ = 7;
148
149     public boolean usesLocalFilePerTable() throws SQLException JavaDoc {
150         checkForClosedConnection();
151         return getMetaDataInfoBoolean(usesLocalFilePerTable__);
152     }
153
154     private final static int storesUpperCaseIdentifiers__ = 8;
155
156     public boolean storesUpperCaseIdentifiers() throws SQLException JavaDoc {
157         checkForClosedConnection();
158         return getMetaDataInfoBoolean(storesUpperCaseIdentifiers__);
159     }
160
161
162     private final static int storesLowerCaseIdentifiers__ = 9;
163
164     public boolean storesLowerCaseIdentifiers() throws SQLException JavaDoc {
165         checkForClosedConnection();
166         return getMetaDataInfoBoolean(storesLowerCaseIdentifiers__);
167     }
168
169     private final static int storesMixedCaseIdentifiers__ = 10;
170
171     public boolean storesMixedCaseIdentifiers() throws SQLException JavaDoc {
172         checkForClosedConnection();
173         return getMetaDataInfoBoolean(storesMixedCaseIdentifiers__);
174     }
175
176     private final static int storesUpperCaseQuotedIdentifiers__ = 11;
177
178     public boolean storesUpperCaseQuotedIdentifiers() throws SQLException JavaDoc {
179         checkForClosedConnection();
180         return getMetaDataInfoBoolean(storesUpperCaseQuotedIdentifiers__);
181     }
182
183     private final static int storesLowerCaseQuotedIdentifiers__ = 12;
184
185     public boolean storesLowerCaseQuotedIdentifiers() throws SQLException JavaDoc {
186         checkForClosedConnection();
187         return getMetaDataInfoBoolean(storesLowerCaseQuotedIdentifiers__);
188     }
189
190     private final static int storesMixedCaseQuotedIdentifiers__ = 13;
191
192     public boolean storesMixedCaseQuotedIdentifiers() throws SQLException JavaDoc {
193         checkForClosedConnection();
194         return getMetaDataInfoBoolean(storesMixedCaseQuotedIdentifiers__);
195     }
196
197     private final static int getSQLKeywords__ = 14;
198
199     public String JavaDoc getSQLKeywords() throws SQLException JavaDoc {
200         checkForClosedConnection();
201         return getMetaDataInfoString(getSQLKeywords__);
202     }
203
204     private final static int getNumericFunctions__ = 15;
205
206     public String JavaDoc getNumericFunctions() throws SQLException JavaDoc {
207         checkForClosedConnection();
208         return getMetaDataInfoString(getNumericFunctions__);
209     }
210
211     private final static int getStringFunctions__ = 16;
212
213     public String JavaDoc getStringFunctions() throws SQLException JavaDoc {
214         checkForClosedConnection();
215         return getMetaDataInfoString(getStringFunctions__);
216     }
217
218     private final static int getSystemFunctions__ = 17;
219
220     public String JavaDoc getSystemFunctions() throws SQLException JavaDoc {
221         checkForClosedConnection();
222         return getMetaDataInfoString(getSystemFunctions__);
223     }
224
225     private final static int getTimeDateFunctions__ = 18;
226
227     public String JavaDoc getTimeDateFunctions() throws SQLException JavaDoc {
228         checkForClosedConnection();
229         return getMetaDataInfoString(getTimeDateFunctions__);
230     }
231
232     private final static int getSearchStringEscape__ = 19;
233
234     public String JavaDoc getSearchStringEscape() throws SQLException JavaDoc {
235         checkForClosedConnection();
236         return getMetaDataInfoString(getSearchStringEscape__);
237     }
238
239     private final static int getExtraNameCharacters__ = 20;
240
241     public String JavaDoc getExtraNameCharacters() throws SQLException JavaDoc {
242         checkForClosedConnection();
243         return getMetaDataInfoString(getExtraNameCharacters__);
244     }
245
246     private final static int supportsAlterTableWithAddColumn__ = 21;
247
248     public boolean supportsAlterTableWithAddColumn() throws SQLException JavaDoc {
249         checkForClosedConnection();
250         return getMetaDataInfoBoolean(supportsAlterTableWithAddColumn__);
251     }
252
253     private final static int supportsAlterTableWithDropColumn__ = 22;
254
255     public boolean supportsAlterTableWithDropColumn() throws SQLException JavaDoc {
256         checkForClosedConnection();
257         return getMetaDataInfoBoolean(supportsAlterTableWithDropColumn__);
258     }
259
260     private final static int supportsConvert__ = 23;
261
262     public boolean supportsConvert() throws SQLException JavaDoc {
263         checkForClosedConnection();
264         return getMetaDataInfoBoolean(supportsConvert__);
265     }
266
267     private final static int supportsConvertType__ = 24;
268
269     public boolean supportsConvert(int fromType, int toType) throws SQLException JavaDoc {
270         checkForClosedConnection();
271         return getMetaDataInfoBoolean_supportsConvert(supportsConvertType__, fromType, toType);
272     }
273
274     private final static int supportsDifferentTableCorrelationNames__ = 25;
275
276     public boolean supportsDifferentTableCorrelationNames() throws SQLException JavaDoc {
277         checkForClosedConnection();
278         return getMetaDataInfoBoolean(supportsDifferentTableCorrelationNames__);
279     }
280
281     private final static int supportsExpressionsInOrderBy__ = 26;
282
283     public boolean supportsExpressionsInOrderBy() throws SQLException JavaDoc {
284         checkForClosedConnection();
285         return getMetaDataInfoBoolean(supportsExpressionsInOrderBy__);
286     }
287
288     private final static int supportsOrderByUnrelated__ = 27;
289
290     public boolean supportsOrderByUnrelated() throws SQLException JavaDoc {
291         checkForClosedConnection();
292         return getMetaDataInfoBoolean(supportsOrderByUnrelated__);
293     }
294
295     private final static int supportsGroupBy__ = 28;
296
297     public boolean supportsGroupBy() throws SQLException JavaDoc {
298         checkForClosedConnection();
299         return getMetaDataInfoBoolean(supportsGroupBy__);
300     }
301
302     private final static int supportsGroupByUnrelated__ = 29;
303
304     public boolean supportsGroupByUnrelated() throws SQLException JavaDoc {
305         checkForClosedConnection();
306         return getMetaDataInfoBoolean(supportsGroupByUnrelated__);
307     }
308
309     private final static int supportsGroupByBeyondSelect__ = 30;
310
311     public boolean supportsGroupByBeyondSelect() throws SQLException JavaDoc {
312         checkForClosedConnection();
313         return getMetaDataInfoBoolean(supportsGroupByBeyondSelect__);
314     }
315
316     private final static int supportsMultipleResultSets__ = 31;
317
318     public boolean supportsMultipleResultSets() throws SQLException JavaDoc {
319         checkForClosedConnection();
320         return getMetaDataInfoBoolean(supportsMultipleResultSets__);
321     }
322
323     private final static int supportsMultipleTransactions__ = 32;
324
325     public boolean supportsMultipleTransactions() throws SQLException JavaDoc {
326         checkForClosedConnection();
327         return getMetaDataInfoBoolean(supportsMultipleTransactions__);
328     }
329
330     private final static int supportsCoreSQLGrammar__ = 33;
331
332     public boolean supportsCoreSQLGrammar() throws SQLException JavaDoc {
333         checkForClosedConnection();
334         return getMetaDataInfoBoolean(supportsCoreSQLGrammar__);
335     }
336
337     private final static int supportsExtendedSQLGrammar__ = 34;
338
339     public boolean supportsExtendedSQLGrammar() throws SQLException JavaDoc {
340         checkForClosedConnection();
341         return getMetaDataInfoBoolean(supportsExtendedSQLGrammar__);
342     }
343
344     private final static int supportsANSI92IntermediateSQL__ = 35;
345
346     public boolean supportsANSI92IntermediateSQL() throws SQLException JavaDoc {
347         checkForClosedConnection();
348         return getMetaDataInfoBoolean(supportsANSI92IntermediateSQL__);
349     }
350
351     private final static int supportsANSI92FullSQL__ = 36;
352
353     public boolean supportsANSI92FullSQL() throws SQLException JavaDoc {
354         checkForClosedConnection();
355         return getMetaDataInfoBoolean(supportsANSI92FullSQL__);
356     }
357
358     private final static int supportsIntegrityEnhancementFacility__ = 37;
359
360     public boolean supportsIntegrityEnhancementFacility() throws SQLException JavaDoc {
361         checkForClosedConnection();
362         return getMetaDataInfoBoolean(supportsIntegrityEnhancementFacility__);
363     }
364
365     private final static int supportsOuterJoins__ = 38;
366
367     public boolean supportsOuterJoins() throws SQLException JavaDoc {
368         checkForClosedConnection();
369         return getMetaDataInfoBoolean(supportsOuterJoins__);
370     }
371
372     private final static int supportsFullOuterJoins__ = 39;
373
374     public boolean supportsFullOuterJoins() throws SQLException JavaDoc {
375         checkForClosedConnection();
376         return getMetaDataInfoBoolean(supportsFullOuterJoins__);
377     }
378
379     private final static int supportsLimitedOuterJoins__ = 40;
380
381     public boolean supportsLimitedOuterJoins() throws SQLException JavaDoc {
382         checkForClosedConnection();
383         return getMetaDataInfoBoolean(supportsLimitedOuterJoins__);
384     }
385
386     private final static int getSchemaTerm__ = 41;
387
388     public String JavaDoc getSchemaTerm() throws SQLException JavaDoc {
389         checkForClosedConnection();
390         return getMetaDataInfoString(getSchemaTerm__);
391     }
392
393     private final static int getProcedureTerm__ = 42;
394
395     public String JavaDoc getProcedureTerm() throws SQLException JavaDoc {
396         checkForClosedConnection();
397         return getMetaDataInfoString(getProcedureTerm__);
398     }
399
400     private final static int getCatalogTerm__ = 43;
401
402     public String JavaDoc getCatalogTerm() throws SQLException JavaDoc {
403         checkForClosedConnection();
404         return getMetaDataInfoString(getCatalogTerm__);
405     }
406
407     private final static int isCatalogAtStart__ = 44;
408
409     public boolean isCatalogAtStart() throws SQLException JavaDoc {
410         checkForClosedConnection();
411         return getMetaDataInfoBoolean(isCatalogAtStart__);
412     }
413
414     private final static int getCatalogSeparator__ = 45;
415
416     public String JavaDoc getCatalogSeparator() throws SQLException JavaDoc {
417         checkForClosedConnection();
418         return getMetaDataInfoString(getCatalogSeparator__);
419     }
420
421     private final static int supportsSchemasInDataManipulation__ = 46;
422
423     public boolean supportsSchemasInDataManipulation() throws SQLException JavaDoc {
424         checkForClosedConnection();
425         return getMetaDataInfoBoolean(supportsSchemasInDataManipulation__);
426     }
427
428     private final static int supportsSchemasInProcedureCalls__ = 47;
429
430     public boolean supportsSchemasInProcedureCalls() throws SQLException JavaDoc {
431         checkForClosedConnection();
432         return getMetaDataInfoBoolean(supportsSchemasInProcedureCalls__);
433     }
434
435     private final static int supportsSchemasInTableDefinitions__ = 48;
436
437     public boolean supportsSchemasInTableDefinitions() throws SQLException JavaDoc {
438         checkForClosedConnection();
439         return getMetaDataInfoBoolean(supportsSchemasInTableDefinitions__);
440     }
441
442
443     private final static int supportsSchemasInIndexDefinitions__ = 49;
444
445     public boolean supportsSchemasInIndexDefinitions() throws SQLException JavaDoc {
446         checkForClosedConnection();
447         return getMetaDataInfoBoolean(supportsSchemasInIndexDefinitions__);
448     }
449
450     private final static int supportsSchemasInPrivilegeDefinitions__ = 50;
451
452     public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException JavaDoc {
453         checkForClosedConnection();
454         return getMetaDataInfoBoolean(supportsSchemasInPrivilegeDefinitions__);
455     }
456
457     private final static int supportsCatalogsInDataManipulation__ = 51;
458
459     public boolean supportsCatalogsInDataManipulation() throws SQLException JavaDoc {
460         checkForClosedConnection();
461         return getMetaDataInfoBoolean(supportsCatalogsInDataManipulation__);
462     }
463
464     private final static int supportsCatalogsInProcedureCalls__ = 52;
465
466     public boolean supportsCatalogsInProcedureCalls() throws SQLException JavaDoc {
467         checkForClosedConnection();
468         return getMetaDataInfoBoolean(supportsCatalogsInProcedureCalls__);
469     }
470
471     private final static int supportsCatalogsInTableDefinitions__ = 53;
472
473     public boolean supportsCatalogsInTableDefinitions() throws SQLException JavaDoc {
474         checkForClosedConnection();
475         return getMetaDataInfoBoolean(supportsCatalogsInTableDefinitions__);
476     }
477
478     private final static int supportsCatalogsInIndexDefinitions__ = 54;
479
480     public boolean supportsCatalogsInIndexDefinitions() throws SQLException JavaDoc {
481         checkForClosedConnection();
482         return getMetaDataInfoBoolean(supportsCatalogsInIndexDefinitions__);
483     }
484
485     private final static int supportsCatalogsInPrivilegeDefinitions__ = 55;
486
487     public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException JavaDoc {
488         checkForClosedConnection();
489         return getMetaDataInfoBoolean(supportsCatalogsInPrivilegeDefinitions__);
490     }
491
492     private final static int supportsPositionedDelete__ = 56;
493
494     public boolean supportsPositionedDelete() throws SQLException JavaDoc {
495         checkForClosedConnection();
496         return getMetaDataInfoBoolean(supportsPositionedDelete__);
497     }
498
499
500     private final static int supportsPositionedUpdate__ = 57;
501
502     public boolean supportsPositionedUpdate() throws SQLException JavaDoc {
503         checkForClosedConnection();
504         return getMetaDataInfoBoolean(supportsPositionedUpdate__);
505     }
506
507     private final static int supportsSelectForUpdate__ = 58;
508
509     public boolean supportsSelectForUpdate() throws SQLException JavaDoc {
510         checkForClosedConnection();
511         return getMetaDataInfoBoolean(supportsSelectForUpdate__);
512     }
513
514     private final static int supportsStoredProcedures__ = 59;
515
516     public boolean supportsStoredProcedures() throws SQLException JavaDoc {
517         checkForClosedConnection();
518         return getMetaDataInfoBoolean(supportsStoredProcedures__);
519     }
520
521     private final static int supportsSubqueriesInComparisons__ = 60;
522
523     public boolean supportsSubqueriesInComparisons() throws SQLException JavaDoc {
524         checkForClosedConnection();
525         return getMetaDataInfoBoolean(supportsSubqueriesInComparisons__);
526     }
527
528     private final static int supportsUnion__ = 61;
529
530     public boolean supportsUnion() throws SQLException JavaDoc {
531         checkForClosedConnection();
532         return getMetaDataInfoBoolean(supportsUnion__);
533     }
534
535     private final static int supportsUnionAll__ = 62;
536
537     public boolean supportsUnionAll() throws SQLException JavaDoc {
538         checkForClosedConnection();
539         return getMetaDataInfoBoolean(supportsUnionAll__);
540
541     }
542
543     private final static int supportsOpenCursorsAcrossCommit__ = 63;
544
545     public boolean supportsOpenCursorsAcrossCommit() throws SQLException JavaDoc {
546         checkForClosedConnection();
547         return getMetaDataInfoBoolean(supportsOpenCursorsAcrossCommit__);
548     }
549
550     private final static int supportsOpenCursorsAcrossRollback__ = 64;
551
552     public boolean supportsOpenCursorsAcrossRollback() throws SQLException JavaDoc {
553         checkForClosedConnection();
554         return getMetaDataInfoBoolean(supportsOpenCursorsAcrossRollback__);
555     }
556
557     private final static int supportsOpenStatementsAcrossCommit__ = 65;
558
559     public boolean supportsOpenStatementsAcrossCommit() throws SQLException JavaDoc {
560         checkForClosedConnection();
561         return getMetaDataInfoBoolean(supportsOpenStatementsAcrossCommit__);
562     }
563
564
565     private final static int supportsOpenStatementsAcrossRollback__ = 66;
566
567     public boolean supportsOpenStatementsAcrossRollback() throws SQLException JavaDoc {
568         checkForClosedConnection();
569         return getMetaDataInfoBoolean(supportsOpenStatementsAcrossRollback__);
570     }
571
572     //----------------------------------------------------------------------
573
// The following group of methods exposes various limitations
574
// based on the target database with the current driver.
575
// Unless otherwise specified, a result of zero means there is no
576
// limit, or the limit is not known.
577
private final static int getMaxBinaryLiteralLength__ = 67;
578
579     public int getMaxBinaryLiteralLength() throws SQLException JavaDoc {
580         checkForClosedConnection();
581         return getMetaDataInfoInt(getMaxBinaryLiteralLength__);
582     }
583
584     private final static int getMaxCharLiteralLength__ = 68;
585
586     public int getMaxCharLiteralLength() throws SQLException JavaDoc {
587         checkForClosedConnection();
588         return getMetaDataInfoInt(getMaxCharLiteralLength__);
589     }
590
591     private final static int getMaxColumnNameLength__ = 69;
592
593     public int getMaxColumnNameLength() throws SQLException JavaDoc {
594         checkForClosedConnection();
595         return getMetaDataInfoInt(getMaxColumnNameLength__);
596     }
597
598     private final static int getMaxColumnsInGroupBy__ = 70;
599
600     public int getMaxColumnsInGroupBy() throws SQLException JavaDoc {
601         checkForClosedConnection();
602         return getMetaDataInfoInt(getMaxColumnsInGroupBy__);
603     }
604
605     private final static int getMaxColumnsInIndex__ = 71;
606
607     public int getMaxColumnsInIndex() throws SQLException JavaDoc {
608         checkForClosedConnection();
609         return getMetaDataInfoInt(getMaxColumnsInIndex__);
610     }
611
612     private final static int getMaxColumnsInOrderBy__ = 72;
613
614     public int getMaxColumnsInOrderBy() throws SQLException JavaDoc {
615         checkForClosedConnection();
616         return getMetaDataInfoInt(getMaxColumnsInOrderBy__);
617     }
618
619     private final static int getMaxColumnsInSelect__ = 73;
620
621     public int getMaxColumnsInSelect() throws SQLException JavaDoc {
622         checkForClosedConnection();
623         return getMetaDataInfoInt(getMaxColumnsInSelect__);
624     }
625
626     private final static int getMaxColumnsInTable__ = 74;
627
628     public int getMaxColumnsInTable() throws SQLException JavaDoc {
629         checkForClosedConnection();
630         return getMetaDataInfoInt(getMaxColumnsInTable__);
631     }
632
633     private final static int getMaxConnections__ = 75;
634
635     public int getMaxConnections() throws SQLException JavaDoc {
636         checkForClosedConnection();
637         return getMetaDataInfoInt(getMaxConnections__);
638     }
639
640     private final static int getMaxCursorNameLength__ = 76;
641
642     public int getMaxCursorNameLength() throws SQLException JavaDoc {
643         checkForClosedConnection();
644         return getMetaDataInfoInt(getMaxCursorNameLength__);
645     }
646
647     private final static int getMaxIndexLength__ = 77;
648
649     public int getMaxIndexLength() throws SQLException JavaDoc {
650         checkForClosedConnection();
651         return getMetaDataInfoInt(getMaxIndexLength__);
652     }
653
654     private final static int getMaxSchemaNameLength__ = 78;
655
656     public int getMaxSchemaNameLength() throws SQLException JavaDoc {
657         checkForClosedConnection();
658         return getMetaDataInfoInt(getMaxSchemaNameLength__);
659     }
660
661     private final static int getMaxProcedureNameLength__ = 79;
662
663     public int getMaxProcedureNameLength() throws SQLException JavaDoc {
664         checkForClosedConnection();
665         return getMetaDataInfoInt(getMaxProcedureNameLength__);
666     }
667
668     private final static int getMaxCatalogNameLength__ = 80;
669
670     public int getMaxCatalogNameLength() throws SQLException JavaDoc {
671         checkForClosedConnection();
672         return getMetaDataInfoInt(getMaxCatalogNameLength__);
673     }
674
675     private final static int getMaxRowSize__ = 81;
676
677     public int getMaxRowSize() throws SQLException JavaDoc {
678         checkForClosedConnection();
679         return getMetaDataInfoInt(getMaxRowSize__);
680     }
681
682     private final static int doesMaxRowSizeIncludeBlobs__ = 82;
683
684     public boolean doesMaxRowSizeIncludeBlobs() throws SQLException JavaDoc {
685         checkForClosedConnection();
686         return getMetaDataInfoBoolean(doesMaxRowSizeIncludeBlobs__);
687     }
688
689     private final static int getMaxStatementLength__ = 83;
690
691     public int getMaxStatementLength() throws SQLException JavaDoc {
692         checkForClosedConnection();
693         return getMetaDataInfoInt(getMaxStatementLength__);
694     }
695
696     private final static int getMaxStatements__ = 84;
697
698     public int getMaxStatements() throws SQLException JavaDoc {
699         checkForClosedConnection();
700         return getMetaDataInfoInt(getMaxStatements__);
701     }
702
703     private final static int getMaxTableNameLength__ = 85;
704
705     public int getMaxTableNameLength() throws SQLException JavaDoc {
706         checkForClosedConnection();
707         return getMetaDataInfoInt(getMaxTableNameLength__);
708     }
709
710     private final static int getMaxTablesInSelect__ = 86;
711
712     public int getMaxTablesInSelect() throws SQLException JavaDoc {
713         checkForClosedConnection();
714         return getMetaDataInfoInt(getMaxTablesInSelect__);
715     }
716
717     private final static int getMaxUserNameLength__ = 87;
718
719     public int getMaxUserNameLength() throws SQLException JavaDoc {
720         checkForClosedConnection();
721         return getMetaDataInfoInt(getMaxUserNameLength__);
722     }
723
724     private final static int getDefaultTransactionIsolation__ = 88;
725
726     public int getDefaultTransactionIsolation() throws SQLException JavaDoc {
727         checkForClosedConnection();
728         return getMetaDataInfoInt(getDefaultTransactionIsolation__);
729     }
730
731     private final static int supportsTransactions__ = 89;
732
733     public boolean supportsTransactions() throws SQLException JavaDoc {
734         checkForClosedConnection();
735         return getMetaDataInfoBoolean(supportsTransactions__);
736     }
737
738     // Stored Procedure will return a String containing a
739
// comma seperated list of all supported levels
740
private final static int supportsTransactionIsolationLevel__ = 90;
741
742     public boolean supportsTransactionIsolationLevel(int level) throws SQLException JavaDoc {
743         checkForClosedConnection();
744         return getMetaDataInfoBooleanWithType(supportsTransactionIsolationLevel__, level);
745     }
746
747
748     private final static int supportsDataDefinitionAndDataManipulationTransactions__ = 91;
749
750     public boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException JavaDoc {
751         checkForClosedConnection();
752         return getMetaDataInfoBoolean(supportsDataDefinitionAndDataManipulationTransactions__);
753     }
754
755     private final static int supportsDataManipulationTransactionsOnly__ = 92;
756
757     public boolean supportsDataManipulationTransactionsOnly() throws SQLException JavaDoc {
758         checkForClosedConnection();
759         return getMetaDataInfoBoolean(supportsDataManipulationTransactionsOnly__);
760     }
761
762     private final static int dataDefinitionCausesTransactionCommit__ = 93;
763
764     public boolean dataDefinitionCausesTransactionCommit() throws SQLException JavaDoc {
765         checkForClosedConnection();
766         return getMetaDataInfoBoolean(dataDefinitionCausesTransactionCommit__);
767     }
768
769     private final static int dataDefinitionIgnoredInTransactions__ = 94;
770
771     public boolean dataDefinitionIgnoredInTransactions() throws SQLException JavaDoc {
772         checkForClosedConnection();
773         return getMetaDataInfoBoolean(dataDefinitionIgnoredInTransactions__);
774     }
775
776     // Stored Procedure will return a String containing a
777
// comma seperated list of all the supported resultSet types
778
private final static int supportsResultSetType__ = 95;
779
780     public boolean supportsResultSetType(int type) throws SQLException JavaDoc {
781         checkForClosedConnection();
782         return getMetaDataInfoBooleanWithType(supportsResultSetType__, type);
783     }
784
785     private final static int supportsResultSetConcurrency__ = 96;
786
787     public boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLException JavaDoc {
788         checkForClosedConnection();
789         return getMetaDataInfoInt_SupportsResultSetConcurrency(supportsResultSetConcurrency__, type, concurrency);
790     }
791
792     // Stored Procedure will return a String containing a
793
// comma seperated list of all the supported result Set types
794
private final static int ownUpdatesAreVisible__ = 97;
795
796     public boolean ownUpdatesAreVisible(int type) throws SQLException JavaDoc {
797         checkForClosedConnection();
798         return getMetaDataInfoBooleanWithType(ownUpdatesAreVisible__, type);
799     }
800
801     // Stored Procedure will return a String containing a
802
// comma seperated list of all the supported result Set types
803
private final static int ownDeletesAreVisible__ = 98;
804
805     public boolean ownDeletesAreVisible(int type) throws SQLException JavaDoc {
806         checkForClosedConnection();
807         return getMetaDataInfoBooleanWithType(ownDeletesAreVisible__, type);
808     }
809
810     // Stored Procedure will return a String containing a
811
// comma seperated list all the supported result Set types
812
private final static int ownInsertsAreVisible__ = 99;
813
814     public boolean ownInsertsAreVisible(int type) throws SQLException JavaDoc {
815         checkForClosedConnection();
816         return getMetaDataInfoBooleanWithType(ownInsertsAreVisible__, type);
817     }
818
819     // Stored Procedure will return a String containing a
820
// comma seperated list of all the supported result Set types
821
private final static int othersUpdatesAreVisible__ = 100;
822
823     public boolean othersUpdatesAreVisible(int type) throws SQLException JavaDoc {
824         checkForClosedConnection();
825         return getMetaDataInfoBooleanWithType(othersUpdatesAreVisible__, type);
826     }
827
828     // Stored Procedure will return a String containing a
829
// comma seperated list of all the supported result Set types
830
private final static int othersDeletesAreVisible__ = 101;
831
832     public boolean othersDeletesAreVisible(int type) throws SQLException JavaDoc {
833         checkForClosedConnection();
834         return getMetaDataInfoBooleanWithType(othersDeletesAreVisible__, type);
835     }
836
837     // Stored Procedure will return a String containing a
838
// comma seperated list of all the supported result Set types
839
private final static int othersInsertsAreVisible__ = 102;
840
841     public boolean othersInsertsAreVisible(int type) throws SQLException JavaDoc {
842         checkForClosedConnection();
843         return getMetaDataInfoBooleanWithType(othersInsertsAreVisible__, type);
844     }
845
846     // Stored Procedure will return a String containing a
847
// comma seperated list of all the supported result Set types
848
private final static int updatesAreDetected__ = 103;
849
850     public boolean updatesAreDetected(int type) throws SQLException JavaDoc {
851         checkForClosedConnection();
852         return getMetaDataInfoBooleanWithType(updatesAreDetected__, type);
853     }
854
855     // Stored Procedure will return a String containing a
856
// comma seperated list of all the supported result Set types
857
private final static int deletesAreDetected__ = 104;
858
859     public boolean deletesAreDetected(int type) throws SQLException JavaDoc {
860         checkForClosedConnection();
861         return getMetaDataInfoBooleanWithType(deletesAreDetected__, type);
862     }
863
864     // Stored Procedure will return a String containing a
865
// comma seperated list of all the supported result Set types
866
private final static int insertsAreDetected__ = 105;
867
868     public boolean insertsAreDetected(int type) throws SQLException JavaDoc {
869         checkForClosedConnection();
870         return getMetaDataInfoBooleanWithType(insertsAreDetected__, type);
871     }
872
873     private final static int supportsBatchUpdates__ = 106;
874
875     public boolean supportsBatchUpdates() throws SQLException JavaDoc {
876         checkForClosedConnection();
877         return getMetaDataInfoBoolean(supportsBatchUpdates__);
878     }
879
880     public boolean supportsSavepoints() throws SQLException JavaDoc {
881         checkForClosedConnection();
882         if (productLevel_.greaterThanOrEqualTo(5, 2, 0)) {
883             return true;
884         }
885
886         return false;
887     }
888
889     // start tagging all abstract methods with an underscore like this !!
890
abstract public String JavaDoc getURL_() throws SqlException;
891
892     public String JavaDoc getURL() throws SQLException JavaDoc {
893         try
894         {
895             checkForClosedConnection();
896             return getURL_();
897         }
898         catch ( SqlException se )
899         {
900             throw se.getSQLException();
901         }
902     }
903
904     public String JavaDoc getUserName() throws SQLException JavaDoc {
905         checkForClosedConnection();
906         return connection_.user_;
907     }
908
909     public boolean isReadOnly() throws SQLException JavaDoc {
910         return false;
911     }
912
913     public String JavaDoc getDatabaseProductName() throws SQLException JavaDoc {
914         checkForClosedConnection();
915         return productLevel_.databaseProductName_;
916     }
917
918     public String JavaDoc getDatabaseProductVersion() throws SQLException JavaDoc {
919         checkForClosedConnection();
920         return productLevel_.databaseProductVersion_;
921     }
922
923     public String JavaDoc getDriverName() throws SQLException JavaDoc {
924         checkForClosedConnection();
925         return Configuration.dncDriverName;
926     }
927
928     public String JavaDoc getDriverVersion() throws SQLException JavaDoc {
929         checkForClosedConnection();
930         return Version.getDriverVersion();
931     }
932
933     // JDBC signature also does not throw SqlException, so we don't check for closed connection.
934
public int getDriverMajorVersion() {
935         return Version.getMajorVersion();
936     }
937
938     // JDBC signature also does not throw SqlException, so we don't check for closed connection.
939
public int getDriverMinorVersion() {
940         return Version.getMinorVersion();
941     }
942
943     //All JDBC Drivers must return false for this method. For this reason we choose
944
//to return FALSE
945
public boolean supportsMixedCaseIdentifiers() throws SQLException JavaDoc {
946         checkForClosedConnection();
947         return false;
948     }
949
950     public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException JavaDoc {
951         checkForClosedConnection();
952         return true;
953     }
954
955     public String JavaDoc getIdentifierQuoteString() throws SQLException JavaDoc {
956         checkForClosedConnection();
957         return "\"";
958     }
959
960     public boolean supportsColumnAliasing() throws SQLException JavaDoc {
961         checkForClosedConnection();
962         return true;
963     }
964
965     public boolean nullPlusNonNullIsNull() throws SQLException JavaDoc {
966         checkForClosedConnection();
967         return true;
968     }
969
970     public boolean supportsTableCorrelationNames() throws SQLException JavaDoc {
971         checkForClosedConnection();
972         return true;
973     }
974
975     public boolean supportsLikeEscapeClause() throws SQLException JavaDoc {
976         checkForClosedConnection();
977         return true;
978     }
979
980     public boolean supportsNonNullableColumns() throws SQLException JavaDoc {
981         checkForClosedConnection();
982         return true;
983     }
984
985     public boolean supportsMinimumSQLGrammar() throws SQLException JavaDoc {
986         checkForClosedConnection();
987         return true;
988     }
989
990     public boolean supportsANSI92EntryLevelSQL() throws SQLException JavaDoc {
991         checkForClosedConnection();
992         return true;
993     }
994
995     public boolean supportsSubqueriesInExists() throws SQLException JavaDoc {
996         checkForClosedConnection();
997         return true;
998     }
999
1000    public boolean supportsSubqueriesInIns() throws SQLException JavaDoc {
1001        checkForClosedConnection();
1002        return true;
1003    }
1004
1005    public boolean supportsSubqueriesInQuantifieds() throws SQLException JavaDoc {
1006        checkForClosedConnection();
1007        return true;
1008    }
1009
1010    public boolean supportsCorrelatedSubqueries() throws SQLException JavaDoc {
1011        checkForClosedConnection();
1012        return true;
1013    }
1014
1015
1016    //------------------------catalog query methods follow--------------------------------------------
1017

1018    // call stored procedure SQLProcedures
1019
// SYSIBM.SQLProcedures(
1020
// CatalogName varchar(128),
1021
// SchemaName varchar(128),
1022
// ProcName varchar(128),
1023
// Options varchar(4000))
1024
//
1025
public java.sql.ResultSet JavaDoc getProcedures(String JavaDoc catalog,
1026                                            String JavaDoc schemaPattern,
1027                                            String JavaDoc procedureNamePattern) throws SQLException JavaDoc {
1028        try
1029        {
1030            synchronized (connection_) {
1031                if (agent_.loggingEnabled()) {
1032                    agent_.logWriter_.traceEntry(this, "getProcedures", catalog, schemaPattern, procedureNamePattern);
1033                }
1034                return getProceduresX(catalog, schemaPattern, procedureNamePattern);
1035            }
1036        }
1037        catch ( SqlException se )
1038        {
1039            throw se.getSQLException();
1040        }
1041    }
1042
1043
1044    private ResultSet getProceduresX(String JavaDoc catalog,
1045                                     String JavaDoc schemaPattern,
1046                                     String JavaDoc procedureNamePattern) throws SqlException {
1047        checkForClosedConnectionX();
1048
1049        PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLPROCEDURES(?,?,?,?)");
1050
1051        cs.setStringX(1, catalog);
1052        cs.setStringX(2, schemaPattern);
1053        cs.setStringX(3, procedureNamePattern);
1054        cs.setStringX(4, getOptions());
1055        return executeCatalogQuery(cs);
1056    }
1057
1058
1059    // call stored procedure SQLProcedureCols
1060
// SYSIBM.SQLProcedureCols(
1061
// CatalogName varchar(128),
1062
// SchemaName varchar(128),
1063
// ProcName varchar(128),
1064
// ParamName varchar(128),
1065
// Options varchar(4000))
1066
//
1067
public java.sql.ResultSet JavaDoc getProcedureColumns(String JavaDoc catalog,
1068                                                  String JavaDoc schemaPattern,
1069                                                  String JavaDoc procedureNamePattern,
1070                                                  String JavaDoc columnNamePattern) throws SQLException JavaDoc {
1071        try
1072        {
1073            synchronized (connection_) {
1074                if (agent_.loggingEnabled()) {
1075                    agent_.logWriter_.traceEntry(this, "getProcedureColumns", catalog, schemaPattern, procedureNamePattern, columnNamePattern);
1076                }
1077                return getProcedureColumnsX(catalog, schemaPattern, procedureNamePattern, columnNamePattern);
1078            }
1079        }
1080        catch ( SqlException se )
1081        {
1082            throw se.getSQLException();
1083        }
1084        
1085    }
1086
1087    private ResultSet getProcedureColumnsX(String JavaDoc catalog,
1088                                           String JavaDoc schemaPattern,
1089                                           String JavaDoc procedureNamePattern,
1090                                           String JavaDoc columnNamePattern) throws SqlException {
1091        checkForClosedConnectionX();
1092        ;
1093
1094        PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLPROCEDURECOLS(?,?,?,?,?)");
1095
1096        cs.setStringX(1, catalog);
1097        cs.setStringX(2, schemaPattern);
1098        cs.setStringX(3, procedureNamePattern);
1099        cs.setStringX(4, columnNamePattern);
1100        cs.setStringX(5, getOptions());
1101        return executeCatalogQuery(cs);
1102    }
1103
1104    /**
1105     * Get the function names available in the database. Calls stored
1106     * procedure <code>SYSIBM.SQLFunctions(CatalogName
1107     * varchar(128), SchemaName varchar(128), FuncName varchar(128),
1108     * Options varchar(4000))</code> on the server. This procedure
1109     * will in turn call
1110     * <code>EmbedDatabaseMetaData.getFunctions(String,String,String)</code><p>
1111     * Compatibility: Only available if both server and client version
1112     * > 10.1, and JDK version >= 1.6. Older clients will not have
1113     * this method available. Newer clients will be able to call this
1114     * method when connected to an older server, but this will be
1115     * trigger an exception in
1116     * <code>checkServerJdbcVersionX()</code>. <p>Upgrade:
1117     * <code>SYSIBM.SQLFunctions</code> is added in
1118     * <code>DataDictionaryImpl.create_10_2_system_procedures
1119     * (TransactionController,UUID)</code> so it will become available
1120     * in newly created databases and after <b>hard</b> upgrade.
1121     *
1122     * @param catalog limit search to this catalog
1123     * @param schemaPattern limit search to schemas matching this pattern
1124     * @param functionNamePattern limit search to functions matching this
1125     * pattern
1126     * @return a <code>ResultSet</code> listing the fucntions
1127     * @exception SqlException if a database error occurs
1128     * @see #getFunctionsX(String, String, String)
1129     * @see org.apache.derby.impl.sql.catalog.DataDictionaryImpl#create_10_2_system_procedures(TransactionController,UUID)
1130     * @see org.apache.derby.impl.jdbc.EmbedDatabaseMetaData#getFunctions(String,String,String)
1131     */

1132
1133    public java.sql.ResultSet JavaDoc getFunctions(String JavaDoc catalog,
1134                                           String JavaDoc schemaPattern,
1135                                           String JavaDoc functionNamePattern)
1136        throws SQLException JavaDoc {
1137        try {
1138            synchronized (connection_) {
1139                if (agent_.loggingEnabled()) {
1140                    agent_.logWriter_.traceEntry(this, "getFunctions",
1141                                                 catalog, schemaPattern,
1142                                                 functionNamePattern);
1143                }
1144                return getFunctionsX(catalog, schemaPattern,
1145                                     functionNamePattern);
1146            }
1147        }
1148        catch (SqlException se) {
1149            throw se.getSQLException();
1150        }
1151    }
1152
1153    /**
1154     * Untraced version of <code>getFunctions(String, String, String)</code>.
1155     * @param catalog limit search to this catalog
1156     * @param schemaPattern limit search to schemas matching this pattern
1157     * @param functionNamePattern limit search to functions matching this
1158     * pattern
1159     * @return a <code>ResultSet</code> listing the fucntions
1160     * @exception SqlException if a database error occurs
1161     * @see #getFunctions(String, String, String)
1162     */

1163    private ResultSet getFunctionsX(String JavaDoc catalog,
1164                                    String JavaDoc schemaPattern,
1165                                    String JavaDoc functionNamePattern)
1166        throws SqlException {
1167        checkForClosedConnectionX();
1168        checkServerJdbcVersionX("getFunctions(String,String,String)", 4, 0);
1169
1170        PreparedStatement cs =
1171            prepareMetaDataQuery("SYSIBM.SQLFUNCTIONS(?,?,?,?)");
1172
1173        cs.setStringX(1, catalog);
1174        cs.setStringX(2, schemaPattern);
1175        cs.setStringX(3, functionNamePattern);
1176        cs.setStringX(4, getOptions());
1177        return executeCatalogQuery(cs);
1178    }
1179
1180    /**
1181     * Get the function names available in the database. Calls stored
1182     * procedure <code>SYSIBM.SQLFunctionParams(CatalogName
1183     * varchar(128), SchemaName varchar(128), FuncName varchar(128),
1184     * ParamName varchar(128), Options varchar(4000))</code> on the
1185     * server. This procedure will in turn call
1186     * <code>EmbedDatabaseMetaData.getFunctionColumns(String,String,
1187     * String,String)</code><p> Compatibility: Only available if both
1188     * server and client version > 10.1, and JDK version >= 1.6. Older
1189     * clients will not have this method available. Newer clients will
1190     * be able to call this method when connected to an older server,
1191     * but this will be trigger an exception in
1192     * <code>checkServerJdbcVersionX()</code>. <p>Upgrade:
1193     * <code>SYSIBM.SQLFunctionParams</code> is added in
1194     * <code>DataDictionaryImpl.create_10_2_system_procedures
1195     * (TransactionController,UUID)</code> so it will become available
1196     * in newly created databases and after <b>hard</b> upgrade.
1197     *
1198     * @param catalog limit search to this catalog
1199     * @param schemaPattern limit search to schemas matching this pattern
1200     * @param functionNamePattern limit search to functions matching this
1201     * pattern
1202     * @return a <code>ResultSet</code> listing the fucntions
1203     * @exception SqlException if a database error occurs
1204     * @see #getFunctionColumnsX(String, String, String,String)
1205     * @see org.apache.derby.impl.sql.catalog.DataDictionaryImpl#create_10_2_system_procedures(TransactionController,UUID)
1206     * @see org.apache.derby.impl.jdbc.EmbedDatabaseMetaData#getFunctions(String,String,String)
1207     */

1208    public java.sql.ResultSet JavaDoc
1209        getFunctionColumns(String JavaDoc catalog,
1210                              String JavaDoc schemaPattern,
1211                              String JavaDoc functionNamePattern,
1212                              String JavaDoc parameterNamePattern)
1213        throws SQLException JavaDoc {
1214        try
1215        {
1216            synchronized (connection_) {
1217                if (agent_.loggingEnabled()) {
1218                    agent_.logWriter_.
1219                        traceEntry(this,
1220                                   "getFunctionColumns",
1221                                   catalog, schemaPattern,
1222                                   functionNamePattern, parameterNamePattern);
1223                }
1224                return getFunctionColumnsX(catalog, schemaPattern,
1225                                              functionNamePattern,
1226                                              parameterNamePattern);
1227            }
1228        }
1229        catch ( SqlException se )
1230        {
1231            throw se.getSQLException();
1232        }
1233    }
1234
1235    /**
1236     * Untraced version of <code>getFunctionColumns(String, String,
1237     * String, String)</code>.
1238     * @param catalog limit search to this catalog
1239     * @param schemaPattern limit search to schemas matching this pattern
1240     * @param functionNamePattern limit search to functions matching this
1241     * pattern
1242     * @param parameterNamePattern limit search to parameters mathing
1243     * this pattern
1244     * @return a <code>ResultSet</code> listing the fucntions
1245     * @exception SqlException if a database error occurs
1246     * @see #getFunctionColumns(String, String, String, String)
1247     */

1248    private ResultSet getFunctionColumnsX(String JavaDoc catalog,
1249                                             String JavaDoc schemaPattern,
1250                                             String JavaDoc functionNamePattern,
1251                                             String JavaDoc parameterNamePattern)
1252        throws SqlException {
1253        checkForClosedConnectionX();
1254        checkServerJdbcVersionX("getFunctionColumns"+
1255                                "(String,String,String,String)", 4, 0);
1256 
1257        PreparedStatement cs =
1258            prepareMetaDataQuery("SYSIBM.SQLFUNCTIONPARAMS(?,?,?,?,?)");
1259
1260        cs.setStringX(1, catalog);
1261        cs.setStringX(2, schemaPattern);
1262        cs.setStringX(3, functionNamePattern);
1263        cs.setStringX(4, parameterNamePattern);
1264        cs.setStringX(5, getOptions());
1265        return executeCatalogQuery(cs);
1266    }
1267
1268    // call stored procedure SQLTables
1269
// SYSIBM.SQLTables(
1270
// CatalogName varchar(128),
1271
// SchemaName varchar(128),
1272
// TableName varchar(128),
1273
// TaleType varchar(4000),
1274
// Options varchar(4000))
1275
//
1276
public java.sql.ResultSet JavaDoc getTables(String JavaDoc catalog,
1277                                        String JavaDoc schemaPattern,
1278                                        String JavaDoc tableNamePattern,
1279                                        String JavaDoc types[]) throws SQLException JavaDoc {
1280        try
1281        {
1282            synchronized (connection_) {
1283                if (agent_.loggingEnabled()) {
1284                    agent_.logWriter_.traceEntry(this, "getTables", catalog, schemaPattern, tableNamePattern, types);
1285                }
1286                return getTablesX(catalog, schemaPattern, tableNamePattern, types);
1287            }
1288        }
1289        catch ( SqlException se )
1290        {
1291            throw se.getSQLException();
1292        }
1293    }
1294
1295    private ResultSet getTablesX(String JavaDoc catalog,
1296                                 String JavaDoc schemaPattern,
1297                                 String JavaDoc tableNamePattern,
1298                                 String JavaDoc types[]) throws SqlException {
1299        try {
1300            checkForClosedConnection();
1301        } catch ( SQLException JavaDoc se ) {
1302            throw new SqlException(se);
1303        }
1304
1305        PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLTABLES(?,?,?,?,?)");
1306
1307        if (catalog == null) {
1308            cs.setNullX(1, java.sql.Types.VARCHAR);
1309        } else {
1310            cs.setStringX(1, catalog);
1311        }
1312
1313        if (schemaPattern == null) {
1314            cs.setNullX(2, java.sql.Types.VARCHAR);
1315        } else {
1316            cs.setStringX(2, schemaPattern);
1317        }
1318
1319        if (tableNamePattern == null) {
1320            cs.setNullX(3, java.sql.Types.VARCHAR);
1321        } else {
1322            cs.setStringX(3, tableNamePattern);
1323        }
1324
1325        String JavaDoc tableTypes = new String JavaDoc();
1326        int i = 0;
1327        if (types == null) {
1328            cs.setNullX(4, java.sql.Types.VARCHAR);
1329        } else if (types.length == 1 && (types[0].trim()).equals("%")) {
1330            cs.setStringX(4, types[0]);
1331        } else {
1332            while (i < types.length) {
1333                if (i > 0) {
1334                    tableTypes = tableTypes.concat(",");
1335                }
1336                tableTypes = tableTypes.concat("'" + types[i] + "'");
1337                i++;
1338            }
1339            cs.setStringX(4, tableTypes);
1340        }
1341        cs.setStringX(5, getOptions());
1342        return executeCatalogQuery(cs);
1343    }
1344
1345    // call stored procedure SQLTables
1346
// SYSIBM.SQLTables(
1347
// CatalogName varchar(128),
1348
// SchemaName varchar(128),
1349
// TableName varchar(128),
1350
// TaleType varchar(4000),
1351
// Options varchar(4000))
1352
//
1353
public java.sql.ResultSet JavaDoc getSchemas() throws SQLException JavaDoc {
1354        try
1355        {
1356            synchronized (connection_) {
1357                if (agent_.loggingEnabled()) {
1358                    agent_.logWriter_.traceEntry(this, "getSchemas");
1359                }
1360                return getSchemasX();
1361            }
1362        }
1363        catch ( SqlException se )
1364        {
1365            throw se.getSQLException();
1366        }
1367    }
1368
1369    private ResultSet getSchemasX() throws SqlException {
1370        try {
1371            checkForClosedConnection();
1372        } catch ( SQLException JavaDoc se ) {
1373            throw new SqlException(se);
1374        }
1375        
1376        ;
1377
1378        PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLTABLES('', '', '', '', 'GETSCHEMAS=1')");
1379        return (ResultSet) cs.executeQueryX();
1380    }
1381
1382
1383    // DERBY does not have the notion of a catalog, so we return a result set with no rows.
1384
public java.sql.ResultSet JavaDoc getCatalogs() throws SQLException JavaDoc {
1385        try
1386        {
1387            synchronized (connection_) {
1388                if (agent_.loggingEnabled()) {
1389                    agent_.logWriter_.traceEntry(this, "getCatalogs");
1390                }
1391                return getCatalogsX();
1392            }
1393        }
1394        catch ( SqlException se )
1395        {
1396            throw se.getSQLException();
1397        }
1398    }
1399
1400    private ResultSet getCatalogsX() throws SqlException {
1401        checkForClosedConnectionX();
1402
1403        PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLTABLES('', '', '', '', 'GETCATALOGS=1')");
1404        return (ResultSet) cs.executeQueryX();
1405    }
1406
1407    // call stored procedure SQLTables
1408
// SYSIBM.SQLTables(
1409
// CatalogName varchar(128),
1410
// SchemaName varchar(128),
1411
// TableName varchar(128),
1412
// TableType varchar(4000),
1413
// Options varchar(4000))
1414
public java.sql.ResultSet JavaDoc getTableTypes() throws SQLException JavaDoc {
1415        try
1416        {
1417            synchronized (connection_) {
1418                if (agent_.loggingEnabled()) {
1419                    agent_.logWriter_.traceEntry(this, "getTableTypes");
1420                }
1421                return getTableTypesX();
1422            }
1423        }
1424        catch ( SqlException se )
1425        {
1426            throw se.getSQLException();
1427        }
1428    }
1429
1430    private ResultSet getTableTypesX() throws SqlException {
1431        checkForClosedConnectionX();
1432        ;
1433
1434        PreparedStatement cs = null;
1435        cs = prepareMetaDataQuery("SYSIBM.SQLTABLES(?,?,?,?,?)");
1436
1437        cs.setStringX(1, "");
1438        cs.setStringX(2, "");
1439        cs.setStringX(3, "");
1440        cs.setStringX(4, "%");
1441        int cursorHold;
1442        if (connection_.holdability() == JDBC30Translation.HOLD_CURSORS_OVER_COMMIT) {
1443            cursorHold = 1;
1444        } else {
1445            cursorHold = 0;
1446        }
1447        cs.setStringX(5, "DATATYPE='JDBC';GETTABLETYPES=1; CURSORHOLD=" + cursorHold);
1448        return executeCatalogQuery(cs);
1449    }
1450
1451
1452    // call stored procedure SQLColumns
1453
// SYSIBM.SQLColumns(
1454
// CatalogName varchar(128),
1455
// SchemaName varchar(128),
1456
// TableName varchar(128),
1457
// ColumnName varchar(128),
1458
// Options varchar(4000))
1459
//
1460
public java.sql.ResultSet JavaDoc getColumns(String JavaDoc catalog,
1461                                         String JavaDoc schemaPattern,
1462                                         String JavaDoc tableNamePattern,
1463                                         String JavaDoc columnNamePattern) throws SQLException JavaDoc {
1464        try
1465        {
1466            synchronized (connection_) {
1467                if (agent_.loggingEnabled()) {
1468                    agent_.logWriter_.traceEntry(this, "getColumns", catalog, schemaPattern, tableNamePattern, columnNamePattern);
1469                }
1470                checkForClosedConnection();
1471                return getColumnsX(catalog, schemaPattern, tableNamePattern, columnNamePattern);
1472            }
1473        }
1474        catch ( SqlException se )
1475        {
1476            throw se.getSQLException();
1477        }
1478    }
1479
1480    private ResultSet getColumnsX(String JavaDoc catalog,
1481                                  String JavaDoc schemaPattern,
1482                                  String JavaDoc tableNamePattern,
1483                                  String JavaDoc columnNamePattern) throws SqlException {
1484        checkForClosedConnectionX();
1485
1486        PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLCOLUMNS(?,?,?,?,?)");
1487
1488        cs.setStringX(1, catalog);
1489        cs.setStringX(2, schemaPattern);
1490        cs.setStringX(3, tableNamePattern);
1491        cs.setStringX(4, columnNamePattern); //Always null for JDBC
1492
cs.setStringX(5, getOptions());
1493        return executeCatalogQuery(cs);
1494    }
1495
1496
1497    // call stored procedure SQLColumnPrivileges
1498
// SYSIBM.SQLColPrivileges(
1499
// CatalogName varchar(128),
1500
// SchemaName varchar(128),
1501
// TableName varchar(128),
1502
// ColumnName varchar(128),
1503
// Options varchar(4000))
1504
//
1505
public java.sql.ResultSet JavaDoc getColumnPrivileges(String JavaDoc catalog,
1506                                                  String JavaDoc schema,
1507                                                  String JavaDoc table,
1508                                                  String JavaDoc columnNamePattern) throws SQLException JavaDoc {
1509        try
1510        {
1511            synchronized (connection_) {
1512                if (agent_.loggingEnabled()) {
1513                    agent_.logWriter_.traceEntry(this, "getColumnPrivileges", catalog, schema, table, columnNamePattern);
1514                }
1515                return getColumnPrivilegesX(catalog, schema, table, columnNamePattern);
1516            }
1517        }
1518        catch ( SqlException se )
1519        {
1520            throw se.getSQLException();
1521        }
1522    }
1523
1524    private ResultSet getColumnPrivilegesX(String JavaDoc catalog,
1525                                           String JavaDoc schema,
1526                                           String JavaDoc table,
1527                                           String JavaDoc columnNamePattern) throws SqlException {
1528        checkForClosedConnectionX();
1529        // check input params, table and columnNamePattern cannot be null
1530
if (table == null) {
1531            throw new SqlException(agent_.logWriter_,
1532                new ClientMessageId(SQLState.TABLE_NAME_CANNOT_BE_NULL));
1533
1534        }
1535
1536        PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLCOLPRIVILEGES(?,?,?,?,?)");
1537
1538        cs.setStringX(1, catalog);
1539        cs.setStringX(2, schema);
1540        cs.setStringX(3, table);
1541        cs.setStringX(4, columnNamePattern);
1542        cs.setStringX(5, getOptions());
1543        return executeCatalogQuery(cs);
1544    }
1545
1546
1547    // call stored procedure SQLTablePrivileges
1548
// SYSIBM.SQLTablePrivileges(
1549
// CatalogName varchar(128),
1550
// SchemaName varchar(128),
1551
// TableName varchar(128),
1552
// Options varchar(4000))
1553
//
1554
public java.sql.ResultSet JavaDoc getTablePrivileges(String JavaDoc catalog,
1555                                                 String JavaDoc schemaPattern,
1556                                                 String JavaDoc tableNamePattern) throws SQLException JavaDoc {
1557        try
1558        {
1559            synchronized (connection_) {
1560                if (agent_.loggingEnabled()) {
1561                    agent_.logWriter_.traceEntry(this, "getTablePrivileges", catalog, schemaPattern, tableNamePattern);
1562                }
1563                return getTablePrivilegesX(catalog, schemaPattern, tableNamePattern);
1564            }
1565        }
1566        catch ( SqlException se )
1567        {
1568            throw se.getSQLException();
1569        }
1570    }
1571
1572    private ResultSet getTablePrivilegesX(String JavaDoc catalog,
1573                                          String JavaDoc schemaPattern,
1574                                          String JavaDoc tableNamePattern) throws SqlException {
1575        checkForClosedConnectionX();
1576        ;
1577
1578        PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLTABLEPRIVILEGES(?,?,?,?)");
1579
1580        cs.setStringX(1, catalog);
1581        cs.setStringX(2, schemaPattern);
1582        cs.setStringX(3, tableNamePattern);
1583        cs.setStringX(4, getOptions());
1584        return executeCatalogQuery(cs);
1585    }
1586
1587
1588    // call stored procedure
1589
// SYSIBM.SQLSPECIALCOLUMNS ( IN COLTYPE SMALLINT,
1590
// IN CATALOG_NAME VARCHAR(128),
1591
// IN SCHEMA_NAME VARCHAR(128),
1592
// IN TABLE_NAME VARCHAR(128),
1593
// IN SCOPE SMALLINT,
1594
// IN NULLABLE SMALLINT,
1595
// IN OPTIONS VARCHAR(4000) )
1596
//
1597
public java.sql.ResultSet JavaDoc getBestRowIdentifier(String JavaDoc catalog,
1598                                                   String JavaDoc schema,
1599                                                   String JavaDoc table,
1600                                                   int scope,
1601                                                   boolean nullable) throws SQLException JavaDoc {
1602        try
1603        {
1604            synchronized (connection_) {
1605                if (agent_.loggingEnabled()) {
1606                    agent_.logWriter_.traceEntry(this, "getBestRowIdentifier", catalog, schema, table, scope, nullable);
1607                }
1608                return getBestRowIdentifierX(catalog, schema, table, scope, nullable);
1609            }
1610        }
1611        catch ( SqlException se )
1612        {
1613            throw se.getSQLException();
1614        }
1615    }
1616
1617    private ResultSet getBestRowIdentifierX(String JavaDoc catalog,
1618                                            String JavaDoc schema,
1619                                            String JavaDoc table,
1620                                            int scope,
1621                                            boolean nullable) throws SqlException {
1622        checkForClosedConnectionX();
1623        ;
1624
1625        // check input params
1626
//
1627
// validate input table, which can not be null
1628
if (table == null) {
1629            throw new SqlException(agent_.logWriter_,
1630                new ClientMessageId(SQLState.TABLE_NAME_CANNOT_BE_NULL));
1631
1632        }
1633        PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLSPECIALCOLUMNS(?,?,?,?,?,?,?)");
1634
1635        cs.setIntX(1, SQL_BEST_ROWID);
1636        cs.setStringX(2, catalog);
1637        cs.setStringX(3, schema);
1638        cs.setStringX(4, table);
1639        cs.setIntX(5, scope);
1640        if (nullable) {
1641            cs.setShortX(6, (short) 1);
1642        } else {
1643            cs.setShortX(6, (short) 0);
1644        }
1645        cs.setStringX(7, getOptions());
1646        return executeCatalogQuery(cs);
1647    }
1648
1649
1650    public java.sql.ResultSet JavaDoc getVersionColumns(String JavaDoc catalog,
1651                                                String JavaDoc schema,
1652                                                String JavaDoc table) throws SQLException JavaDoc {
1653        try
1654        {
1655            synchronized (connection_) {
1656                if (agent_.loggingEnabled()) {
1657                    agent_.logWriter_.traceEntry(this, "getVersionColumns", catalog, schema, table);
1658                }
1659                return getVersionColumnsX(catalog, schema, table);
1660            }
1661        }
1662        catch ( SqlException se )
1663        {
1664            throw se.getSQLException();
1665        }
1666    }
1667
1668    private ResultSet getVersionColumnsX(String JavaDoc catalog,
1669                                         String JavaDoc schema,
1670                                         String JavaDoc table) throws SqlException {
1671        checkForClosedConnectionX();
1672
1673        // validate input table, which can not be null
1674
if (table == null) {
1675            throw new SqlException(agent_.logWriter_,
1676                new ClientMessageId(SQLState.TABLE_NAME_CANNOT_BE_NULL));
1677
1678        }
1679        PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLSPECIALCOLUMNS(?,?,?,?,?,?,?)");
1680
1681        cs.setIntX(1, SQL_ROWVER);
1682        cs.setStringX(2, catalog);
1683        cs.setStringX(3, schema);
1684        cs.setStringX(4, table);
1685        cs.setIntX(5, 0);
1686        cs.setShortX(6, (short) 0);
1687        cs.setStringX(7, getOptions());
1688
1689        return executeCatalogQuery(cs);
1690    }
1691
1692    // call stored procedure SQLPrimaryKeys
1693
// SYSIBM.SQLPrimaryKeys(
1694
// CatalogName varchar(128),
1695
// SchemaName varchar(128),
1696
// TableName varchar(128),
1697
// Options varchar(4000))
1698
//
1699
public java.sql.ResultSet JavaDoc getPrimaryKeys(String JavaDoc catalog,
1700                                             String JavaDoc schema,
1701                                             String JavaDoc table) throws SQLException JavaDoc {
1702        try
1703        {
1704            synchronized (connection_) {
1705                if (agent_.loggingEnabled()) {
1706                    agent_.logWriter_.traceEntry(this, "getPrimaryKeys", catalog, schema, table);
1707                }
1708                return getPrimaryKeysX(catalog, schema, table);
1709            }
1710        }
1711        catch ( SqlException se )
1712        {
1713            throw se.getSQLException();
1714        }
1715    }
1716
1717    private ResultSet getPrimaryKeysX(String JavaDoc catalog,
1718                                      String JavaDoc schema,
1719                                      String JavaDoc table) throws SqlException {
1720        checkForClosedConnectionX();
1721        ;
1722
1723        // validate the input table name
1724
if (table == null) {
1725            throw new SqlException(agent_.logWriter_,
1726                new ClientMessageId(SQLState.TABLE_NAME_CANNOT_BE_NULL));
1727
1728        }
1729        PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLPRIMARYKEYS(?,?,?,?)");
1730
1731        cs.setStringX(1, catalog);
1732        cs.setStringX(2, schema);
1733        cs.setStringX(3, table);
1734        cs.setStringX(4, getOptions());
1735        return executeCatalogQuery(cs);
1736    }
1737
1738
1739    // call storlastGetPrimaryKeysResultSet_ed procedure SQLForeignKeys
1740
// SYSIBM.SQLForeignKeys(
1741
// PKCatalogName varchar(128),
1742
// PKSchemaName varchar(128),
1743
// PKTableName varchar(128),
1744
// FKCatalogName varchar(128),
1745
// FKSchemaName varchar(128),
1746
// FKTableName varchar(128),
1747
// Options varchar(4000))
1748
//
1749
public java.sql.ResultSet JavaDoc getImportedKeys(String JavaDoc catalog,
1750                                              String JavaDoc schema,
1751                                              String JavaDoc table) throws SQLException JavaDoc {
1752        try
1753        {
1754            synchronized (connection_) {
1755                if (agent_.loggingEnabled()) {
1756                    agent_.logWriter_.traceEntry(this, "getImportedKeys", catalog, schema, table);
1757                }
1758                return getImportedKeysX(catalog, schema, table);
1759            }
1760        }
1761        catch ( SqlException se )
1762        {
1763            throw se.getSQLException();
1764        }
1765    }
1766
1767    private ResultSet getImportedKeysX(String JavaDoc catalog,
1768                                       String JavaDoc schema,
1769                                       String JavaDoc table) throws SqlException {
1770        checkForClosedConnectionX();
1771
1772        PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLFOREIGNKEYS(?,?,?,?,?,?,?)");
1773
1774        cs.setStringX(1, "");
1775        cs.setStringX(2, null);
1776        cs.setStringX(3, "");
1777        cs.setStringX(4, catalog);
1778        cs.setStringX(5, schema);
1779        cs.setStringX(6, table);
1780        // We're passing the keyword EXPORTEDKEY, but this support may not be in the GA version of SPs.
1781
// As a workaround in getCrossReference(), we'll just "select * where 0=1" when primaryTable==""
1782
if (connection_.holdability() == JDBC30Translation.HOLD_CURSORS_OVER_COMMIT) {
1783            cs.setStringX(7, "DATATYPE='JDBC';IMPORTEDKEY=1; CURSORHOLD=1");
1784        } else {
1785            cs.setStringX(7, "DATATYPE='JDBC';IMPORTEDKEY=1; CURSORHOLD=0");
1786        }
1787        return executeCatalogQuery(cs);
1788    }
1789
1790    // call stored procedure SQLForeignKeys
1791
// SYSIBM.SQLForeignKeys(
1792
// PKCatalogName varchar(128),
1793
// PKSchemaName varchar(128),
1794
// PKTableName varchar(128),
1795
// FKCatalogName varchar(128),
1796
// FKSchemaName varchar(128),
1797
// FKTableName varchar(128),
1798
// Options varchar(4000))
1799
//
1800
public java.sql.ResultSet JavaDoc getExportedKeys(String JavaDoc catalog,
1801                                              String JavaDoc schema,
1802                                              String JavaDoc table) throws SQLException JavaDoc {
1803        try
1804        {
1805            synchronized (connection_) {
1806                if (agent_.loggingEnabled()) {
1807                    agent_.logWriter_.traceEntry(this, "getExportedKeys", catalog, schema, table);
1808                }
1809                return getExportedKeysX(catalog, schema, table);
1810            }
1811        }
1812        catch ( SqlException se )
1813        {
1814            throw se.getSQLException();
1815        }
1816    }
1817
1818    private ResultSet getExportedKeysX(String JavaDoc catalog,
1819                                       String JavaDoc schema,
1820                                       String JavaDoc table) throws SqlException {
1821        checkForClosedConnectionX();
1822        ;
1823
1824        PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLFOREIGNKEYS(?,?,?,?,?,?,?)");
1825
1826        cs.setStringX(1, catalog);
1827        cs.setStringX(2, schema);
1828        cs.setStringX(3, table);
1829        cs.setStringX(4, "");
1830        cs.setStringX(5, null);
1831        cs.setStringX(6, "");
1832        // We're passing the keyword EXPORTEDKEY, but this support may not be in the GA version of SPs.
1833
// As a workaround in getCrossReference(), we'll just "select * where 0=1" when foreignTable==""
1834
if (connection_.holdability() == JDBC30Translation.HOLD_CURSORS_OVER_COMMIT) {
1835            cs.setStringX(7, "DATATYPE='JDBC';EXPORTEDKEY=1; CURSORHOLD=1");
1836        } else {
1837            cs.setStringX(7, "DATATYPE='JDBC';EXPORTEDKEY=1; CURSORHOLD=0");
1838        }
1839        return executeCatalogQuery(cs);
1840    }
1841
1842    // call stored procedure SQLForeignKeys
1843
// SYSIBM.SQLForeignKeys(
1844
// PKCatalogName varchar(128),
1845
// PKSchemaName varchar(128),
1846
// PKTableName varchar(128),
1847
// FKCatalogName varchar(128),
1848
// FKSchemaName varchar(128),
1849
// FKTableName varchar(128),
1850
// Options varchar(4000))
1851
//
1852
public java.sql.ResultSet JavaDoc getCrossReference(String JavaDoc primaryCatalog,
1853                                                String JavaDoc primarySchema,
1854                                                String JavaDoc primaryTable,
1855                                                String JavaDoc foreignCatalog,
1856                                                String JavaDoc foreignSchema,
1857                                                String JavaDoc foreignTable) throws SQLException JavaDoc {
1858        try
1859        {
1860            synchronized (connection_) {
1861                if (agent_.loggingEnabled()) {
1862                    agent_.logWriter_.traceEntry(this, "getCrossReference", primaryCatalog, primarySchema, primaryTable, foreignCatalog, foreignSchema, foreignTable);
1863                }
1864                return getCrossReferenceX(primaryCatalog, primarySchema, primaryTable,
1865                        foreignCatalog, foreignSchema, foreignTable);
1866            }
1867        }
1868        catch ( SqlException se )
1869        {
1870            throw se.getSQLException();
1871        }
1872    }
1873
1874
1875    private ResultSet getCrossReferenceX(String JavaDoc primaryCatalog,
1876                                         String JavaDoc primarySchema,
1877                                         String JavaDoc primaryTable,
1878                                         String JavaDoc foreignCatalog,
1879                                         String JavaDoc foreignSchema,
1880                                         String JavaDoc foreignTable) throws SqlException {
1881        checkForClosedConnectionX();
1882        ;
1883
1884        // check input params, primaryTable and foreignTable cannot be null
1885
if (primaryTable == null) {
1886            throw new SqlException(agent_.logWriter_,
1887                new ClientMessageId(SQLState.PRIMARY_TABLE_NAME_IS_NULL));
1888
1889        }
1890
1891        if (foreignTable == null) {
1892            throw new SqlException(agent_.logWriter_,
1893                new ClientMessageId(SQLState.FOREIGN_TABLE_NAME_IS_NULL));
1894
1895        }
1896
1897        PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLFOREIGNKEYS(?,?,?,?,?,?,?)");
1898
1899        cs.setStringX(1, primaryCatalog);
1900        cs.setStringX(2, primarySchema);
1901        cs.setStringX(3, primaryTable);
1902        cs.setStringX(4, foreignCatalog);
1903        cs.setStringX(5, foreignSchema);
1904        cs.setStringX(6, foreignTable);
1905        cs.setStringX(7, getOptions());
1906        return executeCatalogQuery(cs);
1907    }
1908
1909    // call stored procedure SQLGetTypeInfo
1910
// SYSIBM.SQLGetTypeInfo (IN DATATYPE SMALLINT,
1911
// IN Options VARCHAR(4000))
1912
//
1913
//
1914
public java.sql.ResultSet JavaDoc getTypeInfo() throws SQLException JavaDoc {
1915        try
1916        {
1917            synchronized (connection_) {
1918                if (agent_.loggingEnabled()) {
1919                    agent_.logWriter_.traceEntry(this, "getTypeInfo");
1920                }
1921                return getTypeInfoX();
1922            }
1923        }
1924        catch ( SqlException se )
1925        {
1926            throw se.getSQLException();
1927        }
1928    }
1929
1930    private ResultSet getTypeInfoX() throws SqlException {
1931        checkForClosedConnectionX();
1932        ;
1933
1934        // check if the last call's resultset is closed or not.
1935
PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLGETTYPEINFO(?,?)");
1936
1937        cs.setShortX(1, (short) 0);
1938        cs.setStringX(2, getOptions());
1939        return executeCatalogQuery(cs);
1940    }
1941
1942
1943    // call stored procedure SQLStatistics
1944
// SYSIBM.SQLStatistics(
1945
// CatalogName varchar(128),
1946
// SchemaName varchar(128),
1947
// TableName varchar(128),
1948
// Unique Smallint,
1949
// Reserved Smallint,
1950
// Options varchar(4000))
1951
//
1952
public java.sql.ResultSet JavaDoc getIndexInfo(String JavaDoc catalog,
1953                                           String JavaDoc schema,
1954                                           String JavaDoc table,
1955                                           boolean unique,
1956                                           boolean approximate) throws SQLException JavaDoc {
1957        try
1958        {
1959            synchronized (connection_) {
1960                if (agent_.loggingEnabled()) {
1961                    agent_.logWriter_.traceEntry(this, "getIndexInfo", catalog, schema, table, unique, approximate);
1962                }
1963                return getIndexInfoX(catalog, schema, table, unique, approximate);
1964            }
1965        }
1966        catch ( SqlException se )
1967        {
1968            throw se.getSQLException();
1969        }
1970    }
1971
1972    private ResultSet getIndexInfoX(String JavaDoc catalog,
1973                                    String JavaDoc schema,
1974                                    String JavaDoc table,
1975                                    boolean unique,
1976                                    boolean approximate) throws SqlException {
1977        checkForClosedConnectionX();
1978
1979        // validate the input table name
1980
if (table == null) {
1981            throw new SqlException(agent_.logWriter_,
1982                new ClientMessageId(SQLState.TABLE_NAME_CANNOT_BE_NULL));
1983        }
1984        PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLSTATISTICS(?,?,?,?,?,?)");
1985
1986        cs.setStringX(1, catalog);
1987        cs.setStringX(2, schema);
1988        cs.setStringX(3, table);
1989
1990        if (unique) {
1991            cs.setShortX(4, SQL_INDEX_UNIQUE);
1992        } else {
1993            cs.setShortX(4, SQL_INDEX_ALL);
1994        }
1995
1996        if (approximate) {
1997            cs.setShortX(5, (short) 1);
1998        } else {
1999            cs.setShortX(5, (short) 0);
2000        }
2001
2002        cs.setStringX(6, getOptions());
2003        return executeCatalogQuery(cs);
2004    }
2005
2006
2007    //--------------------------JDBC 2.0-----------------------------
2008

2009    public java.sql.ResultSet JavaDoc getUDTs(String JavaDoc catalog,
2010                                      String JavaDoc schemaPattern,
2011                                      String JavaDoc typeNamePattern,
2012                                      int[] types) throws SQLException JavaDoc {
2013        try
2014        {
2015            synchronized (connection_) {
2016                if (agent_.loggingEnabled()) {
2017                    agent_.logWriter_.traceEntry(this, "getUDTs", catalog, schemaPattern, typeNamePattern, types);
2018                }
2019                return getUDTsX(catalog, schemaPattern, typeNamePattern, types);
2020            }
2021        }
2022        catch ( SqlException se )
2023        {
2024            throw se.getSQLException();
2025        }
2026    }
2027
2028    private ResultSet getUDTsX(String JavaDoc catalog,
2029                               String JavaDoc schemaPattern,
2030                               String JavaDoc typeNamePattern,
2031                               int[] types) throws SqlException {
2032        checkForClosedConnectionX();
2033        ;
2034
2035        PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLUDTS(?,?,?,?,?)");
2036
2037        cs.setStringX(1, catalog);
2038        cs.setStringX(2, schemaPattern);
2039        cs.setStringX(3, typeNamePattern);
2040        int i = 0;
2041        String JavaDoc udtTypes = new String JavaDoc();
2042        while (types != null && i < types.length) {
2043            if (i > 0) {
2044                udtTypes = udtTypes.concat(",");
2045            }
2046            udtTypes = udtTypes.concat(String.valueOf(types[i]));
2047            i++;
2048        }
2049        cs.setStringX(4, udtTypes);
2050        cs.setStringX(5, getOptions());
2051        return executeCatalogQuery(cs);
2052    }
2053
2054
2055    // helper method for the catalog queries only
2056
private String JavaDoc getOptions() {
2057        int cursorHold;
2058        if (connection_.holdability() == JDBC30Translation.HOLD_CURSORS_OVER_COMMIT) {
2059            cursorHold = 1;
2060        } else {
2061            cursorHold = 0;
2062        }
2063        return "DATATYPE='JDBC';DYNAMIC=0;REPORTPUBLICPRIVILEGES=1;CURSORHOLD=" + cursorHold;
2064
2065    }
2066
2067    // Derby uses a PreparedStatement argument rather than a callable statement
2068
private ResultSet executeCatalogQuery(PreparedStatement cs)
2069        throws SqlException {
2070        try {
2071            return cs.executeQueryX();
2072        } catch (SqlException e) {
2073            if (e.getErrorCode() == -440) {
2074                SqlException newException = new SqlException(agent_.logWriter_,
2075                        new ClientMessageId(SQLState.STORED_PROC_NOT_INSTALLED));
2076                newException.setNextException(e);
2077                throw newException;
2078            } else if (e.getErrorCode() == -444) {
2079                SqlException newException = new SqlException(agent_.logWriter_,
2080                    new ClientMessageId(SQLState.STORED_PROC_LOAD_MODULE_NOT_FOUND));
2081                newException.setNextException(e);
2082                throw newException;
2083            } else {
2084                throw e;
2085            }
2086        }
2087    }
2088
2089    public java.sql.Connection JavaDoc getConnection() throws SQLException JavaDoc {
2090        checkForClosedConnection();
2091        return connection_;
2092    }
2093
2094    // ------------------- JDBC 3.0 -------------------------
2095

2096    public boolean supportsNamedParameters() throws SQLException JavaDoc {
2097        checkForClosedConnection();
2098        return false;
2099    }
2100
2101    public boolean supportsMultipleOpenResults() throws SQLException JavaDoc {
2102        checkForClosedConnection();
2103        return true;
2104    }
2105
2106    public boolean supportsGetGeneratedKeys() throws SQLException JavaDoc {
2107        checkForClosedConnection();
2108        return false;
2109    }
2110
2111    public java.sql.ResultSet JavaDoc getSuperTypes(String JavaDoc catalog,
2112                                            String JavaDoc schemaPattern,
2113                                            String JavaDoc typeNamePattern) throws SQLException JavaDoc {
2114        try
2115        {
2116            synchronized (connection_) {
2117                if (agent_.loggingEnabled()) {
2118                    agent_.logWriter_.traceEntry(this, "getSuperTypes", catalog, schemaPattern, typeNamePattern);
2119                }
2120                return getSuperTypesX();
2121            }
2122        }
2123        catch ( SqlException se )
2124        {
2125            throw se.getSQLException();
2126        }
2127    }
2128
2129    private ResultSet getSuperTypesX() throws SqlException {
2130        checkForClosedConnectionX();
2131        String JavaDoc sql = "SELECT CAST(NULL AS VARCHAR(128)) AS TYPE_CAT," +
2132                "CAST(NULL AS VARCHAR(128)) AS TYPE_SCHEM," +
2133                "VARCHAR('', 128) AS TYPE_NAME," +
2134                "CAST(NULL AS VARCHAR(128)) AS SUPERTYPE_CAT," +
2135                "CAST(NULL AS VARCHAR(128)) AS SUPERTYPE_SCHEM," +
2136                "VARCHAR('', 128) AS SUPERTYPE_NAME " +
2137                "FROM SYSIBM.SYSDUMMY1 WHERE 1=0 WITH UR ";
2138        PreparedStatement ps = connection_.prepareDynamicCatalogQuery(sql);
2139        return ps.executeQueryX();
2140    }
2141
2142    public java.sql.ResultSet JavaDoc getSuperTables(String JavaDoc catalog,
2143                                             String JavaDoc schemaPattern,
2144                                             String JavaDoc tableNamePattern) throws SQLException JavaDoc {
2145        try
2146        {
2147            synchronized (connection_) {
2148                if (agent_.loggingEnabled()) {
2149                    agent_.logWriter_.traceEntry(this, "getSuperTables", catalog, schemaPattern, tableNamePattern);
2150                }
2151                return getSuperTablesX();
2152            }
2153        }
2154        catch ( SqlException se )
2155        {
2156            throw se.getSQLException();
2157        }
2158    }
2159
2160    private ResultSet getSuperTablesX() throws SqlException {
2161        checkForClosedConnectionX();
2162        java.lang.String JavaDoc sql = "SELECT CAST(NULL AS VARCHAR(128)) AS TABLE_CAT," +
2163                "CAST(NULL AS VARCHAR(128)) AS TABLE_SCHEM," +
2164                "VARCHAR('', 128) AS TABLE_NAME," +
2165                "VARCHAR('', 128) AS SUPERTABLE_NAME FROM SYSIBM.SYSDUMMY1 " +
2166                "WHERE 1=0 WITH UR";
2167        PreparedStatement ps = connection_.prepareDynamicCatalogQuery(sql);
2168        return ps.executeQueryX();
2169    }
2170
2171
2172    public java.sql.ResultSet JavaDoc getAttributes(String JavaDoc catalog,
2173                                            String JavaDoc schemaPattern,
2174                                            String JavaDoc typeNamePattern,
2175                                            String JavaDoc attributeNamePattern) throws SQLException JavaDoc {
2176        try
2177        {
2178            synchronized (connection_) {
2179                if (agent_.loggingEnabled()) {
2180                    agent_.logWriter_.traceEntry(this, "getAttributes", catalog, schemaPattern, typeNamePattern, attributeNamePattern);
2181                }
2182                return getAttributesX();
2183            }
2184        }
2185        catch ( SqlException se )
2186        {
2187            throw se.getSQLException();
2188        }
2189    }
2190
2191    private ResultSet getAttributesX() throws SqlException {
2192        checkForClosedConnectionX();
2193        java.lang.String JavaDoc sql = "SELECT CAST(NULL AS VARCHAR(128)) AS TYPE_CAT," +
2194                "CAST(NULL AS VARCHAR(128)) AS TYPE_SCHEM," +
2195                "VARCHAR('', 128) AS TYPE_NAME," +
2196                "VARCHAR('',128) AS ATTR_NAME," +
2197                "0 AS DATA_TYPE," +
2198                "VARCHAR('',129) AS ATTR_TYPE_NAME," +
2199                "0 AS ATTR_SIZE," +
2200                "0 AS DECIMAL_DIGITS," +
2201                "0 AS NUM_PREC_RADIX," +
2202                "2 AS NULLABLE," +
2203                "CAST(NULL AS VARCHAR(254)) AS REMARKS," +
2204                "CAST(NULL AS VARCHAR(128)) AS ATTR_DEF," +
2205                "0 AS SQL_DATA_TYPE," +
2206                "0 AS SQL_DATETIME_SUB," +
2207                "0 AS CHAR_OCTET_LENGTH," +
2208                "0 AS ORDINAL_POSITION," +
2209                "VARCHAR('',128) AS IS_NULLABLE," +
2210                "CAST(NULL AS VARCHAR(128)) AS SCOPE_CATALOG," +
2211                "CAST(NULL AS VARCHAR(128)) AS SCOPE_SCHEMA," +
2212                "CAST(NULL AS VARCHAR(128)) AS SCOPE_TABLE," +
2213                "CAST(NULL AS SMALLINT) AS SOURCE_DATA_TYPE " +
2214                "FROM SYSIBM.SYSDUMMY1 WHERE 1=0 WITH UR";
2215        PreparedStatement ps = connection_.prepareDynamicCatalogQuery(sql);
2216        return ps.executeQueryX();
2217    }
2218
2219    public boolean supportsResultSetHoldability(int holdability) throws SQLException JavaDoc {
2220        checkForClosedConnection();
2221        return true;
2222    }
2223
2224    public int getResultSetHoldability() throws SQLException JavaDoc {
2225        checkForClosedConnection();
2226        return java.sql.ResultSet.HOLD_CURSORS_OVER_COMMIT;
2227    }
2228
2229    public int getDatabaseMajorVersion() throws SQLException JavaDoc {
2230        checkForClosedConnection();
2231        return productLevel_.versionLevel_;
2232    }
2233
2234    public int getDatabaseMinorVersion() throws SQLException JavaDoc {
2235        checkForClosedConnection();
2236        return productLevel_.releaseLevel_;
2237    }
2238
2239    public int getJDBCMajorVersion() throws SQLException JavaDoc {
2240        checkForClosedConnection();
2241        return 3;
2242    }
2243
2244    public int getJDBCMinorVersion() throws SQLException JavaDoc {
2245        checkForClosedConnection();
2246        return 0;
2247    }
2248
2249    public int getSQLStateType() throws SQLException JavaDoc {
2250        checkForClosedConnection();
2251        return sqlStateSQL99;
2252    }
2253
2254    public boolean locatorsUpdateCopy() throws SQLException JavaDoc {
2255        checkForClosedConnection();
2256        return false;
2257    }
2258
2259    public boolean supportsStatementPooling() throws SQLException JavaDoc {
2260        checkForClosedConnection();
2261        return false;
2262    }
2263
2264    //--------------------Abstract material layer call-down methods-----------------
2265

2266    // Compute feature set based on release
2267
abstract protected void computeFeatureSet_();
2268
2269    //------------helper methods for meta data info call methods------------------
2270

2271
2272    private boolean getMetaDataInfoBoolean(int infoCallIndex) throws SQLException JavaDoc {
2273        try
2274        {
2275            if (metaDataInfoIsCached_) {
2276                return ((Integer JavaDoc) metaDataInfoCache_[infoCallIndex]).intValue() != 0;
2277            }
2278            metaDataInfoCall();
2279            return ((Integer JavaDoc) metaDataInfoCache_[infoCallIndex]).intValue() != 0;
2280        }
2281        catch ( SqlException se )
2282        {
2283            throw se.getSQLException();
2284        }
2285    }
2286
2287    private int getMetaDataInfoInt(int infoCallIndex) throws SQLException JavaDoc {
2288        try
2289        {
2290            if (metaDataInfoIsCached_) {
2291                return ((Integer JavaDoc) metaDataInfoCache_[infoCallIndex]).intValue();
2292            }
2293            metaDataInfoCall();
2294            return ((Integer JavaDoc) metaDataInfoCache_[infoCallIndex]).intValue();
2295        }
2296        catch ( SqlException se )
2297        {
2298            throw se.getSQLException();
2299        }
2300            
2301    }
2302
2303    private String JavaDoc getMetaDataInfoString(int infoCallIndex) throws SQLException JavaDoc {
2304        try
2305        {
2306            if (metaDataInfoIsCached_) {
2307                return (String JavaDoc) metaDataInfoCache_[infoCallIndex];
2308            }
2309            metaDataInfoCall();
2310            return (String JavaDoc) metaDataInfoCache_[infoCallIndex];
2311        }
2312        catch ( SqlException se )
2313        {
2314            throw se.getSQLException();
2315        }
2316    }
2317
2318
2319    private boolean getMetaDataInfoBooleanWithType(int infoCallIndex, int type)
2320        throws SQLException JavaDoc {
2321
2322        boolean clientValue =
2323            getMetaDataInfoBooleanWithTypeClient(infoCallIndex, type);
2324        
2325        // DERBY-1252. In Derby <= 10.x, clients (incl JCC) do not have
2326
// logic to negotiate down these values with the server, so
2327
// for features introduced with 10.x, x >= 2 (e.g. SUR
2328
// DERBY-775, in 10.2), the server will return 10.0 values for
2329
// any version 10.x so as not to break existing apps running
2330
// an older 10 client (e.g. 10.1 client for DERBY-775).
2331
// Reciprocally, this means clients at 10.x, where x => 2,
2332
// must disregard the server's (too conservative) answers for
2333
// these features, see logic in
2334
// getMetaDataInfoBooleanWithTypeClient.
2335
//
2336
// For Derby >= 11, the down-negotiation code below which is
2337
// presently commented out should be activated, and the values
2338
// returned from the server should once more reflect reality.
2339

2340        // Commented out till we hit Derby 11:
2341
//
2342
// boolean serverValue =
2343
// getMetaDataInfoBooleanWithTypeServer(infoCallIndex, type);
2344
//
2345
// return clientValue && serverValue;
2346

2347        return clientValue;
2348    }
2349
2350
2351    // Client's view of boolean metadata.
2352
//
2353
// For values which depend on (added) functionality in *both* the
2354
// client and the server, the client should have its own view of
2355
// all such values here. For other values, it can defer to the
2356
// server. This is a prerequisite for negotiating down in a mixed
2357
// client/Server context. Note that metadata negotiation should
2358
// mirror the similar negotiation for use of the feature itself,
2359
// for example, for scrollable updatable result sets of type
2360
// insensitive, the server will downgrade to read-only if it is
2361
// older than 10.2.
2362
//
2363
// See also comments in getMetaDataInfoBooleanWithType and
2364
// engine/org/apache/derby/impl/sql/catalog/metadata_net.properties.
2365
//
2366
private boolean getMetaDataInfoBooleanWithTypeClient(int infoCallIndex,
2367                                                         int type)
2368        throws SQLException JavaDoc {
2369
2370        switch (infoCallIndex) {
2371        case updatesAreDetected__:
2372        case deletesAreDetected__:
2373        case ownUpdatesAreVisible__:
2374        case ownDeletesAreVisible__:
2375            
2376            if (productLevel_.greaterThanOrEqualTo(10,2,0) &&
2377                type == ResultSet.TYPE_SCROLL_INSENSITIVE) {
2378                return true;
2379            } else {
2380                return getMetaDataInfoBooleanWithTypeServer(infoCallIndex,
2381                                                            type);
2382            }
2383        case insertsAreDetected__:
2384        case ownInsertsAreVisible__:
2385            if (productLevel_.greaterThanOrEqualTo(10,2,0) &&
2386                type == ResultSet.TYPE_SCROLL_INSENSITIVE) {
2387                return false;
2388            } else {
2389                return getMetaDataInfoBooleanWithTypeServer(infoCallIndex,
2390                                                            type);
2391            }
2392        default:
2393            return getMetaDataInfoBooleanWithTypeServer(infoCallIndex,
2394                                                        type);
2395        }
2396    }
2397
2398
2399    private boolean getMetaDataInfoBooleanWithTypeServer(int infoCallIndex,
2400                                                     int type)
2401        throws SQLException JavaDoc {
2402
2403        // Stored Procedure will return a String containing a
2404
// comma seperated list of all the supported result Set types
2405
// not throwing any exception right now even if the the type is wrong as per the spec
2406
try
2407        {
2408            String JavaDoc returnedFromSP = null;
2409            if (metaDataInfoIsCached_) {
2410                returnedFromSP = (String JavaDoc) metaDataInfoCache_[infoCallIndex];
2411            } else {
2412                metaDataInfoCall();
2413                returnedFromSP = (String JavaDoc) metaDataInfoCache_[infoCallIndex];
2414            }
2415            java.util.StringTokenizer JavaDoc st = new java.util.StringTokenizer JavaDoc(returnedFromSP, ",");
2416            while (st.hasMoreTokens()) {
2417                if ((new Integer JavaDoc(st.nextToken())).intValue() == type) {
2418                    return true;
2419                }
2420            }
2421            return false;
2422        }
2423        catch ( SqlException se )
2424        {
2425            throw se.getSQLException();
2426        }
2427    }
2428
2429    private boolean getMetaDataInfoInt_SupportsResultSetConcurrency(int infoCallIndex, int type, int concurrency) throws SQLException JavaDoc {
2430        // The stored procured will return a String containing a list
2431
// of lists: For each result set type in the outer list, an
2432
// inner list gives the allowed concurrencies for that type:
2433
// The encoding syntax is reproduced here from the server file
2434
// 'metadata_net.properties (please keep in synch!):
2435
//
2436
// String syntax:
2437
// <type> { "," <concurrency>}* { ";" <type> { "," <concurrency>}* }}*
2438
//
2439
// <type> ::= <the integer value for that type from interface java.sql.Resultset
2440
// i.e. TYPE_FORWARD_ONLY is 1003>
2441
// <concurrency> ::= <the integer value for that concurrency
2442
// from interface java.sql.Resultset, i.e.
2443
// CONCUR_UPDATABLE is 1008>
2444
try
2445        {
2446            String JavaDoc returnedFromSP = null;
2447            if (metaDataInfoIsCached_) {
2448                returnedFromSP = (String JavaDoc) metaDataInfoCache_[infoCallIndex];
2449            } else {
2450                metaDataInfoCall();
2451                returnedFromSP = (String JavaDoc) metaDataInfoCache_[infoCallIndex];
2452            }
2453            java.util.StringTokenizer JavaDoc st = new java.util.StringTokenizer JavaDoc(returnedFromSP, ";");
2454            while (st.hasMoreTokens()) {
2455                java.util.StringTokenizer JavaDoc stForConc =
2456            new java.util.StringTokenizer JavaDoc(st.nextToken(), ",");
2457                if ((new Integer JavaDoc(stForConc.nextToken())).intValue() == type) {
2458                    while (stForConc.hasMoreTokens()) {
2459                        if ((new Integer JavaDoc(stForConc.nextToken())).intValue() == concurrency) {
2460                            return true;
2461                        }
2462                    }
2463                    return false;
2464                }
2465            }
2466            return false;
2467        }
2468        catch ( SqlException se )
2469        {
2470            throw se.getSQLException();
2471        }
2472    }
2473
2474    private boolean getMetaDataInfoBoolean_supportsConvert(int infoCallIndex, int fromType, int toType) throws SQLException JavaDoc {
2475        // The Stored procedure will return a String contain a list of all the valid conversions it support
2476
// For eg. If the database conversion from char(1) to date(91), time(92) and
2477
// Decimal(3) to char(1) ,double(8)
2478
// then StoredProcedure string will return "1,91,92;3,1,8"
2479
// see how fromTypes are seperated by ";"
2480
try
2481        {
2482            String JavaDoc returnedFromSP = null;
2483            if (metaDataInfoIsCached_) {
2484                returnedFromSP = (String JavaDoc) metaDataInfoCache_[infoCallIndex];
2485            } else {
2486                metaDataInfoCall();
2487                returnedFromSP = (String JavaDoc) metaDataInfoCache_[infoCallIndex];
2488            }
2489            java.util.StringTokenizer JavaDoc st = new java.util.StringTokenizer JavaDoc(returnedFromSP, ";");
2490            while (st.hasMoreTokens()) {
2491                java.util.StringTokenizer JavaDoc stForType = new java.util.StringTokenizer JavaDoc(st.nextToken(), ",");
2492                if ((new Integer JavaDoc(stForType.nextToken())).intValue() == fromType) {
2493                    while (st.hasMoreTokens()) {
2494                        if ((new Integer JavaDoc(st.nextToken())).intValue() == toType) {
2495                            return true;
2496                        }
2497                    }
2498                    return false;
2499                }
2500            }
2501            return false;
2502        }
2503        catch ( SqlException se )
2504        {
2505            throw se.getSQLException();
2506        }
2507    }
2508
2509    // We synchronize at this level so that we don't have to synchronize all
2510
// the meta data info methods. If we just return hardwired answers we don't
2511
// need to synchronize at the higher level.
2512
private void metaDataInfoCall() throws SqlException {
2513        synchronized (connection_) {
2514            ResultSet rs;
2515
2516            // These remote calls return a result set containing a single row.
2517
// Each column in the row corresponds to a particular get meta data info
2518
// method.
2519
PreparedStatement ps = prepareMetaDataQuery("SYSIBM.MetaData()");
2520            rs = (ResultSet) ps.executeQueryX();
2521            rs.nextX();
2522            int ColumnCount;
2523            try {
2524                ColumnCount = ((ColumnMetaData) rs.getMetaDataX()).getColumnCount();
2525            } catch ( SQLException JavaDoc se ) {
2526                throw new SqlException(se);
2527            }
2528            for (int infoCallIndex = 0;
2529                 (infoCallIndex < ColumnCount && infoCallIndex < metaDataInfoCache_.length);
2530                 infoCallIndex++) {
2531                metaDataInfoCache_[infoCallIndex] = rs.getObjectX(infoCallIndex + 1);
2532            }
2533            metaDataInfoIsCached_ = true;
2534            rs.closeX();
2535        }
2536    }
2537
2538    // ------------------- JDBC 4.0 -------------------------
2539

2540    /**
2541     * Retrieves whether this database supports invoking user-defined
2542     * or vendor functions using the stored procedure escape syntax.
2543     *
2544     * @return <code>true</code>, since Derby supports the escape syntax
2545     * @exception SQLException if a database access error occurs
2546     */

2547    public final boolean supportsStoredFunctionsUsingCallSyntax()
2548        throws SQLException JavaDoc
2549    {
2550        checkForClosedConnection();
2551        return true;
2552    }
2553
2554    /**
2555     * Retrieves whether an <code>SQLException</code> will cause all
2556     * open <code>ResultSet</code>s to be closed when auto-commit is
2557     * <code>true</code>.
2558     *
2559     * @return <code>false</code>, since Derby does not close all open
2560     * result sets when an error occurs
2561     * @exception SQLException if a database access error occurs
2562     */

2563    public final boolean autoCommitFailureClosesAllResultSets()
2564        throws SQLException JavaDoc
2565    {
2566        checkForClosedConnection();
2567        return false;
2568    }
2569
2570    /**
2571     * Retrieves whether this JDBC driver provides its own
2572     * <code>QueryObjectGenerator</code>.
2573     *
2574     * @return <code>false</code>, since Derby does not provide its
2575     * own generator
2576     * @exception SQLException if a database access error occurs
2577     */

2578    public final boolean providesQueryObjectGenerator() throws SQLException JavaDoc {
2579        checkForClosedConnection();
2580        return false;
2581    }
2582
2583    /**
2584     * Get the schema names available in this database. The results
2585     * are ordered by schema name.
2586     *
2587     * <p>The schema columns are:
2588     * <ol>
2589     * <li><strong>TABLE_SCHEM</strong> String =&gt; schema name</li>
2590     * <li><strong>TABLE_CATALOG</strong> String =&gt; catalog name
2591     * (may be <code>null</code>)</li>
2592     * </ol>
2593     *
2594     * @param catalog catalog name used to narrow down the search; ""
2595     * means no catalog, <code>null</code> means any catalog
2596     * @param schemaPattern schema name used to narrow down the
2597     * search, <code>null</code> means schema name should not be used
2598     * to narrow down search
2599     * @return a <code>ResultSet</code> object in which each row is a
2600     * schema description
2601     * @exception SQLException if a database error occurs
2602     */

2603    public ResultSet getSchemas(String JavaDoc catalog, String JavaDoc schemaPattern)
2604        throws SQLException JavaDoc
2605    {
2606        try {
2607            synchronized (connection_) {
2608                if (agent_.loggingEnabled()) {
2609                    agent_.logWriter_.traceEntry(this, "getSchemas");
2610                }
2611                return getSchemasX(catalog, schemaPattern);
2612            }
2613        } catch (SqlException se) {
2614            throw se.getSQLException();
2615        }
2616    }
2617
2618    /**
2619     * Untraced version of <code>getSchemas(String, String)</code>.
2620     *
2621     * @param catalog catalog name
2622     * @param schemaPattern pattern for schema name
2623     * @return a <code>ResultSet</code> value
2624     * @exception SqlException if a database error occurs
2625     * @see #getSchemas(String, String)
2626     */

2627    private ResultSet getSchemasX(String JavaDoc catalog, String JavaDoc schemaPattern)
2628        throws SqlException
2629    {
2630        checkForClosedConnectionX();
2631
2632        // If the server has not implemented support for JDBC 4.0,
2633
// SYSIBM.SQLTABLES does not recognize the GETSCHEMAS=2
2634
// option, and it will call getTables() instead of
2635
// getSchemas(). Therefore, check server version and throw an
2636
// exception if the server does not support JDBC 4.0.
2637
checkServerJdbcVersionX("getSchemas(String, String)", 4, 0);
2638
2639        String JavaDoc call = "SYSIBM.SQLTABLES(?, ?, '', '', 'GETSCHEMAS=2')";
2640        PreparedStatement cs = prepareMetaDataQuery(call);
2641        if (catalog == null) {
2642            cs.setNullX(1, java.sql.Types.VARCHAR);
2643        } else {
2644            cs.setStringX(1, catalog);
2645        }
2646        if (schemaPattern == null) {
2647            cs.setNullX(2, java.sql.Types.VARCHAR);
2648        } else {
2649            cs.setStringX(2, schemaPattern);
2650        }
2651        return cs.executeQueryX();
2652    }
2653
2654    /**
2655     * Returns a list of the client info properties supported by the
2656     * driver. The result set contains the following columns:
2657     *
2658     * <p>
2659     * <ol>
2660     * <li>NAME String=&gt; The name of the client info property.</li>
2661     * <li>MAX_LEN int=&gt; The maximum length of the value for the
2662     * property.</li>
2663     * <li>DEFAULT_VALUE String=&gt; The default value of the property.</li>
2664     * <li>DESCRIPTION String=&gt; A description of the property.</li>
2665     * </ol>
2666     *
2667     * <p>The <code>ResultSet</code> is sorted by the NAME column.
2668     *
2669     * @return A <code>ResultSet</code> object; each row is a
2670     * supported client info property
2671     * @exception SQLException if an error occurs
2672     */

2673    public ResultSet getClientInfoProperties() throws SQLException JavaDoc {
2674        try {
2675            synchronized (connection_) {
2676                if (agent_.loggingEnabled()) {
2677                    agent_.logWriter_.traceEntry(this,
2678                                                 "getClientInfoProperties");
2679                }
2680                return getClientInfoPropertiesX();
2681            }
2682        } catch (SqlException se) {
2683            throw se.getSQLException();
2684        }
2685    }
2686
2687    /**
2688     * Untraced version of <code>getClientInfoProperties()</code>.
2689     * Returns an empty <code>ResultSet</code> with the correct column
2690     * names.
2691     *
2692     * @return a <code>ResultSet</code> value
2693     * @exception SqlException if a database error occurs
2694     * @see #getClientInfoProperties
2695     */

2696    private ResultSet getClientInfoPropertiesX() throws SqlException {
2697        checkForClosedConnectionX();
2698        final String JavaDoc sql =
2699            "SELECT CAST(NULL AS VARCHAR(128)) AS NAME, " +
2700            "CAST(NULL AS INT) AS MAX_LEN, " +
2701            "CAST(NULL AS VARCHAR(128)) AS DEFAULT_VALUE, " +
2702            "CAST(NULL AS VARCHAR(128)) AS DESCRIPTION " +
2703            "FROM SYSIBM.SYSDUMMY1 WHERE 1=0 WITH UR";
2704        PreparedStatement ps = connection_.prepareDynamicCatalogQuery(sql);
2705        return ps.executeQueryX();
2706    }
2707
2708    //----------------------------helper methods----------------------------------
2709

2710
2711    private PreparedStatement prepareMetaDataQuery(String JavaDoc cmd) throws SqlException {
2712        PreparedStatement ps;
2713
2714        ps = (org.apache.derby.client.am.PreparedStatement)
2715                connection_.prepareStatementX("CALL " + cmd,
2716                        java.sql.ResultSet.TYPE_FORWARD_ONLY,
2717                        java.sql.ResultSet.CONCUR_READ_ONLY,
2718                        connection_.holdability(),
2719                        java.sql.Statement.NO_GENERATED_KEYS,
2720                        null);
2721        return ps;
2722    }
2723
2724    /**
2725     * A "public" version of checkForClosedConnection() that throws
2726     * SQLException instead of SqlException. In particular this is used
2727     * by all the DatabaseMetadata methods
2728     */

2729    protected void checkForClosedConnection() throws SQLException JavaDoc
2730    {
2731        try {
2732            checkForClosedConnectionX();
2733        } catch ( SqlException se ) {
2734            throw se.getSQLException();
2735        }
2736    }
2737    
2738    private void checkForClosedConnectionX() throws SqlException {
2739        if (connection_.isClosedX()) {
2740            agent_.checkForDeferredExceptions();
2741            throw new SqlException(agent_.logWriter_,
2742                new ClientMessageId(SQLState.NO_CURRENT_CONNECTION));
2743
2744        } else {
2745            agent_.checkForDeferredExceptions();
2746        }
2747    }
2748
2749    /**
2750     * Checks whether the server supports a JDBC version. If the
2751     * server does not support the JDBC version, an exception is
2752     * thrown.
2753     *
2754     * @param method name of the method for which support is needed on
2755     * the server (used in exception message)
2756     * @param major minimum JDBC major version
2757     * @param minor minimum JDBC minor version if major version matches
2758     * @exception SqlException if the server does not support the
2759     * specified JDBC version
2760     */

2761    protected void checkServerJdbcVersionX(String JavaDoc method, int major, int minor)
2762        throws SqlException
2763    {
2764        if (serverJdbcMajorVersion < major ||
2765            (serverJdbcMajorVersion == major &&
2766             serverJdbcMinorVersion < minor)) {
2767            throw new SqlException(agent_.logWriter_,
2768                new ClientMessageId(SQLState.JDBC_METHOD_NOT_SUPPORTED_BY_SERVER), method);
2769        }
2770    }
2771}
2772
Popular Tags