1 21 22 package org.apache.derby.impl.sql.catalog; 23 24 import org.apache.derby.iapi.types.TypeId; 25 import org.apache.derby.iapi.reference.JDBC30Translation; 26 import org.apache.derby.iapi.sql.dictionary.SystemColumn; 27 import org.apache.derby.catalog.TypeDescriptor; 28 29 import org.apache.derby.iapi.types.DataValueDescriptor; 30 31 import org.apache.derby.iapi.types.DataValueFactory; 32 import org.apache.derby.iapi.types.RowLocation; 33 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.AliasDescriptor; 37 import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator; 38 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 39 import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext; 40 import org.apache.derby.iapi.sql.dictionary.TupleDescriptor; 41 42 import org.apache.derby.iapi.sql.execute.ExecutionContext; 43 import org.apache.derby.iapi.sql.execute.ExecIndexRow; 44 import org.apache.derby.iapi.sql.execute.ExecRow; 45 import org.apache.derby.iapi.sql.execute.ExecutionFactory; 46 47 import org.apache.derby.iapi.error.StandardException; 48 49 import org.apache.derby.iapi.services.sanity.SanityManager; 50 51 import org.apache.derby.iapi.services.uuid.UUIDFactory; 52 53 import org.apache.derby.catalog.AliasInfo; 54 import org.apache.derby.catalog.UUID; 55 56 57 80 81 class SYSALIASESRowFactory extends CatalogRowFactory 82 { 83 84 private static final int SYSALIASES_COLUMN_COUNT = 9; 85 private static final int SYSALIASES_ALIASID = 1; 86 private static final int SYSALIASES_ALIAS = 2; 87 private static final int SYSALIASES_SCHEMAID = 3; 88 private static final int SYSALIASES_JAVACLASSNAME = 4; 89 private static final int SYSALIASES_ALIASTYPE = 5; 90 private static final int SYSALIASES_NAMESPACE = 6; 91 private static final int SYSALIASES_SYSTEMALIAS = 7; 92 public static final int SYSALIASES_ALIASINFO = 8; 93 private static final int SYSALIASES_SPECIFIC_NAME = 9; 94 95 96 protected static final int SYSALIASES_INDEX1_ID = 0; 97 98 protected static final int SYSALIASES_INDEX2_ID = 1; 99 100 protected static final int SYSALIASES_INDEX3_ID = 2; 101 102 private static final boolean[] uniqueness = null; 104 105 private static int[][] indexColumnPositions = 106 { 107 {SYSALIASES_SCHEMAID, SYSALIASES_ALIAS, SYSALIASES_NAMESPACE}, 108 {SYSALIASES_ALIASID}, 109 {SYSALIASES_SCHEMAID, SYSALIASES_SPECIFIC_NAME}, 110 }; 111 112 private static final String [] uuids = 113 { 114 "c013800d-00d7-ddbd-08ce-000a0a411400" ,"c013800d-00d7-ddbd-75d4-000a0a411400" ,"c013800d-00d7-ddbe-b99d-000a0a411400" ,"c013800d-00d7-ddbe-c4e1-000a0a411400" ,"c013800d-00d7-ddbe-34ae-000a0a411400" }; 120 121 127 public SYSALIASESRowFactory(UUIDFactory uuidf, ExecutionFactory ef, DataValueFactory dvf, 128 boolean convertIdToLower) 129 { 130 super(uuidf,ef,dvf,convertIdToLower); 131 initInfo(SYSALIASES_COLUMN_COUNT, "SYSALIASES", indexColumnPositions, uniqueness, uuids); 132 } 133 134 140 148 public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) 149 throws StandardException 150 { 151 DataValueDescriptor col; 152 String schemaID = null; 153 String javaClassName = null; 154 String sAliasType = null; 155 String aliasID = null; 156 String aliasName = null; 157 String specificName = null; 158 char cAliasType = AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR; 159 char cNameSpace = AliasInfo.ALIAS_NAME_SPACE_PROCEDURE_AS_CHAR; 160 boolean systemAlias = false; 161 AliasInfo aliasInfo = null; 162 163 if (td != null) { 164 165 AliasDescriptor ad = (AliasDescriptor)td; 166 aliasID = ad.getUUID().toString(); 167 aliasName = ad.getDescriptorName(); 168 schemaID = ad.getSchemaUUID().toString(); 169 javaClassName = ad.getJavaClassName(); 170 cAliasType = ad.getAliasType(); 171 cNameSpace = ad.getNameSpace(); 172 systemAlias = ad.getSystemAlias(); 173 aliasInfo = ad.getAliasInfo(); 174 specificName = ad.getSpecificName(); 175 176 char[] charArray = new char[1]; 177 charArray[0] = cAliasType; 178 sAliasType = new String (charArray); 179 180 if (SanityManager.DEBUG) 181 { 182 switch (cAliasType) 183 { 184 case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR: 185 case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR: 186 case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR: 187 break; 188 189 default: 190 SanityManager.THROWASSERT( 191 "Unexpected value (" + cAliasType + 192 ") for aliasType"); 193 } 194 } 195 } 196 197 198 199 200 203 204 205 ExecRow row = getExecutionFactory().getValueRow(SYSALIASES_COLUMN_COUNT); 206 207 208 row.setColumn(SYSALIASES_ALIASID, dvf.getCharDataValue(aliasID)); 209 210 211 row.setColumn(SYSALIASES_ALIAS, dvf.getVarcharDataValue(aliasName)); 212 214 215 row.setColumn(SYSALIASES_SCHEMAID, dvf.getCharDataValue(schemaID)); 216 217 218 row.setColumn(SYSALIASES_JAVACLASSNAME, dvf.getLongvarcharDataValue(javaClassName)); 219 220 221 row.setColumn(SYSALIASES_ALIASTYPE, dvf.getCharDataValue(sAliasType)); 222 223 224 String sNameSpace = new String (new char[] { cNameSpace }); 225 226 row.setColumn 227 (SYSALIASES_NAMESPACE, dvf.getCharDataValue(sNameSpace)); 228 229 230 231 row.setColumn 232 (SYSALIASES_SYSTEMALIAS, dvf.getDataValue(systemAlias)); 233 234 235 row.setColumn(SYSALIASES_ALIASINFO, 236 dvf.getDataValue(aliasInfo)); 237 238 239 row.setColumn 240 (SYSALIASES_SPECIFIC_NAME, dvf.getVarcharDataValue(specificName)); 241 242 243 return row; 244 } 245 246 252 261 public TupleDescriptor buildDescriptor( 262 ExecRow row, 263 TupleDescriptor parentTupleDescriptor, 264 DataDictionary dd ) 265 throws StandardException 266 { 267 if (SanityManager.DEBUG) 268 { 269 SanityManager.ASSERT( 270 row.nColumns() == SYSALIASES_COLUMN_COUNT, 271 "Wrong number of columns for a SYSALIASES row"); 272 } 273 274 char cAliasType; 275 char cNameSpace; 276 DataValueDescriptor col; 277 String aliasID; 278 UUID aliasUUID; 279 String aliasName; 280 String javaClassName; 281 String sAliasType; 282 String sNameSpace; 283 String typeStr; 284 boolean systemAlias = false; 285 AliasInfo aliasInfo = null; 286 287 288 col = row.getColumn(SYSALIASES_ALIASID); 289 aliasID = col.getString(); 290 aliasUUID = getUUIDFactory().recreateUUID(aliasID); 291 292 293 col = row.getColumn(SYSALIASES_ALIAS); 294 aliasName = col.getString(); 295 296 297 col = row.getColumn(SYSALIASES_SCHEMAID); 298 UUID schemaUUID = col.isNull() ? null : getUUIDFactory().recreateUUID(col.getString()); 299 300 301 col = row.getColumn(SYSALIASES_JAVACLASSNAME); 302 javaClassName = col.getString(); 303 304 305 col = row.getColumn(SYSALIASES_ALIASTYPE); 306 sAliasType = col.getString(); 307 if (SanityManager.DEBUG) 308 { 309 SanityManager.ASSERT(sAliasType.length() == 1, 310 "Fifth column (aliastype) type incorrect"); 311 switch (sAliasType.charAt(0)) 312 { 313 case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR: 314 case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR: 315 case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR: 316 break; 317 318 default: 319 SanityManager.THROWASSERT("Invalid type value '" 320 +sAliasType+ "' for alias"); 321 } 322 } 323 324 cAliasType = sAliasType.charAt(0); 325 326 327 col = row.getColumn(SYSALIASES_NAMESPACE); 328 sNameSpace = col.getString(); 329 if (SanityManager.DEBUG) 330 { 331 SanityManager.ASSERT(sNameSpace.length() == 1, 332 "Sixth column (namespace) type incorrect"); 333 switch (sNameSpace.charAt(0)) 334 { 335 case AliasInfo.ALIAS_NAME_SPACE_PROCEDURE_AS_CHAR: 336 case AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR: 337 case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR: 338 break; 339 340 default: 341 SanityManager.THROWASSERT("Invalid type value '" 342 +sNameSpace+ "' for alias"); 343 } 344 } 345 346 cNameSpace = sNameSpace.charAt(0); 347 348 349 350 col = row.getColumn(SYSALIASES_SYSTEMALIAS); 351 systemAlias = col.getBoolean(); 352 353 354 col = row.getColumn(SYSALIASES_ALIASINFO); 355 aliasInfo = (AliasInfo) col.getObject(); 356 357 358 col = row.getColumn(SYSALIASES_SPECIFIC_NAME); 359 String specificName = col.getString(); 360 361 362 363 return new AliasDescriptor(dd, aliasUUID, aliasName, 364 schemaUUID, javaClassName, cAliasType, 365 cNameSpace, systemAlias, 366 aliasInfo, specificName); 367 } 368 369 378 public SystemColumn[] buildColumnList() 379 { 380 return new SystemColumn[] { 381 382 SystemColumnImpl.getUUIDColumn("ALIASID", false), 383 SystemColumnImpl.getIdentifierColumn("ALIAS", false), 384 SystemColumnImpl.getUUIDColumn("SCHEMAID", true), 385 SystemColumnImpl.getColumn("JAVACLASSNAME", 386 java.sql.Types.LONGVARCHAR, false, Integer.MAX_VALUE), 387 SystemColumnImpl.getIndicatorColumn("ALIASTYPE"), 388 SystemColumnImpl.getIndicatorColumn("NAMESPACE"), 389 SystemColumnImpl.getColumn("SYSTEMALIAS", 390 JDBC30Translation.SQL_TYPES_BOOLEAN, false), 391 SystemColumnImpl.getJavaColumn("ALIASINFO", 392 "org.apache.derby.catalog.AliasInfo", true), 393 SystemColumnImpl.getIdentifierColumn("SPECIFICNAME", false) 394 }; 395 } 396 } 397 | Popular Tags |