001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.catalog.SYSKEYSRowFactory
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.sql.catalog;
023:
024: import org.apache.derby.iapi.types.TypeId;
025: import org.apache.derby.iapi.sql.dictionary.SystemColumn;
026: import org.apache.derby.catalog.TypeDescriptor;
027:
028: import org.apache.derby.iapi.types.DataValueDescriptor;
029:
030: import org.apache.derby.iapi.types.DataValueFactory;
031: import org.apache.derby.iapi.types.RowLocation;
032:
033: import org.apache.derby.iapi.sql.dictionary.CatalogRowFactory;
034: import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
035: import org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor;
036: import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator;
037: import org.apache.derby.iapi.sql.dictionary.DataDictionary;
038: import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext;
039: import org.apache.derby.iapi.sql.dictionary.KeyConstraintDescriptor;
040: import org.apache.derby.iapi.sql.dictionary.SubKeyConstraintDescriptor;
041: import org.apache.derby.iapi.sql.dictionary.TupleDescriptor;
042:
043: import org.apache.derby.iapi.sql.execute.ExecIndexRow;
044: import org.apache.derby.iapi.sql.execute.ExecutionContext;
045: import org.apache.derby.iapi.sql.execute.ExecRow;
046: import org.apache.derby.iapi.sql.execute.ExecutionFactory;
047:
048: import org.apache.derby.iapi.error.StandardException;
049:
050: import org.apache.derby.iapi.services.sanity.SanityManager;
051:
052: import org.apache.derby.iapi.services.monitor.Monitor;
053: import org.apache.derby.catalog.UUID;
054: import org.apache.derby.iapi.services.uuid.UUIDFactory;
055:
056: import org.apache.derby.catalog.IndexDescriptor;
057:
058: /**
059: * Factory for creating a SYSKEYS row.
060: *
061: * @author jerry
062: */
063:
064: public class SYSKEYSRowFactory extends CatalogRowFactory {
065: private static final String TABLENAME_STRING = "SYSKEYS";
066:
067: protected static final int SYSKEYS_COLUMN_COUNT = 2;
068: protected static final int SYSKEYS_CONSTRAINTID = 1;
069: protected static final int SYSKEYS_CONGLOMERATEID = 2;
070:
071: protected static final int SYSKEYS_INDEX1_ID = 0;
072:
073: private static final boolean[] uniqueness = null;
074:
075: private static final int[][] indexColumnPositions = { { SYSKEYS_CONSTRAINTID } };
076:
077: private static final String[] uuids = {
078: "80000039-00d0-fd77-3ed8-000a0a0b1900" // catalog UUID
079: , "8000003c-00d0-fd77-3ed8-000a0a0b1900" // heap UUID
080: , "8000003b-00d0-fd77-3ed8-000a0a0b1900" // SYSKEYS_INDEX1
081: };
082:
083: /////////////////////////////////////////////////////////////////////////////
084: //
085: // CONSTRUCTORS
086: //
087: /////////////////////////////////////////////////////////////////////////////
088:
089: public SYSKEYSRowFactory(UUIDFactory uuidf, ExecutionFactory ef,
090: DataValueFactory dvf, boolean convertIdToLower) {
091: super (uuidf, ef, dvf, convertIdToLower);
092: initInfo(SYSKEYS_COLUMN_COUNT, TABLENAME_STRING,
093: indexColumnPositions, uniqueness, uuids);
094: }
095:
096: /////////////////////////////////////////////////////////////////////////////
097: //
098: // METHODS
099: //
100: /////////////////////////////////////////////////////////////////////////////
101:
102: /**
103: * Make a SYSKEYS row
104: *
105: * @return Row suitable for inserting into SYSKEYS.
106: *
107: * @exception StandardException thrown on failure
108: */
109: public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent)
110: throws StandardException {
111: DataValueDescriptor col;
112: ExecRow row;
113: UUID oid;
114: String constraintID = null;
115: String conglomerateID = null;
116:
117: if (td != null) {
118: KeyConstraintDescriptor constraint = (KeyConstraintDescriptor) td;
119:
120: /*
121: ** We only allocate a new UUID if the descriptor doesn't already have one.
122: ** For descriptors replicated from a Source system, we already have an UUID.
123: */
124: oid = constraint.getUUID();
125: constraintID = oid.toString();
126:
127: conglomerateID = constraint.getIndexUUIDString();
128: }
129:
130: /* Insert info into syskeys */
131:
132: /* RESOLVE - It would be nice to require less knowledge about syskeys
133: * and have this be more table driven.
134: */
135:
136: /* Build the row to insert */
137: row = getExecutionFactory().getValueRow(SYSKEYS_COLUMN_COUNT);
138:
139: /* 1st column is CONSTRAINTID (UUID - char(36)) */
140: row.setColumn(SYSKEYS_CONSTRAINTID, dvf
141: .getCharDataValue(constraintID));
142: /* 2nd column is CONGLOMERATEID (UUID - char(36)) */
143: row.setColumn(SYSKEYS_CONGLOMERATEID, dvf
144: .getCharDataValue(conglomerateID));
145:
146: return row;
147: }
148:
149: ///////////////////////////////////////////////////////////////////////////
150: //
151: // ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
152: //
153: ///////////////////////////////////////////////////////////////////////////
154:
155: /**
156: * Make a SubConstraintDescriptor out of a SYSKEYS row
157: *
158: * @param row a SYSKEYS row
159: * @param parentTupleDescriptor Null for this kind of descriptor.
160: * @param dd dataDictionary
161: *
162: * @exception StandardException thrown on failure
163: */
164: public TupleDescriptor buildDescriptor(ExecRow row,
165: TupleDescriptor parentTupleDescriptor, DataDictionary dd)
166: throws StandardException {
167: SubKeyConstraintDescriptor keyDesc = null;
168:
169: if (SanityManager.DEBUG) {
170: SanityManager.ASSERT(
171: row.nColumns() == SYSKEYS_COLUMN_COUNT,
172: "Wrong number of columns for a SYSKEYS row");
173: }
174:
175: DataValueDescriptor col;
176: DataDescriptorGenerator ddg;
177: UUID constraintUUID;
178: UUID conglomerateUUID;
179: String constraintUUIDString;
180: String conglomerateUUIDString;
181:
182: ddg = dd.getDataDescriptorGenerator();
183:
184: /* 1st column is CONSTRAINTID (UUID - char(36)) */
185: col = row.getColumn(SYSKEYS_CONSTRAINTID);
186: constraintUUIDString = col.getString();
187: constraintUUID = getUUIDFactory().recreateUUID(
188: constraintUUIDString);
189:
190: /* 2nd column is CONGLOMERATEID (UUID - char(36)) */
191: col = row.getColumn(SYSKEYS_CONGLOMERATEID);
192: conglomerateUUIDString = col.getString();
193: conglomerateUUID = getUUIDFactory().recreateUUID(
194: conglomerateUUIDString);
195:
196: /* now build and return the descriptor */
197:
198: keyDesc = new SubKeyConstraintDescriptor(constraintUUID,
199: conglomerateUUID);
200: return keyDesc;
201: }
202:
203: /**
204: * Builds a list of columns suitable for creating this Catalog.
205: *
206: *
207: * @return array of SystemColumn suitable for making this catalog.
208: */
209: public SystemColumn[] buildColumnList() {
210: int index = 0;
211: SystemColumn[] columnList = new SystemColumn[SYSKEYS_COLUMN_COUNT];
212:
213: // describe columns
214:
215: columnList[index++] = new SystemColumnImpl(
216: convertIdCase("CONSTRAINTID"), // column name
217: SYSKEYS_CONSTRAINTID, // column number
218: 0, // precision
219: 0, // scale
220: false, // nullability
221: "CHAR", // dataType
222: true, // built-in type
223: 36 // maxLength
224: );
225:
226: columnList[index++] = new SystemColumnImpl(
227: convertIdCase("CONGLOMERATEID"), // column name
228: SYSKEYS_CONGLOMERATEID, // column number
229: 0, // precision
230: 0, // scale
231: false, // nullability
232: "CHAR", // dataType
233: true, // built-in type
234: 36 // maxLength
235: );
236:
237: return columnList;
238: }
239:
240: }
|