KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > catalog > SystemColumnImpl


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.catalog.SystemColumnImpl
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.sql.catalog;
23
24 import java.sql.Types JavaDoc;
25
26 import org.apache.derby.iapi.sql.dictionary.SystemColumn;
27 import org.apache.derby.iapi.error.StandardException;
28 import org.apache.derby.iapi.types.DataTypeDescriptor;
29 import org.apache.derby.iapi.types.DataValueDescriptor;
30 import org.apache.derby.iapi.types.DataValueFactory;
31 import org.apache.derby.iapi.types.TypeId;
32
33 /**
34  * Implements the description of a column in a system table.
35  *
36  *
37  * @version 0.1
38  * @author Rick Hillegas
39  */

40
41 class SystemColumnImpl implements SystemColumn
42 {
43     private final String JavaDoc name;
44    
45     /**
46      * Fully described type of the column.
47      */

48     private final DataTypeDescriptor type;
49     
50     /**
51      * Create a system column for a builtin type.
52      *
53      * @param name
54      * name of column
55      * @param jdbcTypeId
56      * JDBC type id from java.sql.Types
57      * @param nullability
58      * Whether or not column accepts nulls.
59      */

60     static SystemColumn getColumn(String JavaDoc name, int jdbcTypeId,
61             boolean nullability) {
62         return new SystemColumnImpl(name, DataTypeDescriptor
63                 .getBuiltInDataTypeDescriptor(jdbcTypeId, nullability));
64     }
65     
66     /**
67      * Create a system column for a builtin type.
68      *
69      * @param name
70      * name of column
71      * @param jdbcTypeId
72      * JDBC type id from java.sql.Types
73      * @param nullability
74      * Whether or not column accepts nulls.
75      */

76     static SystemColumn getColumn(String JavaDoc name, int jdbcTypeId,
77             boolean nullability,int maxLength) {
78         return new SystemColumnImpl(name, DataTypeDescriptor
79                 .getBuiltInDataTypeDescriptor(jdbcTypeId, nullability, maxLength));
80     }
81     
82     /**
83      * Create a system column for an identifer with consistent type of
84      * VARCHAR(128)
85      *
86      * @param name
87      * Name of the column.
88      * @param nullability
89      * Nullability of the column.
90      * @return Object representing the column.
91      */

92     static SystemColumn getIdentifierColumn(String JavaDoc name, boolean nullability) {
93         return new SystemColumnImpl(name, DataTypeDescriptor
94                 .getBuiltInDataTypeDescriptor(Types.VARCHAR, nullability, 128));
95     }
96
97     /**
98      * Create a system column for a character representation of a UUID with
99      * consistent type of CHAR(36)
100      *
101      * @param name
102      * Name of the column.
103      * @param nullability
104      * Nullability of the column.
105      * @return Object representing the column.
106      */

107     static SystemColumn getUUIDColumn(String JavaDoc name, boolean nullability) {
108         return new SystemColumnImpl(name, DataTypeDescriptor
109                 .getBuiltInDataTypeDescriptor(Types.CHAR, nullability, 36));
110     }
111
112     /**
113      * Create a system column for a character representation of an indicator
114      * column with consistent type of CHAR(1) NOT NULL
115      *
116      * @param name
117      * Name of the column.
118      * @return Object representing the column.
119      */

120     static SystemColumn getIndicatorColumn(String JavaDoc name) {
121         return new SystemColumnImpl(name, DataTypeDescriptor
122                 .getBuiltInDataTypeDescriptor(Types.CHAR, false, 1));
123     }
124
125     /**
126      * Create a system column for a java column.
127      *
128      * @param name
129      * Name of the column.
130      * @param javaClassName
131      * @param nullability
132      * Nullability of the column.
133      * @return Object representing the column.
134      */

135     static SystemColumn getJavaColumn(String JavaDoc name, String JavaDoc javaClassName,
136             boolean nullability) {
137
138         TypeId typeId = TypeId.getUserDefinedTypeId(javaClassName, false);
139
140         DataTypeDescriptor dtd = new DataTypeDescriptor(typeId, nullability);
141         return new SystemColumnImpl(name, dtd);
142     }
143
144     /**
145      * Create a SystemColumnImpl representing the given name and type.
146      */

147     private SystemColumnImpl(String JavaDoc name, DataTypeDescriptor type) {
148         this.name = name;
149         this.type = type;
150     }
151
152     /**
153      * Constructor to create a description of a column in a system table.
154      *
155      * @param name
156      * of column.
157      * @param id
158      * of column.
159      * @param nullability
160      * Whether or not column accepts nulls.
161      * @param dataType
162      * Datatype of column.
163      * @param maxLength
164      * Maximum length of data in column.
165      */

166     SystemColumnImpl( String JavaDoc name,
167                                 int id,
168                                 boolean nullability,
169                                 String JavaDoc dataType,
170                                 boolean builtInType,
171                                 int maxLength )
172     {
173         this.name = name;
174         
175         TypeId typeId;
176
177         if (builtInType)
178         {
179             typeId = TypeId.getBuiltInTypeId(dataType);
180         }
181         else
182         {
183
184             typeId = TypeId.getUserDefinedTypeId(dataType, false);
185         }
186
187         this.type = new DataTypeDescriptor(
188                                typeId,
189                                0,
190                                0,
191                                nullability,
192                                maxLength
193                                );
194     }
195     SystemColumnImpl( String JavaDoc name,
196             int id,
197             int ignoreP,
198             int ignoreS,
199             boolean nullability,
200             String JavaDoc dataType,
201             boolean builtInType,
202             int maxLength )
203 {
204         this(name, id, nullability, dataType, builtInType, maxLength);
205 }
206
207     /**
208      * Constructor to create a description of a column in a system table.
209      * This constructor is used for SQL Identifiers (varchar 128).
210      *
211      * @param name of column.
212      * @param id of column.
213      * @param nullability Whether or not column accepts nulls.
214      */

215     SystemColumnImpl( String JavaDoc name,
216                                 int id,
217                                 boolean nullability)
218     {
219         this(name, id, nullability, "VARCHAR", true, 128);
220     }
221
222     /**
223      * Gets the name of this column.
224      *
225      * @return The column name.
226      */

227     public String JavaDoc getName()
228     {
229         return name;
230     }
231
232     /**
233      * Return the type of this column.
234      */

235     public DataTypeDescriptor getType() {
236         return type;
237     }
238 }
239
240
Popular Tags