1 21 22 package org.apache.derby.impl.sql.catalog; 23 24 import org.apache.derby.iapi.services.context.ContextManager; 25 import org.apache.derby.iapi.services.context.ContextService; 26 27 import org.apache.derby.iapi.services.monitor.Monitor; 28 29 import org.apache.derby.iapi.services.sanity.SanityManager; 30 31 import org.apache.derby.iapi.services.io.StoredFormatIds; 32 import org.apache.derby.iapi.services.io.Formatable; 33 34 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 35 import org.apache.derby.iapi.sql.dictionary.ColumnDescriptor; 36 import org.apache.derby.iapi.sql.dictionary.DefaultDescriptor; 37 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 38 import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext; 39 import org.apache.derby.iapi.sql.dictionary.TableDescriptor; 40 41 import org.apache.derby.iapi.error.StandardException; 42 import org.apache.derby.iapi.error.PublicAPI; 43 44 import org.apache.derby.iapi.services.i18n.MessageService; 45 46 import org.apache.derby.iapi.services.uuid.UUIDFactory; 47 48 import org.apache.derby.catalog.UUID; 49 import org.apache.derby.catalog.Dependable; 50 import org.apache.derby.catalog.DependableFinder; 51 52 import org.apache.derby.iapi.reference.SQLState; 53 54 import java.io.ObjectOutput ; 55 import java.io.ObjectInput ; 56 import java.io.IOException ; 57 58 64 65 public class DDdependableFinder implements DependableFinder, Formatable 66 { 67 73 private transient DataDictionary dataDictionary; 74 private transient UUIDFactory uuidFactory; 75 76 private final int formatId; 77 78 84 87 public DDdependableFinder(int formatId) 88 { 89 this.formatId = formatId; 90 } 91 92 98 public String toString() 99 { 100 return getSQLObjectType(); 101 } 102 103 110 116 public void readExternal( ObjectInput in ) 117 throws IOException , ClassNotFoundException 118 { 119 } 120 121 127 public void writeExternal( ObjectOutput out ) 128 throws IOException 129 { 130 } 131 132 137 public final int getTypeFormatId() 138 { 139 return formatId; 140 } 141 142 148 149 159 public final Dependable getDependable(String dependableObjectID) throws java.sql.SQLException 160 { 161 165 return getDependable(recreateUUID(dependableObjectID)); 166 } 167 168 176 public final Dependable getDependable(UUID dependableObjectID) 177 throws java.sql.SQLException 178 { 179 try 180 { 181 return getDependable(getDataDictionary(),dependableObjectID); 182 } 183 catch (StandardException se) 184 { 185 throw PublicAPI.wrapStandardException(se); 186 } 187 } 188 189 193 public final String getSQLObjectName(String idString) throws java.sql.SQLException 194 { 195 196 try { 197 198 203 return getSQLObjectName(getDataDictionary(), recreateUUID(idString)); 204 } 205 catch (StandardException se) 206 { 207 throw PublicAPI.wrapStandardException( se ); 208 } 209 } 210 211 212 215 public String getSQLObjectType() 216 { 217 switch (formatId) 218 { 219 case StoredFormatIds.ALIAS_DESCRIPTOR_FINDER_V01_ID: 220 return Dependable.ALIAS; 221 222 case StoredFormatIds.CONGLOMERATE_DESCRIPTOR_FINDER_V01_ID: 223 return Dependable.CONGLOMERATE; 224 225 case StoredFormatIds.CONSTRAINT_DESCRIPTOR_FINDER_V01_ID: 226 return Dependable.CONSTRAINT; 227 228 case StoredFormatIds.DEFAULT_DESCRIPTOR_FINDER_V01_ID: 229 return Dependable.DEFAULT; 230 231 case StoredFormatIds.FILE_INFO_FINDER_V01_ID: 232 return Dependable.FILE; 233 234 case StoredFormatIds.SCHEMA_DESCRIPTOR_FINDER_V01_ID: 235 return Dependable.SCHEMA; 236 237 case StoredFormatIds.SPS_DESCRIPTOR_FINDER_V01_ID: 238 return Dependable.STORED_PREPARED_STATEMENT; 239 240 case StoredFormatIds.TABLE_DESCRIPTOR_FINDER_V01_ID: 241 return Dependable.TABLE; 242 243 case StoredFormatIds.COLUMN_DESCRIPTOR_FINDER_V01_ID: 244 return Dependable.COLUMNS_IN_TABLE; 245 246 case StoredFormatIds.TRIGGER_DESCRIPTOR_FINDER_V01_ID: 247 return Dependable.TRIGGER; 248 249 case StoredFormatIds.VIEW_DESCRIPTOR_FINDER_V01_ID: 250 return Dependable.VIEW; 251 252 case StoredFormatIds.TABLE_PERMISSION_FINDER_V01_ID: 253 return Dependable.TABLE_PERMISSION; 254 255 case StoredFormatIds.COLUMNS_PERMISSION_FINDER_V01_ID: 256 return Dependable.COLUMNS_PERMISSION; 257 258 case StoredFormatIds.ROUTINE_PERMISSION_FINDER_V01_ID: 259 return Dependable.ROUTINE_PERMISSION; 260 261 default: 262 if (SanityManager.DEBUG) 263 { 264 SanityManager.THROWASSERT( 265 "getSQLObjectType() called with unexpeced formatId = " + formatId); 266 } 267 return null; 268 } 269 } 270 271 278 private DataDictionary getDataDictionary() 279 throws StandardException 280 { 281 if ( dataDictionary == null ) 282 { 283 ContextManager cm = ContextService.getFactory().getCurrentContextManager(); 284 DataDictionaryContext ddc = (DataDictionaryContext) 285 (cm.getContext(DataDictionaryContext.CONTEXT_ID)); 286 dataDictionary = ddc.getDataDictionary(); 287 } 288 return dataDictionary; 289 } 290 291 298 private UUID recreateUUID(String idString) 299 { 300 if (uuidFactory == null) 301 { 302 uuidFactory = Monitor.getMonitor().getUUIDFactory(); 303 } 304 return uuidFactory.recreateUUID(idString); 305 } 306 307 311 protected Dependable getDependable(DataDictionary dd, UUID dependableObjectID) 312 throws StandardException 313 { 314 switch (formatId) 315 { 316 case StoredFormatIds.ALIAS_DESCRIPTOR_FINDER_V01_ID: 317 return dd.getAliasDescriptor(dependableObjectID); 318 319 case StoredFormatIds.CONGLOMERATE_DESCRIPTOR_FINDER_V01_ID: 320 return dd.getConglomerateDescriptor(dependableObjectID); 321 322 case StoredFormatIds.CONSTRAINT_DESCRIPTOR_FINDER_V01_ID: 323 return dd.getConstraintDescriptor(dependableObjectID); 324 325 case StoredFormatIds.DEFAULT_DESCRIPTOR_FINDER_V01_ID: 326 ColumnDescriptor cd = dd.getColumnDescriptorByDefaultId(dependableObjectID); 327 DefaultDescriptor ddi = new DefaultDescriptor( 328 dd, 329 cd.getDefaultUUID(), cd.getReferencingUUID(), 330 cd.getPosition()); 331 return ddi; 332 333 case StoredFormatIds.FILE_INFO_FINDER_V01_ID: 334 return dd.getFileInfoDescriptor(dependableObjectID); 335 336 case StoredFormatIds.SCHEMA_DESCRIPTOR_FINDER_V01_ID: 337 return dd.getSchemaDescriptor(dependableObjectID, null); 338 339 case StoredFormatIds.SPS_DESCRIPTOR_FINDER_V01_ID: 340 return dd.getSPSDescriptor(dependableObjectID); 341 342 case StoredFormatIds.TABLE_DESCRIPTOR_FINDER_V01_ID: 343 return dd.getTableDescriptor(dependableObjectID); 344 345 case StoredFormatIds.TRIGGER_DESCRIPTOR_FINDER_V01_ID: 346 return dd.getTriggerDescriptor(dependableObjectID); 347 348 case StoredFormatIds.VIEW_DESCRIPTOR_FINDER_V01_ID: 349 return dd.getViewDescriptor(dependableObjectID); 350 351 case StoredFormatIds.COLUMNS_PERMISSION_FINDER_V01_ID: 352 return dd.getColumnPermissions(dependableObjectID); 353 354 case StoredFormatIds.TABLE_PERMISSION_FINDER_V01_ID: 355 return dd.getTablePermissions(dependableObjectID); 356 357 case StoredFormatIds.ROUTINE_PERMISSION_FINDER_V01_ID: 358 return dd.getRoutinePermissions(dependableObjectID); 359 360 default: 361 if (SanityManager.DEBUG) 362 { 363 SanityManager.THROWASSERT( 364 "getDependable() called with unexpeced formatId = " + formatId); 365 } 366 return null; 367 } 368 } 369 370 374 protected String getSQLObjectName(DataDictionary dd, UUID dependableObjectID) 375 throws StandardException 376 { 377 switch (formatId) 378 { 379 case StoredFormatIds.ALIAS_DESCRIPTOR_FINDER_V01_ID: 380 return dd.getAliasDescriptor(dependableObjectID).getDescriptorName(); 381 382 case StoredFormatIds.CONGLOMERATE_DESCRIPTOR_FINDER_V01_ID: 383 return dd.getConglomerateDescriptor(dependableObjectID).getConglomerateName(); 384 385 case StoredFormatIds.CONSTRAINT_DESCRIPTOR_FINDER_V01_ID: 386 return dd.getConstraintDescriptor(dependableObjectID).getConstraintName(); 387 388 case StoredFormatIds.DEFAULT_DESCRIPTOR_FINDER_V01_ID: 389 ColumnDescriptor columnDescriptor = dd.getColumnDescriptorByDefaultId( dependableObjectID ); 390 TableDescriptor tableDescriptor = dd.getTableDescriptor( 391 columnDescriptor.getReferencingUUID()); 392 393 return MessageService.getTextMessage( 394 SQLState.LANG_COLUMN_DEFAULT, 395 tableDescriptor.getQualifiedName() + "." + 396 columnDescriptor.getColumnName()); 397 398 case StoredFormatIds.FILE_INFO_FINDER_V01_ID: 399 return dd.getFileInfoDescriptor(dependableObjectID).getName(); 400 401 case StoredFormatIds.SCHEMA_DESCRIPTOR_FINDER_V01_ID: 402 return dd.getSchemaDescriptor(dependableObjectID, null).getSchemaName(); 403 404 case StoredFormatIds.SPS_DESCRIPTOR_FINDER_V01_ID: 405 return dd.getSPSDescriptor(dependableObjectID).getName(); 406 407 case StoredFormatIds.TABLE_DESCRIPTOR_FINDER_V01_ID: 408 case StoredFormatIds.COLUMN_DESCRIPTOR_FINDER_V01_ID: 409 return getDependable(dd, dependableObjectID).getObjectName(); 410 411 case StoredFormatIds.TRIGGER_DESCRIPTOR_FINDER_V01_ID: 412 return dd.getTriggerDescriptor(dependableObjectID).getName(); 413 414 case StoredFormatIds.VIEW_DESCRIPTOR_FINDER_V01_ID: 415 return dd.getTableDescriptor(dependableObjectID).getName(); 416 417 case StoredFormatIds.COLUMNS_PERMISSION_FINDER_V01_ID: 418 return dd.getColumnPermissions(dependableObjectID).getObjectName(); 419 420 case StoredFormatIds.TABLE_PERMISSION_FINDER_V01_ID: 421 return dd.getTablePermissions(dependableObjectID).getObjectName(); 422 423 case StoredFormatIds.ROUTINE_PERMISSION_FINDER_V01_ID: 424 return dd.getRoutinePermissions(dependableObjectID).getObjectName(); 425 426 default: 427 if (SanityManager.DEBUG) 428 { 429 SanityManager.THROWASSERT( 430 "getSQLObjectName() called with unexpeced formatId = " + formatId); 431 } 432 return null; 433 } 434 } 435 } 436 | Popular Tags |