KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.catalog.SYSCHECKSRowFactory
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.DataValueDescriptor;
25
26 import org.apache.derby.iapi.types.DataValueFactory;
27
28 import org.apache.derby.iapi.types.TypeId;
29 import org.apache.derby.iapi.types.RowLocation;
30
31 import org.apache.derby.iapi.types.DataTypeDescriptor;
32
33 import org.apache.derby.iapi.sql.dictionary.SystemColumn;
34 import org.apache.derby.iapi.sql.dictionary.CatalogRowFactory;
35 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
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.SubCheckConstraintDescriptor;
40 import org.apache.derby.iapi.sql.dictionary.CheckConstraintDescriptor;
41 import org.apache.derby.iapi.sql.dictionary.TupleDescriptor;
42 import org.apache.derby.iapi.sql.dictionary.ViewDescriptor;
43
44 import org.apache.derby.iapi.sql.execute.ExecutionContext;
45 import org.apache.derby.iapi.sql.execute.ExecIndexRow;
46 import org.apache.derby.iapi.sql.execute.ExecRow;
47 import org.apache.derby.iapi.sql.execute.ExecutionFactory;
48
49 import org.apache.derby.iapi.error.StandardException;
50
51 import org.apache.derby.iapi.services.sanity.SanityManager;
52
53 import org.apache.derby.catalog.ReferencedColumns;
54 import org.apache.derby.catalog.TypeDescriptor;
55 import org.apache.derby.iapi.services.uuid.UUIDFactory;
56 import org.apache.derby.catalog.UUID;
57
58 import java.sql.Types JavaDoc;
59 import java.util.Properties JavaDoc;
60
61 /**
62  * Factory for creating a SYSCHECKS row.
63  *
64  * @author jerry
65  */

66
67 class SYSCHECKSRowFactory extends CatalogRowFactory
68 {
69     private static final String JavaDoc TABLENAME_STRING = "SYSCHECKS";
70
71     private static final int SYSCHECKS_COLUMN_COUNT = 3;
72     private static final int SYSCHECKS_CONSTRAINTID = 1;
73     private static final int SYSCHECKS_CHECKDEFINITION = 2;
74     private static final int SYSCHECKS_REFERENCEDCOLUMNS = 3;
75
76     static final int SYSCHECKS_INDEX1_ID = 0;
77
78     // index is unique.
79
private static final boolean[] uniqueness = null;
80
81     private static final int[][] indexColumnPositions =
82     {
83         {SYSCHECKS_CONSTRAINTID}
84     };
85
86     private static final String JavaDoc[] uuids =
87     {
88          "80000056-00d0-fd77-3ed8-000a0a0b1900" // catalog UUID
89
,"80000059-00d0-fd77-3ed8-000a0a0b1900" // heap UUID
90
,"80000058-00d0-fd77-3ed8-000a0a0b1900" // SYSCHECKS_INDEX1 UUID
91
};
92
93
94
95     /////////////////////////////////////////////////////////////////////////////
96
//
97
// CONSTRUCTORS
98
//
99
/////////////////////////////////////////////////////////////////////////////
100

101     SYSCHECKSRowFactory(UUIDFactory uuidf, ExecutionFactory ef, DataValueFactory dvf,
102                                  boolean convertIdToLower)
103     {
104         super(uuidf,ef,dvf,convertIdToLower);
105         initInfo(SYSCHECKS_COLUMN_COUNT, TABLENAME_STRING, indexColumnPositions, uniqueness, uuids );
106     }
107
108     /////////////////////////////////////////////////////////////////////////////
109
//
110
// METHODS
111
//
112
/////////////////////////////////////////////////////////////////////////////
113

114   /**
115      * Make a SYSCHECKS row
116      *
117      * @param td CheckConstraintDescriptorImpl
118      *
119      * @return Row suitable for inserting into SYSCHECKS.
120      *
121      * @exception StandardException thrown on failure
122      */

123     public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent)
124                     throws StandardException
125     {
126         DataValueDescriptor col;
127         ExecIndexRow row;
128         ReferencedColumns rcd = null;
129         String JavaDoc checkDefinition = null;
130         String JavaDoc constraintID = null;
131
132         if (td != null)
133         {
134             CheckConstraintDescriptor cd = (CheckConstraintDescriptor)td;
135             /*
136             ** We only allocate a new UUID if the descriptor doesn't already have one.
137             ** For descriptors replicated from a Source system, we already have an UUID.
138             */

139             constraintID = cd.getUUID().toString();
140
141             checkDefinition = cd.getConstraintText();
142
143             rcd = cd.getReferencedColumnsDescriptor();
144         }
145
146         /* Build the row */
147         row = getExecutionFactory().getIndexableRow(SYSCHECKS_COLUMN_COUNT);
148
149         /* 1st column is CONSTRAINTID (UUID - char(36)) */
150         row.setColumn(SYSCHECKS_CONSTRAINTID, dvf.getCharDataValue(constraintID));
151
152         /* 2nd column is CHECKDEFINITION */
153         row.setColumn(SYSCHECKS_CHECKDEFINITION,
154                 dvf.getLongvarcharDataValue(checkDefinition));
155
156         /* 3rd column is REFERENCEDCOLUMNS
157          * (user type org.apache.derby.catalog.ReferencedColumns)
158          */

159         row.setColumn(SYSCHECKS_REFERENCEDCOLUMNS,
160             dvf.getDataValue(rcd));
161
162         return row;
163     }
164
165     ///////////////////////////////////////////////////////////////////////////
166
//
167
// ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
168
//
169
///////////////////////////////////////////////////////////////////////////
170

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

