001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.catalog.SYSFILESRowFactory
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.services.monitor.Monitor;
025: import org.apache.derby.iapi.services.sanity.SanityManager;
026: import org.apache.derby.iapi.db.Database;
027: import org.apache.derby.iapi.error.StandardException;
028:
029: import org.apache.derby.iapi.sql.dictionary.CatalogRowFactory;
030: import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator;
031: import org.apache.derby.iapi.sql.dictionary.DataDictionary;
032: import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
033: import org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor;
034: import org.apache.derby.iapi.sql.dictionary.SystemColumn;
035: import org.apache.derby.iapi.sql.dictionary.TupleDescriptor;
036: import org.apache.derby.iapi.types.TypeId;
037: import org.apache.derby.iapi.types.DataValueFactory;
038: import org.apache.derby.iapi.types.RowLocation;
039: import org.apache.derby.iapi.sql.execute.ExecIndexRow;
040: import org.apache.derby.iapi.sql.execute.ExecRow;
041: import org.apache.derby.iapi.sql.execute.ExecutionContext;
042: import org.apache.derby.iapi.sql.execute.ExecutionFactory;
043: import org.apache.derby.iapi.types.DataTypeDescriptor;
044: import org.apache.derby.iapi.types.DataValueDescriptor;
045: import org.apache.derby.iapi.types.TypeId;
046: import org.apache.derby.iapi.services.uuid.UUIDFactory;
047: import org.apache.derby.catalog.TypeDescriptor;
048: import org.apache.derby.catalog.UUID;
049:
050: import java.sql.Types;
051: import java.util.Properties;
052:
053: /**
054: * Factory for creating a SYSFILES row.
055: *
056: *
057: * @version 0.1
058: * @author Rick Hillegas (extracted from DataDictionaryImpl).
059: */
060:
061: class SYSFILESRowFactory extends CatalogRowFactory {
062: private static final String TABLENAME_STRING = "SYSFILES";
063:
064: private static final int SYSFILES_COLUMN_COUNT = 4;
065:
066: /* Column #s (1 based) */
067: private static final int ID_COL_NUM = 1;
068: private static final String ID_COL_NAME = "FILEID";
069:
070: private static final int SCHEMA_ID_COL_NUM = 2;
071: private static final String SCHEMA_ID_COL_NAME = "SCHEMAID";
072:
073: private static final int NAME_COL_NUM = 3;
074: private static final String NAME_COL_NAME = "FILENAME";
075:
076: private static final int GENERATION_ID_COL_NUM = 4;
077: private static final String GENERATION_ID_COL_NAME = "GENERATIONID";
078:
079: static final int SYSFILES_INDEX1_ID = 0;
080: static final int SYSFILES_INDEX2_ID = 1;
081:
082: private static final int[][] indexColumnPositions = {
083: { NAME_COL_NUM, SCHEMA_ID_COL_NUM }, { ID_COL_NUM } };
084:
085: private static final boolean[] uniqueness = null;
086:
087: private static final String[] uuids = {
088: "80000000-00d3-e222-873f-000a0a0b1900", // catalog UUID
089: "80000000-00d3-e222-9920-000a0a0b1900", // heap UUID
090: "80000000-00d3-e222-a373-000a0a0b1900", // SYSSQLFILES_INDEX1
091: "80000000-00d3-e222-be7b-000a0a0b1900" // SYSSQLFILES_INDEX2
092: };
093:
094: /////////////////////////////////////////////////////////////////////////////
095: //
096: // CONSTRUCTORS
097: //
098: /////////////////////////////////////////////////////////////////////////////
099:
100: SYSFILESRowFactory(UUIDFactory uuidf, ExecutionFactory ef,
101: DataValueFactory dvf, boolean convertIdToLower) {
102: super (uuidf, ef, dvf, convertIdToLower);
103: initInfo(SYSFILES_COLUMN_COUNT, TABLENAME_STRING,
104: indexColumnPositions, uniqueness, uuids);
105: }
106:
107: /////////////////////////////////////////////////////////////////////////////
108: //
109: // METHODS
110: //
111: /////////////////////////////////////////////////////////////////////////////
112:
113: /**
114: * Make a SYSFILES row
115: *
116: * @return Row suitable for inserting into SYSFILES
117: *
118: * @exception StandardException thrown on failure
119: */
120:
121: public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent)
122: throws StandardException {
123: String id_S = null;
124: String schemaId_S = null;
125: String SQLname = null;
126: long generationId = 0;
127:
128: ExecRow row;
129:
130: if (td != null) {
131: FileInfoDescriptor descriptor = (FileInfoDescriptor) td;
132: id_S = descriptor.getUUID().toString();
133: schemaId_S = descriptor.getSchemaDescriptor().getUUID()
134: .toString();
135: SQLname = descriptor.getName();
136: generationId = descriptor.getGenerationId();
137: }
138:
139: /* Build the row to insert */
140: row = getExecutionFactory().getValueRow(SYSFILES_COLUMN_COUNT);
141:
142: /* 1st column is ID (UUID - char(36)) */
143: row.setColumn(ID_COL_NUM, dvf.getCharDataValue(id_S));
144:
145: /* 2nd column is SCHEMAID (UUID - char(36)) */
146: row.setColumn(SCHEMA_ID_COL_NUM, dvf
147: .getCharDataValue(schemaId_S));
148:
149: /* 3rd column is NAME (varchar(30)) */
150: row.setColumn(NAME_COL_NUM, dvf.getVarcharDataValue(SQLname));
151:
152: /* 4th column is GENERATIONID (long) */
153: row.setColumn(GENERATION_ID_COL_NUM, dvf
154: .getDataValue(generationId));
155:
156: return row;
157: }
158:
159: ///////////////////////////////////////////////////////////////////////////
160: //
161: // ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
162: //
163: ///////////////////////////////////////////////////////////////////////////
164:
165: /**
166: * Make a descriptor out of a SYSFILES row
167: *
168: * @param row a row
169: * @param parentTupleDescriptor Null for this kind of descriptor.
170: * @param dd dataDictionary
171: *
172: * @return a descriptor equivalent to a row
173: *
174: * @exception StandardException thrown on failure
175: */
176: public TupleDescriptor buildDescriptor(ExecRow row,
177: TupleDescriptor parentTupleDescriptor, DataDictionary dd)
178: throws StandardException {
179: if (SanityManager.DEBUG) {
180: if (row.nColumns() != SYSFILES_COLUMN_COUNT) {
181: SanityManager
182: .THROWASSERT("Wrong number of columns for a SYSFILES row: "
183: + row.nColumns());
184: }
185: }
186:
187: DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
188:
189: String id_S;
190: UUID id;
191: String schemaId_S;
192: UUID schemaId;
193: String name;
194: long generationId;
195: DataValueDescriptor col;
196:
197: SchemaDescriptor schemaDescriptor;
198: FileInfoDescriptor result;
199:
200: /* 1st column is ID (UUID - char(36)) */
201: col = row.getColumn(ID_COL_NUM);
202: id_S = col.getString();
203: id = getUUIDFactory().recreateUUID(id_S);
204:
205: /* 2nd column is SchemaId */
206: col = row.getColumn(SCHEMA_ID_COL_NUM);
207: schemaId_S = col.getString();
208: schemaId = getUUIDFactory().recreateUUID(schemaId_S);
209:
210: schemaDescriptor = dd.getSchemaDescriptor(schemaId, null);
211: if (SanityManager.DEBUG) {
212: if (schemaDescriptor == null) {
213: SanityManager
214: .THROWASSERT("Missing schema for FileInfo: "
215: + id_S);
216: }
217: }
218:
219: /* 3nd column is NAME (varchar(128)) */
220: col = row.getColumn(NAME_COL_NUM);
221: name = col.getString();
222:
223: /* 4th column is generationId (long) */
224: col = row.getColumn(GENERATION_ID_COL_NUM);
225: generationId = col.getLong();
226:
227: result = ddg.newFileInfoDescriptor(id, schemaDescriptor, name,
228: generationId);
229: return result;
230: }
231:
232: /**
233: * Builds a list of columns suitable for creating this Catalog.
234: *
235: *
236: * @return array of SystemColumn suitable for making this catalog.
237: */
238: public SystemColumn[] buildColumnList() {
239: return new SystemColumn[] {
240: SystemColumnImpl.getUUIDColumn(ID_COL_NAME, false),
241: SystemColumnImpl.getUUIDColumn(SCHEMA_ID_COL_NAME,
242: false),
243: SystemColumnImpl.getIdentifierColumn(NAME_COL_NAME,
244: false),
245: SystemColumnImpl.getColumn(GENERATION_ID_COL_NAME,
246: Types.BIGINT, false)
247:
248: };
249: }
250: }
|