KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.catalog.SYSKEYSRowFactory
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.TypeId;
25 import org.apache.derby.iapi.sql.dictionary.SystemColumn;
26 import org.apache.derby.catalog.TypeDescriptor;
27
28 import org.apache.derby.iapi.types.DataValueDescriptor;
29
30 import org.apache.derby.iapi.types.DataValueFactory;
31 import org.apache.derby.iapi.types.RowLocation;
32
33 import org.apache.derby.iapi.sql.dictionary.CatalogRowFactory;
34 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
35 import org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor;
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.DataDictionaryContext;
39 import org.apache.derby.iapi.sql.dictionary.KeyConstraintDescriptor;
40 import org.apache.derby.iapi.sql.dictionary.SubKeyConstraintDescriptor;
41 import org.apache.derby.iapi.sql.dictionary.TupleDescriptor;
42
43 import org.apache.derby.iapi.sql.execute.ExecIndexRow;
44 import org.apache.derby.iapi.sql.execute.ExecutionContext;
45 import org.apache.derby.iapi.sql.execute.ExecRow;
46 import org.apache.derby.iapi.sql.execute.ExecutionFactory;
47
48 import org.apache.derby.iapi.error.StandardException;
49
50 import org.apache.derby.iapi.services.sanity.SanityManager;
51
52 import org.apache.derby.iapi.services.monitor.Monitor;
53 import org.apache.derby.catalog.UUID;
54 import org.apache.derby.iapi.services.uuid.UUIDFactory;
55
56 import org.apache.derby.catalog.IndexDescriptor;
57
58 /**
59  * Factory for creating a SYSKEYS row.
60  *
61  * @author jerry
62  */

63
64 public class SYSKEYSRowFactory extends CatalogRowFactory
65 {
66     private static final String JavaDoc TABLENAME_STRING = "SYSKEYS";
67
68     protected static final int SYSKEYS_COLUMN_COUNT = 2;
69     protected static final int SYSKEYS_CONSTRAINTID = 1;
70     protected static final int SYSKEYS_CONGLOMERATEID = 2;
71
72     protected static final int SYSKEYS_INDEX1_ID = 0;
73
74     private static final boolean[] uniqueness = null;
75
76     private static final int[][] indexColumnPositions =
77     {
78         {SYSKEYS_CONSTRAINTID}
79     };
80
81     private static final String JavaDoc[] uuids =
82     {
83          "80000039-00d0-fd77-3ed8-000a0a0b1900" // catalog UUID
84
,"8000003c-00d0-fd77-3ed8-000a0a0b1900" // heap UUID
85
,"8000003b-00d0-fd77-3ed8-000a0a0b1900" // SYSKEYS_INDEX1
86
};
87
88     /////////////////////////////////////////////////////////////////////////////
89
//
90
// CONSTRUCTORS
91
//
92
/////////////////////////////////////////////////////////////////////////////
93

94     public SYSKEYSRowFactory(UUIDFactory uuidf, ExecutionFactory ef, DataValueFactory dvf,
95                                  boolean convertIdToLower)
96     {
97         super(uuidf,ef,dvf,convertIdToLower);
98         initInfo(SYSKEYS_COLUMN_COUNT, TABLENAME_STRING, indexColumnPositions, uniqueness, uuids );
99     }
100
101     /////////////////////////////////////////////////////////////////////////////
102
//
103
// METHODS
104
//
105
/////////////////////////////////////////////////////////////////////////////
106

107   /**
108      * Make a SYSKEYS row
109      *
110      * @return Row suitable for inserting into SYSKEYS.
111      *
112      * @exception StandardException thrown on failure
113      */

114     public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent)
115                     throws StandardException
116     {
117         DataValueDescriptor col;
118         ExecRow row;
119         UUID oid;
120         String JavaDoc constraintID = null;
121         String JavaDoc conglomerateID = null;
122
123         if (td != null)
124         {
125             KeyConstraintDescriptor constraint = (KeyConstraintDescriptor)td;
126
127             /*
128             ** We only allocate a new UUID if the descriptor doesn't already have one.
129             ** For descriptors replicated from a Source system, we already have an UUID.
130             */

131             oid = constraint.getUUID();
132             constraintID = oid.toString();
133
134             conglomerateID = constraint.getIndexUUIDString();
135         }
136
137         /* Insert info into syskeys */
138
139         /* RESOLVE - It would be nice to require less knowledge about syskeys
140          * and have this be more table driven.
141          */

142
143         /* Build the row to insert */
144         row = getExecutionFactory().getValueRow(SYSKEYS_COLUMN_COUNT);
145
146         /* 1st column is CONSTRAINTID (UUID - char(36)) */
147         row.setColumn(SYSKEYS_CONSTRAINTID, dvf.getCharDataValue(constraintID));
148         /* 2nd column is CONGLOMERATEID (UUID - char(36)) */
149         row.setColumn(SYSKEYS_CONGLOMERATEID, dvf.getCharDataValue(conglomerateID));
150
151         return row;
152     }
153
154
155
156     ///////////////////////////////////////////////////////////////////////////
157
//
158
// ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
159
//
160
///////////////////////////////////////////////////////////////////////////
161

