Search in sources :

Example 1 with SQLChar

use of org.apache.derby.iapi.types.SQLChar 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());
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) SQLChar(org.apache.derby.iapi.types.SQLChar) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) ScanQualifier(org.apache.derby.iapi.sql.execute.ScanQualifier) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RowLocation(org.apache.derby.iapi.types.RowLocation)

Example 2 with SQLChar

use of org.apache.derby.iapi.types.SQLChar 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);
}
Also used : TupleDescriptor(org.apache.derby.iapi.sql.dictionary.TupleDescriptor) SQLChar(org.apache.derby.iapi.types.SQLChar) ScanQualifier(org.apache.derby.iapi.sql.execute.ScanQualifier) ColumnDescriptorList(org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList) ConglomerateDescriptorList(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptorList) ArrayList(java.util.ArrayList) TriggerDescriptorList(org.apache.derby.iapi.sql.dictionary.TriggerDescriptorList) List(java.util.List) ConstraintDescriptorList(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList) LinkedList(java.util.LinkedList) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 3 with SQLChar

use of org.apache.derby.iapi.types.SQLChar 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);
}
Also used : TupleDescriptor(org.apache.derby.iapi.sql.dictionary.TupleDescriptor) SQLChar(org.apache.derby.iapi.types.SQLChar) ScanQualifier(org.apache.derby.iapi.sql.execute.ScanQualifier) ColumnDescriptorList(org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList) ConglomerateDescriptorList(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptorList) ArrayList(java.util.ArrayList) TriggerDescriptorList(org.apache.derby.iapi.sql.dictionary.TriggerDescriptorList) List(java.util.List) ConstraintDescriptorList(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList) LinkedList(java.util.LinkedList) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 4 with SQLChar

use of org.apache.derby.iapi.types.SQLChar in project derby by apache.

the class DataDictionaryImpl method getSPSDescriptorIndex2Scan.

/**
 * Scan sysstatements_index2 (stmtid) for a match.
 * Note that we do not do a lookup of parameter info.
 *
 * @return SPSDescriptor	The matching descriptor, if any.
 *
 * @exception StandardException		Thrown on failure
 */
private SPSDescriptor getSPSDescriptorIndex2Scan(String stmtUUID) throws StandardException {
    DataValueDescriptor stmtIDOrderable;
    TabInfoImpl ti = getNonCoreTI(SYSSTATEMENTS_CATALOG_NUM);
    /* Use stmtIdOrderable in both start 
		 * and stop position for scan. 
		 */
    stmtIDOrderable = new SQLChar(stmtUUID);
    /* Set up the start/stop position for the scan */
    ExecIndexRow keyRow = exFactory.getIndexableRow(1);
    keyRow.setColumn(1, stmtIDOrderable);
    SPSDescriptor spsd = getDescriptorViaIndex(SYSSTATEMENTSRowFactory.SYSSTATEMENTS_INDEX1_ID, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, (List<TupleDescriptor>) null, SPSDescriptor.class, false);
    return spsd;
}
Also used : TupleDescriptor(org.apache.derby.iapi.sql.dictionary.TupleDescriptor) SQLChar(org.apache.derby.iapi.types.SQLChar) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) SPSDescriptor(org.apache.derby.iapi.sql.dictionary.SPSDescriptor)

Example 5 with SQLChar

use of org.apache.derby.iapi.types.SQLChar in project derby by apache.

the class SYSTABLEPERMSRowFactory method buildIndexKeyRow.

/**
 * builds a key row given for a given index number.
 */
public ExecIndexRow buildIndexKeyRow(int indexNumber, PermissionsDescriptor perm) throws StandardException {
    ExecIndexRow row = null;
    switch(indexNumber) {
        case GRANTEE_TABLE_GRANTOR_INDEX_NUM:
            // RESOLVE We do not support the FOR GRANT OPTION, so table permission rows are unique on the
            // grantee and table UUID columns. The grantor column will always have the name of the owner of the
            // table. So the index key, used for searching the index, only has grantee and table UUID columns.
            // It does not have a grantor column.
            // 
            // If we support FOR GRANT OPTION then there may be multiple table permissions rows for a
            // (grantee, tableID) combination. We must either handle the multiple rows, which is necessary for
            // checking permissions, or add a grantor column to the key, which is necessary for granting or revoking
            // permissions.
            row = getExecutionFactory().getIndexableRow(2);
            row.setColumn(1, getAuthorizationID(perm.getGrantee()));
            String tableUUIDStr = ((TablePermsDescriptor) perm).getTableUUID().toString();
            row.setColumn(2, new SQLChar(tableUUIDStr));
            break;
        case TABLEPERMSID_INDEX_NUM:
            row = getExecutionFactory().getIndexableRow(1);
            String tablePermsUUIDStr = perm.getObjectID().toString();
            row.setColumn(1, new SQLChar(tablePermsUUIDStr));
            break;
        case TABLEID_INDEX_NUM:
            row = getExecutionFactory().getIndexableRow(1);
            tableUUIDStr = ((TablePermsDescriptor) perm).getTableUUID().toString();
            row.setColumn(1, new SQLChar(tableUUIDStr));
            break;
    }
    return row;
}
Also used : SQLChar(org.apache.derby.iapi.types.SQLChar) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) TablePermsDescriptor(org.apache.derby.iapi.sql.dictionary.TablePermsDescriptor)

Aggregations

SQLChar (org.apache.derby.iapi.types.SQLChar)60 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)42 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)22 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)21 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)18 UUID (org.apache.derby.catalog.UUID)15 SQLLongint (org.apache.derby.iapi.types.SQLLongint)13 RawContainerHandle (org.apache.derby.iapi.store.raw.data.RawContainerHandle)12 RawTransaction (org.apache.derby.iapi.store.raw.xact.RawTransaction)12 RowLocation (org.apache.derby.iapi.types.RowLocation)10 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)9 TupleDescriptor (org.apache.derby.iapi.sql.dictionary.TupleDescriptor)8 StandardException (org.apache.derby.shared.common.error.StandardException)8 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)7 UserType (org.apache.derby.iapi.types.UserType)7 ScanController (org.apache.derby.iapi.store.access.ScanController)6 ArrayList (java.util.ArrayList)5 Properties (java.util.Properties)5 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)4 LinkedList (java.util.LinkedList)3