1 21 22 package org.apache.derby.impl.sql.catalog; 23 24 import org.apache.derby.iapi.services.monitor.Monitor; 25 import org.apache.derby.iapi.services.sanity.SanityManager; 26 import org.apache.derby.iapi.db.Database; 27 import org.apache.derby.iapi.error.StandardException; 28 29 import org.apache.derby.iapi.sql.dictionary.CatalogRowFactory; 30 import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator; 31 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 32 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor; 33 import org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor; 34 import org.apache.derby.iapi.sql.dictionary.SystemColumn; 35 import org.apache.derby.iapi.sql.dictionary.TupleDescriptor; 36 import org.apache.derby.iapi.types.TypeId; 37 import org.apache.derby.iapi.types.DataValueFactory; 38 import org.apache.derby.iapi.types.RowLocation; 39 import org.apache.derby.iapi.sql.execute.ExecIndexRow; 40 import org.apache.derby.iapi.sql.execute.ExecRow; 41 import org.apache.derby.iapi.sql.execute.ExecutionContext; 42 import org.apache.derby.iapi.sql.execute.ExecutionFactory; 43 import org.apache.derby.iapi.types.DataTypeDescriptor; 44 import org.apache.derby.iapi.types.DataValueDescriptor; 45 import org.apache.derby.iapi.types.TypeId; 46 import org.apache.derby.iapi.services.uuid.UUIDFactory; 47 import org.apache.derby.catalog.TypeDescriptor; 48 import org.apache.derby.catalog.UUID; 49 50 import java.sql.Types ; 51 import java.util.Properties ; 52 53 60 61 class SYSFILESRowFactory extends CatalogRowFactory 62 { 63 private static final String TABLENAME_STRING = "SYSFILES"; 64 65 private static final int SYSFILES_COLUMN_COUNT = 4; 66 67 68 private static final int ID_COL_NUM = 1; 69 private static final String ID_COL_NAME = "FILEID"; 70 71 private static final int SCHEMA_ID_COL_NUM = 2; 72 private static final String SCHEMA_ID_COL_NAME = "SCHEMAID"; 73 74 private static final int NAME_COL_NUM = 3; 75 private static final String NAME_COL_NAME = "FILENAME"; 76 77 private static final int GENERATION_ID_COL_NUM = 4; 78 private static final String GENERATION_ID_COL_NAME = "GENERATIONID"; 79 80 static final int SYSFILES_INDEX1_ID = 0; 81 static final int SYSFILES_INDEX2_ID = 1; 82 83 private static final int[][] indexColumnPositions = 84 { 85 {NAME_COL_NUM, SCHEMA_ID_COL_NUM}, 86 {ID_COL_NUM} 87 }; 88 89 private static final boolean[] uniqueness = null; 90 91 private static final String [] uuids = 92 { 93 "80000000-00d3-e222-873f-000a0a0b1900", "80000000-00d3-e222-9920-000a0a0b1900", "80000000-00d3-e222-a373-000a0a0b1900", "80000000-00d3-e222-be7b-000a0a0b1900" }; 98 99 105 SYSFILESRowFactory(UUIDFactory uuidf, ExecutionFactory ef, DataValueFactory dvf, 106 boolean convertIdToLower) 107 { 108 super(uuidf,ef,dvf,convertIdToLower); 109 initInfo(SYSFILES_COLUMN_COUNT, TABLENAME_STRING, 110 indexColumnPositions, uniqueness, uuids ); 111 } 112 113 119 126 127 public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) 128 throws StandardException 129 { 130 String id_S = null; 131 String schemaId_S = null; 132 String SQLname = null; 133 long generationId = 0; 134 135 ExecRow row; 136 137 if (td != null) 138 { 139 FileInfoDescriptor descriptor = (FileInfoDescriptor)td; 140 id_S = descriptor.getUUID().toString(); 141 schemaId_S = descriptor.getSchemaDescriptor().getUUID().toString(); 142 SQLname = descriptor.getName(); 143 generationId = descriptor.getGenerationId(); 144 } 145 146 147 row = getExecutionFactory().getValueRow(SYSFILES_COLUMN_COUNT); 148 149 150 row.setColumn(ID_COL_NUM, dvf.getCharDataValue(id_S)); 151 152 153 row.setColumn(SCHEMA_ID_COL_NUM, dvf.getCharDataValue(schemaId_S)); 154 155 156 row.setColumn(NAME_COL_NUM, dvf.getVarcharDataValue(SQLname)); 157 158 159 row.setColumn(GENERATION_ID_COL_NUM, dvf.getDataValue(generationId)); 160 161 return row; 162 } 163 164 170 181 public TupleDescriptor buildDescriptor( 182 ExecRow row, 183 TupleDescriptor parentTupleDescriptor, 184 DataDictionary dd ) 185 throws StandardException 186 { 187 if (SanityManager.DEBUG) 188 { 189 if (row.nColumns() != SYSFILES_COLUMN_COUNT) 190 { 191 SanityManager.THROWASSERT("Wrong number of columns for a SYSFILES row: "+ 192 row.nColumns()); 193 } 194 } 195 196 DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator(); 197 198 String id_S; 199 UUID id; 200 String schemaId_S; 201 UUID schemaId; 202 String name; 203 long generationId; 204 DataValueDescriptor col; 205 206 SchemaDescriptor schemaDescriptor; 207 FileInfoDescriptor result; 208 209 210 col = row.getColumn(ID_COL_NUM); 211 id_S = col.getString(); 212 id = getUUIDFactory().recreateUUID(id_S); 213 214 215 col = row.getColumn(SCHEMA_ID_COL_NUM); 216 schemaId_S = col.getString(); 217 schemaId = getUUIDFactory().recreateUUID(schemaId_S); 218 219 schemaDescriptor = dd.getSchemaDescriptor(schemaId, null); 220 if (SanityManager.DEBUG) 221 { 222 if (schemaDescriptor == null) 223 { 224 SanityManager.THROWASSERT("Missing schema for FileInfo: "+id_S); 225 } 226 } 227 228 229 col = row.getColumn(NAME_COL_NUM); 230 name = col.getString(); 231 232 233 col = row.getColumn(GENERATION_ID_COL_NUM); 234 generationId = col.getLong(); 235 236 result = ddg.newFileInfoDescriptor(id,schemaDescriptor,name, 237 generationId); 238 return result; 239 } 240 241 247 public SystemColumn[] buildColumnList() 248 { 249 return new SystemColumn[] { 250 SystemColumnImpl.getUUIDColumn(ID_COL_NAME, false), 251 SystemColumnImpl.getUUIDColumn(SCHEMA_ID_COL_NAME, false), 252 SystemColumnImpl.getIdentifierColumn(NAME_COL_NAME, false), 253 SystemColumnImpl.getColumn(GENERATION_ID_COL_NAME, Types.BIGINT, false) 254 255 }; 256 } 257 } 258 | Popular Tags |