use of org.apache.derby.iapi.types.SQLVarchar in project derby by apache.
the class DataDictionaryImpl method getRoleGrantGraph.
/**
* Return an in-memory representation of the role grant graph (sans
* grant of roles to users, only role-role relation.
*
* @param tc Transaction Controller
* @param inverse make graph on inverse grant relation
* @return hash map representing role grant graph.
* <ul><li>Key: rolename,</li>
* <li>Value: List<RoleGrantDescriptor> representing a
* grant of that rolename to another role (not user).
* </li>
* </ul>
*
* FIXME: Need to cache graph and invalidate when role graph is modified.
* Currently, we always read from SYSROLES.
*/
HashMap<String, List<RoleGrantDescriptor>> getRoleGrantGraph(TransactionController tc, boolean inverse) throws StandardException {
HashMap<String, List<RoleGrantDescriptor>> hm = new HashMap<String, List<RoleGrantDescriptor>>();
TabInfoImpl ti = getNonCoreTI(SYSROLES_CATALOG_NUM);
SYSROLESRowFactory rf = (SYSROLESRowFactory) ti.getCatalogRowFactory();
DataValueDescriptor isDefOrderable = new SQLVarchar("N");
ScanQualifier[][] scanQualifier = exFactory.getScanQualifier(1);
scanQualifier[0][0].setQualifier(SYSROLESRowFactory.SYSROLES_ISDEF - 1, /* to zero-based */
isDefOrderable, 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);
ExecRow outRow = rf.makeEmptyRow();
RoleGrantDescriptor grantDescr;
while (sc.fetchNext(outRow.getRowArray())) {
grantDescr = (RoleGrantDescriptor) rf.buildDescriptor(outRow, (TupleDescriptor) null, this);
// Next call is potentially inefficient. We could read in
// definitions first in a separate hash table limiting
// this to a 2-pass scan.
RoleGrantDescriptor granteeDef = getRoleDefinitionDescriptor(grantDescr.getGrantee());
if (granteeDef == null) {
// not a role, must be user authid, skip
continue;
}
String hashKey;
if (inverse) {
hashKey = granteeDef.getRoleName();
} else {
hashKey = grantDescr.getRoleName();
}
List<RoleGrantDescriptor> arcs = hm.get(hashKey);
if (arcs == null) {
arcs = new LinkedList<RoleGrantDescriptor>();
}
arcs.add(grantDescr);
hm.put(hashKey, arcs);
}
sc.close();
return hm;
}
use of org.apache.derby.iapi.types.SQLVarchar in project derby by apache.
the class DataDictionaryImpl method upgradeCLOBGETSUBSTRING_10_6.
/**
* 10.6 upgrade logic to update the return type of SYSIBM.CLOBGETSUBSTRING. The length of the
* return type was changed in 10.5 but old versions of the metadata were not
* upgraded at that time. See DERBY-4214.
*/
void upgradeCLOBGETSUBSTRING_10_6(TransactionController tc) throws StandardException {
TabInfoImpl ti = getNonCoreTI(SYSALIASES_CATALOG_NUM);
ExecIndexRow keyRow = exFactory.getIndexableRow(3);
DataValueDescriptor aliasNameOrderable = new SQLVarchar("CLOBGETSUBSTRING");
DataValueDescriptor nameSpaceOrderable = new SQLChar(new String(new char[] { AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR }));
keyRow.setColumn(1, new SQLChar(SchemaDescriptor.SYSIBM_SCHEMA_UUID));
keyRow.setColumn(2, aliasNameOrderable);
keyRow.setColumn(3, nameSpaceOrderable);
AliasDescriptor oldAD = getDescriptorViaIndex(SYSALIASESRowFactory.SYSALIASES_INDEX1_ID, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, (List<TupleDescriptor>) null, AliasDescriptor.class, true, TransactionController.ISOLATION_REPEATABLE_READ, tc);
RoutineAliasInfo oldRai = (RoutineAliasInfo) oldAD.getAliasInfo();
TypeDescriptor newReturnType = DataTypeDescriptor.getCatalogType(Types.VARCHAR, Limits.MAX_CLOB_RETURN_LEN);
RoutineAliasInfo newRai = new RoutineAliasInfo(oldRai.getMethodName(), oldRai.getParameterCount(), oldRai.getParameterNames(), oldRai.getParameterTypes(), oldRai.getParameterModes(), oldRai.getMaxDynamicResultSets(), oldRai.getParameterStyle(), oldRai.getSQLAllowed(), oldRai.isDeterministic(), oldRai.hasVarargs(), oldRai.hasDefinersRights(), oldRai.calledOnNullInput(), newReturnType);
AliasDescriptor newAD = new AliasDescriptor(this, oldAD.getUUID(), oldAD.getObjectName(), oldAD.getSchemaUUID(), oldAD.getJavaClassName(), oldAD.getAliasType(), oldAD.getNameSpace(), oldAD.getSystemAlias(), newRai, oldAD.getSpecificName());
ExecRow newRow = ti.getCatalogRowFactory().makeRow(newAD, null);
ti.updateRow(keyRow, newRow, SYSALIASESRowFactory.SYSALIASES_INDEX1_ID, new boolean[] { false, false, false }, (int[]) null, tc);
}
use of org.apache.derby.iapi.types.SQLVarchar in project derby by apache.
the class DataDictionaryImpl method getConstraintDescriptor.
/**
* Get a ConstraintDescriptor given its name and schema ID.
* Please use getConstraintDescriptorByName() if you have the
* constraint's table descriptor, it is much faster.
*
* @param constraintName Constraint name.
* @param schemaID The schema UUID
*
* @return The ConstraintDescriptor for the constraint.
*
* @exception StandardException Thrown on failure
*/
public ConstraintDescriptor getConstraintDescriptor(String constraintName, UUID schemaID) throws StandardException {
DataValueDescriptor UUIDStringOrderable;
DataValueDescriptor constraintNameOrderable;
TabInfoImpl ti = getNonCoreTI(SYSCONSTRAINTS_CATALOG_NUM);
/* Construct keys for both start and stop positions for scan */
constraintNameOrderable = new SQLVarchar(constraintName);
UUIDStringOrderable = getIDValueAsCHAR(schemaID);
/* Set up the start/stop position for the scan */
ExecIndexRow keyRow = exFactory.getIndexableRow(2);
keyRow.setColumn(1, constraintNameOrderable);
keyRow.setColumn(2, UUIDStringOrderable);
return getConstraintDescriptorViaIndex(SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_INDEX2_ID, keyRow, ti, (TableDescriptor) null, (ConstraintDescriptorList) null, false);
}
use of org.apache.derby.iapi.types.SQLVarchar in project derby by apache.
the class DataDictionaryImpl method updateColumnDescriptor.
/**
* Update the column descriptor in question. Updates
* every row in the base conglomerate.
*
* @param cd The ColumnDescriptor
* @param formerUUID The UUID for this column in SYSCOLUMNS,
* may differ from what is in cd if this
* is the column that is being set.
* @param formerName The name for this column in SYSCOLUMNS
* may differ from what is in cd 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
*/
private void updateColumnDescriptor(ColumnDescriptor cd, UUID formerUUID, String formerName, int[] colsToSet, TransactionController tc) throws StandardException {
ExecIndexRow keyRow1 = null;
ExecRow row;
DataValueDescriptor refIDOrderable;
DataValueDescriptor columnNameOrderable;
TabInfoImpl ti = coreInfo[SYSCOLUMNS_CORE_NUM];
SYSCOLUMNSRowFactory rf = (SYSCOLUMNSRowFactory) ti.getCatalogRowFactory();
/* Use objectID/columnName in both start
* and stop position for index 1 scan.
*/
refIDOrderable = getIDValueAsCHAR(formerUUID);
columnNameOrderable = new SQLVarchar(formerName);
/* Set up the start/stop position for the scan */
keyRow1 = (ExecIndexRow) exFactory.getIndexableRow(2);
keyRow1.setColumn(1, refIDOrderable);
keyRow1.setColumn(2, columnNameOrderable);
// build the row to be stuffed into SYSCOLUMNS.
row = rf.makeRow(cd, null);
/*
** Figure out if the index in syscolumns needs
** to be updated.
*/
if (SanityManager.DEBUG) {
SanityManager.ASSERT(rf.getNumIndexes() == 2, "There are more indexes on syscolumns than expected, the code herein needs to change");
}
boolean[] bArray = new boolean[rf.getNumIndexes()];
/*
** Do we need to update indexes?
*/
if (colsToSet == null) {
bArray[0] = true;
bArray[1] = true;
} else {
/*
** Check the specific columns for indexed
** columns.
*/
for (int i = 0; i < colsToSet.length; i++) {
if ((colsToSet[i] == rf.SYSCOLUMNS_COLUMNNAME) || (colsToSet[i] == rf.SYSCOLUMNS_REFERENCEID)) {
bArray[0] = true;
break;
} else if (colsToSet[i] == rf.SYSCOLUMNS_COLUMNDEFAULTID) {
bArray[1] = true;
break;
}
}
}
ti.updateRow(keyRow1, row, SYSCOLUMNSRowFactory.SYSCOLUMNS_INDEX1_ID, bArray, colsToSet, tc);
}
use of org.apache.derby.iapi.types.SQLVarchar in project derby by apache.
the class DataDictionaryImpl method getUser.
public UserDescriptor getUser(String userName) throws StandardException {
//
// No sense looking for the SYSUSERS congomerate until the database
// is hard-upgraded to 10.9 or later.
//
dictionaryVersion.checkVersion(DD_VERSION_DERBY_10_9, "NATIVE AUTHENTICATION");
ExecIndexRow keyRow;
TabInfoImpl ti = getNonCoreTI(SYSUSERS_CATALOG_NUM);
/* Set up the start/stop position for the scan */
keyRow = (ExecIndexRow) exFactory.getIndexableRow(1);
keyRow.setColumn(1, new SQLVarchar(userName));
return getDescriptorViaIndex(SYSUSERSRowFactory.SYSUSERS_INDEX1_ID, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, (List<TupleDescriptor>) null, UserDescriptor.class, false);
}
Aggregations