1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 package com.sun.star.comp.sdbc;
22 
23 import java.util.ArrayList;
24 import java.util.Map;
25 import java.util.TreeMap;
26 
27 import org.apache.openoffice.comp.sdbc.dbtools.util.CustomColumn;
28 import org.apache.openoffice.comp.sdbc.dbtools.util.CustomResultSet;
29 import org.apache.openoffice.comp.sdbc.dbtools.util.CustomResultSetMetaData;
30 import org.apache.openoffice.comp.sdbc.dbtools.util.ORowSetValue;
31 
32 import com.sun.star.beans.PropertyValue;
33 import com.sun.star.lang.IllegalArgumentException;
34 import com.sun.star.lib.uno.helper.WeakBase;
35 import com.sun.star.sdbc.ColumnValue;
36 import com.sun.star.sdbc.DataType;
37 import com.sun.star.sdbc.SQLException;
38 import com.sun.star.sdbc.XConnection;
39 import com.sun.star.sdbc.XDatabaseMetaData2;
40 import com.sun.star.sdbc.XResultSet;
41 import com.sun.star.sdbc.XResultSetMetaData;
42 import com.sun.star.sdbc.XResultSetMetaDataSupplier;
43 import com.sun.star.sdbc.XRow;
44 import com.sun.star.uno.AnyConverter;
45 import com.sun.star.uno.UnoRuntime;
46 
47 public class JavaSQLDatabaseMetaData extends WeakBase implements XDatabaseMetaData2 {
48     private final java.sql.DatabaseMetaData jdbcDatabaseMetaData;
49     private final JavaSQLConnection connection;
50     private final ConnectionLog logger;
51 
JavaSQLDatabaseMetaData(java.sql.DatabaseMetaData jdbcDatabaseMetaData, JavaSQLConnection connection)52     public JavaSQLDatabaseMetaData(java.sql.DatabaseMetaData jdbcDatabaseMetaData, JavaSQLConnection connection) {
53         this.jdbcDatabaseMetaData = jdbcDatabaseMetaData;
54         this.connection = connection;
55         this.logger = connection.getLogger();
56     }
57 
58     @Override
getConnection()59     public XConnection getConnection() throws SQLException {
60         return connection;
61     }
62 
63     @Override
getConnectionInfo()64     public PropertyValue[] getConnectionInfo() {
65         return connection.getConnectionInfo();
66     }
67 
wrapResultSet(java.sql.ResultSet resultSet)68     private XResultSet wrapResultSet(java.sql.ResultSet resultSet) {
69         if (resultSet == null) {
70             return null;
71         }
72         return new JavaSQLResultSet(resultSet, connection);
73     }
74 
75     @Override
getTypeInfo()76     public XResultSet getTypeInfo() throws SQLException {
77         try {
78             return wrapResultSet(jdbcDatabaseMetaData.getTypeInfo());
79         } catch (java.sql.SQLException jdbcSQLException) {
80             throw Tools.toUnoException(this, jdbcSQLException);
81         }
82     }
83 
84     @Override
getCatalogs()85     public XResultSet getCatalogs() throws SQLException {
86         try {
87             return wrapResultSet(jdbcDatabaseMetaData.getCatalogs());
88         } catch (java.sql.SQLException jdbcSQLException) {
89             throw Tools.toUnoException(this, jdbcSQLException);
90         }
91     }
92 
93     @Override
getCatalogSeparator()94     public String getCatalogSeparator() throws SQLException {
95         try {
96             String catalogSeparator = jdbcDatabaseMetaData.getCatalogSeparator();
97             if (catalogSeparator == null) {
98                 catalogSeparator = "";
99             }
100             return catalogSeparator;
101         } catch (java.sql.SQLException jdbcSQLException) {
102             throw Tools.toUnoException(this, jdbcSQLException);
103         }
104     }
105 
106     @Override
getSchemas()107     public XResultSet getSchemas() throws SQLException {
108         try {
109             return wrapResultSet(jdbcDatabaseMetaData.getCatalogs());
110         } catch (java.sql.SQLException jdbcSQLException) {
111             throw Tools.toUnoException(this, jdbcSQLException);
112         }
113     }
114 
115     @Override
getColumnPrivileges(Object catalog, String schema, String table, String columnNamePattern)116     public XResultSet getColumnPrivileges(Object catalog, String schema, String table,
117             String columnNamePattern) throws SQLException {
118 
119         try {
120             String jdbcCatalog = null;
121             if (AnyConverter.isString(catalog)) {
122                 jdbcCatalog = AnyConverter.toString(catalog);
123             }
124             if (schema.equals("%")) {
125                 schema = null;
126             }
127             return wrapResultSet(jdbcDatabaseMetaData.getColumnPrivileges(
128                     jdbcCatalog, schema, table, columnNamePattern));
129         } catch (java.sql.SQLException | IllegalArgumentException exception) {
130             throw Tools.toUnoException(this, exception);
131         }
132     }
133 
134     @Override
getColumns(Object catalog, String schemaPattern, String tableNamePattern, String columnNamePattern)135     public XResultSet getColumns(Object catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException {
136         try {
137             String jdbcCatalog = null;
138             if (AnyConverter.isString(catalog)) {
139                 jdbcCatalog = AnyConverter.toString(catalog);
140             }
141             if (schemaPattern.equals("%")) {
142                 schemaPattern = null;
143             }
144             return wrapResultSet(jdbcDatabaseMetaData.getColumns(
145                     jdbcCatalog, schemaPattern, tableNamePattern, columnNamePattern));
146         } catch (java.sql.SQLException | IllegalArgumentException exception) {
147             throw Tools.toUnoException(this, exception);
148         }
149     }
150 
151     @Override
getTables(Object catalog, String schemaPattern, String tableNamePattern, String[] types)152     public XResultSet getTables(Object catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException {
153         try {
154             // the SDBC API allows to pass "%" as table type filter, but in JDBC, "all table types"
155             // is represented by the table type being null
156             String[] jdbcTypes = types;
157             for (String type : types) {
158                 if (type.equals("%")) {
159                     jdbcTypes = null;
160                     break;
161                 }
162             }
163             String jdbcCatalog = null;
164             if (AnyConverter.isString(catalog)) {
165                 jdbcCatalog = AnyConverter.toString(catalog);
166             }
167             // if we are to display "all catalogs", then respect CatalogRestriction
168             if (jdbcCatalog == null) {
169                 Object catalogRestriction = connection.getCatalogRestriction();
170                 if (AnyConverter.isString(catalogRestriction)) {
171                     jdbcCatalog = AnyConverter.toString(catalogRestriction);
172                 }
173             }
174             if (schemaPattern.equals("%")) {
175                 Object schemaRestriction = connection.getSchemaRestriction();
176                 if (AnyConverter.isString(schemaRestriction)) {
177                     schemaPattern = AnyConverter.toString(schemaRestriction);
178                 }
179             }
180             return wrapResultSet(jdbcDatabaseMetaData.getTables(
181                     jdbcCatalog, schemaPattern, tableNamePattern, jdbcTypes));
182         } catch (java.sql.SQLException | IllegalArgumentException exception) {
183             throw Tools.toUnoException(this, exception);
184         }
185     }
186 
187     @Override
getProcedureColumns(Object catalog, String schemaNamePattern, String procedureNamePattern, String columnNamePattern)188     public XResultSet getProcedureColumns(Object catalog, String schemaNamePattern, String procedureNamePattern,
189             String columnNamePattern) throws SQLException {
190         try {
191             String jdbcCatalog = null;
192             if (AnyConverter.isString(catalog)) {
193                 jdbcCatalog = AnyConverter.toString(catalog);
194             }
195             if (schemaNamePattern.equals("%")) {
196                 schemaNamePattern = null;
197             }
198             return wrapResultSet(jdbcDatabaseMetaData.getProcedureColumns(
199                     jdbcCatalog, schemaNamePattern, procedureNamePattern, columnNamePattern));
200         } catch (java.sql.SQLException | IllegalArgumentException exception) {
201             throw Tools.toUnoException(this, exception);
202         }
203     }
204 
205     @Override
getProcedures(Object catalog, String schemaNamePattern, String procedureNamePattern)206     public XResultSet getProcedures(Object catalog, String schemaNamePattern, String procedureNamePattern) throws SQLException {
207         try {
208             String jdbcCatalog = null;
209             if (AnyConverter.isString(catalog)) {
210                 jdbcCatalog = AnyConverter.toString(catalog);
211             }
212             if (schemaNamePattern.equals("%")) {
213                 schemaNamePattern = null;
214             }
215             return wrapResultSet(jdbcDatabaseMetaData.getProcedures(
216                     jdbcCatalog, schemaNamePattern, procedureNamePattern));
217         } catch (java.sql.SQLException | IllegalArgumentException exception) {
218             throw Tools.toUnoException(this, exception);
219         }
220     }
221 
222     @Override
getVersionColumns(Object catalog, String schema, String table)223     public XResultSet getVersionColumns(Object catalog, String schema, String table) throws SQLException {
224         try {
225             String jdbcCatalog = null;
226             if (AnyConverter.isString(catalog)) {
227                 jdbcCatalog = AnyConverter.toString(catalog);
228             }
229             if (schema.equals("%")) {
230                 schema = null;
231             }
232             return wrapResultSet(jdbcDatabaseMetaData.getVersionColumns(jdbcCatalog, schema, table));
233         } catch (java.sql.SQLException | IllegalArgumentException exception) {
234             throw Tools.toUnoException(this, exception);
235         }
236     }
237 
238     @Override
getMaxBinaryLiteralLength()239     public int getMaxBinaryLiteralLength() throws SQLException {
240         try {
241             return jdbcDatabaseMetaData.getMaxBinaryLiteralLength();
242         } catch (java.sql.SQLException jdbcSQLException) {
243             throw Tools.toUnoException(this, jdbcSQLException);
244         }
245     }
246 
247     @Override
getMaxRowSize()248     public int getMaxRowSize() throws SQLException {
249         try {
250             return jdbcDatabaseMetaData.getMaxRowSize();
251         } catch (java.sql.SQLException jdbcSQLException) {
252             throw Tools.toUnoException(this, jdbcSQLException);
253         }
254     }
255 
256     @Override
getMaxCatalogNameLength()257     public int getMaxCatalogNameLength() throws SQLException {
258         try {
259             return jdbcDatabaseMetaData.getMaxCatalogNameLength();
260         } catch (java.sql.SQLException jdbcSQLException) {
261             throw Tools.toUnoException(this, jdbcSQLException);
262         }
263     }
264 
265     @Override
getMaxCharLiteralLength()266     public int getMaxCharLiteralLength() throws SQLException {
267         try {
268             return jdbcDatabaseMetaData.getMaxCharLiteralLength();
269         } catch (java.sql.SQLException jdbcSQLException) {
270             throw Tools.toUnoException(this, jdbcSQLException);
271         }
272     }
273 
274     @Override
getMaxColumnNameLength()275     public int getMaxColumnNameLength() throws SQLException {
276         try {
277             return jdbcDatabaseMetaData.getMaxColumnNameLength();
278         } catch (java.sql.SQLException jdbcSQLException) {
279             throw Tools.toUnoException(this, jdbcSQLException);
280         }
281     }
282 
283     @Override
getMaxColumnsInIndex()284     public int getMaxColumnsInIndex() throws SQLException {
285         try {
286             return jdbcDatabaseMetaData.getMaxColumnsInIndex();
287         } catch (java.sql.SQLException jdbcSQLException) {
288             throw Tools.toUnoException(this, jdbcSQLException);
289         }
290     }
291 
292     @Override
getMaxCursorNameLength()293     public int getMaxCursorNameLength() throws SQLException {
294         try {
295             return jdbcDatabaseMetaData.getMaxCursorNameLength();
296         } catch (java.sql.SQLException jdbcSQLException) {
297             throw Tools.toUnoException(this, jdbcSQLException);
298         }
299     }
300 
301     @Override
getMaxConnections()302     public int getMaxConnections() throws SQLException {
303         try {
304             return jdbcDatabaseMetaData.getMaxConnections();
305         } catch (java.sql.SQLException jdbcSQLException) {
306             throw Tools.toUnoException(this, jdbcSQLException);
307         }
308     }
309 
310     @Override
getMaxColumnsInTable()311     public int getMaxColumnsInTable() throws SQLException {
312         try {
313             return jdbcDatabaseMetaData.getMaxColumnsInTable();
314         } catch (java.sql.SQLException jdbcSQLException) {
315             throw Tools.toUnoException(this, jdbcSQLException);
316         }
317     }
318 
319     @Override
getMaxStatementLength()320     public int getMaxStatementLength() throws SQLException {
321         try {
322             return jdbcDatabaseMetaData.getMaxStatementLength();
323         } catch (java.sql.SQLException jdbcSQLException) {
324             throw Tools.toUnoException(this, jdbcSQLException);
325         }
326     }
327 
328     @Override
getMaxTableNameLength()329     public int getMaxTableNameLength() throws SQLException {
330         try {
331             return jdbcDatabaseMetaData.getMaxTableNameLength();
332         } catch (java.sql.SQLException jdbcSQLException) {
333             throw Tools.toUnoException(this, jdbcSQLException);
334         }
335     }
336 
337     @Override
getMaxTablesInSelect()338     public int getMaxTablesInSelect() throws SQLException {
339         try {
340             return jdbcDatabaseMetaData.getMaxTablesInSelect();
341         } catch (java.sql.SQLException jdbcSQLException) {
342             throw Tools.toUnoException(this, jdbcSQLException);
343         }
344     }
345 
346     @Override
getExportedKeys(Object catalog, String schema, String table)347     public XResultSet getExportedKeys(Object catalog, String schema, String table) throws SQLException {
348         try {
349             String jdbcCatalog = null;
350             if (AnyConverter.isString(catalog)) {
351                 jdbcCatalog = AnyConverter.toString(catalog);
352             }
353             if (schema.equals("%")) {
354                 schema = null;
355             }
356             return wrapResultSet(jdbcDatabaseMetaData.getExportedKeys(jdbcCatalog, schema, table));
357         } catch (java.sql.SQLException | IllegalArgumentException exception) {
358             throw Tools.toUnoException(this, exception);
359         }
360     }
361 
362     @Override
getImportedKeys(Object catalog, String schema, String table)363     public XResultSet getImportedKeys(Object catalog, String schema, String table) throws SQLException {
364         try {
365             String jdbcCatalog = null;
366             if (AnyConverter.isString(catalog)) {
367                 jdbcCatalog = AnyConverter.toString(catalog);
368             }
369             if (schema.equals("%")) {
370                 schema = null;
371             }
372             return wrapResultSet(jdbcDatabaseMetaData.getImportedKeys(jdbcCatalog, schema, table));
373         } catch (java.sql.SQLException | IllegalArgumentException exception) {
374             throw Tools.toUnoException(this, exception);
375         }
376     }
377 
378     @Override
getPrimaryKeys(Object catalog, String schema, String table)379     public XResultSet getPrimaryKeys(Object catalog, String schema, String table) throws SQLException {
380         try {
381             String jdbcCatalog = null;
382             if (AnyConverter.isString(catalog)) {
383                 jdbcCatalog = AnyConverter.toString(catalog);
384             }
385             if (schema.equals("%")) {
386                 schema = null;
387             }
388             return wrapResultSet(jdbcDatabaseMetaData.getPrimaryKeys(jdbcCatalog, schema, table));
389         } catch (java.sql.SQLException | IllegalArgumentException exception) {
390             throw Tools.toUnoException(this, exception);
391         }
392     }
393 
394     @Override
getIndexInfo(Object catalog, String schema, String table, boolean unique, boolean approximate)395     public XResultSet getIndexInfo(Object catalog, String schema, String table,
396             boolean unique, boolean approximate) throws SQLException {
397         try {
398             String jdbcCatalog = null;
399             if (AnyConverter.isString(catalog)) {
400                 jdbcCatalog = AnyConverter.toString(catalog);
401             }
402             if (schema.equals("%")) {
403                 schema = null;
404             }
405             return wrapResultSet(jdbcDatabaseMetaData.getIndexInfo(
406                     jdbcCatalog, schema, table, unique, approximate));
407         } catch (java.sql.SQLException | IllegalArgumentException exception) {
408             throw Tools.toUnoException(this, exception);
409         }
410     }
411 
412     @Override
getBestRowIdentifier(Object catalog, String schema, String table, int scope, boolean nullable)413     public XResultSet getBestRowIdentifier(Object catalog, String schema, String table,
414             int scope, boolean nullable) throws SQLException {
415         try {
416             String jdbcCatalog = null;
417             if (AnyConverter.isString(catalog)) {
418                 jdbcCatalog = AnyConverter.toString(catalog);
419             }
420             if (schema.equals("%")) {
421                 schema = null;
422             }
423             return wrapResultSet(jdbcDatabaseMetaData.getBestRowIdentifier(
424                     jdbcCatalog, schema, table, scope, nullable));
425         } catch (java.sql.SQLException | IllegalArgumentException exception) {
426             throw Tools.toUnoException(this, exception);
427         }
428     }
429 
getTablesPrivilegesMetadata()430     private XResultSetMetaData getTablesPrivilegesMetadata() {
431         CustomColumn[] columns = new CustomColumn[7];
432         columns[0] = new CustomColumn();
433         columns[0].setColumnName("TABLE_CAT");
434         columns[0].setNullable(ColumnValue.NULLABLE);
435         columns[0].setColumnDisplaySize(3);
436         columns[0].setPrecision(0);
437         columns[0].setScale(0);
438         columns[0].setColumnType(DataType.VARCHAR);
439         columns[1] = new CustomColumn();
440         columns[1].setColumnName("TABLE_SCHEM");
441         columns[1].setNullable(ColumnValue.NULLABLE);
442         columns[1].setColumnDisplaySize(3);
443         columns[1].setPrecision(0);
444         columns[1].setScale(0);
445         columns[1].setColumnType(DataType.VARCHAR);
446         columns[2] = new CustomColumn();
447         columns[2].setColumnName("TABLE_NAME");
448         columns[2].setNullable(ColumnValue.NO_NULLS);
449         columns[2].setColumnDisplaySize(3);
450         columns[2].setPrecision(0);
451         columns[2].setScale(0);
452         columns[2].setColumnType(DataType.VARCHAR);
453         columns[3] = new CustomColumn();
454         columns[3].setColumnName("GRANTOR");
455         columns[3].setNullable(ColumnValue.NULLABLE);
456         columns[3].setColumnDisplaySize(0);
457         columns[3].setPrecision(0);
458         columns[3].setScale(0);
459         columns[3].setColumnType(DataType.VARCHAR);
460         columns[4] = new CustomColumn();
461         columns[4].setColumnName("GRANTEE");
462         columns[4].setNullable(ColumnValue.NO_NULLS);
463         columns[4].setColumnDisplaySize(0);
464         columns[4].setPrecision(0);
465         columns[4].setScale(0);
466         columns[4].setColumnType(DataType.VARCHAR);
467         columns[5] = new CustomColumn();
468         columns[5].setColumnName("PRIVILEGE");
469         columns[5].setNullable(ColumnValue.NULLABLE);
470         columns[5].setColumnDisplaySize(0);
471         columns[5].setPrecision(0);
472         columns[5].setScale(0);
473         columns[5].setColumnType(DataType.VARCHAR);
474         columns[6] = new CustomColumn();
475         columns[6].setColumnName("IS_GRANTABLE");
476         columns[6].setNullable(ColumnValue.NULLABLE);
477         columns[6].setColumnDisplaySize(0);
478         columns[6].setPrecision(0);
479         columns[6].setScale(0);
480         columns[6].setColumnType(DataType.VARCHAR);
481         return new CustomResultSetMetaData(columns);
482     }
483 
generateOwnTablePrivileges(Object catalog, String schemaPattern, String tableNamePattern)484     private XResultSet generateOwnTablePrivileges(Object catalog, String schemaPattern,
485             String tableNamePattern) throws SQLException {
486 
487         XResultSetMetaData resultSetMetaData = getTablesPrivilegesMetadata();
488 
489         ArrayList<ORowSetValue[]> privileges = new ArrayList<>();
490         String[] privilegeTypes = {
491                 "SELECT", "INSERT", "DELETE", "UPDATE", "CREATE",
492                 "READ", "ALTER", "DROP", "REFERENCE"
493         };
494         XResultSet tables = getTables(catalog, schemaPattern, tableNamePattern,
495                 new String[] {"VIEW", "TABLE", "%"});
496         String username = getUserName();
497         XRow row = UnoRuntime.queryInterface(XRow.class, tables);
498         while (tables.next()) {
499             for (String privilegeType : privilegeTypes) {
500                 ORowSetValue[] privilege = new ORowSetValue[7];
501                 privilege[0] = new ORowSetValue(row.getString(1));
502                 privilege[1] = new ORowSetValue(row.getString(2));
503                 privilege[2] = new ORowSetValue(row.getString(3));
504                 privilege[3] = new ORowSetValue("");
505                 privilege[3].setNull();
506                 privilege[4] = new ORowSetValue(username);
507                 privilege[5] = new ORowSetValue(privilegeType);
508                 privilege[6] = new ORowSetValue("YES");
509                 privileges.add(privilege);
510             }
511         }
512         return new CustomResultSet(resultSetMetaData, privileges);
513     }
514 
515     @Override
getTablePrivileges(Object catalog, String schemaPattern, String tableNamePattern)516     public XResultSet getTablePrivileges(Object catalog, String schemaPattern, String tableNamePattern) throws SQLException {
517         try {
518             if (connection.isIgnoreDriverPrivilegesEnabled()) {
519                 return generateOwnTablePrivileges(catalog, schemaPattern, tableNamePattern);
520             }
521             String jdbcCatalog = null;
522             if (AnyConverter.isString(catalog)) {
523                 jdbcCatalog = AnyConverter.toString(catalog);
524             }
525             if (schemaPattern.equals("%")) {
526                 schemaPattern = null;
527             }
528             java.sql.ResultSet javaResults = jdbcDatabaseMetaData.getTablePrivileges(jdbcCatalog, schemaPattern, tableNamePattern);
529             if (javaResults != null) {
530                 XResultSet results = new JavaSQLResultSet(javaResults, connection);
531                 // we have to check the result columns for the tables privileges
532                 // #106324#
533                 XResultSetMetaDataSupplier metaDataSupplier = UnoRuntime.queryInterface(XResultSetMetaDataSupplier.class, results);
534                 XResultSetMetaData metaData = null;
535                 if (metaDataSupplier != null) {
536                     metaData = metaDataSupplier.getMetaData();
537                 }
538                 if (metaData != null && metaData.getColumnCount() != 7) {
539                     // here we know that the count of column doesn't match
540                     Map<Integer,Integer> columnMatching = new TreeMap<>();
541                     String[] privileges = new String[] {
542                             "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "GRANTOR", "GRANTEE", "PRIVILEGE", "IS_GRANTABLE"
543                     };
544                     int count = metaData.getColumnCount();
545                     for (int i = 1; i <= count; i++) {
546                         String columnName = metaData.getColumnName(i);
547                         for (int j = 0; j < privileges.length; j++) {
548                             if (columnName.equals(privileges[j])) {
549                                 columnMatching.put(i, j);
550                                 break;
551                             }
552                         }
553                     }
554                     // fill our own resultset
555                     ArrayList<ORowSetValue[]> rowsOut = new ArrayList<>();
556                     XRow row = UnoRuntime.queryInterface(XRow.class, results);
557                     while (results.next()) {
558                         ORowSetValue[] rowOut = new ORowSetValue[7];
559                         for (int i = 0; i < rowOut.length; i++) {
560                             rowOut[i] = new ORowSetValue("");
561                             rowOut[i].setNull();
562                         }
563                         for (Map.Entry<Integer,Integer> entry : columnMatching.entrySet()) {
564                             String value = row.getString(entry.getKey());
565                             if (row.wasNull()) {
566                                 rowOut[entry.getValue()].setNull();
567                             } else {
568                                 rowOut[entry.getValue()].setString(value);
569                             }
570                         }
571                         rowsOut.add(rowOut);
572                     }
573                     results = new CustomResultSet(getTablesPrivilegesMetadata(), rowsOut);
574                 }
575                 return results;
576             } else {
577                 return null;
578             }
579         } catch (java.sql.SQLException | IllegalArgumentException exception) {
580             throw Tools.toUnoException(this, exception);
581         }
582     }
583 
584     @Override
getCrossReference(Object primaryCatalog, String primarySchema, String primaryTable, Object foreignCatalog, String foreignSchema, String foreignTable)585     public XResultSet getCrossReference(Object primaryCatalog, String primarySchema, String primaryTable,
586             Object foreignCatalog, String foreignSchema, String foreignTable) throws SQLException {
587         try {
588             String jdbcPrimaryCatalog = null;
589             if (AnyConverter.isString(primaryCatalog)) {
590                 jdbcPrimaryCatalog = AnyConverter.toString(primaryCatalog);
591             }
592             String jdbcForeignCatalog = null;
593             if (AnyConverter.isString(foreignCatalog)) {
594                 jdbcForeignCatalog = AnyConverter.toString(foreignCatalog);
595             }
596             if (primarySchema.equals("%")) {
597                 primarySchema = null;
598             }
599             if (foreignSchema.equals("%")) {
600                 foreignSchema = null;
601             }
602             return wrapResultSet(jdbcDatabaseMetaData.getCrossReference(
603                     jdbcPrimaryCatalog, primarySchema, primaryTable,
604                     jdbcForeignCatalog, foreignSchema, foreignTable));
605         } catch (java.sql.SQLException | IllegalArgumentException exception) {
606             throw Tools.toUnoException(this, exception);
607         }
608     }
609 
610     @Override
doesMaxRowSizeIncludeBlobs()611     public boolean doesMaxRowSizeIncludeBlobs() throws SQLException {
612         try {
613             return jdbcDatabaseMetaData.doesMaxRowSizeIncludeBlobs();
614         } catch (java.sql.SQLException jdbcSQLException) {
615             throw Tools.toUnoException(this, jdbcSQLException);
616         }
617     }
618 
619     @Override
storesLowerCaseQuotedIdentifiers()620     public boolean storesLowerCaseQuotedIdentifiers() throws SQLException {
621         try {
622             return jdbcDatabaseMetaData.storesLowerCaseQuotedIdentifiers();
623         } catch (java.sql.SQLException jdbcSQLException) {
624             throw Tools.toUnoException(this, jdbcSQLException);
625         }
626     }
627 
628     @Override
storesLowerCaseIdentifiers()629     public boolean storesLowerCaseIdentifiers() throws SQLException {
630         try {
631             return jdbcDatabaseMetaData.storesLowerCaseIdentifiers();
632         } catch (java.sql.SQLException jdbcSQLException) {
633             throw Tools.toUnoException(this, jdbcSQLException);
634         }
635     }
636 
637     @Override
storesMixedCaseIdentifiers()638     public boolean storesMixedCaseIdentifiers() throws SQLException {
639         try {
640             return jdbcDatabaseMetaData.storesMixedCaseIdentifiers();
641         } catch (java.sql.SQLException jdbcSQLException) {
642             throw Tools.toUnoException(this, jdbcSQLException);
643         }
644     }
645 
646     @Override
storesMixedCaseQuotedIdentifiers()647     public boolean storesMixedCaseQuotedIdentifiers() throws SQLException {
648         try {
649             return jdbcDatabaseMetaData.storesMixedCaseQuotedIdentifiers();
650         } catch (java.sql.SQLException jdbcSQLException) {
651             throw Tools.toUnoException(this, jdbcSQLException);
652         }
653     }
654 
655     @Override
storesUpperCaseQuotedIdentifiers()656     public boolean storesUpperCaseQuotedIdentifiers() throws SQLException {
657         try {
658             return jdbcDatabaseMetaData.storesUpperCaseQuotedIdentifiers();
659         } catch (java.sql.SQLException jdbcSQLException) {
660             throw Tools.toUnoException(this, jdbcSQLException);
661         }
662     }
663 
664     @Override
storesUpperCaseIdentifiers()665     public boolean storesUpperCaseIdentifiers() throws SQLException {
666         try {
667             return jdbcDatabaseMetaData.storesUpperCaseIdentifiers();
668         } catch (java.sql.SQLException jdbcSQLException) {
669             throw Tools.toUnoException(this, jdbcSQLException);
670         }
671     }
672 
673     @Override
supportsAlterTableWithAddColumn()674     public boolean supportsAlterTableWithAddColumn() throws SQLException {
675         try {
676             return jdbcDatabaseMetaData.supportsAlterTableWithAddColumn();
677         } catch (java.sql.SQLException jdbcSQLException) {
678             throw Tools.toUnoException(this, jdbcSQLException);
679         }
680     }
681 
682     @Override
supportsAlterTableWithDropColumn()683     public boolean supportsAlterTableWithDropColumn() throws SQLException {
684         try {
685             return jdbcDatabaseMetaData.supportsAlterTableWithDropColumn();
686         } catch (java.sql.SQLException jdbcSQLException) {
687             throw Tools.toUnoException(this, jdbcSQLException);
688         }
689     }
690 
691     @Override
getMaxIndexLength()692     public int getMaxIndexLength() throws SQLException {
693         try {
694             return jdbcDatabaseMetaData.getMaxIndexLength();
695         } catch (java.sql.SQLException jdbcSQLException) {
696             throw Tools.toUnoException(this, jdbcSQLException);
697         }
698     }
699 
700     @Override
supportsNonNullableColumns()701     public boolean supportsNonNullableColumns() throws SQLException {
702         try {
703             return jdbcDatabaseMetaData.supportsNonNullableColumns();
704         } catch (java.sql.SQLException jdbcSQLException) {
705             throw Tools.toUnoException(this, jdbcSQLException);
706         }
707     }
708 
709     @Override
getCatalogTerm()710     public String getCatalogTerm() throws SQLException {
711         try {
712             String catalogTerm = jdbcDatabaseMetaData.getCatalogTerm();
713             if (catalogTerm == null) {
714                 catalogTerm = "";
715             }
716             return catalogTerm;
717         } catch (java.sql.SQLException jdbcSQLException) {
718             throw Tools.toUnoException(this, jdbcSQLException);
719         }
720     }
721 
722     @Override
getIdentifierQuoteString()723     public String getIdentifierQuoteString() throws SQLException {
724         try {
725             String identifierQuoteString = jdbcDatabaseMetaData.getIdentifierQuoteString();
726             if (identifierQuoteString == null) {
727                 identifierQuoteString = "";
728             }
729             return identifierQuoteString;
730         } catch (java.sql.SQLException jdbcSQLException) {
731             throw Tools.toUnoException(this, jdbcSQLException);
732         }
733     }
734 
735     @Override
getExtraNameCharacters()736     public String getExtraNameCharacters() throws SQLException {
737         try {
738             String extraNameCharacters = jdbcDatabaseMetaData.getExtraNameCharacters();
739             if (extraNameCharacters == null) {
740                 extraNameCharacters = "";
741             }
742             return extraNameCharacters;
743         } catch (java.sql.SQLException jdbcSQLException) {
744             throw Tools.toUnoException(this, jdbcSQLException);
745         }
746     }
747 
748     @Override
supportsDifferentTableCorrelationNames()749     public boolean supportsDifferentTableCorrelationNames() throws SQLException {
750         try {
751             return jdbcDatabaseMetaData.supportsDifferentTableCorrelationNames();
752         } catch (java.sql.SQLException jdbcSQLException) {
753             throw Tools.toUnoException(this, jdbcSQLException);
754         }
755     }
756 
757     @Override
isCatalogAtStart()758     public boolean isCatalogAtStart() throws SQLException {
759         try {
760             return jdbcDatabaseMetaData.isCatalogAtStart();
761         } catch (java.sql.SQLException jdbcSQLException) {
762             throw Tools.toUnoException(this, jdbcSQLException);
763         }
764     }
765 
766     @Override
dataDefinitionIgnoredInTransactions()767     public boolean dataDefinitionIgnoredInTransactions() throws SQLException {
768         try {
769             return jdbcDatabaseMetaData.dataDefinitionIgnoredInTransactions();
770         } catch (java.sql.SQLException jdbcSQLException) {
771             throw Tools.toUnoException(this, jdbcSQLException);
772         }
773     }
774 
775     @Override
dataDefinitionCausesTransactionCommit()776     public boolean dataDefinitionCausesTransactionCommit() throws SQLException {
777         try {
778             return jdbcDatabaseMetaData.dataDefinitionCausesTransactionCommit();
779         } catch (java.sql.SQLException jdbcSQLException) {
780             throw Tools.toUnoException(this, jdbcSQLException);
781         }
782     }
783 
784     @Override
supportsDataManipulationTransactionsOnly()785     public boolean supportsDataManipulationTransactionsOnly() throws SQLException {
786         try {
787             return jdbcDatabaseMetaData.supportsDataDefinitionAndDataManipulationTransactions();
788         } catch (java.sql.SQLException jdbcSQLException) {
789             throw Tools.toUnoException(this, jdbcSQLException);
790         }
791     }
792 
793     @Override
supportsDataDefinitionAndDataManipulationTransactions()794     public boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException {
795         try {
796             return jdbcDatabaseMetaData.supportsDataDefinitionAndDataManipulationTransactions();
797         } catch (java.sql.SQLException jdbcSQLException) {
798             throw Tools.toUnoException(this, jdbcSQLException);
799         }
800     }
801 
802     @Override
supportsPositionedDelete()803     public boolean supportsPositionedDelete() throws SQLException {
804         try {
805             return jdbcDatabaseMetaData.supportsPositionedDelete();
806         } catch (java.sql.SQLException jdbcSQLException) {
807             throw Tools.toUnoException(this, jdbcSQLException);
808         }
809     }
810 
811     @Override
supportsPositionedUpdate()812     public boolean supportsPositionedUpdate() throws SQLException {
813         try {
814             return jdbcDatabaseMetaData.supportsPositionedUpdate();
815         } catch (java.sql.SQLException jdbcSQLException) {
816             throw Tools.toUnoException(this, jdbcSQLException);
817         }
818     }
819 
820     @Override
supportsOpenStatementsAcrossRollback()821     public boolean supportsOpenStatementsAcrossRollback() throws SQLException {
822         try {
823             return jdbcDatabaseMetaData.supportsOpenStatementsAcrossRollback();
824         } catch (java.sql.SQLException jdbcSQLException) {
825             throw Tools.toUnoException(this, jdbcSQLException);
826         }
827     }
828 
829     @Override
supportsOpenStatementsAcrossCommit()830     public boolean supportsOpenStatementsAcrossCommit() throws SQLException {
831         try {
832             return jdbcDatabaseMetaData.supportsOpenStatementsAcrossCommit();
833         } catch (java.sql.SQLException jdbcSQLException) {
834             throw Tools.toUnoException(this, jdbcSQLException);
835         }
836     }
837 
838     @Override
supportsOpenCursorsAcrossCommit()839     public boolean supportsOpenCursorsAcrossCommit() throws SQLException {
840         try {
841             return jdbcDatabaseMetaData.supportsOpenCursorsAcrossCommit();
842         } catch (java.sql.SQLException jdbcSQLException) {
843             throw Tools.toUnoException(this, jdbcSQLException);
844         }
845     }
846 
847     @Override
supportsOpenCursorsAcrossRollback()848     public boolean supportsOpenCursorsAcrossRollback() throws SQLException {
849         try {
850             return jdbcDatabaseMetaData.supportsOpenCursorsAcrossRollback();
851         } catch (java.sql.SQLException jdbcSQLException) {
852             throw Tools.toUnoException(this, jdbcSQLException);
853         }
854     }
855 
856     @Override
supportsTransactionIsolationLevel(int level)857     public boolean supportsTransactionIsolationLevel(int level) throws SQLException {
858         try {
859             return jdbcDatabaseMetaData.supportsTransactionIsolationLevel(level);
860         } catch (java.sql.SQLException jdbcSQLException) {
861             throw Tools.toUnoException(this, jdbcSQLException);
862         }
863     }
864 
865     @Override
supportsSchemasInDataManipulation()866     public boolean supportsSchemasInDataManipulation() throws SQLException {
867         try {
868             return jdbcDatabaseMetaData.supportsSchemasInDataManipulation();
869         } catch (java.sql.SQLException jdbcSQLException) {
870             throw Tools.toUnoException(this, jdbcSQLException);
871         }
872     }
873 
874     @Override
supportsANSI92FullSQL()875     public boolean supportsANSI92FullSQL() throws SQLException {
876         try {
877             return jdbcDatabaseMetaData.supportsANSI92FullSQL();
878         } catch (java.sql.SQLException jdbcSQLException) {
879             throw Tools.toUnoException(this, jdbcSQLException);
880         }
881     }
882 
883     @Override
supportsANSI92EntryLevelSQL()884     public boolean supportsANSI92EntryLevelSQL() throws SQLException {
885         try {
886             return jdbcDatabaseMetaData.supportsANSI92EntryLevelSQL();
887         } catch (java.sql.SQLException jdbcSQLException) {
888             throw Tools.toUnoException(this, jdbcSQLException);
889         }
890     }
891 
892     @Override
supportsIntegrityEnhancementFacility()893     public boolean supportsIntegrityEnhancementFacility() throws SQLException {
894         try {
895             return jdbcDatabaseMetaData.supportsIntegrityEnhancementFacility();
896         } catch (java.sql.SQLException jdbcSQLException) {
897             throw Tools.toUnoException(this, jdbcSQLException);
898         }
899     }
900 
901     @Override
supportsSchemasInIndexDefinitions()902     public boolean supportsSchemasInIndexDefinitions() throws SQLException {
903         try {
904             return jdbcDatabaseMetaData.supportsSchemasInIndexDefinitions();
905         } catch (java.sql.SQLException jdbcSQLException) {
906             throw Tools.toUnoException(this, jdbcSQLException);
907         }
908     }
909 
910     @Override
supportsCatalogsInIndexDefinitions()911     public boolean supportsCatalogsInIndexDefinitions() throws SQLException {
912         try {
913             return jdbcDatabaseMetaData.supportsCatalogsInIndexDefinitions();
914         } catch (java.sql.SQLException jdbcSQLException) {
915             throw Tools.toUnoException(this, jdbcSQLException);
916         }
917     }
918 
919     @Override
supportsCatalogsInDataManipulation()920     public boolean supportsCatalogsInDataManipulation() throws SQLException {
921         try {
922             return jdbcDatabaseMetaData.supportsCatalogsInDataManipulation();
923         } catch (java.sql.SQLException jdbcSQLException) {
924             throw Tools.toUnoException(this, jdbcSQLException);
925         }
926     }
927 
928     @Override
supportsCatalogsInTableDefinitions()929     public boolean supportsCatalogsInTableDefinitions() throws SQLException {
930         try {
931             return jdbcDatabaseMetaData.supportsCatalogsInTableDefinitions();
932         } catch (java.sql.SQLException jdbcSQLException) {
933             throw Tools.toUnoException(this, jdbcSQLException);
934         }
935     }
936 
937     @Override
supportsSchemasInTableDefinitions()938     public boolean supportsSchemasInTableDefinitions() throws SQLException {
939         try {
940             return jdbcDatabaseMetaData.supportsSchemasInTableDefinitions();
941         } catch (java.sql.SQLException jdbcSQLException) {
942             throw Tools.toUnoException(this, jdbcSQLException);
943         }
944     }
945 
946     @Override
supportsOuterJoins()947     public boolean supportsOuterJoins() throws SQLException {
948         try {
949             return jdbcDatabaseMetaData.supportsOuterJoins();
950         } catch (java.sql.SQLException jdbcSQLException) {
951             throw Tools.toUnoException(this, jdbcSQLException);
952         }
953     }
954 
955     @Override
getTableTypes()956     public XResultSet getTableTypes() throws SQLException {
957         try {
958             return new JavaSQLResultSet(jdbcDatabaseMetaData.getTableTypes(), connection);
959         } catch (java.sql.SQLException jdbcSQLException) {
960             throw Tools.toUnoException(this, jdbcSQLException);
961         }
962     }
963 
964     @Override
getMaxStatements()965     public int getMaxStatements() throws SQLException {
966         try {
967             return jdbcDatabaseMetaData.getMaxStatements();
968         } catch (java.sql.SQLException jdbcSQLException) {
969             throw Tools.toUnoException(this, jdbcSQLException);
970         }
971     }
972 
973     @Override
getMaxProcedureNameLength()974     public int getMaxProcedureNameLength() throws SQLException {
975         try {
976             return jdbcDatabaseMetaData.getMaxProcedureNameLength();
977         } catch (java.sql.SQLException jdbcSQLException) {
978             throw Tools.toUnoException(this, jdbcSQLException);
979         }
980     }
981 
982     @Override
getMaxSchemaNameLength()983     public int getMaxSchemaNameLength() throws SQLException {
984         try {
985             return jdbcDatabaseMetaData.getMaxSchemaNameLength();
986         } catch (java.sql.SQLException jdbcSQLException) {
987             throw Tools.toUnoException(this, jdbcSQLException);
988         }
989     }
990 
991     @Override
supportsTransactions()992     public boolean supportsTransactions() throws SQLException {
993         try {
994             return jdbcDatabaseMetaData.supportsTransactions();
995         } catch (java.sql.SQLException jdbcSQLException) {
996             throw Tools.toUnoException(this, jdbcSQLException);
997         }
998     }
999 
1000     @Override
allProceduresAreCallable()1001     public boolean allProceduresAreCallable() throws SQLException {
1002         try {
1003             return jdbcDatabaseMetaData.allProceduresAreCallable();
1004         } catch (java.sql.SQLException jdbcSQLException) {
1005             throw Tools.toUnoException(this, jdbcSQLException);
1006         }
1007     }
1008 
1009     @Override
supportsStoredProcedures()1010     public boolean supportsStoredProcedures() throws SQLException {
1011         try {
1012             return jdbcDatabaseMetaData.supportsStoredProcedures();
1013         } catch (java.sql.SQLException jdbcSQLException) {
1014             throw Tools.toUnoException(this, jdbcSQLException);
1015         }
1016     }
1017 
1018     @Override
supportsSelectForUpdate()1019     public boolean supportsSelectForUpdate() throws SQLException {
1020         try {
1021             return jdbcDatabaseMetaData.supportsSelectForUpdate();
1022         } catch (java.sql.SQLException jdbcSQLException) {
1023             throw Tools.toUnoException(this, jdbcSQLException);
1024         }
1025     }
1026 
1027     @Override
allTablesAreSelectable()1028     public boolean allTablesAreSelectable() throws SQLException {
1029         try {
1030             return jdbcDatabaseMetaData.allTablesAreSelectable();
1031         } catch (java.sql.SQLException jdbcSQLException) {
1032             throw Tools.toUnoException(this, jdbcSQLException);
1033         }
1034     }
1035 
1036     @Override
isReadOnly()1037     public boolean isReadOnly() throws SQLException {
1038         try {
1039             return jdbcDatabaseMetaData.isReadOnly();
1040         } catch (java.sql.SQLException jdbcSQLException) {
1041             throw Tools.toUnoException(this, jdbcSQLException);
1042         }
1043     }
1044 
1045     @Override
usesLocalFiles()1046     public boolean usesLocalFiles() throws SQLException {
1047         try {
1048             return jdbcDatabaseMetaData.usesLocalFiles();
1049         } catch (java.sql.SQLException jdbcSQLException) {
1050             throw Tools.toUnoException(this, jdbcSQLException);
1051         }
1052     }
1053 
1054     @Override
usesLocalFilePerTable()1055     public boolean usesLocalFilePerTable() throws SQLException {
1056         try {
1057             return jdbcDatabaseMetaData.usesLocalFilePerTable();
1058         } catch (java.sql.SQLException jdbcSQLException) {
1059             throw Tools.toUnoException(this, jdbcSQLException);
1060         }
1061     }
1062 
1063     @Override
supportsTypeConversion()1064     public boolean supportsTypeConversion() throws SQLException {
1065         // This was calling JDBC's supportsTypeConversion(), which doesn't exist
1066         try {
1067             return jdbcDatabaseMetaData.supportsConvert();
1068         } catch (java.sql.SQLException jdbcSQLException) {
1069             throw Tools.toUnoException(this, jdbcSQLException);
1070         }
1071     }
1072 
1073     @Override
nullPlusNonNullIsNull()1074     public boolean nullPlusNonNullIsNull() throws SQLException {
1075         try {
1076             return jdbcDatabaseMetaData.nullPlusNonNullIsNull();
1077         } catch (java.sql.SQLException jdbcSQLException) {
1078             throw Tools.toUnoException(this, jdbcSQLException);
1079         }
1080     }
1081 
1082     @Override
supportsColumnAliasing()1083     public boolean supportsColumnAliasing() throws SQLException {
1084         try {
1085             return jdbcDatabaseMetaData.supportsColumnAliasing();
1086         } catch (java.sql.SQLException jdbcSQLException) {
1087             throw Tools.toUnoException(this, jdbcSQLException);
1088         }
1089     }
1090 
1091     @Override
supportsTableCorrelationNames()1092     public boolean supportsTableCorrelationNames() throws SQLException {
1093         try {
1094             return jdbcDatabaseMetaData.supportsTableCorrelationNames();
1095         } catch (java.sql.SQLException jdbcSQLException) {
1096             throw Tools.toUnoException(this, jdbcSQLException);
1097         }
1098     }
1099 
1100     @Override
supportsConvert(int fromType, int toType)1101     public boolean supportsConvert(int fromType, int toType) throws SQLException {
1102         try {
1103             return jdbcDatabaseMetaData.supportsConvert(fromType, toType);
1104         } catch (java.sql.SQLException jdbcSQLException) {
1105             throw Tools.toUnoException(this, jdbcSQLException);
1106         }
1107     }
1108 
1109     @Override
supportsExpressionsInOrderBy()1110     public boolean supportsExpressionsInOrderBy() throws SQLException {
1111         try {
1112             return jdbcDatabaseMetaData.supportsExpressionsInOrderBy();
1113         } catch (java.sql.SQLException jdbcSQLException) {
1114             throw Tools.toUnoException(this, jdbcSQLException);
1115         }
1116     }
1117 
1118     @Override
supportsGroupBy()1119     public boolean supportsGroupBy() throws SQLException {
1120         try {
1121             return jdbcDatabaseMetaData.supportsGroupBy();
1122         } catch (java.sql.SQLException jdbcSQLException) {
1123             throw Tools.toUnoException(this, jdbcSQLException);
1124         }
1125     }
1126 
1127     @Override
supportsGroupByBeyondSelect()1128     public boolean supportsGroupByBeyondSelect() throws SQLException {
1129         try {
1130             return jdbcDatabaseMetaData.supportsGroupByBeyondSelect();
1131         } catch (java.sql.SQLException jdbcSQLException) {
1132             throw Tools.toUnoException(this, jdbcSQLException);
1133         }
1134     }
1135 
1136     @Override
supportsGroupByUnrelated()1137     public boolean supportsGroupByUnrelated() throws SQLException {
1138         try {
1139             return jdbcDatabaseMetaData.supportsGroupByUnrelated();
1140         } catch (java.sql.SQLException jdbcSQLException) {
1141             throw Tools.toUnoException(this, jdbcSQLException);
1142         }
1143     }
1144 
1145     @Override
supportsMultipleTransactions()1146     public boolean supportsMultipleTransactions() throws SQLException {
1147         try {
1148             return jdbcDatabaseMetaData.supportsMultipleTransactions();
1149         } catch (java.sql.SQLException jdbcSQLException) {
1150             throw Tools.toUnoException(this, jdbcSQLException);
1151         }
1152     }
1153 
1154     @Override
supportsMultipleResultSets()1155     public boolean supportsMultipleResultSets() throws SQLException {
1156         try {
1157             return jdbcDatabaseMetaData.supportsMultipleResultSets();
1158         } catch (java.sql.SQLException jdbcSQLException) {
1159             throw Tools.toUnoException(this, jdbcSQLException);
1160         }
1161     }
1162 
1163     @Override
supportsLikeEscapeClause()1164     public boolean supportsLikeEscapeClause() throws SQLException {
1165         try {
1166             return jdbcDatabaseMetaData.supportsLikeEscapeClause();
1167         } catch (java.sql.SQLException jdbcSQLException) {
1168             throw Tools.toUnoException(this, jdbcSQLException);
1169         }
1170     }
1171 
1172     @Override
supportsOrderByUnrelated()1173     public boolean supportsOrderByUnrelated() throws SQLException {
1174         try {
1175             return jdbcDatabaseMetaData.supportsOrderByUnrelated();
1176         } catch (java.sql.SQLException jdbcSQLException) {
1177             throw Tools.toUnoException(this, jdbcSQLException);
1178         }
1179     }
1180 
1181     @Override
supportsUnion()1182     public boolean supportsUnion() throws SQLException {
1183         try {
1184             return jdbcDatabaseMetaData.supportsUnion();
1185         } catch (java.sql.SQLException jdbcSQLException) {
1186             throw Tools.toUnoException(this, jdbcSQLException);
1187         }
1188     }
1189 
1190     @Override
supportsUnionAll()1191     public boolean supportsUnionAll() throws SQLException {
1192         try {
1193             return jdbcDatabaseMetaData.supportsUnionAll();
1194         } catch (java.sql.SQLException jdbcSQLException) {
1195             throw Tools.toUnoException(this, jdbcSQLException);
1196         }
1197     }
1198 
1199     @Override
supportsMixedCaseIdentifiers()1200     public boolean supportsMixedCaseIdentifiers() throws SQLException {
1201         try {
1202             return jdbcDatabaseMetaData.supportsMixedCaseIdentifiers();
1203         } catch (java.sql.SQLException jdbcSQLException) {
1204             throw Tools.toUnoException(this, jdbcSQLException);
1205         }
1206     }
1207 
1208     @Override
supportsMixedCaseQuotedIdentifiers()1209     public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException {
1210         try {
1211             return jdbcDatabaseMetaData.supportsMixedCaseQuotedIdentifiers();
1212         } catch (java.sql.SQLException jdbcSQLException) {
1213             throw Tools.toUnoException(this, jdbcSQLException);
1214         }
1215     }
1216 
1217     @Override
nullsAreSortedAtEnd()1218     public boolean nullsAreSortedAtEnd() throws SQLException {
1219         try {
1220             return jdbcDatabaseMetaData.nullsAreSortedAtEnd();
1221         } catch (java.sql.SQLException jdbcSQLException) {
1222             throw Tools.toUnoException(this, jdbcSQLException);
1223         }
1224     }
1225 
1226     @Override
nullsAreSortedAtStart()1227     public boolean nullsAreSortedAtStart() throws SQLException {
1228         try {
1229             return jdbcDatabaseMetaData.nullsAreSortedAtStart();
1230         } catch (java.sql.SQLException jdbcSQLException) {
1231             throw Tools.toUnoException(this, jdbcSQLException);
1232         }
1233     }
1234 
1235     @Override
nullsAreSortedHigh()1236     public boolean nullsAreSortedHigh() throws SQLException {
1237         try {
1238             return jdbcDatabaseMetaData.nullsAreSortedHigh();
1239         } catch (java.sql.SQLException jdbcSQLException) {
1240             throw Tools.toUnoException(this, jdbcSQLException);
1241         }
1242     }
1243 
1244     @Override
nullsAreSortedLow()1245     public boolean nullsAreSortedLow() throws SQLException {
1246         try {
1247             return jdbcDatabaseMetaData.nullsAreSortedLow();
1248         } catch (java.sql.SQLException jdbcSQLException) {
1249             throw Tools.toUnoException(this, jdbcSQLException);
1250         }
1251     }
1252 
1253     @Override
supportsCatalogsInProcedureCalls()1254     public boolean supportsCatalogsInProcedureCalls() throws SQLException {
1255         try {
1256             return jdbcDatabaseMetaData.supportsCatalogsInProcedureCalls();
1257         } catch (java.sql.SQLException jdbcSQLException) {
1258             throw Tools.toUnoException(this, jdbcSQLException);
1259         }
1260     }
1261 
1262     @Override
supportsSchemasInProcedureCalls()1263     public boolean supportsSchemasInProcedureCalls() throws SQLException {
1264         try {
1265             return jdbcDatabaseMetaData.supportsSchemasInProcedureCalls();
1266         } catch (java.sql.SQLException jdbcSQLException) {
1267             throw Tools.toUnoException(this, jdbcSQLException);
1268         }
1269     }
1270 
1271     @Override
supportsCatalogsInPrivilegeDefinitions()1272     public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException {
1273         try {
1274             return jdbcDatabaseMetaData.supportsCatalogsInPrivilegeDefinitions();
1275         } catch (java.sql.SQLException jdbcSQLException) {
1276             throw Tools.toUnoException(this, jdbcSQLException);
1277         }
1278     }
1279 
1280     @Override
supportsSchemasInPrivilegeDefinitions()1281     public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException {
1282         try {
1283             return jdbcDatabaseMetaData.supportsSchemasInPrivilegeDefinitions();
1284         } catch (java.sql.SQLException jdbcSQLException) {
1285             throw Tools.toUnoException(this, jdbcSQLException);
1286         }
1287     }
1288 
1289     @Override
supportsCorrelatedSubqueries()1290     public boolean supportsCorrelatedSubqueries() throws SQLException {
1291         try {
1292             return jdbcDatabaseMetaData.supportsCorrelatedSubqueries();
1293         } catch (java.sql.SQLException jdbcSQLException) {
1294             throw Tools.toUnoException(this, jdbcSQLException);
1295         }
1296     }
1297 
1298     @Override
supportsSubqueriesInComparisons()1299     public boolean supportsSubqueriesInComparisons() throws SQLException {
1300         try {
1301             return jdbcDatabaseMetaData.supportsSubqueriesInComparisons();
1302         } catch (java.sql.SQLException jdbcSQLException) {
1303             throw Tools.toUnoException(this, jdbcSQLException);
1304         }
1305     }
1306 
1307     @Override
supportsSubqueriesInExists()1308     public boolean supportsSubqueriesInExists() throws SQLException {
1309         try {
1310             return jdbcDatabaseMetaData.supportsSubqueriesInExists();
1311         } catch (java.sql.SQLException jdbcSQLException) {
1312             throw Tools.toUnoException(this, jdbcSQLException);
1313         }
1314     }
1315 
1316     @Override
supportsSubqueriesInIns()1317     public boolean supportsSubqueriesInIns() throws SQLException {
1318         try {
1319             return jdbcDatabaseMetaData.supportsSubqueriesInIns();
1320         } catch (java.sql.SQLException jdbcSQLException) {
1321             throw Tools.toUnoException(this, jdbcSQLException);
1322         }
1323     }
1324 
1325     @Override
supportsSubqueriesInQuantifieds()1326     public boolean supportsSubqueriesInQuantifieds() throws SQLException {
1327         try {
1328             return jdbcDatabaseMetaData.supportsSubqueriesInQuantifieds();
1329         } catch (java.sql.SQLException jdbcSQLException) {
1330             throw Tools.toUnoException(this, jdbcSQLException);
1331         }
1332     }
1333 
1334     @Override
supportsANSI92IntermediateSQL()1335     public boolean supportsANSI92IntermediateSQL() throws SQLException {
1336         try {
1337             return jdbcDatabaseMetaData.supportsANSI92IntermediateSQL();
1338         } catch (java.sql.SQLException jdbcSQLException) {
1339             throw Tools.toUnoException(this, jdbcSQLException);
1340         }
1341     }
1342 
1343     @Override
getURL()1344     public String getURL() throws SQLException {
1345         String url = connection.getURL();
1346         if (url == null) {
1347             try {
1348                 url = jdbcDatabaseMetaData.getURL();
1349             } catch (java.sql.SQLException jdbcSQLException) {
1350                 throw Tools.toUnoException(this, jdbcSQLException);
1351             }
1352         }
1353         return url;
1354     }
1355 
1356     @Override
getUserName()1357     public String getUserName() throws SQLException {
1358         try {
1359             String username = jdbcDatabaseMetaData.getUserName();
1360             if (username == null) {
1361                 username = "";
1362             }
1363             return username;
1364         } catch (java.sql.SQLException jdbcSQLException) {
1365             throw Tools.toUnoException(this, jdbcSQLException);
1366         }
1367     }
1368 
1369     @Override
getDriverName()1370     public String getDriverName() throws SQLException {
1371         try {
1372             String driverName = jdbcDatabaseMetaData.getDriverName();
1373             if (driverName == null) {
1374                 driverName = "";
1375             }
1376             return driverName;
1377         } catch (java.sql.SQLException jdbcSQLException) {
1378             throw Tools.toUnoException(this, jdbcSQLException);
1379         }
1380     }
1381 
1382     @Override
getDriverVersion()1383     public String getDriverVersion() throws SQLException {
1384         try {
1385             String driverVersion = jdbcDatabaseMetaData.getDriverVersion();
1386             if (driverVersion == null) {
1387                 driverVersion = "";
1388             }
1389             return driverVersion;
1390         } catch (java.sql.SQLException jdbcSQLException) {
1391             throw Tools.toUnoException(this, jdbcSQLException);
1392         }
1393     }
1394 
1395     @Override
getDatabaseProductVersion()1396     public String getDatabaseProductVersion() throws SQLException {
1397         try {
1398             String databaseProductVersion = jdbcDatabaseMetaData.getDatabaseProductVersion();
1399             if (databaseProductVersion == null) {
1400                 databaseProductVersion = "";
1401             }
1402             return databaseProductVersion;
1403         } catch (java.sql.SQLException jdbcSQLException) {
1404             throw Tools.toUnoException(this, jdbcSQLException);
1405         }
1406     }
1407 
1408     @Override
getDatabaseProductName()1409     public String getDatabaseProductName() throws SQLException {
1410         try {
1411             String databaseProductName = jdbcDatabaseMetaData.getDatabaseProductName();
1412             if (databaseProductName == null) {
1413                 databaseProductName = "";
1414             }
1415             return databaseProductName;
1416         } catch (java.sql.SQLException jdbcSQLException) {
1417             throw Tools.toUnoException(this, jdbcSQLException);
1418         }
1419     }
1420 
1421     @Override
getProcedureTerm()1422     public String getProcedureTerm() throws SQLException {
1423         try {
1424             String procedureTerm = jdbcDatabaseMetaData.getProcedureTerm();
1425             if (procedureTerm == null) {
1426                 procedureTerm = "";
1427             }
1428             return procedureTerm;
1429         } catch (java.sql.SQLException jdbcSQLException) {
1430             throw Tools.toUnoException(this, jdbcSQLException);
1431         }
1432     }
1433 
1434     @Override
getSchemaTerm()1435     public String getSchemaTerm() throws SQLException {
1436         try {
1437             String schemaTerm = jdbcDatabaseMetaData.getSchemaTerm();
1438             if (schemaTerm == null) {
1439                 schemaTerm = "";
1440             }
1441             return schemaTerm;
1442         } catch (java.sql.SQLException jdbcSQLException) {
1443             throw Tools.toUnoException(this, jdbcSQLException);
1444         }
1445     }
1446 
1447     @Override
getDriverMajorVersion()1448     public int getDriverMajorVersion() {
1449         return jdbcDatabaseMetaData.getDriverMajorVersion();
1450     }
1451 
1452     @Override
getDriverMinorVersion()1453     public int getDriverMinorVersion() {
1454         return jdbcDatabaseMetaData.getDriverMinorVersion();
1455     }
1456 
1457     @Override
getDefaultTransactionIsolation()1458     public int getDefaultTransactionIsolation() throws SQLException {
1459         try {
1460             return jdbcDatabaseMetaData.getDefaultTransactionIsolation();
1461         } catch (java.sql.SQLException jdbcSQLException) {
1462             throw Tools.toUnoException(this, jdbcSQLException);
1463         }
1464     }
1465 
1466     @Override
getSQLKeywords()1467     public String getSQLKeywords() throws SQLException {
1468         try {
1469             String sqlKeywords = jdbcDatabaseMetaData.getSQLKeywords();
1470             if (sqlKeywords == null) {
1471                 sqlKeywords = "";
1472             }
1473             return sqlKeywords;
1474         } catch (java.sql.SQLException jdbcSQLException) {
1475             throw Tools.toUnoException(this, jdbcSQLException);
1476         }
1477     }
1478 
1479     @Override
getSearchStringEscape()1480     public String getSearchStringEscape() throws SQLException {
1481         try {
1482             String searchStringEscape = jdbcDatabaseMetaData.getSearchStringEscape();
1483             if (searchStringEscape == null) {
1484                 searchStringEscape = "";
1485             }
1486             return searchStringEscape;
1487         } catch (java.sql.SQLException jdbcSQLException) {
1488             throw Tools.toUnoException(this, jdbcSQLException);
1489         }
1490     }
1491 
1492     @Override
getStringFunctions()1493     public String getStringFunctions() throws SQLException {
1494         try {
1495             String stringFunctions = jdbcDatabaseMetaData.getStringFunctions();
1496             if (stringFunctions == null) {
1497                 stringFunctions = "";
1498             }
1499             return stringFunctions;
1500         } catch (java.sql.SQLException jdbcSQLException) {
1501             throw Tools.toUnoException(this, jdbcSQLException);
1502         }
1503     }
1504 
1505     @Override
getTimeDateFunctions()1506     public String getTimeDateFunctions() throws SQLException {
1507         try {
1508             String timeDateFunctions = jdbcDatabaseMetaData.getTimeDateFunctions();
1509             if (timeDateFunctions == null) {
1510                 timeDateFunctions = "";
1511             }
1512             return timeDateFunctions;
1513         } catch (java.sql.SQLException jdbcSQLException) {
1514             throw Tools.toUnoException(this, jdbcSQLException);
1515         }
1516     }
1517 
1518     @Override
getSystemFunctions()1519     public String getSystemFunctions() throws SQLException {
1520         try {
1521             String systemFunctions = jdbcDatabaseMetaData.getSystemFunctions();
1522             if (systemFunctions == null) {
1523                 systemFunctions = "";
1524             }
1525             return systemFunctions;
1526         } catch (java.sql.SQLException jdbcSQLException) {
1527             throw Tools.toUnoException(this, jdbcSQLException);
1528         }
1529     }
1530 
1531     @Override
getNumericFunctions()1532     public String getNumericFunctions() throws SQLException {
1533         try {
1534             String numericFunctions = jdbcDatabaseMetaData.getNumericFunctions();
1535             if (numericFunctions == null) {
1536                 numericFunctions = "";
1537             }
1538             return numericFunctions;
1539         } catch (java.sql.SQLException jdbcSQLException) {
1540             throw Tools.toUnoException(this, jdbcSQLException);
1541         }
1542     }
1543 
1544     @Override
supportsExtendedSQLGrammar()1545     public boolean supportsExtendedSQLGrammar() throws SQLException {
1546         try {
1547             return jdbcDatabaseMetaData.supportsExtendedSQLGrammar();
1548         } catch (java.sql.SQLException jdbcSQLException) {
1549             throw Tools.toUnoException(this, jdbcSQLException);
1550         }
1551     }
1552 
1553     @Override
supportsCoreSQLGrammar()1554     public boolean supportsCoreSQLGrammar() throws SQLException {
1555         try {
1556             return jdbcDatabaseMetaData.supportsCoreSQLGrammar();
1557         } catch (java.sql.SQLException jdbcSQLException) {
1558             throw Tools.toUnoException(this, jdbcSQLException);
1559         }
1560     }
1561 
1562     @Override
supportsMinimumSQLGrammar()1563     public boolean supportsMinimumSQLGrammar() {
1564         try {
1565             return jdbcDatabaseMetaData.supportsMinimumSQLGrammar();
1566         } catch (java.sql.SQLException jdbcSQLException) {
1567             // FIXME: SDBC bug. Must be able to throw exception.
1568             //throw Tools.toUnoException(this, jdbcSQLException);
1569             return false;
1570         }
1571     }
1572 
1573     @Override
supportsFullOuterJoins()1574     public boolean supportsFullOuterJoins() throws SQLException {
1575         try {
1576             return jdbcDatabaseMetaData.supportsFullOuterJoins();
1577         } catch (java.sql.SQLException jdbcSQLException) {
1578             throw Tools.toUnoException(this, jdbcSQLException);
1579         }
1580     }
1581 
1582     @Override
supportsLimitedOuterJoins()1583     public boolean supportsLimitedOuterJoins() throws SQLException {
1584         try {
1585             return jdbcDatabaseMetaData.supportsLimitedOuterJoins();
1586         } catch (java.sql.SQLException jdbcSQLException) {
1587             throw Tools.toUnoException(this, jdbcSQLException);
1588         }
1589     }
1590 
1591     @Override
getMaxColumnsInGroupBy()1592     public int getMaxColumnsInGroupBy() throws SQLException {
1593         try {
1594             return jdbcDatabaseMetaData.getMaxColumnsInGroupBy();
1595         } catch (java.sql.SQLException jdbcSQLException) {
1596             throw Tools.toUnoException(this, jdbcSQLException);
1597         }
1598     }
1599 
1600     @Override
getMaxColumnsInOrderBy()1601     public int getMaxColumnsInOrderBy() throws SQLException {
1602         try {
1603             return jdbcDatabaseMetaData.getMaxColumnsInOrderBy();
1604         } catch (java.sql.SQLException jdbcSQLException) {
1605             throw Tools.toUnoException(this, jdbcSQLException);
1606         }
1607     }
1608 
1609     @Override
getMaxColumnsInSelect()1610     public int getMaxColumnsInSelect() throws SQLException {
1611         try {
1612             return jdbcDatabaseMetaData.getMaxColumnsInSelect();
1613         } catch (java.sql.SQLException jdbcSQLException) {
1614             throw Tools.toUnoException(this, jdbcSQLException);
1615         }
1616     }
1617 
1618     @Override
getMaxUserNameLength()1619     public int getMaxUserNameLength() throws SQLException {
1620         try {
1621             return jdbcDatabaseMetaData.getMaxUserNameLength();
1622         } catch (java.sql.SQLException jdbcSQLException) {
1623             throw Tools.toUnoException(this, jdbcSQLException);
1624         }
1625     }
1626 
1627     @Override
supportsResultSetType(int type)1628     public boolean supportsResultSetType(int type) throws SQLException {
1629         try {
1630             return jdbcDatabaseMetaData.supportsResultSetType(type);
1631         } catch (java.sql.SQLException jdbcSQLException) {
1632             throw Tools.toUnoException(this, jdbcSQLException);
1633         }
1634     }
1635 
1636     @Override
supportsResultSetConcurrency(int setType, int concurrency)1637     public boolean supportsResultSetConcurrency(int setType, int concurrency) throws SQLException {
1638         try {
1639             return jdbcDatabaseMetaData.supportsResultSetConcurrency(setType, concurrency);
1640         } catch (java.sql.SQLException jdbcSQLException) {
1641             throw Tools.toUnoException(this, jdbcSQLException);
1642         }
1643     }
1644 
1645     @Override
ownUpdatesAreVisible(int setType)1646     public boolean ownUpdatesAreVisible(int setType) throws SQLException {
1647         try {
1648             return jdbcDatabaseMetaData.ownUpdatesAreVisible(setType);
1649         } catch (java.sql.SQLException jdbcSQLException) {
1650             throw Tools.toUnoException(this, jdbcSQLException);
1651         }
1652     }
1653 
1654     @Override
ownDeletesAreVisible(int setType)1655     public boolean ownDeletesAreVisible(int setType) throws SQLException {
1656         try {
1657             return jdbcDatabaseMetaData.ownDeletesAreVisible(setType);
1658         } catch (java.sql.SQLException jdbcSQLException) {
1659             throw Tools.toUnoException(this, jdbcSQLException);
1660         }
1661     }
1662 
1663     @Override
ownInsertsAreVisible(int setType)1664     public boolean ownInsertsAreVisible(int setType) throws SQLException {
1665         try {
1666             return jdbcDatabaseMetaData.ownInsertsAreVisible(setType);
1667         } catch (java.sql.SQLException jdbcSQLException) {
1668             throw Tools.toUnoException(this, jdbcSQLException);
1669         }
1670     }
1671 
1672     @Override
othersUpdatesAreVisible(int setType)1673     public boolean othersUpdatesAreVisible(int setType) throws SQLException {
1674         try {
1675             return jdbcDatabaseMetaData.othersUpdatesAreVisible(setType);
1676         } catch (java.sql.SQLException jdbcSQLException) {
1677             throw Tools.toUnoException(this, jdbcSQLException);
1678         }
1679     }
1680 
1681     @Override
othersDeletesAreVisible(int setType)1682     public boolean othersDeletesAreVisible(int setType) throws SQLException {
1683         try {
1684             return jdbcDatabaseMetaData.othersDeletesAreVisible(setType);
1685         } catch (java.sql.SQLException jdbcSQLException) {
1686             throw Tools.toUnoException(this, jdbcSQLException);
1687         }
1688     }
1689 
1690     @Override
othersInsertsAreVisible(int setType)1691     public boolean othersInsertsAreVisible(int setType) throws SQLException {
1692         try {
1693             return jdbcDatabaseMetaData.othersInsertsAreVisible(setType);
1694         } catch (java.sql.SQLException jdbcSQLException) {
1695             throw Tools.toUnoException(this, jdbcSQLException);
1696         }
1697     }
1698 
1699     @Override
updatesAreDetected(int setType)1700     public boolean updatesAreDetected(int setType) throws SQLException {
1701         try {
1702             return jdbcDatabaseMetaData.updatesAreDetected(setType);
1703         } catch (java.sql.SQLException jdbcSQLException) {
1704             throw Tools.toUnoException(this, jdbcSQLException);
1705         }
1706     }
1707 
1708     @Override
deletesAreDetected(int setType)1709     public boolean deletesAreDetected(int setType) throws SQLException {
1710         try {
1711             return jdbcDatabaseMetaData.deletesAreDetected(setType);
1712         } catch (java.sql.SQLException jdbcSQLException) {
1713             throw Tools.toUnoException(this, jdbcSQLException);
1714         }
1715     }
1716 
1717     @Override
insertsAreDetected(int setType)1718     public boolean insertsAreDetected(int setType) throws SQLException {
1719         try {
1720             return jdbcDatabaseMetaData.insertsAreDetected(setType);
1721         } catch (java.sql.SQLException jdbcSQLException) {
1722             throw Tools.toUnoException(this, jdbcSQLException);
1723         }
1724     }
1725 
1726     @Override
supportsBatchUpdates()1727     public boolean supportsBatchUpdates() throws SQLException {
1728         try {
1729             return jdbcDatabaseMetaData.supportsBatchUpdates();
1730         } catch (java.sql.SQLException jdbcSQLException) {
1731             throw Tools.toUnoException(this, jdbcSQLException);
1732         }
1733     }
1734 
1735     @Override
getUDTs(Object catalog, String schemaPattern, String typeNamePattern, int[] types)1736     public XResultSet getUDTs(Object catalog, String schemaPattern,
1737             String typeNamePattern, int[] types) throws SQLException {
1738         try {
1739             String jdbcCatalog = null;
1740             if (AnyConverter.isString(catalog)) {
1741                 jdbcCatalog = AnyConverter.toString(catalog);
1742             }
1743             if (schemaPattern.equals("%")) {
1744                 schemaPattern = null;
1745             }
1746             return wrapResultSet(jdbcDatabaseMetaData.getUDTs(jdbcCatalog, schemaPattern, typeNamePattern, types));
1747         } catch (java.sql.SQLException | IllegalArgumentException exception) {
1748             throw Tools.toUnoException(this, exception);
1749         }
1750     }
1751 }
1752