KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.catalog.SYSSCHEMASRowFactory
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 org.apache.derby.iapi.types.DataTypeDescriptor;
25 import org.apache.derby.iapi.types.TypeId;
26 import org.apache.derby.iapi.types.DataValueDescriptor;
27
28 import org.apache.derby.iapi.types.TypeId;
29 import org.apache.derby.iapi.sql.dictionary.SystemColumn;
30 import org.apache.derby.catalog.TypeDescriptor;
31
32 import org.apache.derby.iapi.types.DataValueFactory;
33 import org.apache.derby.iapi.types.RowLocation;
34
35 import org.apache.derby.iapi.sql.dictionary.CatalogRowFactory;
36 import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator;
37 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
38 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
39 import org.apache.derby.iapi.sql.dictionary.TupleDescriptor;
40
41 import org.apache.derby.iapi.sql.execute.ExecutionFactory;
42 import org.apache.derby.iapi.sql.execute.ExecIndexRow;
43 import org.apache.derby.iapi.sql.execute.ExecRow;
44
45 import org.apache.derby.iapi.error.StandardException;
46
47 import org.apache.derby.iapi.services.monitor.Monitor;
48 import org.apache.derby.catalog.UUID;
49 import org.apache.derby.iapi.services.uuid.UUIDFactory;
50
51 import org.apache.derby.iapi.services.sanity.SanityManager;
52
53 /**
54  * Factory for creating a SYSSCHEMAS row.
55  *
56  *
57  * @version 0.1
58  * @author Jamie
59  */

60
61 public class SYSSCHEMASRowFactory extends CatalogRowFactory
62 {
63     private static final String JavaDoc TABLENAME_STRING = "SYSSCHEMAS";
64
65     public static final int SYSSCHEMAS_COLUMN_COUNT = 3;
66     /* Column #s for sysinfo (1 based) */
67     public static final int SYSSCHEMAS_SCHEMAID = 1;
68     public static final int SYSSCHEMAS_SCHEMANAME = 2;
69     public static final int SYSSCHEMAS_SCHEMAAID = 3;
70
71     protected static final int SYSSCHEMAS_INDEX1_ID = 0;
72     protected static final int SYSSCHEMAS_INDEX2_ID = 1;
73
74
75     private static final int[][] indexColumnPositions =
76     {
77         {SYSSCHEMAS_SCHEMANAME},
78         {SYSSCHEMAS_SCHEMAID}
79     };
80     
81     private static final boolean[] uniqueness = null;
82
83     private static final String JavaDoc[] uuids =
84     {
85          "80000022-00d0-fd77-3ed8-000a0a0b1900" // catalog UUID
86
,"8000002a-00d0-fd77-3ed8-000a0a0b1900" // heap UUID
87
,"80000024-00d0-fd77-3ed8-000a0a0b1900" // SYSSCHEMAS_INDEX1
88
,"80000026-00d0-fd77-3ed8-000a0a0b1900" // SYSSCHEMAS_INDEX2
89
};
90
91     /////////////////////////////////////////////////////////////////////////////
92
//
93
// CONSTRUCTORS
94
//
95
/////////////////////////////////////////////////////////////////////////////
96

97     public SYSSCHEMASRowFactory(UUIDFactory uuidf, ExecutionFactory ef, DataValueFactory dvf,
98                                  boolean convertIdToLower)
99     {
100         super(uuidf,ef,dvf,convertIdToLower);
101         initInfo(SYSSCHEMAS_COLUMN_COUNT, TABLENAME_STRING,
102                  indexColumnPositions, uniqueness, uuids );
103     }
104
105     /////////////////////////////////////////////////////////////////////////////
106
//
107
// METHODS
108
//
109
/////////////////////////////////////////////////////////////////////////////
110

111   /**
112      * Make a SYSSCHEMAS row
113      *
114      * @return Row suitable for inserting into SYSSCHEMAS.
115      *
116      * @exception StandardException thrown on failure
117      */

118
119     public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent)
120                     throws StandardException
121     {
122         DataTypeDescriptor dtd;
123         ExecRow row;
124         DataValueDescriptor col;
125         String JavaDoc name = null;
126         UUID oid = null;
127         String JavaDoc uuid = null;
128         String JavaDoc aid = null;
129
130         if (td != null)
131         {
132             SchemaDescriptor schemaDescriptor = (SchemaDescriptor)td;
133
134             name = schemaDescriptor.getSchemaName();
135             oid = schemaDescriptor.getUUID();
136             if ( oid == null )
137             {
138                 oid = getUUIDFactory().createUUID();
139                 schemaDescriptor.setUUID(oid);
140             }
141             uuid = oid.toString();
142
143             aid = schemaDescriptor.getAuthorizationId();
144         }
145
146         /* Build the row to insert */
147         row = getExecutionFactory().getValueRow(SYSSCHEMAS_COLUMN_COUNT);
148
149         /* 1st column is SCHEMAID */
150         row.setColumn(1, dvf.getCharDataValue(uuid));
151
152         /* 2nd column is SCHEMANAME */
153         row.setColumn(2, dvf.getVarcharDataValue(name));
154
155         /* 3rd column is SCHEMAAID */
156         row.setColumn(3, dvf.getVarcharDataValue(aid));
157
158         return row;
159     }
160
161
162     ///////////////////////////////////////////////////////////////////////////
163
//
164
// ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
165
//
166
///////////////////////////////////////////////////////////////////////////
167

