📄 datadictionaryimpl.java
字号:
* @param schemaName The name of the schema we're interested in. Must not be null. * @param tc TransactionController * * @param raiseError whether an exception should be thrown if the schema does not exist. * * @return The descriptor for the schema. Can be null (not found) if raiseError is false. * * @exception StandardException Thrown on error */ public SchemaDescriptor getSchemaDescriptor(String schemaName, TransactionController tc, boolean raiseError) throws StandardException { /* ** Check for APP and SYS schemas before going any ** further. */ if ( tc == null ) { tc = getTransactionCompile(); } if (getSystemSchemaDescriptor().getSchemaName().equals(schemaName)) { return getSystemSchemaDescriptor(); } else if (getSysIBMSchemaDescriptor().getSchemaName().equals(schemaName)) { // oh you are really asking SYSIBM, if this db is soft upgraded // from pre 52, I may have 2 versions for you, one on disk // (user SYSIBM), one imaginary (builtin). The // one on disk (real one, if it exists), should always be used. if (dictionaryVersion.checkVersion( DataDictionary.DD_VERSION_CS_5_2, null)) { return getSysIBMSchemaDescriptor(); } } /* ** Manual lookup */ SchemaDescriptor sd = locateSchemaRow(schemaName, tc); //if no schema found and schema name is SESSION, then create an //in-memory schema descriptor if (sd == null && getDeclaredGlobalTemporaryTablesSchemaDescriptor().getSchemaName().equals(schemaName)) { return getDeclaredGlobalTemporaryTablesSchemaDescriptor(); } if (sd == null && raiseError) { throw StandardException.newException( SQLState.LANG_SCHEMA_DOES_NOT_EXIST, schemaName); } else { return sd; } } /** * Get the target schema by searching for a matching row * in SYSSCHEMAS by schemaId. Read only scan. * * @param schemaId The id of the schema we're interested in. * If non-null, overrides schemaName * * @param tc TransactionController. If null, one * is gotten off of the language connection context. * * @return The row for the schema * * @exception StandardException Thrown on error */ private SchemaDescriptor locateSchemaRow(UUID schemaId, TransactionController tc) throws StandardException { DataValueDescriptor UUIDStringOrderable; TabInfo ti = coreInfo[SYSSCHEMAS_CORE_NUM]; /* Use UUIDStringOrderable in both start and stop positions for scan */ UUIDStringOrderable = dvf.getCharDataValue(schemaId.toString()); /* Set up the start/stop position for the scan */ ExecIndexRow keyRow = exFactory.getIndexableRow(1); keyRow.setColumn(1, UUIDStringOrderable); return (SchemaDescriptor) getDescriptorViaIndex( SYSSCHEMASRowFactory.SYSSCHEMAS_INDEX2_ID, keyRow, (ScanQualifier [][]) null, ti, (TupleDescriptor) null, (List) null, false); } /** * Get the target schema by searching for a matching row * in SYSSCHEMAS by schema name. Read only scan. * * @param schemaName The name of the schema we're interested in. * If schemaId is null, used to qual. * * @param tc TransactionController. If null, one * is gotten off of the language connection context. * * @return The row for the schema * * @exception StandardException Thrown on error */ private SchemaDescriptor locateSchemaRow(String schemaName, TransactionController tc) throws StandardException { DataValueDescriptor schemaNameOrderable; TabInfo ti = coreInfo[SYSSCHEMAS_CORE_NUM]; /* Use aliasNameOrderable in both start * and stop position for scan. */ schemaNameOrderable = dvf.getVarcharDataValue(schemaName); /* Set up the start/stop position for the scan */ ExecIndexRow keyRow = exFactory.getIndexableRow(1); keyRow.setColumn(1, schemaNameOrderable); return (SchemaDescriptor) getDescriptorViaIndex( SYSSCHEMASRowFactory.SYSSCHEMAS_INDEX1_ID, keyRow, (ScanQualifier [][]) null, ti, (TupleDescriptor) null, (List) null, false); } /** * Get the descriptor for the named schema. If the schemaId * parameter is NULL, it gets the descriptor for the current (default) * schema. Schema descriptors include authorization ids and schema ids. * SQL92 allows a schema to specify a default character set - we will * not support this. Will check default schema for a match * before scanning a system table. * * @param schemaId The id of the schema we're interested in. * If the name is NULL, get the descriptor for the * current schema. * @param tc TransactionController * * * @return The descriptor for the schema. <I> Warning: <\I> may * return NULL if schemaName is non-NULL and doesn't exist * in SYSSCHEMAS * * @exception StandardException Thrown on error */ public SchemaDescriptor getSchemaDescriptor(UUID schemaId, TransactionController tc) throws StandardException { SchemaDescriptor sd = null; if ( tc == null ) { tc = getTransactionCompile(); } /* ** Check for APP and SYS schemas before going any ** further. */ if (schemaId != null) { if (getSystemSchemaDescriptor().getUUID().equals(schemaId)) { return getSystemSchemaDescriptor(); } else if (getSysIBMSchemaDescriptor().getUUID().equals(schemaId)) { return getSysIBMSchemaDescriptor(); } } /* ** If we aren't booting, lets see if we already ** have the descriptor. If we are in the middle ** of booting we cannot get the LanguageConnectionContext. */ if (!booting) { LanguageConnectionContext lcc = getLCC(); if (lcc != null) { sd = lcc.getDefaultSchema(); if ((sd != null) && ((schemaId == null) || schemaId.equals(sd.getUUID()))) { return sd; } } } return locateSchemaRow(schemaId, tc); } /** * @see DataDictionary#addDescriptor */ public void addDescriptor(TupleDescriptor td, TupleDescriptor parent, int catalogNumber, boolean duplicatesAllowed, TransactionController tc) throws StandardException { addDescriptorNow(td, parent, catalogNumber, duplicatesAllowed, tc, true); } private void addDescriptorNow(TupleDescriptor td, TupleDescriptor parent, int catalogNumber, boolean duplicatesAllowed, TransactionController tc, boolean wait) throws StandardException { TabInfo ti = (catalogNumber < NUM_CORE) ? coreInfo[catalogNumber] : getNonCoreTI(catalogNumber); ExecRow row = ti.getCatalogRowFactory().makeRow(td, parent); int insertRetCode = ti.insertRow(row, tc, wait); if (!duplicatesAllowed) { if (insertRetCode != TabInfo.ROWNOTDUPLICATE) throw duplicateDescriptorException(td, parent); } } private StandardException duplicateDescriptorException(TupleDescriptor tuple, TupleDescriptor parent) { if (parent != null) return StandardException.newException(SQLState.LANG_OBJECT_ALREADY_EXISTS_IN_OBJECT, tuple.getDescriptorType(), tuple.getDescriptorName(), parent.getDescriptorType(), parent.getDescriptorName()); else return StandardException.newException(SQLState.LANG_OBJECT_ALREADY_EXISTS, tuple.getDescriptorType(), tuple.getDescriptorName()); } /** array version of addDescriptor. * @see DataDictionary#addDescriptor */ public void addDescriptorArray(TupleDescriptor[] td, TupleDescriptor parent, int catalogNumber, boolean allowDuplicates, TransactionController tc) throws StandardException { TabInfo ti = (catalogNumber < NUM_CORE) ? coreInfo[catalogNumber] : getNonCoreTI(catalogNumber); CatalogRowFactory crf = ti.getCatalogRowFactory(); ExecRow[] rl = new ExecRow[td.length]; for (int index = 0; index < td.length; index++) { ExecRow row = crf.makeRow(td[index], parent); rl[index] = row; } int insertRetCode = ti.insertRowList( rl, tc ); if (!allowDuplicates && insertRetCode != TabInfo.ROWNOTDUPLICATE) { throw duplicateDescriptorException(td[insertRetCode], parent); } } /** * Drop the descriptor for a schema, given the schema's name * * @param schemaName The name of the schema to drop * @param tc TransactionController for the transaction * * @return Nothing * * @exception StandardException Thrown on error */ public void dropSchemaDescriptor(String schemaName, TransactionController tc) throws StandardException { ExecIndexRow keyRow1 = null; DataValueDescriptor schemaNameOrderable; TabInfo ti = coreInfo[SYSSCHEMAS_CORE_NUM]; if (SanityManager.DEBUG) { SchemaDescriptor sd = getSchemaDescriptor(schemaName, getTransactionCompile(), true); if (!isSchemaEmpty(sd)) { SanityManager.THROWASSERT("Attempt to drop schema "+schemaName+" that is not empty"); } } /* Use schemaNameOrderable in both start * and stop position for index 1 scan. */ schemaNameOrderable = dvf.getVarcharDataValue(schemaName); /* Set up the start/stop position for the scan */ keyRow1 = exFactory.getIndexableRow(1); keyRow1.setColumn(1, schemaNameOrderable); ti.deleteRow( tc, keyRow1, SYSSCHEMASRowFactory.SYSSCHEMAS_INDEX1_ID ); } /** * Get the descriptor for the named table within the given schema. * If the schema parameter is NULL, it looks for the table in the * current (default) schema. Table descriptors include object ids, * object types (table, view, etc.) * * @param tableName The name of the table to get the descriptor for * @param schema The descriptor for the schema the table lives in. * If null, use the system schema. * * @return The descriptor for the table, null if table does not * exist. * * @exception StandardException Thrown on failure */ public TableDescriptor getTableDescriptor(String tableName, SchemaDescriptor schema) throws StandardException { TableDescriptor retval = null; /* ** If we didn't get a schema descriptor, we had better ** have a system table. */ if (SanityManager.DEBUG) { if ((schema == null) && !tableName.startsWith("SYS")) { SanityManager.THROWASSERT("null schema for non system table "+tableName); } } SchemaDescriptor sd = (schema == null) ? getSystemSchemaDescriptor() : schema; UUID schemaUUID = sd.getUUID(); TableKey tableKey = new TableKey(schemaUUID, tableName); /* Only use the cache if we're in compile-only mode */ if (getCacheMode() == DataDictionary.COMPILE_ONLY_MODE) { NameTDCacheable cacheEntry = (NameTDCacheable) nameTdCache.find(tableKey); if (cacheEntry != null) { retval = cacheEntry.getTableDescriptor(); // bind in previous command might have set refernced cols retval.setReferencedColumnMap(null); nameTdCache.release(cacheEntry); } return retval; } return getTableDescriptorIndex1Scan(tableName, schemaUUID.toString()); } /** * Scan systables_index1 (tablename, schemaid) for a match. * * @return TableDescriptor The matching descriptor, if any. * * @exception StandardException Thrown on failure */ private TableDescriptor getTableDescriptorIndex1Scan( String tableName, String schemaUUID) throws StandardException { DataValueDescriptor schemaIDOrderable; DataValueDescriptor tableNameOrderable; TableDescriptor td; TabInfo ti = coreInfo[SYSTABLES_CORE_NUM]; /* Use tableNameOrderable and schemaIdOrderable in both start * and stop position for scan. */ tableNameOrderable = dvf.getVarcharDataValue(tableName); schemaIDOrderable = dvf.getCharDataValue(schemaUUID); /* Set up the start/stop position for the scan */ ExecIndexRow keyRow = exFactory.getIndexableRow(2);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -