KickJava   Java API By Example, From Geeks To Geeks.

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


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

64
65 public class SYSDEPENDSRowFactory extends CatalogRowFactory
66 {
67     private static final String JavaDoc TABLENAME_STRING = "SYSDEPENDS";
68
69     protected static final int SYSDEPENDS_COLUMN_COUNT = 4;
70     protected static final int SYSDEPENDS_DEPENDENTID = 1;
71     protected static final int SYSDEPENDS_DEPENDENTTYPE = 2;
72     protected static final int SYSDEPENDS_PROVIDERID = 3;
73     protected static final int SYSDEPENDS_PROVIDERTYPE = 4;
74
75     protected static final int SYSDEPENDS_INDEX1_ID = 0;
76     protected static final int SYSDEPENDS_INDEX2_ID = 1;
77
78     
79     private static final boolean[] uniqueness = {
80                                                        false,
81                                                        false
82                                                      };
83
84     private static final int[][] indexColumnPositions =
85     {
86         {SYSDEPENDS_DEPENDENTID},
87         {SYSDEPENDS_PROVIDERID}
88     };
89
90     private static final String JavaDoc[] uuids =
91     {
92          "8000003e-00d0-fd77-3ed8-000a0a0b1900" // catalog UUID
93
,"80000043-00d0-fd77-3ed8-000a0a0b1900" // heap UUID
94
,"80000040-00d0-fd77-3ed8-000a0a0b1900" // SYSDEPENDS_INDEX1
95
,"80000042-00d0-fd77-3ed8-000a0a0b1900" // SYSDEPENDS_INDEX2
96
};
97
98     /////////////////////////////////////////////////////////////////////////////
99
//
100
// CONSTRUCTORS
101
//
102
/////////////////////////////////////////////////////////////////////////////
103

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

118   /**
119      * Make a SYSDEPENDS row
120      *
121      * @param td DependencyDescriptor. If its null then we want to make an empty
122      * row.
123      *
124      * @return Row suitable for inserting into SYSDEPENDS.
125      *
126      * @exception StandardException thrown on failure
127      */

128     public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent)
129                     throws StandardException
130     {
131         DataValueDescriptor col;
132         ExecRow row;
133         String JavaDoc dependentID = null;
134         DependableFinder dependentBloodhound = null;
135         String JavaDoc providerID = null;
136         DependableFinder providerBloodhound = null;
137
138         if (td != null)
139         {
140             DependencyDescriptor dd = (DependencyDescriptor)td;
141             dependentID = dd.getUUID().toString();
142             dependentBloodhound = dd.getDependentFinder();
143             if ( dependentBloodhound == null )
144             {
145                 throw StandardException.newException(SQLState.DEP_UNABLE_TO_STORE);
146             }
147
148             providerID = dd.getProviderID().toString();
149             providerBloodhound = dd.getProviderFinder();
150             if ( providerBloodhound == null )
151             {
152                 throw StandardException.newException(SQLState.DEP_UNABLE_TO_STORE);
153             }
154
155         }
156
157         /* Insert info into sysdepends */
158
159         /* RESOLVE - It would be nice to require less knowledge about sysdepends
160          * and have this be more table driven.
161          */

162
163         /* Build the row to insert */
164         row = getExecutionFactory().getValueRow(SYSDEPENDS_COLUMN_COUNT);
165
166         /* 1st column is DEPENDENTID (UUID - char(36)) */
167         row.setColumn(SYSDEPENDS_DEPENDENTID, dvf.getCharDataValue(dependentID));
168
169         /* 2nd column is DEPENDENTFINDER */
170         row.setColumn(SYSDEPENDS_DEPENDENTTYPE,
171                 dvf.getDataValue(dependentBloodhound));
172
173         /* 3rd column is PROVIDERID (UUID - char(36)) */
174         row.setColumn(SYSDEPENDS_PROVIDERID, dvf.getCharDataValue(providerID));
175
176         /* 4th column is PROVIDERFINDER */
177         row.setColumn(SYSDEPENDS_PROVIDERTYPE,
178                 dvf.getDataValue(providerBloodhound));
179
180         return row;
181     }
182
183     ///////////////////////////////////////////////////////////////////////////
184
//
185
// ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
186
//
187
///////////////////////////////////////////////////////////////////////////
188

