Search in sources :

Example 16 with DataValueDescriptor

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

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

the class DataDictionaryImpl method upgradeJarStorage.

/**
 * Called by the upgrade code to upgrade the way we store jar files in the
 * database.<p/>
 * We now use UUID as part of the file name to avoid problems with path
 * delimiters. Also, we henceforth use no schema subdirectories since there
 * is no chance of name collision with the UUID.
 *
 * @param tc TransactionController to use.
 */
protected void upgradeJarStorage(TransactionController tc) throws StandardException {
    TabInfoImpl ti = getNonCoreTI(SYSFILES_CATALOG_NUM);
    SYSFILESRowFactory rf = (SYSFILESRowFactory) ti.getCatalogRowFactory();
    ExecRow outRow = rf.makeEmptyRow();
    /*
        ** Table scan
        */
    ScanController scanController = tc.openScan(// conglomerate to open
    ti.getHeapConglomerate(), // don't hold open across commit
    false, // for read
    0, TransactionController.MODE_TABLE, TransactionController.ISOLATION_REPEATABLE_READ, // all fields as objects
    (FormatableBitSet) null, // start position - first row
    (DataValueDescriptor[]) null, // startSearchOperation - none
    0, // scanQualifier,
    (Qualifier[][]) null, // stop position -through last row
    (DataValueDescriptor[]) null, // stopSearchOperation - none
    0);
    Map<String, Object> schemas = new HashMap<String, Object>();
    try {
        while (scanController.fetchNext(outRow.getRowArray())) {
            FileInfoDescriptor fid = (FileInfoDescriptor) rf.buildDescriptor(outRow, null, this);
            schemas.put(fid.getSchemaDescriptor().getSchemaName(), null);
            JarUtil.upgradeJar(tc, fid);
        }
    } finally {
        scanController.close();
    }
    Iterator<String> i = schemas.keySet().iterator();
    FileResource fh = tc.getFileHandler();
    // remove those directories with their contents
    while (i.hasNext()) {
        fh.removeJarDir(FileResource.JAR_DIRECTORY_NAME + File.separatorChar + i.next());
    }
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) FileInfoDescriptor(org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor) HashMap(java.util.HashMap) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) FileResource(org.apache.derby.iapi.store.access.FileResource) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 18 with DataValueDescriptor

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

the class DataDictionaryImpl method dropSubKeyConstraint.

/**
 * Drop the matching row from syskeys when dropping a primary key
 * or unique constraint.
 *
 * @param constraint	the constraint
 * @param tc			The TransactionController
 *
 * @exception StandardException		Thrown on failure
 */
private void dropSubKeyConstraint(ConstraintDescriptor constraint, TransactionController tc) throws StandardException {
    ExecIndexRow keyRow1 = null;
    DataValueDescriptor constraintIdOrderable;
    TabInfoImpl ti;
    int baseNum;
    int indexNum;
    if (constraint.getConstraintType() == DataDictionary.FOREIGNKEY_CONSTRAINT) {
        baseNum = SYSFOREIGNKEYS_CATALOG_NUM;
        indexNum = SYSFOREIGNKEYSRowFactory.SYSFOREIGNKEYS_INDEX1_ID;
        /*
			** If we have a foreign key, we need to decrement the 
			** reference count of the contraint that this FK references.
			** We need to do this *before* we drop the foreign key
			** because of the way FK.getReferencedConstraint() works.	
			*/
        if (constraint.getConstraintType() == DataDictionary.FOREIGNKEY_CONSTRAINT) {
            ReferencedKeyConstraintDescriptor refDescriptor = (ReferencedKeyConstraintDescriptor) getConstraintDescriptor(((ForeignKeyConstraintDescriptor) constraint).getReferencedConstraintId());
            if (refDescriptor != null) {
                refDescriptor.decrementReferenceCount();
                int[] colsToSet = new int[1];
                colsToSet[0] = SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_REFERENCECOUNT;
                updateConstraintDescriptor(refDescriptor, refDescriptor.getUUID(), colsToSet, tc);
            }
        }
    } else {
        baseNum = SYSKEYS_CATALOG_NUM;
        indexNum = SYSKEYSRowFactory.SYSKEYS_INDEX1_ID;
    }
    ti = getNonCoreTI(baseNum);
    /* Use constraintIdOrderable in both start 
		 * and stop position for index 1 scan. 
		 */
    constraintIdOrderable = getIDValueAsCHAR(constraint.getUUID());
    /* Set up the start/stop position for the scan */
    keyRow1 = (ExecIndexRow) exFactory.getIndexableRow(1);
    keyRow1.setColumn(1, constraintIdOrderable);
    ti.deleteRow(tc, keyRow1, indexNum);
}
Also used : ReferencedKeyConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) ForeignKeyConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ForeignKeyConstraintDescriptor) SQLLongint(org.apache.derby.iapi.types.SQLLongint)

Example 19 with DataValueDescriptor

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

the class DataDictionaryImpl method getConglomerateDescriptorsScan.

/**
 * Populate the ConglomerateDescriptorList for the
 * specified TableDescriptor by scanning sysconglomerates.
 *
 * MT synchronization: it is assumed that the caller has synchronized
 * on the CDL in the given TD.
 *
 * @param td			The TableDescriptor.
 *
 * @exception StandardException		Thrown on failure
 */
private void getConglomerateDescriptorsScan(TableDescriptor td) throws StandardException {
    ConglomerateDescriptorList cdl = td.getConglomerateDescriptorList();
    ExecIndexRow keyRow3 = null;
    DataValueDescriptor tableIDOrderable;
    TabInfoImpl ti = coreInfo[SYSCONGLOMERATES_CORE_NUM];
    /* Use tableIDOrderable in both start and stop positions for scan */
    tableIDOrderable = getIDValueAsCHAR(td.getUUID());
    /* Set up the start/stop position for the scan */
    keyRow3 = (ExecIndexRow) exFactory.getIndexableRow(1);
    keyRow3.setColumn(1, tableIDOrderable);
    getDescriptorViaIndex(SYSCONGLOMERATESRowFactory.SYSCONGLOMERATES_INDEX3_ID, keyRow3, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, cdl, ConglomerateDescriptor.class, false);
}
Also used : ConglomerateDescriptorList(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptorList) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 20 with DataValueDescriptor

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

DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)328 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)72 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)62 RowLocation (org.apache.derby.iapi.types.RowLocation)54 SQLLongint (org.apache.derby.iapi.types.SQLLongint)51 StandardException (org.apache.derby.shared.common.error.StandardException)43 SQLChar (org.apache.derby.iapi.types.SQLChar)42 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)36 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)36 ScanController (org.apache.derby.iapi.store.access.ScanController)35 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)32 UUID (org.apache.derby.catalog.UUID)31 TupleDescriptor (org.apache.derby.iapi.sql.dictionary.TupleDescriptor)24 RawTransaction (org.apache.derby.iapi.store.raw.xact.RawTransaction)16 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)15 RawContainerHandle (org.apache.derby.iapi.store.raw.data.RawContainerHandle)15 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)15 Properties (java.util.Properties)14 UserType (org.apache.derby.iapi.types.UserType)13 Page (org.apache.derby.iapi.store.raw.Page)11