Search in sources :

Example 1 with SQLVarchar

use of org.apache.derby.iapi.types.SQLVarchar 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 SQLVarchar

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

the class DataDictionaryImpl method updateUser.

public void updateUser(UserDescriptor newDescriptor, TransactionController tc) throws StandardException {
    ExecIndexRow keyRow;
    TabInfoImpl ti = getNonCoreTI(SYSUSERS_CATALOG_NUM);
    /* Set up the start/stop position for the scan */
    keyRow = (ExecIndexRow) exFactory.getIndexableRow(1);
    keyRow.setColumn(1, new SQLVarchar(newDescriptor.getUserName()));
    // this zeroes out the password in the UserDescriptor
    ExecRow row = ti.getCatalogRowFactory().makeRow(newDescriptor, null);
    boolean[] bArray = { false };
    int[] colsToUpdate = { SYSUSERSRowFactory.HASHINGSCHEME_COL_NUM, SYSUSERSRowFactory.PASSWORD_COL_NUM, SYSUSERSRowFactory.LASTMODIFIED_COL_NUM };
    ti.updateRow(keyRow, row, SYSUSERSRowFactory.SYSUSERS_INDEX1_ID, bArray, colsToUpdate, tc);
}
Also used : ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 3 with SQLVarchar

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

the class DataDictionaryImpl method updateSchemaAuth.

/**
 * Update authorizationId of specified schemaName
 *
 * @param schemaName			Schema Name of system schema
 * @param authorizationId		authorizationId of new schema owner
 * @param tc					The TransactionController to use
 *
 * @exception StandardException		Thrown on failure
 */
public void updateSchemaAuth(String schemaName, String authorizationId, TransactionController tc) throws StandardException {
    ExecIndexRow keyRow;
    DataValueDescriptor schemaNameOrderable;
    TabInfoImpl ti = coreInfo[SYSSCHEMAS_CORE_NUM];
    /* Use schemaNameOrderable in both start 
		 * and stop position for index 1 scan. 
		 */
    schemaNameOrderable = new SQLVarchar(schemaName);
    /* Set up the start/stop position for the scan */
    keyRow = (ExecIndexRow) exFactory.getIndexableRow(1);
    keyRow.setColumn(1, schemaNameOrderable);
    SYSSCHEMASRowFactory rf = (SYSSCHEMASRowFactory) ti.getCatalogRowFactory();
    ExecRow row = rf.makeEmptyRow();
    row.setColumn(SYSSCHEMASRowFactory.SYSSCHEMAS_SCHEMAAID, new SQLVarchar(authorizationId));
    boolean[] bArray = { false, false };
    int[] colsToUpdate = { SYSSCHEMASRowFactory.SYSSCHEMAS_SCHEMAAID };
    ti.updateRow(keyRow, row, SYSSCHEMASRowFactory.SYSSCHEMAS_INDEX1_ID, bArray, colsToUpdate, tc);
}
Also used : ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 4 with SQLVarchar

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

the class DataDictionaryImpl method dropRoleGrant.

/**
 * @see DataDictionary#dropRoleGrant
 */
public void dropRoleGrant(String roleName, String grantee, String grantor, TransactionController tc) throws StandardException {
    DataValueDescriptor roleNameOrderable;
    DataValueDescriptor granteeOrderable;
    DataValueDescriptor grantorOrderable;
    TabInfoImpl ti = getNonCoreTI(SYSROLES_CATALOG_NUM);
    roleNameOrderable = new SQLVarchar(roleName);
    granteeOrderable = new SQLVarchar(grantee);
    grantorOrderable = new SQLVarchar(grantor);
    /* Set up the start/stop position for the scan */
    ExecIndexRow keyRow = exFactory.getIndexableRow(3);
    keyRow.setColumn(1, roleNameOrderable);
    keyRow.setColumn(2, granteeOrderable);
    keyRow.setColumn(3, grantorOrderable);
    ti.deleteRow(tc, keyRow, SYSROLESRowFactory.SYSROLES_INDEX_ID_EE_OR_IDX);
}
Also used : DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 5 with SQLVarchar

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

the class DataDictionaryImpl method visitPermsByGrantee.