162     /**
163      * Make a SubConstraintDescriptor out of a SYSKEYS row
164      *
165      * @param row a SYSKEYS row
166      * @param parentTupleDescriptor Null for this kind of descriptor.
167      * @param dd dataDictionary
168      *
169      * @exception StandardException thrown on failure
170      */

171     public TupleDescriptor buildDescriptor(
172         ExecRow row,
173         TupleDescriptor parentTupleDescriptor,
174         DataDictionary dd )
175                     throws StandardException
176     {
177         SubKeyConstraintDescriptor keyDesc = null;
178
179         if (SanityManager.DEBUG)
180         {
181             SanityManager.ASSERT(
182                 row.nColumns() == SYSKEYS_COLUMN_COUNT,
183                 "Wrong number of columns for a SYSKEYS row");
184         }
185
186         DataValueDescriptor col;
187         DataDescriptorGenerator ddg;
188         UUID constraintUUID;
189         UUID conglomerateUUID;
190         String JavaDoc constraintUUIDString;
191         String JavaDoc conglomerateUUIDString;
192
193         ddg = dd.getDataDescriptorGenerator();
194
195         /* 1st column is CONSTRAINTID (UUID - char(36)) */
196         col = row.getColumn(SYSKEYS_CONSTRAINTID);
197         constraintUUIDString = col.getString();
198         constraintUUID = getUUIDFactory().recreateUUID(constraintUUIDString);
199
200         /* 2nd column is CONGLOMERATEID (UUID - char(36)) */
201         col = row.getColumn(SYSKEYS_CONGLOMERATEID);
202         conglomerateUUIDString = col.getString();
203         conglomerateUUID = getUUIDFactory().recreateUUID(conglomerateUUIDString);
204
205         /* now build and return the descriptor */
206
207         keyDesc = new SubKeyConstraintDescriptor(
208                                         constraintUUID,
209                                         conglomerateUUID);
210         return keyDesc;
211     }
212
213     /**
214      * Builds a list of columns suitable for creating this Catalog.
215      *
216      *
217      * @return array of SystemColumn suitable for making this catalog.
218      */

219     public SystemColumn[] buildColumnList()
220     {
221         int index = 0;
222         SystemColumn[] columnList = new SystemColumn[SYSKEYS_COLUMN_COUNT];
223
224         // describe columns
225

226         columnList[index++] =
227                     new SystemColumnImpl(
228                             convertIdCase( "CONSTRAINTID"), // column name
229
SYSKEYS_CONSTRAINTID, // column number
230
0, // precision
231
0, // scale
232
false, // nullability
233
"CHAR", // dataType
234
true, // built-in type
235
36 // maxLength
236
);
237
238         columnList[index++] =
239                     new SystemColumnImpl(
240                             convertIdCase( "CONGLOMERATEID"), // column name
241
SYSKEYS_CONGLOMERATEID, // column number
242
0, // precision
243
0, // scale
244
false, // nullability
245
"CHAR", // dataType
246
true, // built-in type
247
36 // maxLength
248
);
249
250         return columnList;
251     }
252
253 }
254
Popular Tags