168     /**
169      * Make an Tuple Descriptor out of a SYSSCHEMAS row
170      *
171      * @param row a SYSSCHEMAS row
172      * @param parentTupleDescriptor unused
173      * @param dd dataDictionary
174      *
175      * @return a descriptor equivalent to a SYSSCHEMAS row
176      *
177      * @exception StandardException thrown on failure
178      */

179     public TupleDescriptor buildDescriptor(
180         ExecRow row,
181         TupleDescriptor parentTupleDescriptor,
182         DataDictionary dd )
183                     throws StandardException
184     {
185         DataValueDescriptor col;
186         SchemaDescriptor descriptor;
187         String JavaDoc name;
188         UUID id;
189         String JavaDoc aid;
190         String JavaDoc uuid;
191         DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
192
193         if (SanityManager.DEBUG)
194         {
195             SanityManager.ASSERT(row.nColumns() == SYSSCHEMAS_COLUMN_COUNT,
196                                  "Wrong number of columns for a SYSSCHEMAS row");
197         }
198
199         // first column is schemaid (UUID - char(36))
200
col = row.getColumn(1);
201         uuid = col.getString();
202         id = getUUIDFactory().recreateUUID(uuid);
203
204         // second column is schemaname (varchar(128))
205
col = row.getColumn(2);
206         name = col.getString();
207
208         // third column is auid (varchar(128))
209
col = row.getColumn(3);
210         aid = col.getString();
211
212         descriptor = ddg.newSchemaDescriptor(name, aid, id);
213
214         return descriptor;
215     }
216
217     /**
218      * Builds a list of columns suitable for creating this Catalog.
219      *
220      *
221      * @return array of SystemColumn suitable for making this catalog.
222      */

223     public SystemColumn[] buildColumnList()
224     {
225         int index = 0;
226         SystemColumn[] columnList = new SystemColumn[SYSSCHEMAS_COLUMN_COUNT];
227
228         // describe columns
229

230         columnList[index++] = new SystemColumnImpl(
231                             convertIdCase( "SCHEMAID"), // name
232
SYSSCHEMAS_SCHEMAID, // column number
233
0, // precision
234
0, // scale
235
false, // nullability
236
"CHAR", // dataType
237
true, // built-in type
238
36 // maxLength
239
);
240         columnList[index++] =
241                     new SystemColumnImpl( // SQL IDENTIFIER
242
convertIdCase( "SCHEMANAME"), // column name
243
SYSSCHEMAS_SCHEMANAME, // column number
244
false // nullability
245
);
246
247         columnList[index++] =
248                     new SystemColumnImpl( // SQL IDENTIFIER
249
convertIdCase( "AUTHORIZATIONID"), // column name
250
SYSSCHEMAS_SCHEMAAID, // column number
251
false // nullability
252
);
253
254
255         return columnList;
256     }
257 }
258
Popular Tags