189     /**
190      * Make a ConstraintDescriptor out of a SYSDEPENDS row
191      *
192      * @param row a SYSDEPENDSS row
193      * @param parentTupleDescriptor Null for this kind of descriptor.
194      * @param dd dataDictionary
195      *
196      * @exception StandardException thrown on failure
197      */

198     public TupleDescriptor buildDescriptor(
199         ExecRow row,
200         TupleDescriptor parentTupleDescriptor,
201         DataDictionary dd )
202                     throws StandardException
203     {
204         DependencyDescriptor dependencyDesc = null;
205
206         if (SanityManager.DEBUG)
207         {
208             SanityManager.ASSERT(
209                 row.nColumns() == SYSDEPENDS_COLUMN_COUNT,
210                 "Wrong number of columns for a SYSDEPENDS row");
211         }
212
213         DataValueDescriptor col;
214         String JavaDoc dependentIDstring;
215         UUID dependentUUID;
216         DependableFinder dependentBloodhound;
217         String JavaDoc providerIDstring;
218         UUID providerUUID;
219         DependableFinder providerBloodhound;
220
221         /* 1st column is DEPENDENTID (UUID - char(36)) */
222         col = row.getColumn(SYSDEPENDS_DEPENDENTID);
223         dependentIDstring = col.getString();
224         dependentUUID = getUUIDFactory().recreateUUID(dependentIDstring);
225
226         /* 2nd column is DEPENDENTTYPE */
227         col = row.getColumn(SYSDEPENDS_DEPENDENTTYPE);
228         dependentBloodhound = (DependableFinder) col.getObject();
229
230         /* 3rd column is PROVIDERID (UUID - char(36)) */
231         col = row.getColumn(SYSDEPENDS_PROVIDERID);
232         providerIDstring = col.getString();
233         providerUUID = getUUIDFactory().recreateUUID(providerIDstring);
234
235         /* 4th column is PROVIDERTYPE */
236         col = row.getColumn(SYSDEPENDS_PROVIDERTYPE);
237         providerBloodhound = (DependableFinder) col.getObject();
238
239         /* now build and return the descriptor */
240         return new DependencyDescriptor(dependentUUID, dependentBloodhound,
241                                            providerUUID, providerBloodhound);
242     }
243
244     /**
245      * Builds a list of columns suitable for creating this Catalog.
246      *
247      *
248      * @return array of SystemColumn suitable for making this catalog.
249      */

250     public SystemColumn[] buildColumnList()
251     {
252         int index = 0;
253         SystemColumn[] columnList = new SystemColumn[SYSDEPENDS_COLUMN_COUNT];
254
255         // describe columns
256

257         columnList[index++] =
258                     new SystemColumnImpl(
259                             convertIdCase( "DEPENDENTID"), // column name
260
SYSDEPENDS_DEPENDENTID, // column number
261
0, // precision
262
0, // scale
263
false, // nullability
264
"CHAR", // dataType
265
true, // built-in type
266
36 // maxLength
267
);
268
269         columnList[index++] =
270                     new SystemColumnImpl(
271                             convertIdCase( "DEPENDENTFINDER"), // column name
272
SYSDEPENDS_DEPENDENTTYPE, // column number
273
0, // precision
274
0, // scale
275
false, // nullability
276
"org.apache.derby.catalog.DependableFinder", // dataType
277
false, // built-in type
278
TypeDescriptor.MAXIMUM_WIDTH_UNKNOWN // maxLength
279
);
280
281         columnList[index++] =
282                     new SystemColumnImpl(
283                             convertIdCase( "PROVIDERID"), // column name
284
SYSDEPENDS_PROVIDERID,
285                             0, // precision
286
0, // scale
287
false, // nullability
288
"CHAR", // datatype
289
true, // built-in type
290
36 // maxLength
291
);
292
293         columnList[index++] =
294                     new SystemColumnImpl(
295                             convertIdCase( "PROVIDERFINDER"), // column name
296
SYSDEPENDS_PROVIDERTYPE, // column number
297
0, // precision
298
0, // scale
299
false, // nullability
300
"org.apache.derby.catalog.DependableFinder", // dataType
301
false, // built-in type
302
TypeDescriptor.MAXIMUM_WIDTH_UNKNOWN // maxLength
303
);
304
305         return columnList;
306     }
307 }
308
Popular Tags