180     public TupleDescriptor buildDescriptor(
181         ExecRow row,
182         TupleDescriptor parentTupleDescriptor,
183         DataDictionary dd )
184                     throws StandardException
185     {
186         SubCheckConstraintDescriptor checkDesc = null;
187
188         if (SanityManager.DEBUG)
189         {
190             SanityManager.ASSERT(
191                 row.nColumns() == SYSCHECKS_COLUMN_COUNT,
192                 "Wrong number of columns for a SYSCHECKS row");
193         }
194
195         DataValueDescriptor col;
196         DataDescriptorGenerator ddg;
197         ReferencedColumns referencedColumns;
198         String JavaDoc constraintText;
199         String JavaDoc constraintUUIDString;
200         UUID constraintUUID;
201
202         ddg = dd.getDataDescriptorGenerator();
203
204         /* 1st column is CONSTRAINTID (UUID - char(36)) */
205         col = row.getColumn(SYSCHECKS_CONSTRAINTID);
206         constraintUUIDString = col.getString();
207         constraintUUID = getUUIDFactory().recreateUUID(constraintUUIDString);
208
209         /* 2nd column is CHECKDEFINITION */
210         col = row.getColumn(SYSCHECKS_CHECKDEFINITION);
211         constraintText = col.getString();
212
213         /* 3rd column is REFERENCEDCOLUMNS */
214         col = row.getColumn(SYSCHECKS_REFERENCEDCOLUMNS);
215         referencedColumns =
216             (ReferencedColumns) col.getObject();
217
218         /* now build and return the descriptor */
219
220         checkDesc = new SubCheckConstraintDescriptor(
221                                         constraintUUID,
222                                         constraintText,
223                                         referencedColumns);
224         return checkDesc;
225     }
226
227     /**
228      * Builds a list of columns suitable for creating this Catalog.
229      *
230      *
231      * @return array of SystemColumn suitable for making this catalog.
232      */

233
234     public SystemColumn[] buildColumnList() {
235         
236        return new SystemColumn[] {
237             SystemColumnImpl.getUUIDColumn("CONSTRAINTID", false),
238             SystemColumnImpl.getColumn("CHECKDEFINITION", Types.LONGVARCHAR, false),
239             SystemColumnImpl.getJavaColumn("REFERENCEDCOLUMNS",
240                     "org.apache.derby.catalog.ReferencedColumns", false)
241         };
242     }
243 }
244
Popular Tags