KickJava   Java API By Example, From Geeks To Geeks.

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


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

60
61 class SYSFILESRowFactory extends CatalogRowFactory
62 {
63     private static final String JavaDoc TABLENAME_STRING = "SYSFILES";
64
65     private static final int SYSFILES_COLUMN_COUNT = 4;
66
67     /* Column #s (1 based) */
68     private static final int ID_COL_NUM = 1;
69     private static final String JavaDoc ID_COL_NAME = "FILEID";
70
71     private static final int SCHEMA_ID_COL_NUM = 2;
72     private static final String JavaDoc SCHEMA_ID_COL_NAME = "SCHEMAID";
73
74     private static final int NAME_COL_NUM = 3;
75     private static final String JavaDoc NAME_COL_NAME = "FILENAME";
76
77     private static final int GENERATION_ID_COL_NUM = 4;
78     private static final String JavaDoc GENERATION_ID_COL_NAME = "GENERATIONID";
79
80     static final int SYSFILES_INDEX1_ID = 0;
81     static final int SYSFILES_INDEX2_ID = 1;
82
83     private static final int[][] indexColumnPositions =
84     {
85         {NAME_COL_NUM, SCHEMA_ID_COL_NUM},
86         {ID_COL_NUM}
87     };
88
89     private static final boolean[] uniqueness = null;
90
91     private static final String JavaDoc[] uuids =
92     {
93         "80000000-00d3-e222-873f-000a0a0b1900", // catalog UUID
94
"80000000-00d3-e222-9920-000a0a0b1900", // heap UUID
95
"80000000-00d3-e222-a373-000a0a0b1900", // SYSSQLFILES_INDEX1
96
"80000000-00d3-e222-be7b-000a0a0b1900" // SYSSQLFILES_INDEX2
97
};
98
99     /////////////////////////////////////////////////////////////////////////////
100
//
101
// CONSTRUCTORS
102
//
103
/////////////////////////////////////////////////////////////////////////////
104

105     SYSFILESRowFactory(UUIDFactory uuidf, ExecutionFactory ef, DataValueFactory dvf,
106                                  boolean convertIdToLower)
107     {
108         super(uuidf,ef,dvf,convertIdToLower);
109         initInfo(SYSFILES_COLUMN_COUNT, TABLENAME_STRING,
110                  indexColumnPositions, uniqueness, uuids );
111     }
112
113     /////////////////////////////////////////////////////////////////////////////
114
//
115
// METHODS
116
//
117
/////////////////////////////////////////////////////////////////////////////
118

119     /**
120      * Make a SYSFILES row
121      *
122      * @return Row suitable for inserting into SYSFILES
123      *
124      * @exception StandardException thrown on failure
125      */

126
127     public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent)
128                     throws StandardException
129     {
130         String JavaDoc id_S = null;
131         String JavaDoc schemaId_S = null;
132         String JavaDoc SQLname = null;
133         long generationId = 0;
134         
135         ExecRow row;
136
137         if (td != null)
138         {
139             FileInfoDescriptor descriptor = (FileInfoDescriptor)td;
140             id_S = descriptor.getUUID().toString();
141             schemaId_S = descriptor.getSchemaDescriptor().getUUID().toString();
142             SQLname = descriptor.getName();
143             generationId = descriptor.getGenerationId();
144         }
145     
146         /* Build the row to insert */
147         row = getExecutionFactory().getValueRow(SYSFILES_COLUMN_COUNT);
148
149         /* 1st column is ID (UUID - char(36)) */
150         row.setColumn(ID_COL_NUM, dvf.getCharDataValue(id_S));
151
152         /* 2nd column is SCHEMAID (UUID - char(36)) */
153         row.setColumn(SCHEMA_ID_COL_NUM, dvf.getCharDataValue(schemaId_S));
154
155         /* 3rd column is NAME (varchar(30)) */
156         row.setColumn(NAME_COL_NUM, dvf.getVarcharDataValue(SQLname));
157
158         /* 4th column is GENERATIONID (long) */
159         row.setColumn(GENERATION_ID_COL_NUM, dvf.getDataValue(generationId));
160
161         return row;
162     }
163
164     ///////////////////////////////////////////////////////////////////////////
165
//
166
// ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
167
//
168
///////////////////////////////////////////////////////////////////////////
169

170     /**
171      * Make a descriptor out of a SYSFILES row
172      *
173      * @param row a row
174      * @param parentTupleDescriptor Null for this kind of descriptor.
175      * @param dd dataDictionary
176      *
177      * @return a descriptor equivalent to a row
178      *
179      * @exception StandardException thrown on failure
180      */

181     public TupleDescriptor buildDescriptor(
182         ExecRow row,
183         TupleDescriptor parentTupleDescriptor,
184         DataDictionary dd )
185                     throws StandardException
186     {
187         if (SanityManager.DEBUG)
188         {
189             if (row.nColumns() != SYSFILES_COLUMN_COUNT)
190             {
191                 SanityManager.THROWASSERT("Wrong number of columns for a SYSFILES row: "+
192                              row.nColumns());
193             }
194         }
195
196         DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
197
198         String JavaDoc id_S;
199         UUID id;
200         String JavaDoc schemaId_S;
201         UUID schemaId;
202         String JavaDoc name;
203         long generationId;
204         DataValueDescriptor col;
205
206         SchemaDescriptor schemaDescriptor;
207         FileInfoDescriptor result;
208
209         /* 1st column is ID (UUID - char(36)) */
210         col = row.getColumn(ID_COL_NUM);
211         id_S = col.getString();
212         id = getUUIDFactory().recreateUUID(id_S);
213
214         /* 2nd column is SchemaId */
215         col = row.getColumn(SCHEMA_ID_COL_NUM);
216         schemaId_S = col.getString();
217         schemaId = getUUIDFactory().recreateUUID(schemaId_S);
218         
219         schemaDescriptor = dd.getSchemaDescriptor(schemaId, null);
220         if (SanityManager.DEBUG)
221         {
222             if (schemaDescriptor == null)
223             {
224                 SanityManager.THROWASSERT("Missing schema for FileInfo: "+id_S);
225             }
226         }
227
228         /* 3nd column is NAME (varchar(128)) */
229         col = row.getColumn(NAME_COL_NUM);
230         name = col.getString();
231
232         /* 4th column is generationId (long) */
233         col = row.getColumn(GENERATION_ID_COL_NUM);
234         generationId = col.getLong();
235
236         result = ddg.newFileInfoDescriptor(id,schemaDescriptor,name,
237                                            generationId);
238         return result;
239     }
240
241     /**
242      * Builds a list of columns suitable for creating this Catalog.
243      *
244      *
245      * @return array of SystemColumn suitable for making this catalog.
246      */

247     public SystemColumn[] buildColumnList()
248     {
249         return new SystemColumn[] {
250            SystemColumnImpl.getUUIDColumn(ID_COL_NAME, false),
251            SystemColumnImpl.getUUIDColumn(SCHEMA_ID_COL_NAME, false),
252            SystemColumnImpl.getIdentifierColumn(NAME_COL_NAME, false),
253            SystemColumnImpl.getColumn(GENERATION_ID_COL_NAME, Types.BIGINT, false)
254                 
255         };
256     }
257 }
258
Popular Tags