use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.
the class DataDictionaryImpl method dropSequenceDescriptor.
/**
* Drops a sequence descriptor
*
* @param descriptor The descriptor to drop
* @param tc The TransactionController.
* @throws StandardException Thrown on failure
*/
public void dropSequenceDescriptor(SequenceDescriptor descriptor, TransactionController tc) throws StandardException {
DataValueDescriptor sequenceIdOrderable;
TabInfoImpl ti = getNonCoreTI(SYSSEQUENCES_CATALOG_NUM);
sequenceIdOrderable = getIDValueAsCHAR(descriptor.getUUID());
/* Set up the start/stop position for the scan */
ExecIndexRow keyRow = (ExecIndexRow) exFactory.getIndexableRow(1);
keyRow.setColumn(1, sequenceIdOrderable);
ti.deleteRow(tc, keyRow, SYSSEQUENCESRowFactory.SYSSEQUENCES_INDEX1_ID);
dropSequenceID(descriptor);
}
use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.
the class DataDictionaryImpl method rewriteSYSCOLPERMSforAlterTable.
/**
* Workhorse for ALTER TABLE-driven mods to SYSCOLPERMS
*
* This method finds all the SYSCOLPERMS rows for this table. Then it
* iterates through each row, either adding a new column to the end of
* the table, or dropping a column from the table, as appropriate. It
* updates each SYSCOLPERMS row to store the new COLUMNS value.
*
* @param tableID The UUID of the table being altered
* @param tc TransactionController for the transaction
* @param columnDescriptor Dropped column info, or null if adding
*
* @exception StandardException Thrown on error
*/
private void rewriteSYSCOLPERMSforAlterTable(UUID tableID, TransactionController tc, ColumnDescriptor columnDescriptor) throws StandardException {
// In Derby authorization mode, permission catalogs may not be present
if (!usesSqlAuthorization)
return;
/* This method has 2 steps to it. First get all the ColPermsDescriptor
for given tableid. And next step is to go back to SYSCOLPERMS to find
unique row corresponding to each of ColPermsDescriptor and update the
"COLUMNS" column in SYSCOLPERMS. The reason for this 2 step process is
that SYSCOLPERMS has a non-unique row on "TABLEID" column and hence
we can't get a unique handle on each of the affected row in SYSCOLPERMS
using just the "TABLEID" column */
// First get all the ColPermsDescriptor for the given tableid from
// SYSCOLPERMS using getDescriptorViaIndex().
// all ColPermsDescriptor for given tableid
List<ColPermsDescriptor> permissionDescriptorsList;
DataValueDescriptor tableIDOrderable = getIDValueAsCHAR(tableID);
TabInfoImpl ti = getNonCoreTI(SYSCOLPERMS_CATALOG_NUM);
SYSCOLPERMSRowFactory rf = (SYSCOLPERMSRowFactory) ti.getCatalogRowFactory();
ExecIndexRow keyRow = exFactory.getIndexableRow(1);
keyRow.setColumn(1, tableIDOrderable);
permissionDescriptorsList = newSList();
getDescriptorViaIndex(SYSCOLPERMSRowFactory.TABLEID_INDEX_NUM, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, permissionDescriptorsList, ColPermsDescriptor.class, false);
/* Next, using each of the ColPermDescriptor's uuid, get the unique row
in SYSCOLPERMS and adjust the "COLUMNS" column in SYSCOLPERMS to
accomodate the added or dropped column in the tableid*/
ExecRow curRow;
ExecIndexRow uuidKey;
// Not updating any indexes on SYSCOLPERMS
boolean[] bArray = new boolean[SYSCOLPERMSRowFactory.TOTAL_NUM_OF_INDEXES];
int[] colsToUpdate = { SYSCOLPERMSRowFactory.COLUMNS_COL_NUM };
for (ColPermsDescriptor colPermsDescriptor : permissionDescriptorsList) {
removePermEntryInCache(colPermsDescriptor);
uuidKey = rf.buildIndexKeyRow(rf.COLPERMSID_INDEX_NUM, colPermsDescriptor);
curRow = ti.getRow(tc, uuidKey, rf.COLPERMSID_INDEX_NUM);
FormatableBitSet columns = (FormatableBitSet) curRow.getColumn(SYSCOLPERMSRowFactory.COLUMNS_COL_NUM).getObject();
// for the dropped column.
if (columnDescriptor == null) {
int currentLength = columns.getLength();
columns.grow(currentLength + 1);
} else {
FormatableBitSet modifiedColumns = new FormatableBitSet(columns);
modifiedColumns.shrink(columns.getLength() - 1);
// FormatableBitSet count from 0.
for (int i = columnDescriptor.getPosition() - 1; i < modifiedColumns.getLength(); i++) {
if (columns.isSet(i + 1))
modifiedColumns.set(i);
else
modifiedColumns.clear(i);
}
columns = modifiedColumns;
}
curRow.setColumn(SYSCOLPERMSRowFactory.COLUMNS_COL_NUM, new UserType((Object) columns));
ti.updateRow(uuidKey, curRow, SYSCOLPERMSRowFactory.COLPERMSID_INDEX_NUM, bArray, colsToUpdate, tc);
}
}
use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.
the class DataDictionaryImpl method getConstraintDescriptorsScan.
/**
* Populate the ConstraintDescriptorList for the specified TableDescriptor.
*
* MT synchronization: it is assumed that the caller has synchronized
* on the CDL in the given TD.
*
* @param td The TableDescriptor.
* @param forUpdate Whether or not to open scan for update
*
* @exception StandardException Thrown on failure
*/
private void getConstraintDescriptorsScan(TableDescriptor td, boolean forUpdate) throws StandardException {
ConstraintDescriptorList cdl = td.getConstraintDescriptorList();
DataValueDescriptor tableIDOrderable = null;
TabInfoImpl ti = getNonCoreTI(SYSCONSTRAINTS_CATALOG_NUM);
/* Use tableIDOrderable in both start and stop positions for scan */
tableIDOrderable = getIDValueAsCHAR(td.getUUID());
/* Set up the start/stop position for the scan */
ExecIndexRow keyRow = (ExecIndexRow) exFactory.getIndexableRow(1);
keyRow.setColumn(1, tableIDOrderable);
getConstraintDescriptorViaIndex(SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_INDEX3_ID, keyRow, ti, td, cdl, forUpdate);
cdl.setScanned(true);
}
use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.
the class DataDictionaryImpl method updateConstraintDescriptor.
/**
* Update the constraint descriptor in question. Updates
* every row in the base conglomerate.
*
* @param cd The Constraint descriptor
* @param formerUUID The UUID for this column in SYSCONSTRAINTS,
* may differ from what is in {@code cd} if this
* is the column that is being set.
* @param colsToSet Array of integers of columns to be modified,
* 1 based. May be null (all columns).
* @param tc The TransactionController to use
*
* @exception StandardException Thrown on failure
*/
public void updateConstraintDescriptor(ConstraintDescriptor cd, UUID formerUUID, int[] colsToSet, TransactionController tc) throws StandardException {
ExecIndexRow keyRow1 = null;
ExecRow row;
DataValueDescriptor IDOrderable;
TabInfoImpl ti = getNonCoreTI(SYSCONSTRAINTS_CATALOG_NUM);
SYSCONSTRAINTSRowFactory rf = (SYSCONSTRAINTSRowFactory) ti.getCatalogRowFactory();
/* Use objectID/columnName in both start
* and stop position for index 1 scan.
*/
IDOrderable = getIDValueAsCHAR(formerUUID);
/* Set up the start/stop position for the scan */
keyRow1 = (ExecIndexRow) exFactory.getIndexableRow(1);
keyRow1.setColumn(1, IDOrderable);
// build the row to be stuffed into SYSCONSTRAINTS.
row = rf.makeRow(cd, null);
/*
** Figure out if the index in sysconstraints needs
** to be updated.
*/
if (SanityManager.DEBUG) {
SanityManager.ASSERT(rf.getNumIndexes() == 3, "There are more indexes on sysconstraints than expected, the code herein needs to change");
}
boolean[] bArray = new boolean[3];
/*
** Do we need to update indexes?
*/
if (colsToSet == null) {
bArray[0] = true;
bArray[1] = true;
bArray[2] = true;
} else {
/*
** Check the specific columns for indexed
** columns.
*/
for (int i = 0; i < colsToSet.length; i++) {
switch(colsToSet[i]) {
case SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_CONSTRAINTID:
bArray[0] = true;
break;
case SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_CONSTRAINTNAME:
case SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_SCHEMAID:
bArray[1] = true;
break;
case SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_TABLEID:
bArray[2] = true;
break;
}
}
}
ti.updateRow(keyRow1, row, SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_INDEX1_ID, bArray, colsToSet, tc);
}
use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.
the class DataDictionaryImpl method dropTriggerDescriptor.
/**
* Drops the given TriggerDescriptor. WARNING: does
* not drop its SPSes!!!
*
* @param descriptor The descriptor to drop
* @param tc The TransactionController.
*
* @exception StandardException Thrown on failure
*/
public void dropTriggerDescriptor(TriggerDescriptor descriptor, TransactionController tc) throws StandardException {
DataValueDescriptor idOrderable;
TabInfoImpl ti = getNonCoreTI(SYSTRIGGERS_CATALOG_NUM);
idOrderable = getIDValueAsCHAR(descriptor.getUUID());
/* Set up the start/stop position for the scan */
ExecIndexRow keyRow = (ExecIndexRow) exFactory.getIndexableRow(1);
keyRow.setColumn(1, idOrderable);
ti.deleteRow(tc, keyRow, SYSTRIGGERSRowFactory.SYSTRIGGERS_INDEX1_ID);
}
Aggregations