use of org.apache.derby.iapi.sql.execute.ExecIndexRow 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.ExecIndexRow in project derby by apache.
the class DataDictionaryImpl method dropViewDescriptor.
/**
* Drops the view descriptor from the data dictionary.
*
* @param vd A descriptor for the view to be dropped
* @param tc TransactionController to use
*
* @exception StandardException Thrown on error
*/
public void dropViewDescriptor(ViewDescriptor vd, TransactionController tc) throws StandardException {
DataValueDescriptor viewIdOrderable;
TabInfoImpl ti = getNonCoreTI(SYSVIEWS_CATALOG_NUM);
/* Use aliasNameOrderable in both start
* and stop position for scan.
*/
viewIdOrderable = getIDValueAsCHAR(vd.getUUID());
/* Set up the start/stop position for the scan */
ExecIndexRow keyRow = (ExecIndexRow) exFactory.getIndexableRow(1);
keyRow.setColumn(1, viewIdOrderable);
ti.deleteRow(tc, keyRow, SYSVIEWSRowFactory.SYSVIEWS_INDEX1_ID);
}
use of org.apache.derby.iapi.sql.execute.ExecIndexRow in project derby by apache.
the class DataDictionaryImpl method dropStatisticsDescriptors.
/**
* @see DataDictionary#dropStatisticsDescriptors
*/
public void dropStatisticsDescriptors(UUID tableUUID, UUID referenceUUID, TransactionController tc) throws StandardException {
TabInfoImpl ti = getNonCoreTI(SYSSTATISTICS_CATALOG_NUM);
DataValueDescriptor first, second;
first = getIDValueAsCHAR(tableUUID);
ExecIndexRow keyRow;
if (referenceUUID != null) {
keyRow = exFactory.getIndexableRow(2);
second = getIDValueAsCHAR(referenceUUID);
keyRow.setColumn(2, second);
} else {
keyRow = exFactory.getIndexableRow(1);
}
keyRow.setColumn(1, first);
ti.deleteRow(tc, keyRow, SYSSTATISTICSRowFactory.SYSSTATISTICS_INDEX1_ID);
}
use of org.apache.derby.iapi.sql.execute.ExecIndexRow 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.ExecIndexRow in project derby by apache.
the class DataDictionaryImpl method getRoleDefinitionDescriptor.
/**
* Get the target role definition by searching for a matching row
* in SYSROLES by rolename where isDef==true. Read only scan.
* Uses index on (rolename, isDef) columns.
*
* @param roleName The name of the role we're interested in.
*
* @return The descriptor (row) for the role
* @exception StandardException Thrown on error
*
* @see DataDictionary#getRoleDefinitionDescriptor
*/
public RoleGrantDescriptor getRoleDefinitionDescriptor(String roleName) throws StandardException {
DataValueDescriptor roleNameOrderable;
DataValueDescriptor isDefOrderable;
TabInfoImpl ti = getNonCoreTI(SYSROLES_CATALOG_NUM);
/* Use aliasNameOrderable , isDefOrderable in both start
* and stop position for scan.
*/
roleNameOrderable = new SQLVarchar(roleName);
isDefOrderable = new SQLVarchar("Y");
/* Set up the start/stop position for the scan */
ExecIndexRow keyRow = exFactory.getIndexableRow(2);
keyRow.setColumn(1, roleNameOrderable);
keyRow.setColumn(2, isDefOrderable);
return getDescriptorViaIndex(SYSROLESRowFactory.SYSROLES_INDEX_ID_DEF_IDX, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, (List<TupleDescriptor>) null, RoleGrantDescriptor.class, false);
}
Aggregations