001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.catalog.SYSSCHEMASRowFactory
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.DataTypeDescriptor;
025: import org.apache.derby.iapi.types.TypeId;
026: import org.apache.derby.iapi.types.DataValueDescriptor;
027:
028: import org.apache.derby.iapi.types.TypeId;
029: import org.apache.derby.iapi.sql.dictionary.SystemColumn;
030: import org.apache.derby.catalog.TypeDescriptor;
031:
032: import org.apache.derby.iapi.types.DataValueFactory;
033: import org.apache.derby.iapi.types.RowLocation;
034:
035: import org.apache.derby.iapi.sql.dictionary.CatalogRowFactory;
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.SchemaDescriptor;
039: import org.apache.derby.iapi.sql.dictionary.TupleDescriptor;
040:
041: import org.apache.derby.iapi.sql.execute.ExecutionFactory;
042: import org.apache.derby.iapi.sql.execute.ExecIndexRow;
043: import org.apache.derby.iapi.sql.execute.ExecRow;
044:
045: import org.apache.derby.iapi.error.StandardException;
046:
047: import org.apache.derby.iapi.services.monitor.Monitor;
048: import org.apache.derby.catalog.UUID;
049: import org.apache.derby.iapi.services.uuid.UUIDFactory;
050:
051: import org.apache.derby.iapi.services.sanity.SanityManager;
052:
053: /**
054: * Factory for creating a SYSSCHEMAS row.
055: *
056: *
057: * @version 0.1
058: * @author Jamie
059: */
060:
061: public class SYSSCHEMASRowFactory extends CatalogRowFactory {
062: private static final String TABLENAME_STRING = "SYSSCHEMAS";
063:
064: public static final int SYSSCHEMAS_COLUMN_COUNT = 3;
065: /* Column #s for sysinfo (1 based) */
066: public static final int SYSSCHEMAS_SCHEMAID = 1;
067: public static final int SYSSCHEMAS_SCHEMANAME = 2;
068: public static final int SYSSCHEMAS_SCHEMAAID = 3;
069:
070: protected static final int SYSSCHEMAS_INDEX1_ID = 0;
071: protected static final int SYSSCHEMAS_INDEX2_ID = 1;
072:
073: private static final int[][] indexColumnPositions = {
074: { SYSSCHEMAS_SCHEMANAME }, { SYSSCHEMAS_SCHEMAID } };
075:
076: private static final boolean[] uniqueness = null;
077:
078: private static final String[] uuids = {
079: "80000022-00d0-fd77-3ed8-000a0a0b1900" // catalog UUID
080: , "8000002a-00d0-fd77-3ed8-000a0a0b1900" // heap UUID
081: , "80000024-00d0-fd77-3ed8-000a0a0b1900" // SYSSCHEMAS_INDEX1
082: , "80000026-00d0-fd77-3ed8-000a0a0b1900" // SYSSCHEMAS_INDEX2
083: };
084:
085: /////////////////////////////////////////////////////////////////////////////
086: //
087: // CONSTRUCTORS
088: //
089: /////////////////////////////////////////////////////////////////////////////
090:
091: public SYSSCHEMASRowFactory(UUIDFactory uuidf, ExecutionFactory ef,
092: DataValueFactory dvf, boolean convertIdToLower) {
093: super (uuidf, ef, dvf, convertIdToLower);
094: initInfo(SYSSCHEMAS_COLUMN_COUNT, TABLENAME_STRING,
095: indexColumnPositions, uniqueness, uuids);
096: }
097:
098: /////////////////////////////////////////////////////////////////////////////
099: //
100: // METHODS
101: //
102: /////////////////////////////////////////////////////////////////////////////
103:
104: /**
105: * Make a SYSSCHEMAS row
106: *
107: * @return Row suitable for inserting into SYSSCHEMAS.
108: *
109: * @exception StandardException thrown on failure
110: */
111:
112: public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent)
113: throws StandardException {
114: DataTypeDescriptor dtd;
115: ExecRow row;
116: DataValueDescriptor col;
117: String name = null;
118: UUID oid = null;
119: String uuid = null;
120: String aid = null;
121:
122: if (td != null) {
123: SchemaDescriptor schemaDescriptor = (SchemaDescriptor) td;
124:
125: name = schemaDescriptor.getSchemaName();
126: oid = schemaDescriptor.getUUID();
127: if (oid == null) {
128: oid = getUUIDFactory().createUUID();
129: schemaDescriptor.setUUID(oid);
130: }
131: uuid = oid.toString();
132:
133: aid = schemaDescriptor.getAuthorizationId();
134: }
135:
136: /* Build the row to insert */
137: row = getExecutionFactory()
138: .getValueRow(SYSSCHEMAS_COLUMN_COUNT);
139:
140: /* 1st column is SCHEMAID */
141: row.setColumn(1, dvf.getCharDataValue(uuid));
142:
143: /* 2nd column is SCHEMANAME */
144: row.setColumn(2, dvf.getVarcharDataValue(name));
145:
146: /* 3rd column is SCHEMAAID */
147: row.setColumn(3, dvf.getVarcharDataValue(aid));
148:
149: return row;
150: }
151:
152: ///////////////////////////////////////////////////////////////////////////
153: //
154: // ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
155: //
156: ///////////////////////////////////////////////////////////////////////////
157:
158: /**
159: * Make an Tuple Descriptor out of a SYSSCHEMAS row
160: *
161: * @param row a SYSSCHEMAS row
162: * @param parentTupleDescriptor unused
163: * @param dd dataDictionary
164: *
165: * @return a descriptor equivalent to a SYSSCHEMAS row
166: *
167: * @exception StandardException thrown on failure
168: */
169: public TupleDescriptor buildDescriptor(ExecRow row,
170: TupleDescriptor parentTupleDescriptor, DataDictionary dd)
171: throws StandardException {
172: DataValueDescriptor col;
173: SchemaDescriptor descriptor;
174: String name;
175: UUID id;
176: String aid;
177: String uuid;
178: DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
179:
180: if (SanityManager.DEBUG) {
181: SanityManager.ASSERT(
182: row.nColumns() == SYSSCHEMAS_COLUMN_COUNT,
183: "Wrong number of columns for a SYSSCHEMAS row");
184: }
185:
186: // first column is schemaid (UUID - char(36))
187: col = row.getColumn(1);
188: uuid = col.getString();
189: id = getUUIDFactory().recreateUUID(uuid);
190:
191: // second column is schemaname (varchar(128))
192: col = row.getColumn(2);
193: name = col.getString();
194:
195: // third column is auid (varchar(128))
196: col = row.getColumn(3);
197: aid = col.getString();
198:
199: descriptor = ddg.newSchemaDescriptor(name, aid, id);
200:
201: return descriptor;
202: }
203:
204: /**
205: * Builds a list of columns suitable for creating this Catalog.
206: *
207: *
208: * @return array of SystemColumn suitable for making this catalog.
209: */
210: public SystemColumn[] buildColumnList() {
211: int index = 0;
212: SystemColumn[] columnList = new SystemColumn[SYSSCHEMAS_COLUMN_COUNT];
213:
214: // describe columns
215:
216: columnList[index++] = new SystemColumnImpl(
217: convertIdCase("SCHEMAID"), // name
218: SYSSCHEMAS_SCHEMAID, // column number
219: 0, // precision
220: 0, // scale
221: false, // nullability
222: "CHAR", // dataType
223: true, // built-in type
224: 36 // maxLength
225: );
226: columnList[index++] = new SystemColumnImpl( // SQL IDENTIFIER
227: convertIdCase("SCHEMANAME"), // column name
228: SYSSCHEMAS_SCHEMANAME, // column number
229: false // nullability
230: );
231:
232: columnList[index++] = new SystemColumnImpl( // SQL IDENTIFIER
233: convertIdCase("AUTHORIZATIONID"), // column name
234: SYSSCHEMAS_SCHEMAAID, // column number
235: false // nullability
236: );
237:
238: return columnList;
239: }
240: }
|