KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quadcap > sql > meta > MetaTypes


1 package com.quadcap.sql.meta;
2
3 /* Copyright 1999 - 2003 Quadcap Software. All rights reserved.
4  *
5  * This software is distributed under the Quadcap Free Software License.
6  * This software may be used or modified for any purpose, personal or
7  * commercial. Open Source redistributions are permitted. Commercial
8  * redistribution of larger works derived from, or works which bundle
9  * this software requires a "Commercial Redistribution License"; see
10  * http://www.quadcap.com/purchase.
11  *
12  * Redistributions qualify as "Open Source" under one of the following terms:
13  *
14  * Redistributions are made at no charge beyond the reasonable cost of
15  * materials and delivery.
16  *
17  * Redistributions are accompanied by a copy of the Source Code or by an
18  * irrevocable offer to provide a copy of the Source Code for up to three
19  * years at the cost of materials and delivery. Such redistributions
20  * must allow further use, modification, and redistribution of the Source
21  * Code under substantially the same terms as this license.
22  *
23  * Redistributions of source code must retain the copyright notices as they
24  * appear in each source code file, these license terms, and the
25  * disclaimer/limitation of liability set forth as paragraph 6 below.
26  *
27  * Redistributions in binary form must reproduce this Copyright Notice,
28  * these license terms, and the disclaimer/limitation of liability set
29  * forth as paragraph 6 below, in the documentation and/or other materials
30  * provided with the distribution.
31  *
32  * The Software is provided on an "AS IS" basis. No warranty is
33  * provided that the Software is free of defects, or fit for a
34  * particular purpose.
35  *
36  * Limitation of Liability. Quadcap Software shall not be liable
37  * for any damages suffered by the Licensee or any third party resulting
38  * from use of the Software.
39  */

40
41 import java.io.IOException JavaDoc;
42
43 import java.util.Vector JavaDoc;
44
45 import java.sql.DatabaseMetaData JavaDoc;
46 import java.sql.SQLException JavaDoc;
47 import java.sql.Types JavaDoc;
48
49 import com.quadcap.sql.Column;
50 import com.quadcap.sql.Row;
51 import com.quadcap.sql.Session;
52
53 import com.quadcap.sql.index.Btree;
54 import com.quadcap.sql.index.BCursor;
55
56 import com.quadcap.sql.types.*;
57
58 import com.quadcap.util.Debug;
59
60 /**
61  * A Cursor supporting the <code>getTypes</code> function.
62  *
63  * @author Stan Bailes
64  */

65 public class MetaTypes extends MetaCursor {
66     static Column[] cols = {
67     new Column("TYPE_NAME", typeString), // 1
68
new Column("DATA_TYPE", typeShort), // 2
69
new Column("PRECISION", typeInt), // 3
70
new Column("LITERAL_PREFIX", typeString), // 4
71
new Column("LITERAL_SUFFIX", typeString), // 5
72
new Column("CREATE_PARAMS", typeString), // 6
73
new Column("NULLABLE", typeShort), // 7
74
new Column("CASE_SENSITIVE", typeBinary), // 8
75
new Column("SEARCHABLE", typeShort), // 9
76
new Column("UNSIGNED_ATTRIBUTE", typeBinary), // 10
77
new Column("FIXED_PREC_SCALE", typeBinary), // 11
78
new Column("AUTO_INCREMENT", typeBinary), // 12
79
new Column("LOCAL_TYPE_NAME", typeString), // 13
80
new Column("MINIMUM_SCALE", typeShort), // 14
81
new Column("MAXIMUM_SCALE", typeShort), // 15
82
new Column("SQL_DATA_TYPE", typeInt), // 16
83
new Column("SQL_DATETIME_SUB", typeInt), // 17
84
new Column("NUM_PREC_RADIX", typeInt), // 18
85
};
86
87     static Type[] types = {
88     TypeBigInt.typeBigInt,
89     TypeBinary.typeBinary,
90     TypeBoolean.typeBoolean,
91     TypeBlob.typeBlob,
92     TypeChar.typeChar,
93         TypeClob.typeClob,
94     TypeDate.typeDate,
95     TypeDecimal.typeDecimal,
96     TypeInt.typeInt,
97     TypeInterval.typeInterval,
98     TypeReal.typeDouble,
99     TypeReal.typeFloat,
100     TypeReal.typeReal,
101     TypeSmallInt.typeSmallInt,
102     TypeTime.typeTime,
103     TypeTimestamp.typeTimestamp,
104     TypeTinyInt.typeTinyInt,
105     TypeVarBinary.typeVarBinary,
106     TypeVarChar.typeVarChar,
107     };
108
109     static int[] sortColumns = { 2 };
110
111     /**
112      * Cursor constructor. We're just a static repository of types
113      */

114     public MetaTypes(Session session)
115     throws SQLException JavaDoc
116     {
117     super(session, null);
118     try {
119         addColumns(cols);
120         for (int i = 0; i < types.length; i++) {
121         addType(types[i]);
122         }
123         sort();
124     } catch (ValueException e) {
125         SQLException JavaDoc te = new SQLException JavaDoc(e.toString(), "Q000R");
126         te.setNextException(e);
127         throw te;
128     }
129     }
130
131     /**
132      * Sort by type
133      */

134     public int[] getSortColumns() {
135     return sortColumns;
136     }
137
138     /**
139      * Helper to build a row for the resultset
140      */

141     void addType(Type type) throws SQLException JavaDoc {
142     Row row = new Row(18);
143     row.set(1, new ValueString(type.getTypeName()));
144     Value dataType = new ValueShort(type.getJDBCType());
145     row.set(2, dataType);
146     row.set(3, new ValueInteger(type.getMaxPrecision()));
147     if (type.isCharType()) {
148         row.set(4, new ValueString("'"));
149         row.set(5, new ValueString("'"));
150     } else {
151         row.set(4, ValueNull.valueNull);
152         row.set(5, ValueNull.valueNull);
153     }
154     row.set(6, new ValueString(type.getCreateParams()));
155     row.set(7, new ValueShort(DatabaseMetaData.typeNullable));
156     row.set(8, ValueBoolean.trueBoolean);
157     row.set(9, new ValueShort(DatabaseMetaData.typeSearchable));
158     row.set(10, new ValueBoolean(!type.isSigned()));
159
160     row.set(11, new ValueBoolean(type.isCurrency()));
161     row.set(12, new ValueBoolean(false));
162     row.set(13, ValueNull.valueNull);
163     row.set(14, new ValueShort(type.getMinScale()));
164     row.set(15, new ValueShort(type.getMaxScale()));
165     row.set(16, ValueNull.valueNull);
166     row.set(17, ValueNull.valueNull);
167     row.set(18, new ValueInteger(10));
168     addRow(row);
169     }
170 }
171
Popular Tags