use of org.apache.derby.iapi.sql.execute.ExecIndexRow in project derby by apache.
the class DataDictionaryImpl method computeSequenceRowLocation.
/**
* Computes the RowLocation in SYSSEQUENCES for a particular sequence. Also
* constructs the sequence descriptor.
*
* @param tc Transaction Controller to use.
* @param sequenceIDstring UUID of the sequence as a string
* @param rowLocation OUTPUT param for returing the row location
* @param sequenceDescriptor OUTPUT param for return the sequence descriptor
*
* @exception StandardException thrown on failure.
*/
public void computeSequenceRowLocation(TransactionController tc, String sequenceIDstring, RowLocation[] rowLocation, SequenceDescriptor[] sequenceDescriptor) throws StandardException {
TabInfoImpl ti = getNonCoreTI(SYSSEQUENCES_CATALOG_NUM);
ExecIndexRow keyRow = null;
keyRow = (ExecIndexRow) exFactory.getIndexableRow(1);
keyRow.setColumn(1, new SQLChar(sequenceIDstring));
rowLocation[0] = ti.getRowLocation(tc, keyRow, SYSSEQUENCESRowFactory.SYSSEQUENCES_INDEX1_ID);
sequenceDescriptor[0] = getDescriptorViaIndex(SYSSEQUENCESRowFactory.SYSSEQUENCES_INDEX1_ID, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, (List<TupleDescriptor>) null, SequenceDescriptor.class, false, TransactionController.ISOLATION_REPEATABLE_READ, tc);
}
use of org.apache.derby.iapi.sql.execute.ExecIndexRow in project derby by apache.
the class DataDictionaryImpl method addRemovePermissionsDescriptor.
/**
* Add or remove a permission to/from the permission database.
*
* @param add if true then the permission is added, if false the permission is removed
* @param perm
* @param grantee
* @param tc
*
* @return True means revoke has removed a privilege from system
* table and hence the caller of this method should send invalidation
* actions to PermssionDescriptor's dependents.
*/
public boolean addRemovePermissionsDescriptor(boolean add, PermissionsDescriptor perm, String grantee, TransactionController tc) throws StandardException {
int catalogNumber = perm.getCatalogNumber();
// It is possible for grant statements to look like following
// grant execute on function f_abs to mamata2, mamata3;
// grant all privileges on t11 to mamata2, mamata3;
// This means that dd.addRemovePermissionsDescriptor will be called
// twice for TablePermsDescriptor and twice for RoutinePermsDescriptor,
// once for each grantee.
// First it's called for mamta2. When a row is inserted for mamta2
// into the correct system table for the permission descriptor, the
// permission descriptor's uuid gets populated with the uuid of
// the row that just got inserted into the system table for mamta2
// Now, when dd.addRemovePermissionsDescriptor gets called again for
// mamta3, the permission descriptor's uuid will still be set to
// the uuid that was used for mamta2. If we do not reset the
// uuid to null, we will think that there is a duplicate row getting
// inserted for the same uuid. In order to get around this, we should
// reset the UUID of passed PermissionDescriptor everytime this method
// is called. This way, there will be no leftover values from previous
// call of this method.
perm.setUUID(null);
perm.setGrantee(grantee);
TabInfoImpl ti = getNonCoreTI(catalogNumber);
PermissionsCatalogRowFactory rf = (PermissionsCatalogRowFactory) ti.getCatalogRowFactory();
int primaryIndexNumber = rf.getPrimaryKeyIndexNumber();
ConglomerateController heapCC = tc.openConglomerate(ti.getHeapConglomerate(), // do not keep open across commits
false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ);
RowLocation rl = null;
try {
rl = heapCC.newRowLocationTemplate();
} finally {
heapCC.close();
heapCC = null;
}
ExecIndexRow key = rf.buildIndexKeyRow(primaryIndexNumber, perm);
ExecRow existingRow = ti.getRow(tc, key, primaryIndexNumber);
if (existingRow == null) {
if (!add) {
// permission and hence uuid can't be non-null
return false;
} else {
// We didn't find an entry in system catalog and this is grant so
// so that means we have to enter a new row in system catalog for
// this grant.
ExecRow row = ti.getCatalogRowFactory().makeRow(perm, (TupleDescriptor) null);
int insertRetCode = ti.insertRow(row, tc);
if (SanityManager.DEBUG) {
SanityManager.ASSERT(insertRetCode == TabInfoImpl.ROWNOTDUPLICATE, "Race condition in inserting table privilege.");
}
}
} else {
// add/remove these permissions to/from the existing permissions
boolean[] colsChanged = new boolean[existingRow.nColumns()];
boolean[] indicesToUpdate = new boolean[rf.getNumIndexes()];
int changedColCount = 0;
if (add) {
changedColCount = rf.orPermissions(existingRow, perm, colsChanged);
} else {
changedColCount = rf.removePermissions(existingRow, perm, colsChanged);
}
if (changedColCount == 0) {
// just return
return false;
}
if (!add) {
// set the uuid of the passed permission descriptor to
// corresponding rows's uuid in permissions system table. The
// permission descriptor's uuid is required to have the
// dependency manager send the revoke privilege action to
// all the dependent objects on that permission descriptor.
rf.setUUIDOfThePassedDescriptor(existingRow, perm);
}
if (changedColCount < 0) {
// No permissions left in the current row
ti.deleteRow(tc, key, primaryIndexNumber);
} else if (changedColCount > 0) {
int[] colsToUpdate = new int[changedColCount];
changedColCount = 0;
for (int i = 0; i < colsChanged.length; i++) {
if (colsChanged[i])
colsToUpdate[changedColCount++] = i + 1;
}
if (SanityManager.DEBUG) {
SanityManager.ASSERT(changedColCount == colsToUpdate.length, "return value of " + rf.getClass().getName() + ".orPermissions does not match the number of booleans it set in colsChanged.");
}
ti.updateRow(key, existingRow, primaryIndexNumber, indicesToUpdate, colsToUpdate, tc);
}
}
// Remove cached permissions data. The cache may hold permissions data for this key even if
// the row in the permissions table is new. In that case the cache may have an entry indicating no
// permissions
removePermEntryInCache(perm);
// any invalidation actions to anyone and hence return false
if (add) {
return false;
} else {
return true;
}
}
use of org.apache.derby.iapi.sql.execute.ExecIndexRow in project derby by apache.
the class DataDictionaryImpl method dropTableDescriptor.
/**
* Drop the table descriptor.
*
* @param td The table descriptor to drop
* @param schema A descriptor for the schema the table
* is a part of. If this parameter is
* NULL, then the table is part of the
* current (default) schema
* @param tc TransactionController for the transaction
*
* @exception StandardException Thrown on error
*/
public void dropTableDescriptor(TableDescriptor td, SchemaDescriptor schema, TransactionController tc) throws StandardException {
ExecIndexRow keyRow1 = null;
DataValueDescriptor schemaIDOrderable;
DataValueDescriptor tableNameOrderable;
TabInfoImpl ti = coreInfo[SYSTABLES_CORE_NUM];
/* Use tableIdOrderable and schemaIdOrderable in both start
* and stop position for index 1 scan.
*/
tableNameOrderable = new SQLVarchar(td.getName());
schemaIDOrderable = getIDValueAsCHAR(schema.getUUID());
/* Set up the start/stop position for the scan */
keyRow1 = (ExecIndexRow) exFactory.getIndexableRow(2);
keyRow1.setColumn(1, tableNameOrderable);
keyRow1.setColumn(2, schemaIDOrderable);
ti.deleteRow(tc, keyRow1, SYSTABLESRowFactory.SYSTABLES_INDEX1_ID);
}
use of org.apache.derby.iapi.sql.execute.ExecIndexRow in project derby by apache.
the class DataDictionaryImpl method dropAliasDescriptor.
/**
* Drop a AliasDescriptor from the DataDictionary
*
* @param ad The AliasDescriptor to drop
* @param tc The TransactionController
*
* @exception StandardException Thrown on failure
*/
public void dropAliasDescriptor(AliasDescriptor ad, TransactionController tc) throws StandardException {
TabInfoImpl ti = getNonCoreTI(SYSALIASES_CATALOG_NUM);
/* Use aliasNameOrderable and nameSpaceOrderable in both start
* and stop position for index 1 scan.
*/
char[] charArray = new char[1];
charArray[0] = ad.getNameSpace();
/* Set up the start/stop position for the scan */
ExecIndexRow keyRow1 = (ExecIndexRow) exFactory.getIndexableRow(3);
keyRow1.setColumn(1, getIDValueAsCHAR(ad.getSchemaUUID()));
keyRow1.setColumn(2, new SQLVarchar(ad.getDescriptorName()));
keyRow1.setColumn(3, new SQLChar(new String(charArray)));
ti.deleteRow(tc, keyRow1, SYSALIASESRowFactory.SYSALIASES_INDEX1_ID);
}
use of org.apache.derby.iapi.sql.execute.ExecIndexRow in project derby by apache.
the class DataDictionaryImpl method locateSchemaRow.
/**
* Get the target schema by searching for a matching row
* in SYSSCHEMAS by schema name. Read only scan.
*
* @param schemaName The name of the schema we're interested in.
* If schemaId is null, used to qual.
*
* @param tc TransactionController. If null, one
* is gotten off of the language connection context.
*
* @return The row for the schema
*
* @exception StandardException Thrown on error
*/
private SchemaDescriptor locateSchemaRow(String schemaName, TransactionController tc) throws StandardException {
DataValueDescriptor schemaNameOrderable;
TabInfoImpl ti = coreInfo[SYSSCHEMAS_CORE_NUM];
/* Use aliasNameOrderable in both start
* and stop position for scan.
*/
schemaNameOrderable = new SQLVarchar(schemaName);
/* Set up the start/stop position for the scan */
ExecIndexRow keyRow = exFactory.getIndexableRow(1);
keyRow.setColumn(1, schemaNameOrderable);
return getDescriptorViaIndex(SYSSCHEMASRowFactory.SYSSCHEMAS_INDEX1_ID, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, (List<TupleDescriptor>) null, SchemaDescriptor.class, false, TransactionController.ISOLATION_REPEATABLE_READ, tc);
}
Aggregations