use of org.apache.derby.iapi.sql.execute.ScanQualifier in project derby by apache.
the class DataDictionaryImpl method getUUIDForCoreTable.
/**
* Get the UUID for the specified system table. Prior
* to Plato, system tables did not have canonical UUIDs, so
* we need to scan systables to get the UUID when we
* are updating the core tables.
*
* @param tableName Name of the table
* @param schemaUUID UUID of schema
* @param tc TransactionController to user
*
* @return UUID The UUID of the core table.
*
* @exception StandardException Thrown on failure
*/
private UUID getUUIDForCoreTable(String tableName, String schemaUUID, TransactionController tc) throws StandardException {
ConglomerateController heapCC;
ExecRow row;
DataValueDescriptor schemaIDOrderable;
DataValueDescriptor tableNameOrderable;
ScanController scanController;
TabInfoImpl ti = coreInfo[SYSTABLES_CORE_NUM];
SYSTABLESRowFactory rf = (SYSTABLESRowFactory) ti.getCatalogRowFactory();
// We only want the 1st column from the heap
row = exFactory.getValueRow(1);
/* Use tableNameOrderable and schemaIdOrderable in both start
* and stop position for scan.
*/
tableNameOrderable = new SQLVarchar(tableName);
schemaIDOrderable = new SQLChar(schemaUUID);
/* Set up the start/stop position for the scan */
ExecIndexRow keyRow = exFactory.getIndexableRow(2);
keyRow.setColumn(1, tableNameOrderable);
keyRow.setColumn(2, schemaIDOrderable);
heapCC = tc.openConglomerate(ti.getHeapConglomerate(), false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ);
ExecRow indexTemplateRow = rf.buildEmptyIndexRow(SYSTABLESRowFactory.SYSTABLES_INDEX1_ID, heapCC.newRowLocationTemplate());
/* Scan the index and go to the data pages for qualifying rows to
* build the column descriptor.
*/
scanController = tc.openScan(// conglomerate to open
ti.getIndexConglomerate(SYSTABLESRowFactory.SYSTABLES_INDEX1_ID), // don't hold open across commit
false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ, // all fields as objects
(FormatableBitSet) null, // start position - first row
keyRow.getRowArray(), // startSearchOperation
ScanController.GE, // scanQualifier,
(ScanQualifier[][]) null, // stop position - through last row
keyRow.getRowArray(), // stopSearchOperation
ScanController.GT);
/* OK to fetch into the template row,
* since we won't be doing a next.
*/
if (scanController.fetchNext(indexTemplateRow.getRowArray())) {
RowLocation baseRowLocation;
baseRowLocation = (RowLocation) indexTemplateRow.getColumn(indexTemplateRow.nColumns());
/* 1st column is TABLEID (UUID - char(36)) */
row.setColumn(SYSTABLESRowFactory.SYSTABLES_TABLEID, new SQLChar());
FormatableBitSet bi = new FormatableBitSet(1);
bi.set(0);
boolean base_row_exists = heapCC.fetch(baseRowLocation, row.getRowArray(), (FormatableBitSet) null);
if (SanityManager.DEBUG) {
// it can not be possible for heap row to disappear while
// holding scan cursor on index at ISOLATION_REPEATABLE_READ.
SanityManager.ASSERT(base_row_exists, "base row not found");
}
}
scanController.close();
heapCC.close();
return uuidFactory.recreateUUID(row.getColumn(1).toString());
}
use of org.apache.derby.iapi.sql.execute.ScanQualifier in project derby by apache.
the class DataDictionaryImpl method getTableDescriptorIndex2Scan.
/**
* 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;
TabInfoImpl ti = coreInfo[SYSTABLES_CORE_NUM];
/* Use tableIDOrderable in both start and stop position for scan.
*/
tableIDOrderable = new SQLChar(tableUUID);
/* Set up the start/stop position for the scan */
ExecIndexRow keyRow = exFactory.getIndexableRow(1);
keyRow.setColumn(1, tableIDOrderable);
td = getDescriptorViaIndex(SYSTABLESRowFactory.SYSTABLES_INDEX2_ID, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, (List<TupleDescriptor>) null, TableDescriptor.class, false);
return finishTableDescriptor(td);
}
use of org.apache.derby.iapi.sql.execute.ScanQualifier in project derby by apache.
the class DataDictionaryImpl method getTableDescriptorIndex1Scan.
/**
* 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;
TabInfoImpl ti = coreInfo[SYSTABLES_CORE_NUM];
/* Use tableNameOrderable and schemaIdOrderable in both start
* and stop position for scan.
*/
tableNameOrderable = new SQLVarchar(tableName);
schemaIDOrderable = new SQLChar(schemaUUID);
/* Set up the start/stop position for the scan */
ExecIndexRow keyRow = exFactory.getIndexableRow(2);
keyRow.setColumn(1, tableNameOrderable);
keyRow.setColumn(2, schemaIDOrderable);
td = getDescriptorViaIndex(SYSTABLESRowFactory.SYSTABLES_INDEX1_ID, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, (List<TupleDescriptor>) null, TableDescriptor.class, false);
return finishTableDescriptor(td);
}
use of org.apache.derby.iapi.sql.execute.ScanQualifier in project derby by apache.
the class DataDictionaryImpl method getViewDescriptorScan.
/**
* Get the information for the view from sys.sysviews.
*
* @param tdi The TableDescriptor for the view.
*
* @return ViewDescriptor The ViewDescriptor for the view.
*
* @exception StandardException Thrown on error
*/
private ViewDescriptor getViewDescriptorScan(TableDescriptor tdi) throws StandardException {
ViewDescriptor vd;
DataValueDescriptor viewIdOrderable;
TabInfoImpl ti = getNonCoreTI(SYSVIEWS_CATALOG_NUM);
UUID viewID = tdi.getUUID();
/* Use viewIdOrderable in both start
* and stop position for scan.
*/
viewIdOrderable = getIDValueAsCHAR(viewID);
/* Set up the start/stop position for the scan */
ExecIndexRow keyRow = exFactory.getIndexableRow(1);
keyRow.setColumn(1, viewIdOrderable);
vd = getDescriptorViaIndex(SYSVIEWSRowFactory.SYSVIEWS_INDEX1_ID, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, (List<TupleDescriptor>) null, ViewDescriptor.class, false);
if (vd != null) {
vd.setViewName(tdi.getName());
}
return vd;
}
use of org.apache.derby.iapi.sql.execute.ScanQualifier in project derby by apache.
the class DataDictionaryImpl method hashAllTableDescriptorsByTableId.
/**
* Get all of the TableDescriptors in the database and hash them
* by TableId This is useful as a performance optimization for the
* locking VTIs. NOTE: This method will scan SYS.SYSTABLES and
* SYS.SYSSCHEMAS at READ UNCOMMITTED.
*
* @param tc TransactionController for the transaction
*
* @return A Hashtable with all of the Table descriptors in the database
* hashed by TableId
*
* @exception StandardException Thrown on failure
*/
@SuppressWarnings("UseOfObsoleteCollectionType")
public Hashtable<UUID, TableDescriptor> hashAllTableDescriptorsByTableId(TransactionController tc) throws StandardException {
Hashtable<UUID, TableDescriptor> ht = new Hashtable<UUID, TableDescriptor>();
ScanController scanController;
ExecRow outRow;
TabInfoImpl ti = coreInfo[SYSTABLES_CORE_NUM];
SYSTABLESRowFactory rf = (SYSTABLESRowFactory) ti.getCatalogRowFactory();
outRow = rf.makeEmptyRow();
scanController = tc.openScan(// sys.systable
ti.getHeapConglomerate(), // don't hold open across commit
false, // for read
0, // scans whole table.
TransactionController.MODE_RECORD, TransactionController.ISOLATION_READ_UNCOMMITTED, // all fields as objects
(FormatableBitSet) null, // start position - first row
(DataValueDescriptor[]) null, // startSearchOperation
ScanController.GE, // scanQualifier,
(ScanQualifier[][]) null, // stop position-through last row
(DataValueDescriptor[]) null, // stopSearchOperation
ScanController.GT);
// fetch() may find the row deleted or purged from the table.
while (scanController.fetchNext(outRow.getRowArray())) {
TableDescriptor td = (TableDescriptor) rf.buildDescriptor(outRow, (TupleDescriptor) null, this, TransactionController.ISOLATION_READ_UNCOMMITTED);
ht.put(td.getUUID(), td);
}
scanController.close();
return ht;
}
Aggregations