KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hsqldb > DITypeInfo


1 /* Copyright (c) 2001-2005, The HSQL Development Group
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  *
10  * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * Neither the name of the HSQL Development Group nor the names of its
15  * contributors may be used to endorse or promote products derived from this
16  * software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
22  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30
31
32 package org.hsqldb;
33
34 import java.util.Locale JavaDoc;
35
36 import org.hsqldb.resources.BundleHandler;
37 import org.hsqldb.store.ValuePool;
38
39 /**
40  * Provides information intrinsic to each standard data type known to
41  * HSQLDB. This includes all types for which standard type codes are known
42  * at the time of writing and thus includes types that may not yet be
43  * supported as table or procedure columns. <p>
44  *
45  * @author boucherb@users
46  * @version 1.8.0
47  * @since 1.7.2
48  */

49 final class DITypeInfo {
50
51     // related to DatabaseMetaDataValues
52
static final int columnNoNulls = 0;
53     static final int columnNullable = 1;
54     static final int typePredNone = 0;
55     static final int typePredChar = 1;
56     static final int typePredBasic = 2;
57     static final int typeSearchable = 3;
58
59     /** BundleHandler id for create params resource bundle. */
60     private int hnd_create_params = -1;
61
62     /** BundleHandler id for local names resource bundle. */
63     private int hnd_local_names = -1;
64
65     /** BundleHandler id for data type remarks resource bundle. */
66     private int hnd_remarks = -1;
67
68     /** The SQL type code on which this object is reporting. */
69     private int type = Types.NULL;
70
71     /** The HSQLDB subtype code on which this object is reporting. */
72     private int typeSub = Types.TYPE_SUB_DEFAULT;
73     boolean locale_set;
74
75     /** Creates a new DITypeInfo object having the default Locale. */
76     DITypeInfo() {
77
78         // boucherb@users 20050515 - patch 1.8.0 - make setLocale lazy
79
//setLocale(Locale.getDefault());
80
}
81
82     /**
83      * Retrieves the maximum Integer.MAX_VALUE bounded length, in bytes, for
84      * character types. <p>
85      *
86      * @return the maximum Integer.MAX_VALUE bounded length, in
87      * bytes, for character types
88      */

89     Integer JavaDoc getCharOctLen() {
90         return null;
91     }
92
93     /**
94      * Retrieves the maximum Long.MAX_VALUE bounded length, in bytes, for
95      * character types. <p>
96      *
97      * @return the maximum Long.MAX_VALUE bounded length, in
98      * bytes, for character types
99      */

100     Long JavaDoc getCharOctLenAct() {
101
102         switch (type) {
103
104             case Types.CHAR :
105             case Types.LONGVARCHAR :
106             case Types.VARCHAR :
107                 return ValuePool.getLong(2L * Integer.MAX_VALUE);
108
109             case Types.CLOB :
110                 return ValuePool.getLong(Long.MAX_VALUE);
111
112             default :
113                 return null;
114         }
115     }
116
117     /**
118      * Retrieves the fully-qualified name of the Java class whose instances
119      * are manufactured by HSQLDB to store table column values in
120      * memory. <p>
121      *
122      * This is also typically the fully-qualified name of the Java class whose
123      * instances are manufactured by HSQLDB in response to
124      * jdbcResultSet.getObject(int). <p>
125      *
126      * @return the fully-qualified name of the Java class whose
127      * instances are manufactured by HSQLDB to store
128      * table column values in memory
129      */

130     String JavaDoc getColStClsName() {
131         return Types.getColStClsName(type);
132     }
133
134     /**
135      * Retrieves a character sequence representing a CSV list, in
136      * DDL declaraion order, of the create parameters for the type. <p>
137      *
138      * @return a character sequence representing a CSV
139      * list, in DDL declaraion order, of the create
140      * parameters for the type.
141      */

142     String JavaDoc getCreateParams() {
143
144         if (!locale_set) {
145             setLocale(Locale.getDefault());
146         }
147
148         String JavaDoc names;
149
150         switch (type) {
151
152             case Types.CHAR :
153             case Types.VARCHAR :
154                 names = "LENGTH";
155                 break;
156
157             case Types.DECIMAL :
158             case Types.NUMERIC :
159                 names = "PRECISION,SCALE";
160                 break;
161
162             case Types.FLOAT :
163             case Types.TIMESTAMP :
164                 names = "PRECISION";
165                 break;
166
167             default :
168                 names = null;
169                 break;
170         }
171
172         return names;
173     }
174
175     /**
176      * Retrieves the fully-qualified name of the HSQLDB-provided java.sql
177      * interface implementation class whose instances would be manufactured
178      * by HSQLDB to retrieve column values of this type, if the
179      * the type does not have a standard Java mapping. <p>
180      *
181      * This value is simply the expected class name, regardless of whether
182      * HSQLDB, the specific HSQLDB distribution instance or the hosting JVM
183      * actually provide or support such implementations. That is, as of a
184      * specific release, HSQLDB may not yet provide such an implementation
185      * or may not automatically map to it or may not support it as a table
186      * column type, the version of java.sql may not define the interface to
187      * implement and the HSQLDB jar may not contain the implementation
188      * classes, even if they are defined in the corresponding release
189      * and build options and are supported under the hosting JVM's java.sql
190      * version.<p>
191      *
192      * @return the fully-qualified name of the HSQLDB-provided java.sql
193      * interface implementation class whose instances would
194      * be manufactured by HSQLDB to retrieve column values of
195      * this type, given that the type does not have a standard Java
196      * mapping and regardless of whether a class with the indicated
197      * name is actually implemented or available on the class path
198      */

199     String JavaDoc getCstMapClsName() {
200
201         switch (type) {
202
203             case Types.ARRAY :
204                 return "org.hsqldb.jdbc.jdbcArray";
205
206             case Types.BLOB :
207                 return "org.hsqldb.jdbc.jdbcBlob";
208
209             case Types.CLOB :
210                 return "org.hsqldb.jdbc.jdbcClob";
211
212             case Types.DISTINCT :
213                 return "org.hsqldb.jdbc.jdbcDistinct";
214
215             case Types.REF :
216                 return "org.hsqldb.jdbc.jdbcRef";
217
218             case Types.STRUCT :
219                 return "org.hsqldb.jdbc.jdbcStruct";
220
221             default :
222                 return null;
223         }
224     }
225
226 // NOTES:
227
// From recent usability testing, this patch and the corresponding patch in
228
// jdbcResultSetMetaData together provide better compatibility with existing
229
// tools than through the previous method of dynamically scanning each result
230
// in jdbcResultSetMetaData. This is especially true given that many tools use
231
// the display size to set their internal max # of characters reserved for
232
// result columns at said position. Also, since adding implementation of
233
// ResultSetMetaData retreived from PreparedStatement's getMetaData method,
234
// there exists the case where there is no data to scan in order to determine
235
// an approximation. Finally, since for plain old Statement objects the only
236
// way to get metadata is to execute the query and since the scan approximation
237
// can vary from one execution to the next, it turns out it's much "safer" and
238
// more usable in a tool setting to simply indicate a large but expected
239
// acceptable number of characters, rather than report either a number generally
240
// too large to handle or a number too small to hold the actual expected maximum
241
// number of characters for result colums of CHAR or VARCHAR types
242

243     /**
244      * Retrieves the maximum length that a String representation of
245      * the type may have. <p>
246      *
247      * The calculation follows these rules: <p>
248      *
249      * <ol>
250      * <li>Long character and datetime types:<p>
251      *
252      * The maximum length/precision, repectively.<p>
253      *
254      * <li>CHAR and VARCHAR types: <p>
255      *
256      * The value of the system property hsqldb.max_xxxchar_display_size
257      * or the magic value 32766 (0x7FFE) (tested usable/accepted by most
258      * tools and compatible with assumptions made by java.io read/write
259      * UTF) when the system property is not defined or is not accessible,
260      * due to security constraints. <p>
261      *
262      * <li>Number types: <p>
263      *
264      * The max precision, plus the length of the negation character (1),
265      * plus (if applicable) the maximum number of characters that may
266      * occupy the exponent character sequence. <p>
267      *
268      * <li>BOOLEAN/BIT types: <p>
269      *
270      * The length of the character sequence "false" (5), the longer of the
271      * two boolean value String representations. <p>
272      *
273      * <li>All remaining types: <p>
274      *
275      * The result of whatever calculation must be performed to determine
276      * the maximum length of the type's String representation. If the
277      * maximum display size is unknown, unknowable or inapplicable, then
278      * zero is returned. <p>
279      *
280      * </ol>
281      *
282      * @return the maximum length that a String representation of
283      * the type may have, or zero (0) if unknown or unknowable
284      */

285     int getMaxDisplaySize() {
286         return Types.getMaxDisplaySize(type);
287     }
288
289     /**
290      * Retrieves the data type, as an Integer. <p>
291      *
292      * @return the data type, as an Integer.
293      */

294     Integer JavaDoc getDataType() {
295         return ValuePool.getInt(type);
296     }
297
298     /**
299      * Retrieves the data subtype, as an Integer. <p>
300      *
301      * @return the data subtype, as an Integer
302      */

303     Integer JavaDoc getDataTypeSub() {
304         return ValuePool.getInt(typeSub);
305     }
306
307     /**
308      * Retrieves the implied or single permitted scale for exact numeric
309      * types, when no scale is declared or no scale declaration is
310      * permitted. <p>
311      *
312      * @return the implied or single permitted scale for exact numeric
313      * types, when no scale is declared or no scale declaration
314      * is permitted
315      */

316     Integer JavaDoc getDefaultScale() {
317
318         switch (type) {
319
320             case Types.BIGINT :
321             case Types.INTEGER :
322             case Types.SMALLINT :
323             case Types.TINYINT :
324                 return ValuePool.getInt(0);
325
326             default :
327                 return null;
328         }
329     }
330
331     /**
332      * Retrieves null (not implemented). <p>
333      *
334      * @return null (not implemented)
335      */

336     Integer JavaDoc getIntervalPrecision() {
337         return null;
338     }
339
340     /**
341      * Retrieves the character(s) prefixing a literal of this type. <p>
342      *
343      * @return the character(s) prefixing a literal of this type.
344      */

345     String JavaDoc getLiteralPrefix() {
346
347         switch (type) {
348
349             case Types.BINARY :
350             case Types.BLOB :
351             case Types.CHAR :
352             case Types.CLOB :
353             case Types.LONGVARBINARY :
354             case Types.LONGVARCHAR :
355             case Types.VARBINARY :
356             case Types.VARCHAR :
357                 return "'";
358
359             case Types.DATALINK :
360                 return "'"; // hypothetically: "{url '";
361

362             case Types.DATE :
363                 return "'"; // or JDBC escape: "{d '";
364

365             case Types.OTHER :
366                 return "'"; // hypothetically: "{o '"; or new "pkg.cls"(...)
367

368             case Types.TIME :
369                 return "'"; // or JDBC escape: "{t '";
370

371             case Types.TIMESTAMP :
372                 return "'"; // or JDBC escape: "{ts '";
373

374             case Types.XML :
375                 return "'"; // hypothetically: "{xml '";
376

377             default :
378                 return null;
379         }
380     }
381
382     /**
383      * Retrieves the character(s) terminating a literal of this type. <p>
384      *
385      * @return the character(s) terminating a literal of this type
386      */

387     String JavaDoc getLiteralSuffix() {
388
389         switch (type) {
390
391             case Types.BINARY :
392             case Types.BLOB :
393             case Types.CHAR :
394             case Types.CLOB :
395             case Types.LONGVARBINARY :
396             case Types.LONGVARCHAR :
397             case Types.VARBINARY :
398             case Types.VARCHAR :
399                 return "'";
400
401             case Types.DATALINK :
402             case Types.DATE :
403             case Types.OTHER :
404             case Types.TIME :
405             case Types.TIMESTAMP :
406             case Types.XML :
407                 return "'"; // or JDBC close escape: "'}";
408

409             default :
410                 return null;
411         }
412     }
413
414     /**
415      * Retrieves a localized representation of the type's name, for human
416      * consumption only. <p>
417      *
418      * @return a localized representation of the type's name
419      */

420     String JavaDoc getLocalName() {
421
422         if (!locale_set) {
423             setLocale(Locale.getDefault());
424         }
425
426         String JavaDoc key = this.getTypeName();
427
428         return BundleHandler.getString(hnd_local_names, key);
429     }
430
431     /**
432      * Retrieves the maximum Short.MAX_VALUE bounded scale supported
433      * for the type. <p>
434      *
435      * @return the maximum Short.MAX_VALUE bounded scale supported
436      * for the type
437      */

438     Integer JavaDoc getMaxScale() {
439
440         switch (type) {
441
442             case Types.BIGINT :
443             case Types.DATE :
444             case Types.TIME :
445             case Types.INTEGER :
446             case Types.SMALLINT :
447             case Types.TINYINT :
448                 return ValuePool.getInt(0);
449
450             case Types.TIMESTAMP :
451                 return ValuePool.getInt(6);
452
453             case Types.DECIMAL :
454             case Types.NUMERIC :
455                 return ValuePool.getInt(Short.MAX_VALUE);
456
457             case Types.FLOAT :
458             case Types.REAL :
459             case Types.DOUBLE :
460                 return ValuePool.getInt(306);
461
462             default :
463                 return null;
464         }
465     }
466
467     /**
468      * Retrieves the maximum Integer.MAX_VALUE bounded scale supported for
469      * the type. <p>
470      *
471      * @return the maximum Integer.MAX_VALUE bounded scale supported
472      * for the type
473      */

474     Integer JavaDoc getMaxScaleAct() {
475
476         switch (type) {
477
478             case Types.DECIMAL :
479             case Types.NUMERIC :
480                 return ValuePool.getInt(Integer.MAX_VALUE);
481
482             default :
483                 return getMaxScale();
484         }
485     }
486
487     /**
488      * Retrieves the minumum Short.MIN_VALUE bounded scale supported for
489      * the type. <p>
490      *
491      * @return the minumum Short.MIN_VALUE bounded scale
492      * supported for the type
493      */

494     Integer JavaDoc getMinScale() {
495
496         switch (type) {
497
498             case Types.BIGINT :
499             case Types.DATE :
500             case Types.INTEGER :
501             case Types.SMALLINT :
502             case Types.TIME :
503             case Types.TIMESTAMP :
504             case Types.TINYINT :
505             case Types.DECIMAL :
506             case Types.NUMERIC :
507                 return ValuePool.getInt(0);
508
509             case Types.FLOAT :
510             case Types.REAL :
511             case Types.DOUBLE :
512                 return ValuePool.getInt(-324);
513
514             default :
515                 return null;
516         }
517     }
518
519     /**
520      * Retrieves the minumum Integer.MIN_VALUE bounded scale supported
521      * for the type. <p>
522      *
523      * @return the minumum Integer.MIN_VALUE bounded scale supported
524      * for the type
525      */

526     Integer JavaDoc getMinScaleAct() {
527         return getMinScale();
528     }
529
530     /**
531      * Retrieves the DatabaseMetaData default nullability code for
532      * the type. <p>
533      *
534      * @return the DatabaseMetaData nullability code for the type.
535      */

536     Integer JavaDoc getNullability() {
537         return ValuePool.getInt(columnNullable);
538     }
539
540     /**
541      * Retrieves the number base which is to be used to interpret the value
542      * reported by getPrecision(). <p>
543      *
544      * @return the number base which is to be used to interpret the
545      * value reported by getPrecision()
546      */

547     Integer JavaDoc getNumPrecRadix() {
548
549         switch (type) {
550
551             case Types.BIGINT :
552             case Types.DECIMAL :
553             case Types.DOUBLE :
554             case Types.INTEGER :
555             case Types.NUMERIC :
556             case Types.REAL :
557             case Types.SMALLINT :
558             case Types.TINYINT :
559                 return ValuePool.getInt(10);
560
561             case Types.FLOAT :
562                 return ValuePool.getInt(2);
563
564             default :
565                 return null;
566         }
567     }
568
569     /**
570      * Retrieves the maximum Integer.MAX_VALUE bounded length or precision for
571      * the type. <p>
572      *
573      * @return the maximum Integer.MAX_VALUE bounded length or
574      * precision for the type
575      */

576     Integer JavaDoc getPrecision() {
577
578         int p = Types.getPrecision(type);
579
580         return p == 0 ? null
581                       : ValuePool.getInt(p);
582     }
583
584     /**
585      * Retrieves the maximum Long.MAX_VALUE bounded length or precision for
586      * the type. <p>
587      *
588      * @return the maximum Long.MAX_VALUE bounded length or
589      * precision for the type
590      */

591     Long JavaDoc getPrecisionAct() {
592
593         Integer JavaDoc temp = getPrecision();
594
595         if (temp == null) {
596             return ValuePool.getLong(Long.MAX_VALUE);
597         } else {
598             return ValuePool.getLong(temp.longValue());
599         }
600     }
601
602     /**
603      * Retrieves the localized remarks (if any) on the type. <p>
604      *
605      * @return the localized remarks on the type.
606      */

607     String JavaDoc getRemarks() {
608
609         if (!locale_set) {
610             setLocale(Locale.getDefault());
611         }
612
613         String JavaDoc key = this.getTypeName();
614
615         return BundleHandler.getString(hnd_remarks, key);
616     }
617
618     /**
619      * Retrieves the DatabaseMetaData searchability code for the type. <p>
620      *
621      * @return the DatabaseMetaData searchability code for the type
622      */

623     Integer JavaDoc getSearchability() {
624         return Types.isSearchable(type) ? ValuePool.getInt(typeSearchable)
625                                         : ValuePool.getInt(typePredNone);
626     }
627
628     /**
629      * Retrieves the SQL CLI data type code for the type. <p>
630      *
631      * @return the SQL CLI data type code for the type
632      */

633     Integer JavaDoc getSqlDataType() {
634
635         // values from SQL200n SQL CLI spec, or DITypes (which in turn borrows
636
// first from java.sql.Types and then SQL200n SQL CLI spec) if there
637
// was no corresponding value in SQL CLI
638
switch (type) {
639
640             case Types.ARRAY :
641                 return ValuePool.getInt(Types.SQL_ARRAY); // SQL_ARRAY
642

643             case Types.BIGINT :
644                 return ValuePool.getInt(Types.SQL_BIGINT); // SQL_BIGINT
645

646             case Types.BINARY :
647                 return ValuePool.getInt(Types.SQL_BLOB); // fredt- was SQL_BIT_VARYING
648

649             case Types.BOOLEAN :
650                 return ValuePool.getInt(Types.SQL_BOOLEAN); // SQL_BOOLEAN
651

652             case Types.BLOB :
653                 return ValuePool.getInt(Types.SQL_BLOB); // SQL_BLOB
654

655             case Types.CHAR :
656                 return ValuePool.getInt(Types.SQL_CHAR); // SQL_CHAR
657

658             case Types.CLOB :
659                 return ValuePool.getInt(Types.SQL_CLOB); // SQL_CLOB
660

661             case Types.DATALINK :
662                 return ValuePool.getInt(Types.SQL_DATALINK); // SQL_DATALINK
663

664             case Types.DATE :
665
666                 // NO: This is the _concise_ code, whereas what we want to
667
// return here is the Data Type Code column value from
668
// Table 38 in the SQL 200n FCD. This method is used
669
// by DatabaseInformationMain to list the sql type
670
// column in the SYSTEM_TYPEINFO table, which is specified
671
// by JDBC as the sql data type code, not the concise code.
672
// That is why there is a sql datetime sub column
673
// specified as well.
674
// return ValuePool.getInt(Types.SQL_DATE); // fredt - was SQL_DATETIME
675
return ValuePool.getInt(Types.SQL_DATETIME);
676
677             case Types.DECIMAL :
678                 return ValuePool.getInt(Types.SQL_DECIMAL); // SQL_DECIMAL
679

680             case Types.DISTINCT :
681                 return ValuePool.getInt(Types.SQL_UDT); // SQL_UDT
682

683             case Types.DOUBLE :
684                 return ValuePool.getInt(Types.SQL_DOUBLE); // SQL_DOUBLE
685

686             case Types.FLOAT :
687                 return ValuePool.getInt(Types.SQL_FLOAT); // SQL_FLOAT
688

689             case Types.INTEGER :
690                 return ValuePool.getInt(Types.SQL_INTEGER); // SQL_INTEGER
691

692             case Types.JAVA_OBJECT :
693                 return ValuePool.getInt(Types.JAVA_OBJECT); // N/A - maybe SQL_UDT?
694

695             case Types.LONGVARBINARY :
696                 return ValuePool.getInt(Types.SQL_BLOB); // was SQL_BIT_VARYING
697

698             case Types.LONGVARCHAR :
699                 return ValuePool.getInt(Types.SQL_CLOB); //
700

701             case Types.NULL :
702                 return ValuePool.getInt(Types.SQL_ALL_TYPES); // SQL_ALL_TYPES
703

704             case Types.NUMERIC :
705                 return ValuePool.getInt(Types.SQL_NUMERIC); // SQL_NUMERIC
706

707             case Types.OTHER :
708                 return ValuePool.getInt(Types.OTHER); // N/A - maybe SQL_UDT?
709

710             case Types.REAL :
711                 return ValuePool.getInt(Types.SQL_REAL); // SQL_REAL
712

713             case Types.REF :
714                 return ValuePool.getInt(Types.SQL_REF); // SQL_REF
715

716             case Types.SMALLINT :
717                 return ValuePool.getInt(Types.SQL_SMALLINT); // SQL_SMALLINTEGER
718

719             case Types.STRUCT :
720                 return ValuePool.getInt(Types.SQL_UDT); // SQL_UDT
721

722             case Types.TIME :
723
724                 // NO: This is the _concise_ code, whereas what we want to
725
// return here is the Data Type Code column value from
726
// Table 38 in the SQL 200n FCD. This method is used
727
// by DatabaseInformationMain to list the sql type
728
// column in the SYSTEM_TYPEINFO table, which is specified
729
// by JDBC as the sql data type code, not the concise code.
730
// That is why there is a sql datetime sub column
731
// specified as well.
732
// return ValuePool.getInt(Types.SQL_TIME); // fredt - was SQL_DATETIME
733
return ValuePool.getInt(Types.SQL_DATETIME);
734
735             case Types.TIMESTAMP :
736
737                 // NO: This is the _concise_ code, whereas what we want to
738
// return here is the Data Type Code column value from
739
// Table 38 in the SQL CLI 200n FCD. This method is used
740
// by DatabaseInformationMain to list the sql type
741
// column in the SYSTEM_TYPEINFO table, which is specified
742
// by JDBC as the sql data type code, not the concise code.
743
// That is why there is a sql datetime sub column
744
// specified as well.
745
// return ValuePool.getInt(Types.SQL_TIMESTAMP); // fredt - was SQL_DATETIME
746
return ValuePool.getInt(Types.SQL_DATETIME);
747
748             case Types.TINYINT :
749                 return ValuePool.getInt(Types.TINYINT); // N/A
750

751             case Types.VARBINARY :
752                 return ValuePool.getInt(Types.SQL_BLOB); // SQL_BIT_VARYING
753

754             case Types.VARCHAR :
755                 return ValuePool.getInt(Types.SQL_VARCHAR); // SQL_VARCHAR
756

757             case Types.XML :
758                 return ValuePool.getInt(Types.SQL_XML); // SQL_XML
759

760             default :
761                 return null;
762         }
763     }
764
765     /**
766      * Retrieves the SQL CLI datetime subcode for the type. <p>
767      *
768      * @return the SQL CLI datetime subcode for the type
769      */

770     Integer JavaDoc getSqlDateTimeSub() {
771
772         switch (type) {
773
774             case Types.DATE :
775                 return ValuePool.getInt(1);
776
777             case Types.TIME :
778                 return ValuePool.getInt(2);
779
780             case Types.TIMESTAMP :
781                 return ValuePool.getInt(3);
782
783             default :
784                 return null;
785         }
786     }
787
788     /**
789      * Retrieve the fully qualified name of the recommended standard Java
790      * primitive, class or java.sql interface mapping for the type. <p>
791      *
792      * @return the fully qualified name of the recommended standard Java
793      * primitive, class or java.sql interface mapping for
794      * the type
795      */

796     String JavaDoc getStdMapClsName() {
797
798         switch (type) {
799
800             case Types.ARRAY :
801                 return "java.sql.Array";
802
803             case Types.BIGINT :
804                 return "long";
805
806             case Types.BINARY :
807             case Types.LONGVARBINARY :
808             case Types.VARBINARY :
809                 return "[B";
810
811             case Types.BOOLEAN :
812                 return "boolean";
813
814             case Types.BLOB :
815                 return "java.sql.Blob";
816
817             case Types.CHAR :
818             case Types.LONGVARCHAR :
819             case Types.VARCHAR :
820                 return "java.lang.String";
821
822             case Types.CLOB :
823                 return "java.sql.Clob";
824
825             case Types.DATALINK :
826                 return "java.net.URL";
827
828             case Types.DATE :
829                 return "java.sql.Date";
830
831             case Types.DECIMAL :
832             case Types.NUMERIC :
833                 return "java.math.BigDecimal";
834
835             case Types.DISTINCT :
836             case Types.JAVA_OBJECT :
837             case Types.OTHER :
838             case Types.XML : // ???
839
return "java.lang.Object";
840
841             case Types.REAL :
842                 return "float";
843
844             case Types.FLOAT :
845             case Types.DOUBLE :
846                 return "double";
847
848             case Types.INTEGER :
849                 return "int";
850
851             case Types.NULL :
852                 return "null";
853
854             case Types.REF :
855                 return "java.sql.Ref";
856
857             case Types.SMALLINT :
858                 return "short";
859
860             case Types.STRUCT :
861                 return "java.sql.Struct";
862
863             case Types.TIME :
864                 return "java.sql.Time";
865
866             case Types.TIMESTAMP :
867                 return "java.sql.Timestamp";
868
869             case Types.TINYINT :
870                 return "byte";
871
872             default :
873                 return null;
874         }
875     }
876
877     /**
878      * Retrieves the data type as an int. <p>
879      *
880      * @return the data type as an int
881      */

882     int getTypeCode() {
883         return type;
884     }
885
886     /**
887      * Retrieves the canonical data type name HSQLDB associates with
888      * the type. <p>
889      *
890      * This typically matches the designated JDBC name, with one or
891      * two exceptions. <p>
892      *
893      * @return the canonical data type name HSQLDB associates with the type
894      */

895     String JavaDoc getTypeName() {
896
897         return typeSub == Types.TYPE_SUB_IGNORECASE
898                ? Types.getTypeName(Types.VARCHAR_IGNORECASE)
899                : Types.getTypeName(type);
900     }
901
902     /**
903      * Retrieves the HSQLDB data subtype as an int. <p>
904      *
905      * @return the HSQLDB data subtype as an int
906      */

907     int getTypeSub() {
908         return this.typeSub;
909     }
910
911     /**
912      * Retrieves whether the type can be an IDENTITY type. <p>
913      *
914      * @return whether the type can be an IDENTITY type.
915      */

916     Boolean JavaDoc isAutoIncrement() {
917
918         switch (type) {
919
920             case Types.DECIMAL :
921             case Types.DOUBLE :
922             case Types.FLOAT :
923             case Types.NUMERIC :
924             case Types.REAL :
925             case Types.SMALLINT :
926             case Types.TINYINT :
927                 return Boolean.FALSE;
928
929             case Types.BIGINT :
930             case Types.INTEGER :
931                 return Boolean.TRUE;
932
933             default :
934                 return null;
935         }
936     }
937
938     /**
939      * Retrieves whether the type is case-sensitive in collations and
940      * comparisons. <p>
941      *
942      * @return whether the type is case-sensitive in collations and
943      * comparisons.
944      */

945     Boolean JavaDoc isCaseSensitive() {
946
947         return typeSub == Types.TYPE_SUB_IGNORECASE ? Boolean.FALSE
948                                                     : Types.isCaseSensitive(
949                                                     type);
950     }
951
952     /**
953      * Retrieves whether, under the current release, class path and hosting
954      * JVM, HSQLDB supports storing this type in table columns. <p>
955      *
956      * This value also typically represents whether HSQLDB supports retrieving
957      * values of this type in the columns of ResultSets.
958      * @return whether, under the current release, class path
959      * and hosting JVM, HSQLDB supports storing this
960      * type in table columns
961      */

962     Boolean JavaDoc isColStClsSupported() {
963
964         return ValuePool.getBoolean(type == Types.NULL ? true
965                                                        : getColStClsName()
966                                                        != null);
967     }
968
969     /**
970      * Retrieves whether values of this type have a fixed precision and
971      * scale. <p>
972      *
973      * @return whether values of this type have a fixed
974      * precision and scale.
975      */

976     Boolean JavaDoc isFixedPrecisionScale() {
977
978         switch (type) {
979
980             case Types.BIGINT :
981             case Types.DECIMAL :
982             case Types.DOUBLE :
983             case Types.FLOAT :
984             case Types.INTEGER :
985             case Types.NUMERIC :
986             case Types.REAL :
987             case Types.SMALLINT :
988             case Types.TINYINT :
989                 return Boolean.FALSE;
990
991             default :
992                 return null;
993         }
994     }
995
996     /**
997      * Retrieve whether the fully qualified name reported by getStdMapClsName()
998      * is supported as a jdbcResultSet.getXXX return type under the current
999      * HSQLDB release, class path and hosting JVM. <p>
1000     *
1001     * @return whether the fully qualified name reported by getStdMapClsName()
1002     * is supported as a jdbcResultSet.getXXX return type under the current
1003     * HSQLDB release, class path and hosting JVM.
1004     */

1005    Boolean JavaDoc isStdMapClsSupported() {
1006
1007        // its ok to use Class.forName here instead of nameSpace.classForName,
1008
// because all standard map classes are loaded by the boot loader
1009
boolean isSup = false;
1010
1011        switch (type) {
1012
1013            case Types.ARRAY : {
1014                try {
1015                    Class.forName("java.sql.Array");
1016
1017                    isSup = true;
1018                } catch (Exception JavaDoc e) {
1019                    isSup = false;
1020                }
1021
1022                break;
1023            }
1024            case Types.BLOB : {
1025                try {
1026                    Class.forName("java.sql.Blob");
1027
1028                    isSup = true;
1029                } catch (Exception JavaDoc e) {
1030                    isSup = false;
1031                }
1032
1033                break;
1034            }
1035            case Types.CLOB : {
1036                try {
1037                    Class.forName("java.sql.Clob");
1038
1039                    isSup = true;
1040                } catch (Exception JavaDoc e) {
1041                    isSup = false;
1042                }
1043
1044                break;
1045            }
1046            case Types.DISTINCT : {
1047                isSup = false;
1048
1049                break;
1050            }
1051            case Types.REF : {
1052                try {
1053                    Class.forName("java.sql.Ref");
1054
1055                    isSup = true;
1056                } catch (Exception JavaDoc e) {
1057                    isSup = false;
1058                }
1059
1060                break;
1061            }
1062            case Types.STRUCT : {
1063                try {
1064                    Class.forName("java.sql.Struct");
1065
1066                    isSup = true;
1067                } catch (Exception JavaDoc e) {
1068                    isSup = false;
1069                }
1070
1071                break;
1072            }
1073            default : {
1074                isSup = (getStdMapClsName() != null);
1075
1076                break;
1077            }
1078        }
1079
1080        return ValuePool.getBoolean(isSup);
1081    }
1082
1083    /**
1084     * Retrieves whether, under the current release, class path and
1085     * hosting JVM, HSQLDB supports passing or receiving this type as
1086     * the value of a procedure column. <p>
1087     *
1088     * @return whether, under the current release, class path and
1089     * hosting JVM, HSQLDB supports passing or receiving
1090     * this type as the value of a procedure column.
1091     */

1092    Boolean JavaDoc isSupportedAsPCol() {
1093
1094        switch (type) {
1095
1096            case Types.NULL : // - for void return type
1097
case Types.JAVA_OBJECT : // - for Connection as first parm and
1098

1099            // Object for return type
1100
case Types.ARRAY : // - for Object[] row of Trigger.fire()
1101
return Boolean.TRUE;
1102
1103            default :
1104                return isSupportedAsTCol();
1105        }
1106    }
1107
1108    /**
1109     * Retrieves whether, under the current release, class path and
1110     * hosting JVM, HSQLDB supports this as the type of a table
1111     * column. <p>
1112     *
1113     * @return whether, under the current release, class path
1114     * and hosting JVM, HSQLDB supports this type
1115     * as the values of a table column
1116     */

1117    Boolean JavaDoc isSupportedAsTCol() {
1118
1119        String JavaDoc columnTypeName;
1120
1121        if (type == Types.NULL) {
1122            return Boolean.FALSE;
1123        }
1124
1125        columnTypeName = Types.getTypeString(type);
1126
1127        return ValuePool.getBoolean(columnTypeName != null);
1128    }
1129
1130    /**
1131     * Retrieves whether values of this type are unsigned. <p>
1132     *
1133     * @return whether values of this type are unsigned
1134     */

1135    Boolean JavaDoc isUnsignedAttribute() {
1136        return Types.isUnsignedAttribute(type);
1137    }
1138
1139    /**
1140     * Assigns the Locale object used to retrieve this object's
1141     * resource bundle dependent values. <p>
1142     *
1143     * @param l the Locale object used to retrieve this object's resource
1144     * bundle dependent values
1145     */

1146    void setLocale(Locale JavaDoc l) {
1147
1148        if (l == null) {
1149            hnd_create_params = hnd_local_names = hnd_remarks = -1;
1150            locale_set = false;
1151
1152            return;
1153        }
1154
1155        Locale JavaDoc oldLocale;
1156
1157        synchronized (BundleHandler.class) {
1158            oldLocale = BundleHandler.getLocale();
1159
1160            BundleHandler.setLocale(l);
1161
1162            hnd_create_params =
1163                BundleHandler.getBundleHandle("data-type-create-parameters",
1164                                              null);
1165            hnd_local_names = BundleHandler.getBundleHandle("data-type-names",
1166                    null);
1167            hnd_remarks = BundleHandler.getBundleHandle("data-type-remarks",
1168                    null);
1169
1170            BundleHandler.setLocale(oldLocale);
1171
1172            locale_set = true;
1173        }
1174    }
1175
1176    /**
1177     * Assigns the SQL data type code on which this object is to report. <p>
1178     *
1179     * @param type the SQL data type code on which this object is to report
1180     */

1181    void setTypeCode(int type) {
1182        this.type = type;
1183    }
1184
1185    /**
1186     * Assigns the HSQLDB data subtype code on which this object is
1187     * to report. <p>
1188     *
1189     * @param typeSub the HSQLDB data subtype code on which this object
1190     * is to report
1191     */

1192    void setTypeSub(int typeSub) {
1193        this.typeSub = typeSub;
1194    }
1195}
1196
Popular Tags