use of org.apache.derby.iapi.sql.execute.ExecIndexRow 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);
}
use of org.apache.derby.iapi.sql.execute.ExecIndexRow in project derby by apache.
the class DataDictionaryImpl method dropTablePermDescriptor.
/**
* Delete the appropriate rows from systableperms when
* dropping a table
*
* @param tc The TransactionController
* @param keyRow Start/stop position.
*
* @exception StandardException Thrown on failure
*/
private void dropTablePermDescriptor(TransactionController tc, ExecIndexRow keyRow) throws StandardException {
ExecRow curRow;
PermissionsDescriptor perm;
TabInfoImpl ti = getNonCoreTI(SYSTABLEPERMS_CATALOG_NUM);
SYSTABLEPERMSRowFactory rf = (SYSTABLEPERMSRowFactory) ti.getCatalogRowFactory();
while ((curRow = ti.getRow(tc, keyRow, rf.TABLEID_INDEX_NUM)) != null) {
perm = (PermissionsDescriptor) rf.buildDescriptor(curRow, (TupleDescriptor) null, this);
removePermEntryInCache(perm);
// Build key on UUID and drop the entry as we want to drop only this row
ExecIndexRow uuidKey;
uuidKey = rf.buildIndexKeyRow(rf.TABLEPERMSID_INDEX_NUM, perm);
ti.deleteRow(tc, uuidKey, rf.TABLEPERMSID_INDEX_NUM);
}
}
use of org.apache.derby.iapi.sql.execute.ExecIndexRow 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);
}
use of org.apache.derby.iapi.sql.execute.ExecIndexRow 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);
}
use of org.apache.derby.iapi.sql.execute.ExecIndexRow 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;
}
Aggregations