📄 datadictionaryimpl.java
字号:
keyRow.setColumn(1, tableNameOrderable); keyRow.setColumn(2, schemaIDOrderable); td = (TableDescriptor) getDescriptorViaIndex( SYSTABLESRowFactory.SYSTABLES_INDEX1_ID, keyRow, (ScanQualifier [][]) null, ti, (TupleDescriptor) null, (List) null, false); return finishTableDescriptor(td); } /** * This method can get called from the DataDictionary cache. * * @param tableKey The TableKey of the table * * @return The descriptor for the table, null if the table does * not exist. * * @exception StandardException Thrown on failure */ TableDescriptor getUncachedTableDescriptor(TableKey tableKey) throws StandardException { return getTableDescriptorIndex1Scan(tableKey.getTableName(), tableKey.getSchemaId().toString()); } /** * Get the descriptor for the table with the given UUID. * * NOTE: I'm assuming that the object store will define an UUID for * persistent objects. I'm also assuming that UUIDs are unique across * schemas, and that the object store will be able to do efficient * lookups across schemas (i.e. that no schema descriptor parameter * is needed). * * @param tableID The UUID of the table to get the descriptor for * * @return The descriptor for the table, null if the table does * not exist. * * @exception StandardException Thrown on failure */ public TableDescriptor getTableDescriptor(UUID tableID) throws StandardException { OIDTDCacheable cacheEntry; TableDescriptor retval = null; /* Only use the cache if we're in compile-only mode */ if (getCacheMode() == DataDictionary.COMPILE_ONLY_MODE) { cacheEntry = (OIDTDCacheable) OIDTdCache.find(tableID); if (cacheEntry != null) { retval = cacheEntry.getTableDescriptor(); // bind in previous command might have set refernced cols retval.setReferencedColumnMap(null); OIDTdCache.release(cacheEntry); } return retval; } return getTableDescriptorIndex2Scan(tableID.toString()); } /** * This method can get called from the DataDictionary cache. * * @param tableID The UUID of the table to get the descriptor for * * @return The descriptor for the table, null if the table does * not exist. * * @exception StandardException Thrown on failure */ protected TableDescriptor getUncachedTableDescriptor(UUID tableID) throws StandardException { return getTableDescriptorIndex2Scan(tableID.toString()); } /** * Scan systables_index2 (tableid) for a match. * * @return TableDescriptor The matching descriptor, if any. * * @exception StandardException Thrown on failure */ private TableDescriptor getTableDescriptorIndex2Scan( String tableUUID) throws StandardException { DataValueDescriptor tableIDOrderable; TableDescriptor td; TabInfo ti = coreInfo[SYSTABLES_CORE_NUM]; /* Use tableNameOrderable and schemaIdOrderable in both start * and stop position for scan. */ tableIDOrderable = dvf.getCharDataValue(tableUUID); /* Set up the start/stop position for the scan */ ExecIndexRow keyRow = exFactory.getIndexableRow(1); keyRow.setColumn(1, tableIDOrderable); td = (TableDescriptor) getDescriptorViaIndex( SYSTABLESRowFactory.SYSTABLES_INDEX2_ID, keyRow, (ScanQualifier [][]) null, ti, (TupleDescriptor) null, (List) null, false); return finishTableDescriptor(td); } /** * Finish filling in the TableDescriptor. * (Build the various lists that hang off the TD.) * * @param td The TableDescriptor. * * @return The completed TableDescriptor. * * @exception StandardException Thrown on failure */ private TableDescriptor finishTableDescriptor(TableDescriptor td) throws StandardException { if (td != null) { synchronized(td) { getColumnDescriptorsScan(td); getConglomerateDescriptorsScan(td); } } return td; } /** * Indicate whether there is anything in the * particular schema. Checks for tables in the * the schema, on the assumption that there cannot * be any other objects in a schema w/o a table. * * @param schema descriptor * * @return true/false * * @exception StandardException on error */ public boolean isSchemaEmpty(SchemaDescriptor sd) throws StandardException { DataValueDescriptor schemaIdOrderable; TransactionController tc = getTransactionCompile(); schemaIdOrderable = getValueAsDVD(sd.getUUID()); if (isSchemaReferenced(tc, coreInfo[SYSTABLES_CORE_NUM], SYSTABLESRowFactory.SYSTABLES_INDEX1_ID, SYSTABLESRowFactory.SYSTABLES_INDEX1_SCHEMAID, schemaIdOrderable)) { return false; } if (isSchemaReferenced(tc, getNonCoreTI(SYSCONSTRAINTS_CATALOG_NUM), SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_INDEX2_ID, 2, schemaIdOrderable)) { return false; } if (isSchemaReferenced(tc, getNonCoreTI(SYSSTATEMENTS_CATALOG_NUM), SYSSTATEMENTSRowFactory.SYSSTATEMENTS_INDEX2_ID, 2, schemaIdOrderable)) { return false; } if (isSchemaReferenced(tc, getNonCoreTI(SYSTRIGGERS_CATALOG_NUM), SYSTRIGGERSRowFactory.SYSTRIGGERS_INDEX2_ID, 2, schemaIdOrderable)) { return false; } return true; } /** * Is the schema id referenced by the system table in question? * Currently assumes that the schema id is in an index. * NOTE: could be generalized a bit, and possibly used * elsewhere... * * @param tc transaction controller * @param ti table info for the system table * @param indexId index id * @param indexCol 1 based index column * @param schemaIdOrderable the schemaid in a char orderable * * @return true if there is a reference to this schema * * @exception StandardException on error */ protected boolean isSchemaReferenced(TransactionController tc, TabInfo ti, int indexId, int indexCol, DataValueDescriptor schemaIdOrderable ) throws StandardException { ConglomerateController heapCC = null; ExecIndexRow indexRow1; ExecIndexRow indexTemplateRow; ExecRow outRow; ScanController scanController = null; boolean foundRow; FormatableBitSet colToCheck = new FormatableBitSet(indexCol); CatalogRowFactory rf = ti.getCatalogRowFactory(); if (SanityManager.DEBUG) { SanityManager.ASSERT(indexId >= 0, "code needs to be enhanced"+ " to support a table scan to find the index id"); } colToCheck.set(indexCol - 1); ScanQualifier[][] qualifier = exFactory.getScanQualifier(1); qualifier[0][0].setQualifier (indexCol - 1, schemaIdOrderable, Orderable.ORDER_OP_EQUALS, false, false, false); outRow = rf.makeEmptyRow(); try { heapCC = tc.openConglomerate( ti.getHeapConglomerate(), false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ); scanController = tc.openScan( ti.getIndexConglomerate(indexId), // conglomerate to open false, // don't hold open across commit 0, // for read TransactionController.MODE_RECORD, // row locking TransactionController.ISOLATION_REPEATABLE_READ, colToCheck, // don't get any rows null, // start position - first row ScanController.GE, // startSearchOperation qualifier, // scanQualifier, null, // stop position - through last row ScanController.GT); // stopSearchOperation foundRow = (scanController.next()); } finally { if (scanController != null) { scanController.close(); } if (heapCC != null) { heapCC.close(); } } return foundRow; } /** * Drop the table descriptor. * * @param descriptor The table descriptor to drop * @param schema A descriptor for the schema the table * is a part of. If this parameter is * NULL, then the table is part of the * current (default) schema * @param tc TransactionController for the transaction * * @return Nothing * * @exception StandardException Thrown on error */ public void dropTableDescriptor(TableDescriptor td, SchemaDescriptor schema, TransactionController tc) throws StandardException { ConglomerateController heapCC; ExecIndexRow keyRow1 = null; DataValueDescriptor schemaIDOrderable; DataValueDescriptor tableNameOrderable; TabInfo ti = coreInfo[SYSTABLES_CORE_NUM]; /* Use tableIdOrderable and schemaIdOrderable in both start * and stop position for index 1 scan. */ tableNameOrderable = dvf.getVarcharDataValue(td.getName()); schemaIDOrderable = getValueAsDVD(schema.getUUID()); /* Set up the start/stop position for the scan */ keyRow1 = (ExecIndexRow) exFactory.getIndexableRow(2); keyRow1.setColumn(1, tableNameOrderable); keyRow1.setColumn(2, schemaIDOrderable); ti.deleteRow( tc, keyRow1, SYSTABLESRowFactory.SYSTABLES_INDEX1_ID ); } /** * Update the lockGranularity for the specified table. * * @param td The TableDescriptor for the table * @param schema The SchemaDescriptor for the table * @param lockGranularity The new lockGranularity * @param tc The TransactionController to use. * * @return Nothing. * * @exception StandardException Thrown on error */ public void updateLockGranularity(TableDescriptor td, SchemaDescriptor schema, char lockGranularity, TransactionController tc) throws StandardException { ConglomerateController heapCC; ExecIndexRow keyRow1 = null; ExecRow row; DataValueDescriptor schemaIDOrderable; DataValueDescriptor tableNameOrderable; TabInfo ti = coreInfo[SYSTABLES_CORE_NUM]; SYSTABLESRowFactory rf = (SYSTABLESRowFactory) ti.getCatalogRowFactory(); /* Use tableIdOrderable and schemaIdOrderable in both start * and stop position for index 1 scan. */ tableNameOrderable = dvf.getVarcharDataValue(td.getName()); schemaIDOrderable = getValueAsDVD(schema.getUUID()); /* Set up the start/stop position for the scan */ keyRow1 = (ExecIndexRow) exFactory.getIndexableRow(2); keyRow1.setColumn(1, tableNameOrderable); keyRow1.setColumn(2, schemaIDOrderable); // build the row to be stuffed into SYSTABLES. row = rf.makeRow(td, schema); // update row in catalog (no indexes) boolean[] bArray = new boolean[2]; for (int index = 0; index < 2; index++) { bArray[index] = false; } ti.updateRow(keyRow1, row, SYSTABLESRowFactory.SYSTABLES_INDEX1_ID, bArray, (int[])null, tc); } /** * Drop all table descriptors for a schema. * * @param schema A descriptor for the schema to drop the tables * from. * * @return Nothing. * * @exception StandardException Thrown on failure */ /* public void dropAllTableDescriptors(SchemaDescriptor schema) throws StandardException { if (SanityManager.DEBUG) SanityManager.NOTREACHED(); } */ /** * Get a ColumnDescriptor given its Default ID. * * @param uuid The UUID of the default * * @return The ColumnDescriptor for the column. * * @exception StandardException Thrown on failure */ public ColumnDescriptor getColumnDescriptorByDef
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -