KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mckoi > database > jdbc > MDatabaseMetaData


1 /**
2  * com.mckoi.database.jdbc.MDatabaseMetaData 23 Jul 2000
3  *
4  * Mckoi SQL Database ( http://www.mckoi.com/database )
5  * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * Version 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License Version 2 for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * Version 2 along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  *
20  * Change Log:
21  *
22  *
23  */

24
25 package com.mckoi.database.jdbc;
26
27 import java.sql.*;
28
29 /**
30  * An implementation of JDBC's DatabaseMetaData.
31  *
32  * @author Tobias Downer
33  */

34
35 public class MDatabaseMetaData implements DatabaseMetaData {
36
37   /**
38    * The Connection object associated with this meta data.
39    */

40   private MConnection connection;
41
42   /**
43    * The name and version of the database we are connected to.
44    */

45   private String JavaDoc database_name, database_version;
46
47   /**
48    * Constructor.
49    */

50   MDatabaseMetaData(MConnection connection) {
51     this.connection = connection;
52   }
53
54   /**
55    * Queries product information about the database we are connected to.
56    */

57   private void queryProductInformation() throws SQLException {
58     if (database_name == null ||
59         database_version == null) {
60       Statement statement = connection.createStatement();
61       ResultSet result = statement.executeQuery("SHOW PRODUCT");
62       result.next();
63       database_name = result.getString("name");
64       database_version = result.getString("version");
65       statement.close();
66       result.close();
67     }
68   }
69
70
71
72   //----------------------------------------------------------------------
73
// First, a variety of minor information about the target database.
74

75   public boolean allProceduresAreCallable() throws SQLException {
76     // NOT SUPPORTED
77
return false;
78   }
79
80   public boolean allTablesAreSelectable() throws SQLException {
81     // No, only tables that the user has read access to,
82
return false;
83   }
84
85   public String JavaDoc getURL() throws SQLException {
86     return connection.getURL();
87   }
88
89   public String JavaDoc getUserName() throws SQLException {
90     Statement statement = connection.createStatement();
91     ResultSet result_set = statement.executeQuery("SELECT USER()");
92     result_set.next();
93     String JavaDoc username = result_set.getString(1);
94     result_set.close();
95     statement.close();
96     return username;
97   }
98
99   public boolean isReadOnly() throws SQLException {
100     Statement statement = connection.createStatement();
101     ResultSet result_set = statement.executeQuery(
102        " SELECT * FROM SYS_INFO.sUSRDatabaseStatistics " +
103        " WHERE \"stat_name\" = 'DatabaseSystem.read_only' ");
104     boolean read_only = result_set.next();
105     result_set.close();
106     statement.close();
107     return read_only;
108   }
109
110   public boolean nullsAreSortedHigh() throws SQLException {
111     return false;
112   }
113
114   public boolean nullsAreSortedLow() throws SQLException {
115     return true;
116   }
117
118   public boolean nullsAreSortedAtStart() throws SQLException {
119     return false;
120   }
121
122   public boolean nullsAreSortedAtEnd() throws SQLException {
123     return false;
124   }
125
126   public String JavaDoc getDatabaseProductName() throws SQLException {
127     queryProductInformation();
128     return database_name;
129   }
130
131   public String JavaDoc getDatabaseProductVersion() throws SQLException {
132     queryProductInformation();
133     return database_version;
134   }
135
136   public String JavaDoc getDriverName() throws SQLException {
137     return MDriver.DRIVER_NAME;
138   }
139
140   public String JavaDoc getDriverVersion() throws SQLException {
141     return MDriver.DRIVER_VERSION;
142   }
143
144   public int getDriverMajorVersion() {
145     return MDriver.DRIVER_MAJOR_VERSION;
146   }
147
148   public int getDriverMinorVersion() {
149     return MDriver.DRIVER_MINOR_VERSION;
150   }
151
152   public boolean usesLocalFiles() throws SQLException {
153     // Depends if we are embedded or not,
154
// ISSUE: We need to keep an eye on this for future enhancements to the
155
// Mckoi URL spec.
156
if (getURL().toLowerCase().startsWith(":jdbc:mckoi:local://")) {
157       return true;
158     }
159     else {
160       return false;
161     }
162   }
163
164   public boolean usesLocalFilePerTable() throws SQLException {
165     // Actually uses 3 files per table. Why would a developer need this info?
166
// Returning false,
167
return false;
168   }
169
170   public boolean supportsMixedCaseIdentifiers() throws SQLException {
171     return true;
172   }
173
174   public boolean storesUpperCaseIdentifiers() throws SQLException {
175     return false;
176   }
177
178   public boolean storesLowerCaseIdentifiers() throws SQLException {
179     return false;
180   }
181
182   public boolean storesMixedCaseIdentifiers() throws SQLException {
183     return true;
184   }
185
186   public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException {
187     return true;
188   }
189
190   public boolean storesUpperCaseQuotedIdentifiers() throws SQLException {
191     return false;
192   }
193
194   public boolean storesLowerCaseQuotedIdentifiers() throws SQLException {
195     return false;
196   }
197
198   public boolean storesMixedCaseQuotedIdentifiers() throws SQLException {
199     return true;
200   }
201
202   public String JavaDoc getIdentifierQuoteString() throws SQLException {
203     return "\"";
204   }
205
206   public String JavaDoc getSQLKeywords() throws SQLException {
207     // not implemented,
208
return "show";
209   }
210
211   public String JavaDoc getNumericFunctions() throws SQLException {
212     // not implemented,
213
// We should put this as a query to the database. It will need to
214
// inspect all user defined functions also.
215
return "";
216   }
217
218   public String JavaDoc getStringFunctions() throws SQLException {
219     // not implemented,
220
// We should put this as a query to the database. It will need to
221
// inspect all user defined functions also.
222
return "";
223   }
224
225   public String JavaDoc getSystemFunctions() throws SQLException {
226     // not implemented,
227
return "";
228   }
229
230   public String JavaDoc getTimeDateFunctions() throws SQLException {
231     // not implemented,
232
// We should put this as a query to the database. It will need to
233
// inspect all user defined functions also.
234
return "";
235   }
236
237   public String JavaDoc getSearchStringEscape() throws SQLException {
238     return "\\";
239   }
240
241   public String JavaDoc getExtraNameCharacters() throws SQLException {
242     return "";
243   }
244
245     //--------------------------------------------------------------------
246
// Functions describing which features are supported.
247

248   public boolean supportsAlterTableWithAddColumn() throws SQLException {
249     return true;
250   }
251
252   public boolean supportsAlterTableWithDropColumn() throws SQLException {
253     return true;
254   }
255
256   public boolean supportsColumnAliasing() throws SQLException {
257     return true;
258   }
259
260   public boolean nullPlusNonNullIsNull() throws SQLException {
261     return true;
262   }
263
264   public boolean supportsConvert() throws SQLException {
265     return false;
266   }
267
268   public boolean supportsConvert(int fromType, int toType) throws SQLException {
269     return false;
270   }
271
272   public boolean supportsTableCorrelationNames() throws SQLException {
273     // Is this, for example, "select * from Part P, Customer as C where ... '
274
// If it is then yes.
275
return true;
276   }
277
278   public boolean supportsDifferentTableCorrelationNames() throws SQLException {
279     // This is easily tested as,
280
// SELECT * FROM Test1 AS Test2;
281
// where 'Test2' is a valid table in the database.
282
return false;
283   }
284
285   public boolean supportsExpressionsInOrderBy() throws SQLException {
286     return true;
287   }
288
289   public boolean supportsOrderByUnrelated() throws SQLException {
290     return true;
291   }
292
293   public boolean supportsGroupBy() throws SQLException {
294     return true;
295   }
296
297   public boolean supportsGroupByUnrelated() throws SQLException {
298     return true;
299   }
300
301   public boolean supportsGroupByBeyondSelect() throws SQLException {
302     // This doesn't make sense - returning false to be safe,
303
return false;
304   }
305
306   public boolean supportsLikeEscapeClause() throws SQLException {
307     return true;
308   }
309
310   public boolean supportsMultipleResultSets() throws SQLException {
311     return false;
312   }
313
314   public boolean supportsMultipleTransactions() throws SQLException {
315     // Of course... :-)
316
return true;
317   }
318
319   public boolean supportsNonNullableColumns() throws SQLException {
320     return true;
321   }
322
323   public boolean supportsMinimumSQLGrammar() throws SQLException {
324     // I need to check this...
325
// What's minimum SQL as defined in ODBC?
326
return false;
327   }
328
329   public boolean supportsCoreSQLGrammar() throws SQLException {
330     // What's core SQL as defined in ODBC?
331
return false;
332   }
333
334   public boolean supportsExtendedSQLGrammar() throws SQLException {
335     return false;
336   }
337
338   public boolean supportsANSI92EntryLevelSQL() throws SQLException {
339     // Not yet...
340
return false;
341   }
342
343   public boolean supportsANSI92IntermediateSQL() throws SQLException {
344     return false;
345   }
346
347   public boolean supportsANSI92FullSQL() throws SQLException {
348     return false;
349   }
350
351   public boolean supportsIntegrityEnhancementFacility() throws SQLException {
352     // ?
353
return false;
354   }
355
356   public boolean supportsOuterJoins() throws SQLException {
357     return true;
358   }
359
360   public boolean supportsFullOuterJoins() throws SQLException {
361     return false;
362   }
363
364   public boolean supportsLimitedOuterJoins() throws SQLException {
365     return true;
366   }
367
368   public String JavaDoc getSchemaTerm() throws SQLException {
369     return "Schema";
370   }
371
372   public String JavaDoc getProcedureTerm() throws SQLException {
373     return "Procedure";
374   }
375
376   public String JavaDoc getCatalogTerm() throws SQLException {
377     return "Catalog";
378   }
379
380   public boolean isCatalogAtStart() throws SQLException {
381     // Don't support catalogs
382
return false;
383   }
384
385   public String JavaDoc getCatalogSeparator() throws SQLException {
386     return "";
387   }
388
389   public boolean supportsSchemasInDataManipulation() throws SQLException {
390     return true;
391   }
392
393   public boolean supportsSchemasInProcedureCalls() throws SQLException {
394     // When we support procedures then true...
395
return true;
396   }
397
398   public boolean supportsSchemasInTableDefinitions() throws SQLException {
399     return true;
400   }
401
402   public boolean supportsSchemasInIndexDefinitions() throws SQLException {
403     return true;
404   }
405
406   public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException {
407     return true;
408   }
409
410   public boolean supportsCatalogsInDataManipulation() throws SQLException {
411     return false;
412   }
413
414   public boolean supportsCatalogsInProcedureCalls() throws SQLException {
415     return false;
416   }
417
418   public boolean supportsCatalogsInTableDefinitions() throws SQLException {
419     return false;
420   }
421
422   public boolean supportsCatalogsInIndexDefinitions() throws SQLException {
423     return false;
424   }
425
426   public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException {
427     return false;
428   }
429
430   public boolean supportsPositionedDelete() throws SQLException {
431     // I'm guessing this comes with updatable result sets.
432
return false;
433   }
434
435   public boolean supportsPositionedUpdate() throws SQLException {
436     // I'm guessing this comes with updatable result sets.
437
return false;
438   }
439
440   public boolean supportsSelectForUpdate() throws SQLException {
441     // I'm not sure what this is,
442
return false;
443   }
444
445   public boolean supportsStoredProcedures() throws SQLException {
446     return false;
447   }
448
449   public boolean supportsSubqueriesInComparisons() throws SQLException {
450     // Not yet,
451
return false;
452   }
453
454   public boolean supportsSubqueriesInExists() throws SQLException {
455     // No 'exists' yet,
456
return false;
457   }
458
459   public boolean supportsSubqueriesInIns() throws SQLException {
460     return true;
461   }
462
463   public boolean supportsSubqueriesInQuantifieds() throws SQLException {
464     // I don't think so,
465
return false;
466   }
467
468   public boolean supportsCorrelatedSubqueries() throws SQLException {
469     // Not yet,
470
return false;
471   }
472
473   public boolean supportsUnion() throws SQLException {
474     return false;
475   }
476
477   public boolean supportsUnionAll() throws SQLException {
478     return false;
479   }
480
481   public boolean supportsOpenCursorsAcrossCommit() throws SQLException {
482     // Sort of, a result set can remain open after a commit...
483
return true;
484   }
485
486   public boolean supportsOpenCursorsAcrossRollback() throws SQLException {
487     // Sort of, a result set can remain open after a commit...
488
return true;
489   }
490
491   public boolean supportsOpenStatementsAcrossCommit() throws SQLException {
492     return true;
493   }
494
495   public boolean supportsOpenStatementsAcrossRollback() throws SQLException {
496     return true;
497   }
498
499     //----------------------------------------------------------------------
500
// The following group of methods exposes various limitations
501
// based on the target database with the current driver.
502
// Unless otherwise specified, a result of zero means there is no
503
// limit, or the limit is not known.
504

505   public int getMaxBinaryLiteralLength() throws SQLException {
506     // No binary literals yet,
507
return 0;
508   }
509
510   public int getMaxCharLiteralLength() throws SQLException {
511     // This is an educated guess...
512
return 32768;
513   }
514
515   public int getMaxColumnNameLength() throws SQLException {
516     // Need to work out this limitation for real. There may be no limit.
517
return 256;
518   }
519
520   public int getMaxColumnsInGroupBy() throws SQLException {
521     // The limit is determined by number of columns in select.
522
return getMaxColumnsInSelect();
523   }
524
525   public int getMaxColumnsInIndex() throws SQLException {
526     // No explicit indexing syntax,
527
return 1;
528   }
529
530   public int getMaxColumnsInOrderBy() throws SQLException {
531     // The limit is determined by number of columns in select.
532
return getMaxColumnsInSelect();
533   }
534
535   public int getMaxColumnsInSelect() throws SQLException {
536     // Probably limited only by resources...
537
return 4096;
538   }
539
540   public int getMaxColumnsInTable() throws SQLException {
541     // Probably limited only by resources...
542
return 4096;
543   }
544
545   public int getMaxConnections() throws SQLException {
546     // Maybe we need to do some benchmarks for this. There's certainly no
547
// limit with regard to licensing.
548
return 8000;
549   }
550
551   public int getMaxCursorNameLength() throws SQLException {
552     // Cursors not supported,
553
return 0;
554   }
555
556   public int getMaxIndexLength() throws SQLException {
557     // No explicit indexing syntax,
558
return 0;
559   }
560
561   public int getMaxSchemaNameLength() throws SQLException {
562     // Schema not supported,
563
return 0;
564   }
565
566   public int getMaxProcedureNameLength() throws SQLException {
567     // Procedures not supported,
568
return 0;
569   }
570
571   public int getMaxCatalogNameLength() throws SQLException {
572     // Catalog not supported,
573
return 0;
574   }
575
576   public int getMaxRowSize() throws SQLException {
577     // Only limited by resources,
578
// Returning 16MB here.
579
return 16 * 1024 * 1024;
580   }
581
582   public boolean doesMaxRowSizeIncludeBlobs() throws SQLException {
583     return false;
584   }
585
586   public int getMaxStatementLength() throws SQLException {
587     // The size of a UTF-8 string?
588
return 60000;
589   }
590
591   public int getMaxStatements() throws SQLException {
592     // No coded limit,
593
return 1024;
594   }
595
596   public int getMaxTableNameLength() throws SQLException {
597     // This is what's in DatabaseConstants.
598
// However, this limitation should no longer be applicable!
599
return 50;
600   }
601
602   public int getMaxTablesInSelect() throws SQLException {
603     // Should be no limit but we'll put an arbitary limit anyway...
604
return 512;
605   }
606
607   public int getMaxUserNameLength() throws SQLException {
608     // This is what's in DatabaseConstants.
609
// However, this limitation should no longer be applicable!
610
return 50;
611   }
612
613     //----------------------------------------------------------------------
614

615   public int getDefaultTransactionIsolation() throws SQLException {
616     // Currently the only supported isolation level
617
return Connection.TRANSACTION_SERIALIZABLE;
618   }
619
620   public boolean supportsTransactions() throws SQLException {
621     // As of version 0.88, yes!
622
return true;
623   }
624
625   public boolean supportsTransactionIsolationLevel(int level)
626               throws SQLException {
627     return (level == Connection.TRANSACTION_SERIALIZABLE);
628   }
629
630   public boolean supportsDataDefinitionAndDataManipulationTransactions()
631                throws SQLException {
632     return true;
633   }
634
635   public boolean supportsDataManipulationTransactionsOnly()
636               throws SQLException {
637     return false;
638   }
639
640   public boolean dataDefinitionCausesTransactionCommit()
641               throws SQLException {
642     return false;
643   }
644
645   public boolean dataDefinitionIgnoredInTransactions()
646               throws SQLException {
647     return false;
648   }
649
650   public ResultSet getProcedures(String JavaDoc catalog, String JavaDoc schemaPattern,
651       String JavaDoc procedureNamePattern) throws SQLException {
652
653     PreparedStatement statement = connection.prepareStatement(
654                             "SHOW JDBC_PROCEDURES ( ?, ?, ? )");
655     statement.setString(1, catalog);
656     statement.setString(2, schemaPattern);
657     statement.setString(3, procedureNamePattern);
658
659     return statement.executeQuery();
660   }
661
662   public ResultSet getProcedureColumns(String JavaDoc catalog,
663       String JavaDoc schemaPattern,
664       String JavaDoc procedureNamePattern,
665       String JavaDoc columnNamePattern) throws SQLException {
666
667     PreparedStatement statement = connection.prepareStatement(
668                  "SHOW JDBC_PROCEDURE_COLUMNS ( ?, ?, ?, ? )");
669     statement.setString(1, catalog);
670     statement.setString(2, schemaPattern);
671     statement.setString(3, procedureNamePattern);
672     statement.setString(4, columnNamePattern);
673
674     return statement.executeQuery();
675   }
676
677   public ResultSet getTables(String JavaDoc catalog, String JavaDoc schemaPattern,
678       String JavaDoc tableNamePattern, String JavaDoc[] types) throws SQLException {
679
680     if (tableNamePattern == null) {
681       tableNamePattern = "%";
682     }
683     if (schemaPattern == null) {
684       schemaPattern = "%";
685     }
686
687     // The 'types' argument
688
String JavaDoc type_part = "";
689     int type_size = 0;
690     if (types != null && types.length > 0) {
691       StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
692       buf.append(" AND \"TABLE_TYPE\" IN ( ");
693       for (int i = 0; i < types.length - 1; ++i) {
694         buf.append("?, ");
695       }
696       buf.append("? ) \n");
697       type_size = types.length;
698       type_part = new String JavaDoc(buf);
699     }
700
701     // Create the statement
702

703     PreparedStatement stmt = connection.prepareStatement(
704         " SELECT * \n" +
705         " FROM \"SYS_JDBC.Tables\" \n" +
706         " WHERE \"TABLE_SCHEM\" LIKE ? \n" +
707         " AND \"TABLE_NAME\" LIKE ? \n" +
708         type_part +
709         " ORDER BY \"TABLE_TYPE\", \"TABLE_SCHEM\", \"TABLE_NAME\" \n"
710     );
711     stmt.setString(1, schemaPattern);
712     stmt.setString(2, tableNamePattern);
713     if (type_size > 0) {
714       for (int i = 0; i < type_size; ++i) {
715         stmt.setString(3 + i, types[i]);
716       }
717     }
718
719     return stmt.executeQuery();
720
721   }
722
723   public ResultSet getSchemas() throws SQLException {
724     Statement statement = connection.createStatement();
725     return statement.executeQuery(
726        " SELECT * \n" +
727        " FROM SYS_JDBC.Schemas \n" +
728        " ORDER BY \"TABLE_SCHEM\" "
729     );
730   }
731
732   public ResultSet getCatalogs() throws SQLException {
733     Statement statement = connection.createStatement();
734     return statement.executeQuery("SHOW JDBC_CATALOGS");
735   }
736
737   public ResultSet getTableTypes() throws SQLException {
738     Statement statement = connection.createStatement();
739     return statement.executeQuery("SHOW JDBC_TABLE_TYPES");
740   }
741
742   public ResultSet getColumns(String JavaDoc catalog, String JavaDoc schemaPattern,
743     String JavaDoc tableNamePattern, String JavaDoc columnNamePattern)
744           throws SQLException {
745
746     if (tableNamePattern == null) {
747       tableNamePattern = "%";
748     }
749     if (schemaPattern == null) {
750       schemaPattern = "%";
751     }
752     if (columnNamePattern == null) {
753       columnNamePattern = "%";
754     }
755
756     PreparedStatement statement = connection.prepareStatement(
757 " SELECT * \n" +
758 " FROM SYS_JDBC.Columns \n" +
759 " WHERE \"TABLE_SCHEM\" LIKE ? \n" +
760 " AND \"TABLE_NAME\" LIKE ? \n" +
761 " AND \"COLUMN_NAME\" LIKE ? \n" +
762 "ORDER BY \"TABLE_SCHEM\", \"TABLE_NAME\", \"ORDINAL_POSITION\""
763     );
764
765     statement.setString(1, schemaPattern);
766     statement.setString(2, tableNamePattern);
767     statement.setString(3, columnNamePattern);
768
769     return statement.executeQuery();
770   }
771
772   public ResultSet getColumnPrivileges(String JavaDoc catalog, String JavaDoc schema,
773       String JavaDoc table, String JavaDoc columnNamePattern) throws SQLException {
774
775     if (columnNamePattern == null) {
776       columnNamePattern = "%";
777     }
778
779     PreparedStatement statement = connection.prepareStatement(
780 " SELECT * FROM SYS_JDBC.ColumnPrivileges \n" +
781 " WHERE (? IS NOT NULL OR \"TABLE_SCHEM\" = ? ) \n" +
782 " AND (? IS NOT NULL OR \"TABLE_NAME\" = ? ) \n" +
783 " AND \"COLUMN_NAME\" LIKE ? \n" +
784 " ORDER BY \"COLUMN_NAME\", \"PRIVILEGE\" "
785     );
786
787     statement.setString(1, schema);
788     statement.setString(2, schema);
789     statement.setString(3, table);
790     statement.setString(4, table);
791     statement.setString(5, columnNamePattern);
792
793     return statement.executeQuery();
794   }
795
796   public ResultSet getTablePrivileges(String JavaDoc catalog, String JavaDoc schemaPattern,
797         String JavaDoc tableNamePattern) throws SQLException {
798
799     if (schemaPattern == null) {
800       schemaPattern = "%";
801     }
802     if (tableNamePattern == null) {
803       tableNamePattern = "%";
804     }
805     
806     PreparedStatement statement = connection.prepareStatement(
807 " SELECT * FROM SYS_JDBC.TablePrivileges \n" +
808 " WHERE \"TABLE_SCHEM\" LIKE ? \n" +
809 " AND \"TABLE_NAME\" LIKE ? \n" +
810 " ORDER BY \"TABLE_SCHEM\", \"TABLE_NAME\", \"PRIVILEGE\" "
811     );
812
813     statement.setString(1, schemaPattern);
814     statement.setString(2, tableNamePattern);
815     
816     return statement.executeQuery();
817   }
818
819   public ResultSet getBestRowIdentifier(String JavaDoc catalog, String JavaDoc schema,
820     String JavaDoc table, int scope, boolean nullable) throws SQLException {
821
822     PreparedStatement statement = connection.prepareStatement(
823                   "SHOW JDBC_BEST_ROW_IDENTIFIER ( ?, ?, ?, ?, ? )");
824     statement.setString(1, catalog);
825     statement.setString(2, schema);
826     statement.setString(3, table);
827     statement.setInt(4, scope);
828     statement.setBoolean(5, nullable);
829
830     return statement.executeQuery();
831   }
832
833   public ResultSet getVersionColumns(String JavaDoc catalog, String JavaDoc schema,
834         String JavaDoc table) throws SQLException {
835
836     PreparedStatement statement = connection.prepareStatement(
837                            "SHOW JDBC_VERSION_COLUMNS ( ?, ?, ? )");
838     statement.setString(1, catalog);
839     statement.setString(2, schema);
840     statement.setString(3, table);
841
842     return statement.executeQuery();
843   }
844
845   public ResultSet getPrimaryKeys(String JavaDoc catalog, String JavaDoc schema,
846         String JavaDoc table) throws SQLException {
847
848     PreparedStatement stmt = connection.prepareStatement(
849 " SELECT * \n" +
850 " FROM SYS_JDBC.PrimaryKeys \n" +
851 " WHERE ( ? IS NULL OR \"TABLE_SCHEM\" = ? ) \n" +
852 " AND \"TABLE_NAME\" = ? \n" +
853 " ORDER BY \"COLUMN_NAME\""
854     );
855     stmt.setString(1, schema);
856     stmt.setString(2, schema);
857     stmt.setString(3, table);
858
859     return stmt.executeQuery();
860
861   }
862
863   public ResultSet getImportedKeys(String JavaDoc catalog, String JavaDoc schema,
864         String JavaDoc table) throws SQLException {
865
866     PreparedStatement stmt = connection.prepareStatement(
867 " SELECT * FROM SYS_JDBC.ImportedKeys \n" +
868 " WHERE ( ? IS NULL OR \"FKTABLE_SCHEM\" = ? )\n" +
869 " AND \"FKTABLE_NAME\" = ? \n" +
870 "ORDER BY \"FKTABLE_SCHEM\", \"FKTABLE_NAME\", \"KEY_SEQ\""
871     );
872     stmt.setString(1, schema);
873     stmt.setString(2, schema);
874     stmt.setString(3, table);
875
876     return stmt.executeQuery();
877   }
878
879   public ResultSet getExportedKeys(String JavaDoc catalog, String JavaDoc schema,
880         String JavaDoc table) throws SQLException {
881
882     PreparedStatement stmt = connection.prepareStatement(
883 " SELECT * FROM SYS_JDBC.ImportedKeys \n" +
884 " WHERE ( ? IS NULL OR \"PKTABLE_SCHEM\" = ? ) \n" +
885 " AND \"PKTABLE_NAME\" = ? \n" +
886 "ORDER BY \"FKTABLE_SCHEM\", \"FKTABLE_NAME\", \"KEY_SEQ\""
887     );
888     stmt.setString(1, schema);
889     stmt.setString(2, schema);
890     stmt.setString(3, table);
891
892     return stmt.executeQuery();
893   }
894
895   public ResultSet getCrossReference(
896     String JavaDoc primaryCatalog, String JavaDoc primarySchema, String JavaDoc primaryTable,
897     String JavaDoc foreignCatalog, String JavaDoc foreignSchema, String JavaDoc foreignTable
898     ) throws SQLException {
899
900     PreparedStatement stmt = connection.prepareStatement(
901 " SELECT * FROM SYS_JDBC.ImportedKeys \n" +
902 " WHERE ( ? IS NULL OR \"PKTABLE_SCHEM\" = ? )\n" +
903 " AND \"PKTABLE_NAME\" = ?\n" +
904 " AND ( ? IS NULL OR \"FKTABLE_SCHEM\" = ? )\n" +
905 " AND \"FKTABLE_NAME\" = ?\n" +
906 "ORDER BY \"FKTABLE_SCHEM\", \"FKTABLE_NAME\", \"KEY_SEQ\"\n"
907     );
908     stmt.setString(1, primarySchema);
909     stmt.setString(2, primarySchema);
910     stmt.setString(3, primaryTable);
911     stmt.setString(4, foreignSchema);
912     stmt.setString(5, foreignSchema);
913     stmt.setString(6, foreignTable);
914
915     return stmt.executeQuery();
916   }
917
918   public ResultSet getTypeInfo() throws SQLException {
919     return connection.createStatement().executeQuery(
920                                    "SELECT * FROM SYS_INFO.sUSRSQLTypeInfo");
921   }
922
923   public ResultSet getIndexInfo(String JavaDoc catalog, String JavaDoc schema, String JavaDoc table,
924       boolean unique, boolean approximate)
925           throws SQLException {
926
927     PreparedStatement statement = connection.prepareStatement(
928                      "SHOW JDBC_INDEX_INFO ( ?, ?, ?, ?, ? )");
929     statement.setString(1, catalog);
930     statement.setString(2, schema);
931     statement.setString(3, table);
932     statement.setBoolean(4, unique);
933     statement.setBoolean(5, approximate);
934
935     return statement.executeQuery();
936   }
937
938 //#IFDEF(JDBC2.0)
939

940     //--------------------------JDBC 2.0-----------------------------
941

942   public boolean supportsResultSetType(int type) throws SQLException {
943     return (type == ResultSet.TYPE_FORWARD_ONLY ||
944             type == ResultSet.TYPE_SCROLL_INSENSITIVE);
945   }
946
947   public boolean supportsResultSetConcurrency(int type, int concurrency)
948       throws SQLException {
949     if (type == ResultSet.TYPE_SCROLL_INSENSITIVE &&
950         concurrency == ResultSet.CONCUR_READ_ONLY) {
951       return true;
952     }
953     return false;
954   }
955
956   public boolean ownUpdatesAreVisible(int type) throws SQLException {
957     return false;
958   }
959
960   public boolean ownDeletesAreVisible(int type) throws SQLException {
961     return false;
962   }
963
964   public boolean ownInsertsAreVisible(int type) throws SQLException {
965     return false;
966   }
967
968   public boolean othersUpdatesAreVisible(int type) throws SQLException {
969     return false;
970   }
971
972   public boolean othersDeletesAreVisible(int type) throws SQLException {
973     return false;
974   }
975
976   public boolean othersInsertsAreVisible(int type) throws SQLException {
977     return false;
978   }
979
980   public boolean updatesAreDetected(int type) throws SQLException {
981     return false;
982   }
983
984   public boolean deletesAreDetected(int type) throws SQLException {
985     return false;
986   }
987
988   public boolean insertsAreDetected(int type) throws SQLException {
989     return false;
990   }
991
992   public boolean supportsBatchUpdates() throws SQLException {
993     return true;
994   }
995
996   public ResultSet getUDTs(String JavaDoc catalog, String JavaDoc schemaPattern,
997           String JavaDoc typeNamePattern, int[] types)
998       throws SQLException {
999
1000    String JavaDoc where_clause = "true";
1001    if (types != null) {
1002      for (int i = 0; i < types.length; ++i) {
1003
1004        int t = types[i];
1005        String JavaDoc tstr = "JAVA_OBJECT";
1006        if (t == Types.STRUCT) {
1007          tstr = "STRUCT";
1008        }
1009        else if (t == Types.DISTINCT) {
1010          tstr = "DISTINCT";
1011        }
1012
1013        if (i != 0) {
1014          where_clause += " AND";
1015        }
1016        where_clause += " DATA_TYPE = '" +
1017                        MckoiConnection.quote(tstr) + "'";
1018      }
1019    }
1020
1021    PreparedStatement statement = connection.prepareStatement(
1022                 "SHOW JDBC_UDTS ( ?, ?, ? ) WHERE " + where_clause);
1023    statement.setString(1, catalog);
1024    statement.setString(2, schemaPattern);
1025    statement.setString(3, typeNamePattern);
1026
1027    return statement.executeQuery();
1028  }
1029
1030  public Connection getConnection() throws SQLException {
1031    return connection;
1032  }
1033
1034//#ENDIF
1035

1036//#IFDEF(JDBC3.0)
1037

1038  // ------------------- JDBC 3.0 -------------------------
1039

1040  public boolean supportsSavepoints() throws SQLException {
1041    // Currently no
1042
return false;
1043  }
1044
1045  public boolean supportsNamedParameters() throws SQLException {
1046    return false;
1047  }
1048
1049  public boolean supportsMultipleOpenResults() throws SQLException {
1050    return false;
1051  }
1052
1053  public boolean supportsGetGeneratedKeys() throws SQLException {
1054    return false;
1055  }
1056
1057  public ResultSet getSuperTypes(String JavaDoc catalog, String JavaDoc schemaPattern,
1058                                 String JavaDoc typeNamePattern) throws SQLException {
1059    throw MSQLException.unsupported();
1060  }
1061
1062  public ResultSet getSuperTables(String JavaDoc catalog, String JavaDoc schemaPattern,
1063                                String JavaDoc tableNamePattern) throws SQLException {
1064    throw MSQLException.unsupported();
1065  }
1066
1067  public ResultSet getAttributes(String JavaDoc catalog, String JavaDoc schemaPattern,
1068                      String JavaDoc typeNamePattern, String JavaDoc attributeNamePattern)
1069                                                         throws SQLException {
1070    throw MSQLException.unsupported();
1071  }
1072
1073  public boolean supportsResultSetHoldability(int holdability)
1074                                                         throws SQLException {
1075    return holdability == ResultSet.HOLD_CURSORS_OVER_COMMIT;
1076  }
1077
1078  public int getResultSetHoldability() throws SQLException {
1079    // Eh? This is in ResultSetMetaData also? An error in the spec or is
1080
// this the *default* holdability of a result set?
1081
return ResultSet.HOLD_CURSORS_OVER_COMMIT;
1082  }
1083
1084  public int getDatabaseMajorVersion() throws SQLException {
1085    throw MSQLException.unsupported();
1086  }
1087
1088  public int getDatabaseMinorVersion() throws SQLException {
1089    throw MSQLException.unsupported();
1090  }
1091
1092  public int getJDBCMajorVersion() throws SQLException {
1093    return 3;
1094  }
1095
1096  public int getJDBCMinorVersion() throws SQLException {
1097    return 0;
1098  }
1099
1100  public int getSQLStateType() throws SQLException {
1101    // ?
1102
throw MSQLException.unsupported();
1103  }
1104
1105  public boolean locatorsUpdateCopy() throws SQLException {
1106    // Doesn't matter because this is not supported.
1107
throw MSQLException.unsupported();
1108  }
1109
1110  public boolean supportsStatementPooling() throws SQLException {
1111    return true;
1112  }
1113
1114//#ENDIF
1115

1116}
1117
Popular Tags