use of org.apache.derby.iapi.sql.execute.ExecRow in project derby by apache.
the class DataDictionaryImpl method bootstrapOneIndex.
private ConglomerateDescriptor bootstrapOneIndex(SchemaDescriptor sd, TransactionController tc, DataDescriptorGenerator ddg, TabInfoImpl ti, int indexNumber, long heapConglomerateNumber) throws StandardException {
boolean isUnique;
ConglomerateController cc;
ExecRow baseRow;
ExecIndexRow indexableRow;
int numColumns;
long conglomId;
RowLocation rl;
CatalogRowFactory rf = ti.getCatalogRowFactory();
IndexRowGenerator irg;
ConglomerateDescriptor conglomerateDescriptor;
initSystemIndexVariables(ti, indexNumber);
irg = ti.getIndexRowGenerator(indexNumber);
numColumns = ti.getIndexColumnCount(indexNumber);
/* Is the index unique */
isUnique = ti.isIndexUnique(indexNumber);
// create an index row template
indexableRow = irg.getIndexRowTemplate();
baseRow = rf.makeEmptyRowForCurrentVersion();
// Get a RowLocation template
cc = tc.openConglomerate(heapConglomerateNumber, false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ);
rl = cc.newRowLocationTemplate();
cc.close();
// Get an index row based on the base row
irg.getIndexRow(baseRow, rl, indexableRow, (FormatableBitSet) null);
// Describe the properties of the index to the store using Properties
// RESOLVE: The following properties assume a BTREE index.
Properties indexProperties = ti.getCreateIndexProperties(indexNumber);
// Tell it the conglomerate id of the base table
indexProperties.put("baseConglomerateId", Long.toString(heapConglomerateNumber));
// All indexes are unique because they contain the RowLocation.
// The number of uniqueness columns must include the RowLocation
// if the user did not specify a unique index.
indexProperties.put("nUniqueColumns", Integer.toString(isUnique ? numColumns : numColumns + 1));
// By convention, the row location column is the last column
indexProperties.put("rowLocationColumn", Integer.toString(numColumns));
// For now, all columns are key fields, including the RowLocation
indexProperties.put("nKeyFields", Integer.toString(numColumns + 1));
/* Create and add the conglomerate (index) */
conglomId = tc.createConglomerate(// we're requesting an index conglomerate
"BTREE", indexableRow.getRowArray(), // default sort order
null, // default collation id's for collumns in all system congloms
null, // default properties
indexProperties, // not temporary
TransactionController.IS_DEFAULT);
conglomerateDescriptor = ddg.newConglomerateDescriptor(conglomId, rf.getIndexName(indexNumber), true, irg, false, rf.getCanonicalIndexUUID(indexNumber), rf.getCanonicalTableUUID(), sd.getUUID());
ti.setIndexConglomerate(conglomerateDescriptor);
return conglomerateDescriptor;
}
use of org.apache.derby.iapi.sql.execute.ExecRow in project derby by apache.
the class DataDictionaryImpl method existsSchemaOwnedBy.
/**
* Return true of there exists a schema whose authorizationId equals
* authid, i.e. SYS.SYSSCHEMAS contains a row whose column
* (AUTHORIZATIONID) equals authid.
*
* @param authid authorizationId
* @param tc TransactionController
* @return true iff there is a matching schema
* @exception StandardException
*/
public boolean existsSchemaOwnedBy(String authid, TransactionController tc) throws StandardException {
TabInfoImpl ti = coreInfo[SYSSCHEMAS_CORE_NUM];
SYSSCHEMASRowFactory rf = (SYSSCHEMASRowFactory) 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(SYSSCHEMASRowFactory.SYSSCHEMAS_SCHEMAAID - 1, /* to zero-based */
authIdOrderable, Orderable.ORDER_OP_EQUALS, false, false, false);
ScanController sc = tc.openScan(ti.getHeapConglomerate(), // 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);
boolean result = false;
try {
ExecRow outRow = rf.makeEmptyRow();
if (sc.fetchNext(outRow.getRowArray())) {
result = true;
}
} finally {
if (sc != null) {
sc.close();
}
if (heapCC != null) {
heapCC.close();
}
}
return result;
}
use of org.apache.derby.iapi.sql.execute.ExecRow in project derby by apache.
the class DataDictionaryImpl method updateTriggerDescriptor.
/**
* Update the trigger descriptor in question. Updates
* every row in the base conglomerate that matches the uuid.
*
* @param triggerd The Trigger descriptor
* @param formerUUID The UUID for this column in SYSTRIGGERS,
* may differ from what is in triggerd if this
* is the column that is being set.
* @param colsToSet Array of ints of columns to be modified,
* 1 based. May be null (all cols).
* @param tc The TransactionController to use
*
* @exception StandardException Thrown on failure
*/
public void updateTriggerDescriptor(TriggerDescriptor triggerd, UUID formerUUID, int[] colsToSet, TransactionController tc) throws StandardException {
ExecIndexRow keyRow1 = null;
ExecRow row;
DataValueDescriptor IDOrderable;
TabInfoImpl ti = getNonCoreTI(SYSTRIGGERS_CATALOG_NUM);
SYSTRIGGERSRowFactory rf = (SYSTRIGGERSRowFactory) ti.getCatalogRowFactory();
/* Use objectID 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 SYSTRIGGERS.
row = rf.makeRow(triggerd, null);
/*
** Figure out if the index in systriggers needs
** to be updated.
*/
if (SanityManager.DEBUG) {
SanityManager.ASSERT(rf.getNumIndexes() == 3, "There are more indexes on systriggers 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 SYSTRIGGERSRowFactory.SYSTRIGGERS_TRIGGERID:
bArray[0] = true;
break;
case SYSTRIGGERSRowFactory.SYSTRIGGERS_TRIGGERNAME:
case SYSTRIGGERSRowFactory.SYSTRIGGERS_SCHEMAID:
bArray[1] = true;
break;
case SYSTRIGGERSRowFactory.SYSTRIGGERS_TABLEID:
bArray[2] = true;
break;
}
}
}
ti.updateRow(keyRow1, row, SYSTRIGGERSRowFactory.SYSTRIGGERS_INDEX1_ID, bArray, colsToSet, tc);
}
use of org.apache.derby.iapi.sql.execute.ExecRow in project derby by apache.
the class DataDictionaryImpl method dropAllRoutinePermDescriptors.
/**
* Drops all routine permission descriptors for the given routine.
*
* @param routineID The UUID of the routine from which to drop
* all the permission descriptors
* @param tc TransactionController for the transaction
*
* @exception StandardException Thrown on error
*/
public void dropAllRoutinePermDescriptors(UUID routineID, TransactionController tc) throws StandardException {
TabInfoImpl ti = getNonCoreTI(SYSROUTINEPERMS_CATALOG_NUM);
SYSROUTINEPERMSRowFactory rf = (SYSROUTINEPERMSRowFactory) ti.getCatalogRowFactory();
DataValueDescriptor routineIdOrderable;
ExecRow curRow;
PermissionsDescriptor perm;
// In Derby authorization mode, permission catalogs may not be present
if (!usesSqlAuthorization)
return;
/* Use tableIDOrderable in both start and stop position for scan. */
routineIdOrderable = getIDValueAsCHAR(routineID);
/* Set up the start/stop position for the scan */
ExecIndexRow keyRow = exFactory.getIndexableRow(1);
keyRow.setColumn(1, routineIdOrderable);
while ((curRow = ti.getRow(tc, keyRow, rf.ALIASID_INDEX_NUM)) != null) {
perm = (PermissionsDescriptor) rf.buildDescriptor(curRow, (TupleDescriptor) null, this);
removePermEntryInCache(perm);
// Build new key based on UUID and drop the entry as we want to drop
// only this row
ExecIndexRow uuidKey;
uuidKey = rf.buildIndexKeyRow(rf.ROUTINEPERMSID_INDEX_NUM, perm);
ti.deleteRow(tc, uuidKey, rf.ROUTINEPERMSID_INDEX_NUM);
}
}
use of org.apache.derby.iapi.sql.execute.ExecRow in project derby by apache.
the class DataDictionaryImpl method addDescriptorArray.
/**
* array version of addDescriptor.
* @see DataDictionary#addDescriptor
*/
public void addDescriptorArray(TupleDescriptor[] td, TupleDescriptor parent, int catalogNumber, boolean allowDuplicates, TransactionController tc) throws StandardException {
TabInfoImpl ti = (catalogNumber < NUM_CORE) ? coreInfo[catalogNumber] : getNonCoreTI(catalogNumber);
CatalogRowFactory crf = ti.getCatalogRowFactory();
ExecRow[] rl = new ExecRow[td.length];
for (int index = 0; index < td.length; index++) {
ExecRow row = crf.makeRow(td[index], parent);
rl[index] = row;
}
int insertRetCode = ti.insertRowList(rl, tc);
if (!allowDuplicates && insertRetCode != TabInfoImpl.ROWNOTDUPLICATE) {
throw duplicateDescriptorException(td[insertRetCode], parent);
}
}
Aggregations