001/*
002 * ModeShape (http://www.modeshape.org)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *       http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.modeshape.jdbc.metadata;
018
019/**
020 * <p>
021 * This class provides constants indicating positions of columns in the <code>ResultSets</code> returned by methods on
022 * <code>MMDatabaseMetaData</code> object. The inner classes represent the methods while attributes represent the column
023 * positions. The name of the constant explains the column content.
024 * </p>
025 * <p>
026 * The constants in the inner classes could include column positions for columns that are hardcoded, columns positions of some
027 * columns on server's <code>Results</code> object.
028 * </p>
029 * <p>
030 * Each of the inner classes have a constant <code>MAX_COLUMNS</code> that represents the number of columns to be read from the
031 * server's <code>Results</code> object.
032 * </p>
033 * <p>
034 * All the column positions are one based. </code>
035 */
036
037public interface JDBCColumnPositions {
038
039    /**
040     * <p>
041     * This class contains constants representing column positions on ResultSet returned by getColumns method on DatabaseMetaData.
042     * The class has constants for columns whose values are to be hardcoded in MMDatabaseMetaData object. <code>MAX_COLUMNS</code>
043     * is the number of columns to be read from server's results from getElements method on <code>Metadata object</code>.
044     * <code>JAVA_CLASS</code> is the column position for element data type on server's Results object.
045     */
046    interface SCHEMAS {
047        /** Number of columns to be read from results returned getElements method. */
048        static final int MAX_COLUMNS = 2;
049        static final int TABLE_CATALOG = 2;
050    }
051
052    /**
053     * <p>
054     * This class contains constants representing column positions on ResultSet returned by getColumns method on DatabaseMetaData.
055     * The class has constants for columns whose values are to be hardcoded in MMDatabaseMetaData object. <code>MAX_COLUMNS</code>
056     * is the number of columns to be read from server's results from getElements method on <code>Metadata object</code>.
057     * <code>JAVA_CLASS</code> is the column position for element data type on server's Results object.
058     */
059    interface CATALOGS {
060
061        /** Number of columns to be read from results returned getElements method. */
062        static final int MAX_COLUMNS = 1;
063    }
064
065    /**
066     * <p>
067     * This class contains constants representing column positions on ResultSet returned by getColumns method on DatabaseMetaData.
068     * The class has constants for columns whose values are to be hardcoded in MMDatabaseMetaData object. <code>MAX_COLUMNS</code>
069     * is the number of columns to be read from server's results from getElements method on <code>Metadata object</code>.
070     * <code>JAVA_CLASS</code> is the column position for element data type on server's Results object.
071     */
072    interface COLUMNS {
073
074        /** Number of columns to be read from results returned getElements method. */
075        static final int MAX_COLUMNS = 22;
076
077        /** Position of column that contains catalog name in which the table for the column is present. */
078        static final int TABLE_CAT = 1;
079
080        static final int TABLE_SCHEM = 2;
081
082        static final int TABLE_NAME = 3;
083
084        static final int COLUMN_NAME = 4;
085
086        /** Position of column that contains SQL type from java.sql.Types for column's data type. */
087        static final int DATA_TYPE = 5;
088
089        /** Position of column that contains local type name used by the data source. */
090        static final int TYPE_NAME = 6;
091
092        static final int COLUMN_SIZE = 7;
093
094        /** Position of column that is not used will contain nulls */
095        static final int BUFFER_LENGTH = 8;
096
097        static final int DECIMAL_DIGITS = 9;
098
099        static final int NUM_PREC_RADIX = 10;
100
101        /** Position of column that has an int value indicating nullablity */
102        static final int NULLABLE = 11;
103
104        /** Position of column containing explanatory notes. */
105        static final int REMARKS = 12;
106
107        static final int COLUMN_DEF = 13;
108
109        /** Position of column that not used will contain nulls */
110        static final int SQL_DATA_TYPE = 14;
111
112        /** Position of column that not used will contain nulls */
113        static final int SQL_DATETIME_SUB = 15;
114
115        static final int CHAR_OCTET_LENGTH = 16;
116
117        static final int ORDINAL_POSITION = 17;
118
119        /** Position of column that has an String value indicating nullablity */
120        static final int IS_NULLABLE = 18;
121
122        static final int SCOPE_CATALOG = 19;
123
124        static final int SCOPE_SCHEMA = 20;
125
126        static final int SCOPE_TABLE = 21;
127
128        static final int SOURCE_DATA_TYPE = 22;
129
130        static final int IS_AUTOINCREMENT = 23;
131
132    }
133
134    /**
135     * <p>
136     * This class contains constants representing column positions on ResultSet returned by getColumns method on DatabaseMetaData.
137     * The class has constants for columns whose values are to be hardcoded in MMDatabaseMetaData object. <code>MAX_COLUMNS</code>
138     * is the number of columns to be read from server's results from getElements method on <code>Metadata object</code>.
139     * <code>JAVA_CLASS</code> is the column position for element data type on server's Results object.
140     */
141    interface TABLES {
142
143        /** Number of columns to be read from results returned getTables method. */
144        static final int MAX_COLUMNS = 10;
145
146        /** Position of column that contains catalog name in which the table is present. */
147        static final int TABLE_CAT = 1;
148        static final int TYPE_CAT = 6;
149        static final int TYPE_SCHEM = 7;
150        static final int TYPE_NAME = 8;
151        static final int SELF_REFERENCING_COL_NAME = 9;
152        static final int REF_GENERATION = 10;
153        static final int ISPHYSICAL = 11;
154    }
155
156    /**
157     * <p>
158     * This class contains constants representing column positions on ResultSet returned by getColumns method on DatabaseMetaData.
159     * The class has constants for columns whose values are to be hardcoded in MMDatabaseMetaData object. <code>MAX_COLUMNS</code>
160     * is the number of columns to be read from server's results from getElements method on <code>Metadata object</code>.
161     * <code>JAVA_CLASS</code> is the column position for element data type on server's Results object.
162     */
163    interface TYPE_INFO {
164
165        /** Number of columns to be read from results returned getElements method. */
166        static final int MAX_COLUMNS = 18;
167
168        /** Position of column that contains local type name used by the data source. */
169        static final int TYPE_NAME = 1;
170
171        /** Position of column that contains SQL type from java.sql.Types for column's data type. */
172        static final int DATA_TYPE = 2;
173
174        static final int PRECISION = 3;
175        /** Position of column that contains prefix used to quote a literal. */
176        static final int LITERAL_PREFIX = 4;
177
178        /** Position of column that contains suffix used to quote a literal. */
179        static final int LITERAL_SUFFIX = 5;
180
181        /** Position of column that contains params used in creating the type. */
182        static final int CREATE_PARAMS = 6;
183
184        /** Position of column that contains the nullable value. */
185        static final int NULLABLE = 7;
186
187        static final int CASE_SENSITIVE = 8;
188
189        /** Position of column that contains the searchable value. */
190        static final int SEARCHABLE = 9;
191
192        /** Position of column that contains the unsigned value. */
193        static final int UNSIGNED_ATTRIBUTE = 10;
194
195        static final int FIXED_PREC_SCALE = 11;
196
197        static final int AUTO_INCREMENT = 12;
198
199        /** Position of column that contains local type name used by the data source. */
200        static final int LOCAL_TYPE_NAME = 13;
201
202        /** Position of column that contains the min scale value. */
203        static final int MINIMUM_SCALE = 14;
204
205        /** Position of column that contains the max scale value. */
206        static final int MAXIMUM_SCALE = 15;
207
208        /** Position of column that not used will contain nulls */
209        static final int SQL_DATA_TYPE = 16;
210
211        /** Position of column that not used will contain nulls */
212        static final int SQL_DATETIME_SUB = 17;
213
214        static final int NUM_PREC_RADIX = 18;
215
216        /** Position of column in server's results containing name of the datatype. */
217        static final int NAME = 19;
218
219        /** Position of column in server's results containing isSigned value. */
220        static final int IS_SIGNED = 20;
221
222        /** Position of column in server's results containing nullType name. */
223        static final int NULL_TYPE_NAME = 21;
224
225        /** Position of column in server's results containing search type name. */
226        static final int SEARCH_TYPE_NAME = 22;
227    }
228
229    /**
230     * This class contains constants representing column positions on ResultSet returned by getUDTS method on DatabaseMetaData.
231     * These constant values are be used to hardcode the column values used in constructin the ResultSet obj.
232     */
233    interface UDTS {
234
235        /** Number of columns to be read from results returned getUserDefinedTypes method. */
236        static final int MAX_COLUMNS = 7;
237
238        // name of the column containing table or Groups name in which UDTS are present.
239        static final int TABLE_NAME = 3;
240
241        // name of the column containing catalog or Virtual database name.
242        static final int TYPE_CAT = 1;
243
244        // name of the column containing schema or Virtual database version.
245        static final int TYPE_SCHEM = 2;
246
247        // name of the column containing name of type name column.
248        static final int TYPE_NAME = 9;
249
250        // name of the column containing class name column.
251        static final int CLASS_NAME = 4;
252
253        // name of the column containing name of sql datatype code column
254        static final int DATA_TYPE = 5;
255
256        // name of the column containing comments column
257        static final int REMARKS = 6;
258
259        static final int BASE_TYPE = 7;
260        /** Position of column in server's results containing java class name. */
261        static final int JAVA_CLASS = 8;
262    }
263
264    /**
265     * <p>
266     * This class contains constants representing column positions on ResultSet returned by getIndexInfo method on
267     * DatabaseMetaData. The class has constants for columns whose values are to be hardcoded in MMDatabaseMetaData object.
268     * <code>MAX_COLUMNS</code> is the number of columns to be read from server's results from the query against
269     * System.KeyElements table.
270     * </p>
271     */
272    interface INDEX_INFO {
273
274        /** Number of columns to be read from results returned by server results. */
275        static final int MAX_COLUMNS = 13;
276
277        /** Position of column that contains catalog name of the table. */
278        static final int TABLE_CAT = 1;
279
280        static final int TABLE_SCHEM = 2;
281
282        static final int TABLE_NAME = 3;
283
284        /** Position of column that contains non uniqueness of the index. */
285        static final int NON_UNIQUE = 4;
286
287        /** Position of column that contains qualifier for the index. */
288        static final int INDEX_QUALIFIER = 5;
289
290        static final int INDEX_NAME = 6;
291
292        /** Position of column that contains type of index. */
293        static final int TYPE = 7;
294
295        static final int ORDINAL_POSITION = 8;
296
297        static final int COLUMN_NAME = 9;
298
299        /** Position of column that contains desc if index is ascending or descending. */
300        static final int ASC_OR_DESC = 10;
301
302        /** Position of column that contains cardinality of the index. */
303        static final int CARDINALITY = 11;
304
305        /** Position of column that contains pages oocupied by table. */
306        static final int PAGES = 12;
307
308        /** Position of column that contains any filter condition. */
309        static final int FILTER_CONDITION = 13;
310
311    }
312
313    /**
314     * <p>
315     * This class contains constants representing column positions on ResultSet returned by getColumns method on DatabaseMetaData.
316     * The class has constants for columns whose values are to be hardcoded in MMDatabaseMetaData object. <code>MAX_COLUMNS</code>
317     * is the number of columns to be read from server's results from getElements method on <code>Metadata object</code>.
318     * <code>JAVA_CLASS</code> is the column position for element data type on server's Results object.
319     */
320    interface PRIMARY_KEYS {
321
322        /** Number of columns to be read from results returned by getPrimaryKeys. */
323        static final int MAX_COLUMNS = 6;
324
325        /** Position of column that contains catalog name of the primaryTable. */
326        static final int TABLE_CAT = 1;
327        static final int TABLE_SCHEM = 2;
328        static final int TABLE_NAME = 3;
329        static final int COLUMN_NAME = 4;
330        static final int KEY_SEQ = 5;
331        static final int PK_NAME = 6;
332    }
333
334    /**
335     * <p>
336     * This class contains constants representing column positions on ResultSet returned by getCrossReferences method on
337     * DatabaseMetaData. The class has constants for columns whose values are to be hardcoded in MMDatabaseMetaData object.
338     * <code>MAX_COLUMNS</code> is the number of columns to be read from server's results from getCrossReferences method on
339     * server's <code>Metadata object</code>.
340     */
341    interface REFERENCE_KEYS {
342
343        /** Number of columns to be read from results returned any of the 3 methods. */
344        static final int MAX_COLUMNS = 14;
345
346        /** Position of column that contains catalog name of the primaryTable. */
347        static final int PKTABLE_CAT = 1;
348
349        /** Position of column that contains scheam name of the primaryTable. */
350        static final int PKTABLE_SCHEM = 2;
351
352        static final int PKTABLE_NAME = 3;
353
354        static final int PKCOLUMN_NAME = 4;
355
356        /** Position of column that contains catalog name of the foreignTable. */
357        static final int FKTABLE_CAT = 5;
358
359        /** Position of column that contains schema name of the foreignTable. */
360        static final int FKTABLE_SCHEM = 6;
361
362        static final int FKTABLE_NAME = 7;
363
364        static final int FKCOLUMN_NAME = 8;
365
366        static final int KEY_SEQ = 9;
367
368        /** Position of column that determines how forein key changes if PK is updated. */
369        static final int UPDATE_RULE = 10;
370
371        /** Position of column that determines how forein key changes if PK is deleted. */
372        static final int DELETE_RULE = 11;
373
374        static final int FK_NAME = 12;
375
376        static final int PK_NAME = 13;
377
378        /** Position of column that determines if forein key constraints can be deffered until commit. */
379        static final int DEFERRABILITY = 14;
380    }
381
382    /**
383     * <p>
384     * This class contains constants representing column positions on ResultSet returned by getProcedures method on
385     * DatabaseMetaData. The class has constants for columns whose values are to be hardcoded in MMDatabaseMetaData object.
386     * <code>MAX_COLUMNS</code> is the number of columns to be read from server's results from getElements method on
387     * <code>Metadata object</code>. <code>JAVA_CLASS</code> is the column position for element data type on server's Results
388     * object.
389     */
390    interface PROCEDURES {
391
392        /** Number of columns to be read from results returned getCrossReferences method. */
393        static final int MAX_COLUMNS = 9;
394
395        /** Position of column that contains catalog name of the procedure. */
396        static final int PROCEDURE_CAT = 1;
397        static final int PROCEDURE_SCHEM = 2;
398        static final int PROCEDURE_NAME = 3;
399
400        /** Position of column the is reserved for future use. */
401        static final int RESERVED_1 = 4;
402
403        /** Position of column the is reserved for future use. */
404        static final int RESERVED_2 = 5;
405
406        /** Position of column the is reserved for future use. */
407        static final int RESERVED_3 = 6;
408
409        static final int REMARKS = 7;
410
411        /** Position of column Procedure type. */
412        static final int PROCEDURE_TYPE = 8;
413
414        static final int SPECIFIC_NAME = 9;
415    }
416
417    /**
418     * <p>
419     * This class contains constants representing column positions on ResultSet returned by getColumns method on DatabaseMetaData.
420     * The class has constants for columns whose values are to be hardcoded in MMDatabaseMetaData object. <code>MAX_COLUMNS</code>
421     * is the number of columns to be read from server's results from getElements method on <code>Metadata object</code>.
422     * <code>JAVA_CLASS</code> is the column position for element data type on server's Results object.
423     */
424    interface PROCEDURE_COLUMNS {
425
426        /** Number of columns to be read from results returned getProcedureColumns method. */
427        static final int MAX_COLUMNS = 20;
428
429        /** Position of column that contains catalog name of the procedure. */
430        static final int PROCEDURE_CAT = 1;
431
432        static final int PROCEDURE_SCHEM = 2;
433        static final int PROCEDURE_NAME = 3;
434        static final int COLUMN_NAME = 4;
435
436        /** Position of the column containing column or element type. */
437        static final int COLUMN_TYPE = 5;
438
439        /** Position of column that contains SQL type from java.sql.Types for column's data type. */
440        static final int DATA_TYPE = 6;
441
442        /** Position of column that contains local type name used by the data source. */
443        static final int TYPE_NAME = 7;
444
445        static final int PRECISION = 8;
446        static final int LENGTH = 9;
447        static final int SCALE = 10;
448        static final int RADIX = 11;
449
450        /** Position of column that contains the nullable value. */
451        static final int NULLABLE = 12;
452
453        /** Position of column that contains comments. */
454        static final int REMARKS = 13;
455        static final int COLUMN_DEF = 14;
456
457        static final int SQL_DATA_TYPE = 15;
458        static final int SQL_DATETIME_SUB = 16;
459        static final int CHAR_OCTET_LENGTH = 17;
460
461        static final int ORDINAL_POSITION = 18;
462
463        static final int IS_NULLABLE = 19;
464
465        static final int SPECIFIC_NAME = 20;
466    }
467
468    /**
469     * <p>
470     * This class contains constants representing column positions on ResultSet returned by getColumns method on DatabaseMetaData.
471     * The class also has constants for columns whose values are to be hardcoded in MMDatabaseMetaData object.
472     * <code>MAX_COLUMNS</code> is the number of columns to be read from server's results from getElements method on
473     * <code>Metadata object</code>.
474     */
475    interface TABLE_PRIVILEGES {
476
477        /** Number of columns to be read from results returned getGroupEntitlements method. */
478        static final int MAX_COLUMNS = 6;
479
480        /**
481         * Position of VirtualDatabaseName column in server's results object returned by getGroupEntitlements method in User API
482         */
483        static final int VIRTUAL_DATABASE_NAME = 0;
484
485        /**
486         * Position of VirtualDatabaseVersion column in server's results object returned by getElementEntitlements method in User
487         * API
488         */
489        static final int VIRTUAL_DATABASE_VERSION = 1;
490
491        /**
492         * Position of GroupName column in server's results object returned by getGroupEntitlements method in User API
493         */
494        static final int GROUP_NAME = 2;
495
496        /**
497         * Position of Grantor column in server's results object returned by getGroupEntitlements method in User API
498         */
499        static final int GRANTOR = 3;
500
501        /**
502         * Position of Grantee column in server's results object returned by getGroupEntitlements method in User API
503         */
504        static final int GRANTEE = 4;
505
506        /**
507         * Position of Permission column in server's results object returned by getGroupEntitlements method in User API
508         */
509        static final int PERMISSION = 5;
510
511        /** Position of the column containing catalog name info. */
512        static final int TABLE_CAT = 0;
513
514        /** Position of the column containing privilage grantable info. */
515        static final int IS_GRANTABLE = 6;
516    }
517
518    /**
519     * <p>
520     * This class contains constants representing column positions on ResultSet returned by getColumns method on DatabaseMetaData.
521     * The class also has constants for columns whose values are to be hardcoded in MMDatabaseMetaData object.
522     * <code>MAX_COLUMNS</code> is the number of columns to be read from server's results from getElements method on
523     * <code>Metadata object</code>.
524     */
525    interface COLUMN_PRIVILEGES {
526
527        /** Number of columns to be read from results returned getElementEntitlements method. */
528        static final int MAX_COLUMNS = 7;
529
530        /**
531         * Position of VirtualDatabaseName column in server's results object returned by getElementEntitlements method in User API
532         */
533        static final int VIRTUAL_DATABASE_NAME = 0;
534
535        /**
536         * Position of VirtualDatabaseVersion column in server's results object returned by getElementEntitlements method in User
537         * API
538         */
539        static final int VIRTUAL_DATABASE_VERSION = 1;
540
541        /**
542         * Position of GroupName column in server's results object returned by getElementEntitlements method in User API
543         */
544        static final int GROUP_NAME = 2;
545
546        /**
547         * Position of ElementName column in server's results object returned by getElementEntitlements method in User API
548         */
549        static final int ELEMENT_NAME = 3;
550
551        /**
552         * Position of Grantor column in server's results object returned by getElementEntitlements method in User API
553         */
554        static final int GRANTOR = 4;
555
556        /**
557         * Position of Grantee column in server's results object returned by getElementEntitlements method in User API
558         */
559        static final int GRANTEE = 5;
560
561        /**
562         * Position of Permission column in server's results object returned by getElementEntitlements method in User API
563         */
564        static final int PERMISSION = 6;
565
566        /** Position of the column containing catalog name info. */
567        static final int TABLE_CAT = 0;
568
569        /** Position of the column containing privilage grantable info. */
570        static final int IS_GRANTABLE = 7;
571    }
572
573}