use of org.apache.derby.iapi.services.io.FormatableBitSet in project derby by apache.
the class DataDictionaryImpl method getAllDependencyDescriptorsList.
/**
* Build and return an List with DependencyDescriptors for
* all of the stored dependencies.
* This is useful for consistency checking.
*
* @return List List of all DependencyDescriptors.
*
* @exception StandardException Thrown on failure
*/
public List<TupleDescriptor> getAllDependencyDescriptorsList() throws StandardException {
ScanController scanController;
TransactionController tc;
ExecRow outRow;
ExecRow templateRow;
List<TupleDescriptor> ddl = newSList();
TabInfoImpl ti = getNonCoreTI(SYSDEPENDS_CATALOG_NUM);
SYSDEPENDSRowFactory rf = (SYSDEPENDSRowFactory) ti.getCatalogRowFactory();
// Get the current transaction controller
tc = getTransactionCompile();
outRow = rf.makeEmptyRow();
scanController = tc.openScan(// conglomerate to open
ti.getHeapConglomerate(), // don't hold open across commit
false, // for read
0, // scans entire table.
TransactionController.MODE_TABLE, TransactionController.ISOLATION_REPEATABLE_READ, // all fields as objects
(FormatableBitSet) null, // start position - first row
null, // startSearchOperation
ScanController.GE, null, // stop position - through last row
null, // stopSearchOperation
ScanController.GT);
while (scanController.fetchNext(outRow.getRowArray())) {
DependencyDescriptor dependencyDescriptor;
dependencyDescriptor = (DependencyDescriptor) rf.buildDescriptor(outRow, (TupleDescriptor) null, this);
ddl.add(dependencyDescriptor);
}
scanController.close();
return ddl;
}
use of org.apache.derby.iapi.services.io.FormatableBitSet in project derby by apache.
the class DataDictionaryImpl method getConstraintDescriptorViaHeap.
/**
* Return a (single or list of) catalog row descriptor(s) from
* SYSCONSTRAINTS through a heap scan
*
* @param scanQualifiers qualifiers
* @param ti The TabInfoImpl to use
* @param parentTupleDescriptor The parentDescriptor, if applicable.
* @param list The list to build, if supplied.
* If null, then caller expects a single descriptor
*
* @return The last matching descriptor
*
* @exception StandardException Thrown on error
*/
protected TupleDescriptor getConstraintDescriptorViaHeap(ScanQualifier[][] scanQualifiers, TabInfoImpl ti, TupleDescriptor parentTupleDescriptor, ConstraintDescriptorList list) throws StandardException {
SYSCONSTRAINTSRowFactory rf = (SYSCONSTRAINTSRowFactory) ti.getCatalogRowFactory();
ExecRow outRow;
ScanController scanController;
TransactionController tc;
ConstraintDescriptor cd = null;
// Get the current transaction controller
tc = getTransactionCompile();
outRow = rf.makeEmptyRow();
/*
** Table scan
*/
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,
scanQualifiers, // stop position -through last row
(DataValueDescriptor[]) null, // stopSearchOperation - none
0);
try {
while (scanController.fetchNext(outRow.getRowArray())) {
SubConstraintDescriptor subCD = null;
switch(rf.getConstraintType(outRow)) {
case DataDictionary.PRIMARYKEY_CONSTRAINT:
case DataDictionary.FOREIGNKEY_CONSTRAINT:
case DataDictionary.UNIQUE_CONSTRAINT:
subCD = getSubKeyConstraint(rf.getConstraintId(outRow), rf.getConstraintType(outRow));
break;
case DataDictionary.CHECK_CONSTRAINT:
subCD = getSubCheckConstraint(rf.getConstraintId(outRow));
break;
default:
if (SanityManager.DEBUG) {
SanityManager.THROWASSERT("unexpected value from " + " rf.getConstraintType(outRow) " + rf.getConstraintType(outRow));
}
}
if (SanityManager.DEBUG) {
SanityManager.ASSERT(subCD != null, "subCD is expected to be non-null");
}
cd = (ConstraintDescriptor) rf.buildDescriptor(outRow, subCD, this);
/* If dList is null, then caller only wants a single descriptor - we're done
* else just add the current descriptor to the list.
*/
if (list == null) {
break;
} else {
list.add(cd);
}
}
} finally {
scanController.close();
}
return cd;
}
use of org.apache.derby.iapi.services.io.FormatableBitSet 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.services.io.FormatableBitSet in project derby by apache.
the class DataDictionaryImpl method getSetAutoincrementValue.
/**
* @see DataDictionary#getSetAutoincrementValue
*/
public NumberDataValue getSetAutoincrementValue(RowLocation rl, TransactionController tc, boolean doUpdate, NumberDataValue newValue, boolean wait) throws StandardException {
int columnNum = SYSCOLUMNSRowFactory.SYSCOLUMNS_AUTOINCREMENTVALUE;
TabInfoImpl ti = coreInfo[SYSCOLUMNS_CORE_NUM];
ConglomerateController heapCC = null;
SYSCOLUMNSRowFactory rf = (SYSCOLUMNSRowFactory) ti.getCatalogRowFactory();
ExecRow row = rf.makeEmptyRow();
FormatableBitSet columnToRead = new FormatableBitSet(SYSCOLUMNSRowFactory.SYSCOLUMNS_COLUMN_COUNT);
// FormatableBitSet is 0 based.
// current value.
columnToRead.set(columnNum - 1);
// start value.
columnToRead.set(columnNum);
// increment value.
columnToRead.set(columnNum + 1);
try {
/* if wait is true then we need to do a wait while trying to
open/fetch from the conglomerate. note we use wait both to
open as well as fetch from the conglomerate.
*/
heapCC = tc.openConglomerate(ti.getHeapConglomerate(), false, (TransactionController.OPENMODE_FORUPDATE | ((wait) ? 0 : TransactionController.OPENMODE_LOCK_NOWAIT)), TransactionController.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ);
// fetch the current value
boolean baseRowExists = heapCC.fetch(rl, row.getRowArray(), columnToRead, wait);
if (SanityManager.DEBUG) {
// We're not prepared for a non-existing base row.
SanityManager.ASSERT(baseRowExists, "base row not found");
}
// while the Row interface is 1 based.
NumberDataValue currentAI = (NumberDataValue) row.getColumn(columnNum);
long currentAIValue = currentAI.getLong();
if (doUpdate) {
// increment the value
NumberDataValue increment = (NumberDataValue) row.getColumn(columnNum + 2);
currentAI = currentAI.plus(currentAI, increment, currentAI);
row.setColumn(columnNum, currentAI);
// store the new value in SYSCOLUMNS
FormatableBitSet columnToUpdate = new FormatableBitSet(SYSCOLUMNSRowFactory.SYSCOLUMNS_COLUMN_COUNT);
// current value.
columnToUpdate.set(columnNum - 1);
heapCC.replace(rl, row.getRowArray(), columnToUpdate);
}
// incrementing it.
if (newValue != null) {
// user has passed in an object; set the current value in there and
// return it.
newValue.setValue(currentAIValue);
return newValue;
} else {
// reuse the object read from row.
currentAI.setValue(currentAIValue);
return currentAI;
}
} finally {
if (heapCC != null)
heapCC.close();
}
}
use of org.apache.derby.iapi.services.io.FormatableBitSet in project derby by apache.
the class DataDictionaryImpl method getConstraintDescriptorViaIndex.
/**
* Return a (single or list of) ConstraintDescriptor(s) from
* SYSCONSTRAINTS where the access is from the index to the heap.
*
* @param indexId The id of the index (0 to # of indexes on table) to use
* @param keyRow The supplied ExecIndexRow for search
* @param ti The TabInfoImpl to use
* @param td The TableDescriptor, if supplied.
* @param dList The list to build, if supplied. If null, then caller expects
* a single descriptor
* @param forUpdate Whether or not to open scan for update
*
* @return The last matching descriptor
*
* @exception StandardException Thrown on error
*/
protected ConstraintDescriptor getConstraintDescriptorViaIndex(int indexId, ExecIndexRow keyRow, TabInfoImpl ti, TableDescriptor td, ConstraintDescriptorList dList, boolean forUpdate) throws StandardException {
SYSCONSTRAINTSRowFactory rf = (SYSCONSTRAINTSRowFactory) ti.getCatalogRowFactory();
ConglomerateController heapCC;
ConstraintDescriptor cd = null;
ExecIndexRow indexRow1;
ExecRow outRow;
RowLocation baseRowLocation;
ScanController scanController;
TransactionController tc;
// Get the current transaction controller
tc = getTransactionCompile();
outRow = rf.makeEmptyRow();
heapCC = tc.openConglomerate(ti.getHeapConglomerate(), false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ);
/* 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(indexId), // don't hold open across commit
false, (forUpdate) ? TransactionController.OPENMODE_FORUPDATE : 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ, // all fields as objects
(FormatableBitSet) null, // start position - exact key match.
keyRow.getRowArray(), // startSearchOperation
ScanController.GE, // scanQualifier,
null, // stop position - exact key match.
keyRow.getRowArray(), // stopSearchOperation
ScanController.GT);
while (scanController.next()) {
SubConstraintDescriptor subCD = null;
// create an index row template
indexRow1 = getIndexRowFromHeapRow(ti.getIndexRowGenerator(indexId), heapCC.newRowLocationTemplate(), outRow);
scanController.fetch(indexRow1.getRowArray());
baseRowLocation = (RowLocation) indexRow1.getColumn(indexRow1.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");
}
switch(rf.getConstraintType(outRow)) {
case DataDictionary.PRIMARYKEY_CONSTRAINT:
case DataDictionary.FOREIGNKEY_CONSTRAINT:
case DataDictionary.UNIQUE_CONSTRAINT:
subCD = getSubKeyConstraint(rf.getConstraintId(outRow), rf.getConstraintType(outRow));
break;
case DataDictionary.CHECK_CONSTRAINT:
subCD = getSubCheckConstraint(rf.getConstraintId(outRow));
break;
default:
if (SanityManager.DEBUG) {
SanityManager.THROWASSERT("unexpected value " + "from rf.getConstraintType(outRow)" + rf.getConstraintType(outRow));
}
}
if (SanityManager.DEBUG) {
SanityManager.ASSERT(subCD != null, "subCD is expected to be non-null");
}
/* Cache the TD in the SCD so that
* the row factory doesn't need to go
* out to disk to get it.
*/
subCD.setTableDescriptor(td);
cd = (ConstraintDescriptor) rf.buildDescriptor(outRow, subCD, this);
/* If dList is null, then caller only wants a single descriptor - we're done
* else just add the current descriptor to the list.
*/
if (dList == null) {
break;
} else {
dList.add(cd);
}
}
scanController.close();
heapCC.close();
return cd;
}
Aggregations