001: package net.sourceforge.squirrel_sql.fw.sql;
002:
003: /*
004: * Copyright (C) 2007 Rob Manning
005: * manningr@users.sourceforge.net
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: import java.sql.DatabaseMetaData;
022: import java.sql.SQLException;
023: import java.util.List;
024:
025: import net.sourceforge.squirrel_sql.fw.datasetviewer.DataSetException;
026: import net.sourceforge.squirrel_sql.fw.datasetviewer.IDataSet;
027: import net.sourceforge.squirrel_sql.fw.datasetviewer.ResultSetDataSet;
028: import net.sourceforge.squirrel_sql.fw.sql.dbobj.BestRowIdentifier;
029:
030: /**
031: * An interface that describes public API of SQLDatabaseMetaData.
032: *
033: * @author manningr
034: */
035: public interface ISQLDatabaseMetaData {
036:
037: /**
038: * Return the name of the current user. Cached on first call.
039: *
040: * @return the current user name.
041: */
042: String getUserName() throws SQLException;
043:
044: /**
045: * Return the database product name for this connection. Cached on first
046: * call.
047: *
048: * @return the database product name for this connection.
049: *
050: * @throws SQLException Thrown if an SQL error occurs.
051: */
052: String getDatabaseProductName() throws SQLException;
053:
054: /**
055: * Return the database product version for this connection. Cached on first
056: * call.
057: *
058: * @return database product version
059: *
060: * @throws SQLException Thrown if an SQL error occurs.
061: */
062: String getDatabaseProductVersion() throws SQLException;
063:
064: /**
065: * Return the database major version for this connection. Cached on first
066: * call.
067: *
068: * @return database major version
069: *
070: * @throws SQLException Thrown if an SQL error occurs.
071: */
072: int getDatabaseMajorVersion() throws SQLException;
073:
074: /**
075: * Return the JDBC driver name for this connection. Cached on first call.
076: *
077: * @return the JDBC driver name for this connection.
078: *
079: * @throws SQLException Thrown if an SQL error occurs.
080: */
081: String getDriverName() throws SQLException;
082:
083: /**
084: * Return the JDBC version of this driver. Cached on first call.
085: *
086: * @return the JDBC version of the driver.
087: *
088: * @throws SQLException Thrown if an SQL error occurs.
089: */
090: int getJDBCVersion() throws SQLException;
091:
092: /**
093: * Return the string used to quote characters in this DBMS. Cached on first
094: * call.
095: *
096: * @return quote string.
097: *
098: * @throws SQLException Thrown if an SQL error occurs.
099: */
100: String getIdentifierQuoteString() throws SQLException;
101:
102: /**
103: * Returns the "cascade" constraints clause which is supported by some
104: * databases when performing a delete to removed child records in dependent
105: * tables which would otherwise be orphaned and make the delete fail.
106: *
107: * @return the "cascade" clause.
108: *
109: * @throws SQLException
110: */
111: String getCascadeClause() throws SQLException;
112:
113: /**
114: * Return a string array containing the names of all the schemas in the
115: * database. Cached on first call.
116: *
117: * @return String[] of the names of the schemas in the database.
118: *
119: * @throws SQLException Thrown if an SQL error occurs.
120: */
121: String[] getSchemas() throws SQLException;
122:
123: /**
124: * Retrieves whether this database supports schemas at all.
125: *
126: * @return <TT>true</TT> if database supports schemas.
127: *
128: * @throws SQLException Thrown if an SQL error occurs.
129: */
130: boolean supportsSchemas() throws SQLException;
131:
132: /**
133: * Retrieves whether a schema name can be used in a data manipulation
134: * statement. Cached on first call.
135: *
136: * @return <TT>true</TT> if a schema name can be used in a data
137: * manipulation statement.
138: *
139: * @throws SQLException Thrown if an SQL error occurs.
140: */
141: boolean supportsSchemasInDataManipulation() throws SQLException;
142:
143: /**
144: * Retrieves whether a schema name can be used in a table definition
145: * statement. Cached on first call.
146: *
147: * @return <TT>true</TT> if a schema name can be used in a table
148: * definition statement.
149: *
150: * @throws SQLException Thrown if an SQL error occurs.
151: */
152: boolean supportsSchemasInTableDefinitions() throws SQLException;
153:
154: /**
155: * Retrieves whether this DBMS supports stored procedures. Cached on first
156: * call.
157: *
158: * @return <TT>true</TT> if DBMS supports stored procedures.
159: *
160: * @throws SQLException Thrown if an SQL error occurs.
161: */
162: boolean supportsStoredProcedures() throws SQLException;
163:
164: /**
165: * Retrieves whether this DBMS supports save points. Cached on first
166: * call.
167: *
168: * @return <TT>true</TT> if DBMS supports save points.
169: *
170: * @throws SQLException if an SQL error occurs.
171: */
172: boolean supportsSavepoints() throws SQLException;
173:
174: /**
175: * Retrieves whether this DBMS supports result sets of the specified type.
176: * Cached on first call.
177: *
178: * @param type the type of the ResultSet. There are constants defined in
179: * the ResultSet class that define the different types.
180: *
181: * @return <TT>true</TT> if DBMS supports this type of ResultSet.
182: *
183: * @throws SQLException if an SQL error occurs.
184: */
185: boolean supportsResultSetType(int type) throws SQLException;
186:
187: /**
188: * Return a string array containing the names of all the catalogs in the
189: * database. Cached on first call.
190: *
191: * @return String[] of the names of the catalogs in the database.
192: *
193: * @throws SQLException Thrown if an SQL error occurs.
194: */
195: String[] getCatalogs() throws SQLException;
196:
197: /**
198: * Retrieves the URL for this DBMS.
199: *
200: * @return the URL for this DBMS or null if it cannot be generated
201: *
202: * @throws SQLException if a database access error occurs
203: */
204: String getURL() throws SQLException;
205:
206: /**
207: * Retrieves the database vendor's preferred term for "catalog".
208: *
209: * @return the vendor term for "catalog"
210: *
211: * @throws SQLException if a database access error occurs
212: */
213: String getCatalogTerm() throws SQLException;
214:
215: /**
216: * Retrieves the database vendor's preferred term for "schema".
217: *
218: * @return the vendor term for "schema"
219: *
220: * @throws SQLException if a database access error occurs
221: */
222: String getSchemaTerm() throws SQLException;
223:
224: /**
225: * Retrieves the database vendor's preferred term for "procedure".
226: *
227: * @return the vendor term for "procedure"
228: *
229: * @throws SQLException if a database access error occurs
230: */
231: String getProcedureTerm() throws SQLException;
232:
233: /**
234: * Retrieves the String that this database uses as the separator between a
235: * catalog and table name. Cached on first call.
236: *
237: * @return The separator character.
238: *
239: * @throws SQLException Thrown if an SQL error occurs.
240: */
241: String getCatalogSeparator() throws SQLException;
242:
243: /**
244: * Retrieves whether this database supports catalogs at all.
245: *
246: * @return <TT>true</TT> fi database supports catalogs.
247: *
248: * @throws SQLException Thrown if an SQL error occurs.
249: */
250: boolean supportsCatalogs() throws SQLException;
251:
252: /**
253: * Retrieves whether a catalog name can be used in a table definition
254: * statement. Cached on first call.
255: *
256: * @return <TT>true</TT> if a catalog name can be used in a table
257: * definition statement.
258: *
259: * @throws SQLException Thrown if an SQL error occurs.
260: */
261: boolean supportsCatalogsInTableDefinitions() throws SQLException;
262:
263: /**
264: * Retrieves whether a catalog name can be used in a data manipulation
265: * statement. Cached on first call.
266: *
267: * @return <TT>true</TT> if a catalog name can be used in a data
268: * manipulation statement.
269: *
270: * @throws SQLException Thrown if an SQL error occurs.
271: */
272: boolean supportsCatalogsInDataManipulation() throws SQLException;
273:
274: /**
275: * Retrieves whether a catalog name can be used in a procedure call. Cached
276: * on first call.
277: *
278: * @return <TT>true</TT> if a catalog name can be used in a procedure
279: * call.
280: *
281: * @throws SQLException Thrown if an SQL error occurs.
282: */
283: boolean supportsCatalogsInProcedureCalls() throws SQLException;
284:
285: /**
286: * Return the <TT>DatabaseMetaData</TT> object for this connection.
287: *
288: * @return The <TT>DatabaseMetaData</TT> object for this connection.
289: *
290: * @throws SQLException Thrown if an SQL error occurs.
291: */
292: DatabaseMetaData getJDBCMetaData() throws SQLException;
293:
294: /**
295: *
296: * @return
297: * @throws SQLException
298: */
299: IDataSet getMetaDataSet() throws SQLException;
300:
301: /**
302: *
303: * @return
304: * @throws DataSetException
305: */
306: IDataSet getTypesDataSet() throws DataSetException;
307:
308: /**
309: * Retrieve information about the data types in the database.
310: *
311: * @throws SQLException Thrown if an SQL error occurs.
312: */
313: DataTypeInfo[] getDataTypes() throws SQLException;
314:
315: /**
316: * NOTE: This method should only be used by SchemaInfo since this class should not and does not cache.
317: *
318: * Retrieve information about the procedures in the system.
319: */
320: IProcedureInfo[] getProcedures(String catalog,
321: String schemaPattern, String procedureNamePattern,
322: ProgressCallBack progressCallBack) throws SQLException;
323:
324: /**
325: * Return a string array containing the different types of tables in this
326: * database. E.G. <TT>"TABLE", "VIEW", "SYSTEM TABLE"</TT>. Cached on first
327: * call.
328: *
329: * @return table type names.
330: *
331: * @throws SQLException Thrown if an SQL error occurs.
332: */
333: String[] getTableTypes() throws SQLException;
334:
335: /**
336: * NOTE: This method should only be used by SchemaInfo since this class sholud not and does not cache.
337: *
338: * Retrieve information about the tables in the system.
339: */
340: ITableInfo[] getTables(String catalog, String schemaPattern,
341: String tableNamePattern, String[] types,
342: ProgressCallBack progressCallBack) throws SQLException;
343:
344: /**
345: * Retrieve information about the UDTs in the system.
346: *
347: * @param catalog The name of the catalog to retrieve UDTs
348: * for. An empty string will return those without a
349: * catalog. <TT>null</TT> means that the catalog
350: * will not be used to narrow the search.
351: * @param schemaPattern The name of the schema to retrieve UDTs
352: * for. An empty string will return those without a
353: * schema. <TT>null</TT> means that the schema
354: * will not be used to narrow the search.
355: * @param typeNamepattern A type name pattern; must match the
356: * type name as it is stored in the
357: * database.
358: * @param types List of user-defined types (JAVA_OBJECT, STRUCT, or
359: * DISTINCT) to include; null returns all types
360: *
361: * @throws SQLException Thrown if an SQL error occurs.
362: */
363: IUDTInfo[] getUDTs(String catalog, String schemaPattern,
364: String typeNamePattern, int[] types) throws SQLException;
365:
366: /**
367: * Retrieve the names of the Numeric Functions that this DBMS supports.
368: * Cached on first call.
369: *
370: * @return String[] of function names.
371: */
372: String[] getNumericFunctions() throws SQLException;
373:
374: /**
375: * Retrieve the names of the String Functions that this DBMS supports.
376: * Cached on first call.
377: *
378: * @return String[] of function names.
379: */
380: String[] getStringFunctions() throws SQLException;
381:
382: /**
383: * Retrieve the names of the System Functions that this DBMS supports.
384: * Cached on first call.
385: *
386: * @return String[] of function names.
387: */
388: String[] getSystemFunctions() throws SQLException;
389:
390: /**
391: * Retrieve the names of the Date/Time Functions that this DBMS supports.
392: * Cached on first call.
393: *
394: * @return String[] of function names.
395: */
396: String[] getTimeDateFunctions() throws SQLException;
397:
398: /**
399: * Retrieve the names of the non-standard keywords that this DBMS supports.
400: * Cached on first call.
401: *
402: * @return String[] of keywords.
403: */
404: String[] getSQLKeywords() throws SQLException;
405:
406: BestRowIdentifier[] getBestRowIdentifier(ITableInfo ti)
407: throws SQLException;
408:
409: /**
410: *
411: * @param ti
412: * @param columnIndices
413: * @param computeWidths
414: * @return
415: * @throws DataSetException
416: */
417: IDataSet getColumnPrivilegesDataSet(ITableInfo ti,
418: int[] columnIndices, boolean computeWidths)
419: throws DataSetException;
420:
421: /**
422: *
423: * @param ti
424: * @return
425: * @throws DataSetException
426: */
427: IDataSet getExportedKeysDataSet(ITableInfo ti)
428: throws DataSetException;
429:
430: ForeignKeyInfo[] getImportedKeysInfo(String catalog, String schema,
431: String tableName) throws SQLException;
432:
433: ForeignKeyInfo[] getImportedKeysInfo(ITableInfo ti)
434: throws SQLException;
435:
436: IDataSet getImportedKeysDataSet(ITableInfo ti)
437: throws DataSetException;
438:
439: ForeignKeyInfo[] getExportedKeysInfo(String catalog, String schema,
440: String tableName) throws SQLException;
441:
442: ForeignKeyInfo[] getExportedKeysInfo(ITableInfo ti)
443: throws SQLException;
444:
445: /**
446: *
447: * @param ti
448: * @param columnIndices
449: * @param computeWidths
450: * @return
451: * @throws DataSetException
452: */
453: ResultSetDataSet getIndexInfo(ITableInfo ti, int[] columnIndices,
454: boolean computeWidths) throws DataSetException;
455:
456: /**
457: * Returns a list of IndexInfos describing indexes for the specified table.
458: *
459: * @param ti the table to find all index information for.
460: * @return a list of IndexInfos
461: * @throws SQLException
462: */
463: public List<IndexInfo> getIndexInfo(ITableInfo ti)
464: throws SQLException;
465:
466: /**
467: *
468: * @param ti
469: * @param columnIndices
470: * @param computeWidths
471: * @return
472: * @throws DataSetException
473: */
474: IDataSet getPrimaryKey(ITableInfo ti, int[] columnIndices,
475: boolean computeWidths) throws DataSetException;
476:
477: /**
478: *
479: * @param ti
480: * @return
481: * @throws SQLException
482: */
483: PrimaryKeyInfo[] getPrimaryKey(ITableInfo ti) throws SQLException;
484:
485: /**
486: *
487: * @param ti
488: * @return
489: * @throws SQLException
490: */
491: PrimaryKeyInfo[] getPrimaryKey(String catalog, String schema,
492: String table) throws SQLException;
493:
494: /**
495: *
496: * @param ti
497: * @return
498: * @throws DataSetException
499: */
500: IDataSet getProcedureColumnsDataSet(IProcedureInfo ti)
501: throws DataSetException;
502:
503: /**
504: *
505: * @param ti
506: * @param columnIndices
507: * @param computeWidths
508: * @return
509: * @throws DataSetException
510: */
511: IDataSet getTablePrivilegesDataSet(ITableInfo ti,
512: int[] columnIndices, boolean computeWidths)
513: throws DataSetException;
514:
515: /**
516: *
517: * @param ti
518: * @return
519: * @throws DataSetException
520: */
521: IDataSet getVersionColumnsDataSet(ITableInfo ti)
522: throws DataSetException;
523:
524: /**
525: *
526: * @param ti
527: * @param columnIndices
528: * @param computeWidths
529: * @return
530: * @throws DataSetException
531: */
532: IDataSet getColumns(ITableInfo ti, int[] columnIndices,
533: boolean computeWidths) throws DataSetException;
534:
535: /**
536: *
537: * @param catalog
538: * @param schema
539: * @param table
540: * @return
541: * @throws SQLException
542: */
543: TableColumnInfo[] getColumnInfo(String catalog, String schema,
544: String table) throws SQLException;
545:
546: /**
547: *
548: * @param ti
549: * @return
550: * @throws SQLException
551: */
552: TableColumnInfo[] getColumnInfo(ITableInfo ti) throws SQLException;
553:
554: /**
555: * Retrieve whether this driver correctly handles Statement.setMaxRows(int).
556: * Some drivers such as version 5.02 of the Opta2000 driver use setMaxRows
557: * for UPDATEs, DELETEs etc. instead of just SELECTs. If this method returns
558: * <TT>false</TT> then setMaxRows should only be applied to statements
559: * that are running SELECTs.
560: *
561: * @return <TT>true</TT> if this driver correctly implements setMaxRows().
562: *
563: * @throws SQLException Thrown if an SQL error occurs.
564: */
565: boolean correctlySupportsSetMaxRows() throws SQLException;
566:
567: /**
568: * Retrieve whether this driver supports multiple result sets. Cached on
569: * first call.
570: *
571: * @return <tt>true</tt> if driver supports multiple result sets
572: * else <tt>false</tt>.
573: *
574: * @throws SQLException Thrown if an SQL error occurs.
575: */
576: boolean supportsMultipleResultSets() throws SQLException;
577:
578: /**
579: * Retrieves whether this database treats mixed case unquoted SQL
580: * identifiers as case insensitive and stores them in upper case.
581: * Cached on first call.
582: *
583: * @return <tt>true</tt> if driver stores upper case identifiers
584: * else <tt>false</tt>.
585: *
586: * @throws SQLException Thrown if an SQL error occurs.
587: */
588: boolean storesUpperCaseIdentifiers() throws SQLException;
589:
590: /**
591: * Clear cache of commonly accessed metadata properties.
592: */
593: void clearCache();
594:
595: }
|