/**
 * Scan <code>indexNo</code> index on a permission table
 * <code>catalog</code>, looking for match(es) for the grantee column
 * (given by granteeColnoInIndex for the catalog in question).
 *
 * The action argument can be either <code>EXISTS</code> or
 * <code>DROP</code> (to check for existence, or to drop that row).
 *
 * There is no index on grantee column only on on any of the
 * permissions tables, so we use the index which contain grantee
 * and scan that, setting up a scan qualifier to match the
 * grantee, then fetch the base row.
 *
 * If this proves too slow, we should add an index on grantee
 * only.
 *
 * @param authId grantee to match against
 * @param tc transaction controller
 * @param catalog the underlying permission table to visit
 * @param indexNo the number of the index by which to access the catalog
 * @param granteeColnoInIndex the column number to match
 *        <code>authId</code> against
 * @param action drop matching rows (<code>DROP</code>), or return
 *        <code>true</code> if there is a matching row
 *        (<code>EXISTS</code>)
 *
 * @return action=EXISTS: return {@code true} if there is a matching row
 *      else return {@code false}.
 * @exception StandardException
 */
private boolean visitPermsByGrantee(String authId, TransactionController tc, int catalog, int indexNo, int granteeColnoInIndex, int action) throws StandardException {
    TabInfoImpl ti = getNonCoreTI(catalog);
    PermissionsCatalogRowFactory rf = (PermissionsCatalogRowFactory) ti.getCatalogRowFactory();
    ConglomerateController heapCC = tc.openConglomerate(ti.getHeapConglomerate(), false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ);
    DataValueDescriptor authIdOrderable = new SQLVarchar(authId);
    ScanQualifier[][] scanQualifier = exFactory.getScanQualifier(1);
    scanQualifier[0][0].setQualifier(granteeColnoInIndex - 1, /* to zero-based */
    authIdOrderable, Orderable.ORDER_OP_EQUALS, false, false, false);
    ScanController sc = tc.openScan(ti.getIndexConglomerate(indexNo), // don't hold open across commit
    false, // for update
    0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ, // all fields as objects
    (FormatableBitSet) null, // start position -
    (DataValueDescriptor[]) null, // startSearchOperation - none
    0, // 
    scanQualifier, // stop position -through last row
    (DataValueDescriptor[]) null, // stopSearchOperation - none
    0);
    try {
        ExecRow outRow = rf.makeEmptyRow();
        ExecIndexRow indexRow = getIndexRowFromHeapRow(ti.getIndexRowGenerator(indexNo), heapCC.newRowLocationTemplate(), outRow);
        while (sc.fetchNext(indexRow.getRowArray())) {
            RowLocation baseRowLocation = (RowLocation) indexRow.getColumn(indexRow.nColumns());
            boolean base_row_exists = heapCC.fetch(baseRowLocation, outRow.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 doesn't exist");
            }
            if (action == DataDictionaryImpl.EXISTS) {
                return true;
            } else if (action == DataDictionaryImpl.DROP) {
                PermissionsDescriptor perm = (PermissionsDescriptor) rf.buildDescriptor(outRow, (TupleDescriptor) null, this);
                removePermEntryInCache(perm);
                ti.deleteRow(tc, indexRow, indexNo);
            }
        }
    } finally {
        if (sc != null) {
            sc.close();
        }
        if (heapCC != null) {
            heapCC.close();
        }
    }
    return false;
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) PermissionsDescriptor(org.apache.derby.iapi.sql.dictionary.PermissionsDescriptor) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) RowLocation(org.apache.derby.iapi.types.RowLocation)

Aggregations

SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)45 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)33 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)30 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)22 SQLChar (org.apache.derby.iapi.types.SQLChar)18 TupleDescriptor (org.apache.derby.iapi.sql.dictionary.TupleDescriptor)13 UUID (org.apache.derby.catalog.UUID)9 SQLLongint (org.apache.derby.iapi.types.SQLLongint)6 ScanController (org.apache.derby.iapi.store.access.ScanController)5 UserType (org.apache.derby.iapi.types.UserType)5 Timestamp (java.sql.Timestamp)4 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)4 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)4 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)4 SQLBoolean (org.apache.derby.iapi.types.SQLBoolean)4 ArrayList (java.util.ArrayList)3 AliasDescriptor (org.apache.derby.iapi.sql.dictionary.AliasDescriptor)3 SQLTimestamp (org.apache.derby.iapi.types.SQLTimestamp)3 LinkedList (java.util.LinkedList)2 List (java.util.List)2