use of org.apache.derby.iapi.sql.dictionary.AliasDescriptor in project derby by apache.
the class SecurityUtil method authorize.
/**
* Raise an exception if the current user does not have permission
* to perform the indicated operation.
*/
public static void authorize(Securable operation) throws StandardException {
LanguageConnectionContext lcc = (LanguageConnectionContext) getContextOrNull(LanguageConnectionContext.CONTEXT_ID);
if (lcc.usesSqlAuthorization()) {
Authorizer authorizer = lcc.getAuthorizer();
DataDictionary dd = lcc.getDataDictionary();
AliasDescriptor ad = dd.getRoutineList(operation.routineSchemaID, operation.routineName, operation.routineType).get(0);
ArrayList<StatementPermission> requiredPermissions = new ArrayList<StatementPermission>();
StatementRoutinePermission executePermission = new StatementRoutinePermission(ad.getObjectID());
requiredPermissions.add(executePermission);
authorizer.authorize(requiredPermissions, lcc.getLastActivation());
}
}
use of org.apache.derby.iapi.sql.dictionary.AliasDescriptor in project derby by apache.
the class CreateAliasNode method bindAggregate.
/**
* Extra logic for binding user-defined aggregate definitions
*/
private void bindAggregate() throws StandardException {
String unqualifiedName = getRelativeName();
//
// A user-defined aggregate cannot have the name of a builtin function which takes 1 argument.
//
SchemaDescriptor sysfun = getSchemaDescriptor("SYSFUN", true);
List<AliasDescriptor> systemFunctions = getDataDictionary().getRoutineList(sysfun.getUUID().toString(), unqualifiedName, AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR);
for (int i = 0; i < systemFunctions.size(); i++) {
AliasDescriptor function = systemFunctions.get(i);
RoutineAliasInfo routineInfo = (RoutineAliasInfo) function.getAliasInfo();
int parameterCount = routineInfo.getParameterCount();
if (parameterCount == 1) {
throw illegalAggregate();
}
}
//
for (int i = 0; i < NON_RESERVED_FUNCTION_NAMES.length; i++) {
if (NON_RESERVED_FUNCTION_NAMES[i].equals(unqualifiedName)) {
throw illegalAggregate();
}
}
//
for (int i = 0; i < NON_RESERVED_AGGREGATES.length; i++) {
if (NON_RESERVED_AGGREGATES[i].equals(unqualifiedName)) {
throw illegalAggregate();
}
}
// now bind the input and return types
AggregateAliasInfo aai = (AggregateAliasInfo) aliasInfo;
aai.setCollationTypeForAllStringTypes(getSchemaDescriptor().getCollationType());
}
use of org.apache.derby.iapi.sql.dictionary.AliasDescriptor in project derby by apache.
the class XMLOptTrace method getOptimizableName.
/**
* Get the name of an optimizable
*/
private TableName getOptimizableName(Optimizable optimizable) {
try {
if (isBaseTable(optimizable)) {
ProjectRestrictNode prn = (ProjectRestrictNode) optimizable;
TableDescriptor td = ((FromBaseTable) prn.getChildResult()).getTableDescriptor();
return makeTableName(td.getSchemaName(), td.getName(), _cm);
} else if (OptimizerImpl.isTableFunction(optimizable)) {
ProjectRestrictNode prn = (ProjectRestrictNode) optimizable;
AliasDescriptor ad = ((StaticMethodCallNode) ((FromVTI) prn.getChildResult()).getMethodCall()).ad;
return makeTableName(ad.getSchemaName(), ad.getName(), _cm);
} else if (isFromTable(optimizable)) {
TableName retval = ((FromTable) ((ProjectRestrictNode) optimizable).getChildResult()).getTableName();
if (retval != null) {
return retval;
}
}
} catch (StandardException e) {
// Technically, an exception could occur here if the table name
// was not previously bound and if an error occured while binding it.
// But the optimizable should have been bound long before optimization,
// so this should not be a problem.
}
String nodeClass = optimizable.getClass().getName();
String unqualifiedName = nodeClass.substring(nodeClass.lastIndexOf(".") + 1);
return makeTableName(null, unqualifiedName, _cm);
}
use of org.apache.derby.iapi.sql.dictionary.AliasDescriptor in project derby by apache.
the class DDLConstantAction method adjustUDTDependencies.
/**
* Add and drop dependencies of a routine on UDTs.
*
* @param lcc Interpreter's state variable for this session.
* @param dd Metadata
* @param ad Alias descriptor for the routine
* @param adding True if we are adding dependencies, false if we're dropping them
*/
protected void adjustUDTDependencies(LanguageConnectionContext lcc, DataDictionary dd, AliasDescriptor ad, boolean adding) throws StandardException {
RoutineAliasInfo routineInfo = null;
AggregateAliasInfo aggInfo = null;
// nothing to do if this is not a routine
switch(ad.getAliasType()) {
case AliasInfo.ALIAS_TYPE_AGGREGATE_AS_CHAR:
aggInfo = (AggregateAliasInfo) ad.getAliasInfo();
break;
case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:
case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:
routineInfo = (RoutineAliasInfo) ad.getAliasInfo();
break;
default:
return;
}
TransactionController tc = lcc.getTransactionExecute();
HashMap<String, AliasDescriptor> addUdtMap = new HashMap<String, AliasDescriptor>();
HashMap<String, AliasDescriptor> dropUdtMap = new HashMap<String, AliasDescriptor>();
HashMap<String, AliasDescriptor> udtMap = adding ? addUdtMap : dropUdtMap;
TypeDescriptor rawReturnType = aggInfo != null ? aggInfo.getReturnType() : routineInfo.getReturnType();
if (rawReturnType != null) {
AliasDescriptor returnTypeAD = dd.getAliasDescriptorForUDT(tc, DataTypeDescriptor.getType(rawReturnType));
if (returnTypeAD != null) {
udtMap.put(returnTypeAD.getObjectID().toString(), returnTypeAD);
}
}
// table functions can have udt columns. track those dependencies.
if ((rawReturnType != null) && rawReturnType.isRowMultiSet()) {
TypeDescriptor[] columnTypes = rawReturnType.getRowTypes();
int columnCount = columnTypes.length;
for (int i = 0; i < columnCount; i++) {
AliasDescriptor columnTypeAD = dd.getAliasDescriptorForUDT(tc, DataTypeDescriptor.getType(columnTypes[i]));
if (columnTypeAD != null) {
udtMap.put(columnTypeAD.getObjectID().toString(), columnTypeAD);
}
}
}
TypeDescriptor[] paramTypes = aggInfo != null ? new TypeDescriptor[] { aggInfo.getForType() } : routineInfo.getParameterTypes();
if (paramTypes != null) {
int paramCount = paramTypes.length;
for (int i = 0; i < paramCount; i++) {
AliasDescriptor paramType = dd.getAliasDescriptorForUDT(tc, DataTypeDescriptor.getType(paramTypes[i]));
if (paramType != null) {
udtMap.put(paramType.getObjectID().toString(), paramType);
}
}
}
adjustUDTDependencies(lcc, dd, ad, addUdtMap, dropUdtMap);
}
use of org.apache.derby.iapi.sql.dictionary.AliasDescriptor in project derby by apache.
the class DDLConstantAction method adjustUDTDependencies.
/**
* Add and drop dependencies of an object on UDTs.
*
* @param lcc Interpreter's state variable for this session.
* @param dd Metadata
* @param dependent Object which depends on UDT
* @param addUdtMap Map of UDTs for which dependencies should be added
* @param dropUdtMap Map of UDT for which dependencies should be dropped
*/
private void adjustUDTDependencies(LanguageConnectionContext lcc, DataDictionary dd, Dependent dependent, HashMap<String, AliasDescriptor> addUdtMap, HashMap<String, AliasDescriptor> dropUdtMap) throws StandardException {
// again, nothing to do if there are no columns of udt type
if ((addUdtMap.isEmpty()) && (dropUdtMap.isEmpty())) {
return;
}
TransactionController tc = lcc.getTransactionExecute();
DependencyManager dm = dd.getDependencyManager();
ContextManager cm = lcc.getContextManager();
// add new dependencies
for (AliasDescriptor ad : addUdtMap.values()) {
dm.addDependency(dependent, ad, cm);
}
// drop dependencies that are orphaned
for (AliasDescriptor ad : dropUdtMap.values()) {
DependencyDescriptor dep = new DependencyDescriptor(dependent, ad);
dd.dropStoredDependency(dep, tc);
}
}
Aggregations