use of org.apache.derby.iapi.sql.compile.CompilerContext in project derby by apache.
the class MatchingClauseNode method bindExpressions.
// ///////////////
//
// BIND MINIONS
//
// ///////////////
/**
* Boilerplate for binding a list of ResultColumns against a FromList
*/
private void bindExpressions(ResultColumnList rcl, FromList fromList) throws StandardException {
CompilerContext cc = getCompilerContext();
final int previousReliability = cc.getReliability();
boolean wasSkippingTypePrivileges = cc.skipTypePrivileges(true);
cc.setReliability(previousReliability | CompilerContext.SQL_IN_ROUTINES_ILLEGAL);
try {
rcl.bindExpressions(fromList, new SubqueryList(getContextManager()), new ArrayList<AggregateNode>());
} finally {
// Restore previous compiler state
cc.setReliability(previousReliability);
cc.skipTypePrivileges(wasSkippingTypePrivileges);
}
}
use of org.apache.derby.iapi.sql.compile.CompilerContext in project derby by apache.
the class MergeNode method bindLeftJoin.
// /////////////////////////
//
// BINDING THE LEFT JOIN
//
// /////////////////////////
/**
* Bind the driving left join select.
* Stuffs the left join SelectNode into the resultSet variable.
*/
private void bindLeftJoin(DataDictionary dd) throws StandardException {
CompilerContext cc = getCompilerContext();
final int previousReliability = cc.getReliability();
try {
cc.setReliability(previousReliability | CompilerContext.SQL_IN_ROUTINES_ILLEGAL);
//
// Don't add any privileges until we bind the matching refinement clauses.
//
IgnoreFilter ignorePermissions = new IgnoreFilter();
getCompilerContext().addPrivilegeFilter(ignorePermissions);
_hojn = new HalfOuterJoinNode(_sourceTable, _targetTable, _searchCondition, null, false, null, getContextManager());
_leftJoinFromList = _hojn.makeFromList(true, true);
_leftJoinFromList.bindTables(dd, new FromList(getOptimizerFactory().doJoinOrderOptimization(), getContextManager()));
if (!sourceIsBase_or_VTI()) {
throw StandardException.newException(SQLState.LANG_SOURCE_NOT_BASE_OR_VTI);
}
FromList topFromList = new FromList(getOptimizerFactory().doJoinOrderOptimization(), getContextManager());
topFromList.addFromTable(_hojn);
// ready to add permissions
getCompilerContext().removePrivilegeFilter(ignorePermissions);
// code generation.
for (MatchingClauseNode mcn : _matchingClauses) {
mcn.bindRefinement(this, _leftJoinFromList);
}
ResultColumnList selectList = buildSelectList();
// save a copy so that we can remap column references when generating the temporary rows
_selectList = selectList.copyListAndObjects();
resultSet = new SelectNode(selectList, topFromList, // where clause
null, // group by list
null, // having clause
null, // window list
null, // optimizer plan override
null, getContextManager());
// Wrap the SELECT in a CursorNode in order to finish binding it.
_leftJoinCursor = new CursorNode("SELECT", resultSet, null, null, null, null, false, CursorNode.READ_ONLY, null, true, getContextManager());
//
// We're only interested in privileges related to the ON clause.
// Otherwise, the driving left join should not contribute any
// privilege requirements.
//
getCompilerContext().addPrivilegeFilter(ignorePermissions);
_leftJoinCursor.bindStatement();
// ready to add permissions again
getCompilerContext().removePrivilegeFilter(ignorePermissions);
// now figure out what privileges are needed for the ON clause
addOnClausePrivileges();
} finally {
// Restore previous compiler state
cc.setReliability(previousReliability);
}
}
use of org.apache.derby.iapi.sql.compile.CompilerContext in project derby by apache.
the class MergeNode method addRoutinePrivilege.
/**
* <p>
* Add EXECUTE privilege on the indicated routine.
* </p>
*/
private void addRoutinePrivilege(StaticMethodCallNode routine) throws StandardException {
CompilerContext cc = getCompilerContext();
cc.pushCurrentPrivType(Authorizer.EXECUTE_PRIV);
cc.addRequiredRoutinePriv(routine.ad);
cc.popCurrentPrivType();
}
use of org.apache.derby.iapi.sql.compile.CompilerContext in project derby by apache.
the class MergeNode method bindExpression.
/**
* Boilerplate for binding an expression against a FromList
*/
void bindExpression(ValueNode value, FromList fromList) throws StandardException {
CompilerContext cc = getCompilerContext();
final int previousReliability = cc.getReliability();
cc.setReliability(previousReliability | CompilerContext.SQL_IN_ROUTINES_ILLEGAL);
cc.pushCurrentPrivType(Authorizer.SELECT_PRIV);
try {
// this adds SELECT priv on referenced columns and EXECUTE privs on referenced routines
value.bindExpression(fromList, new SubqueryList(getContextManager()), new ArrayList<AggregateNode>());
} finally {
// Restore previous compiler state
cc.popCurrentPrivType();
cc.setReliability(previousReliability);
}
}
use of org.apache.derby.iapi.sql.compile.CompilerContext in project derby by apache.
the class NextSequenceNode method bindExpression.
/**
* Bind this expression. This means binding the sub-expressions,
* as well as figuring out what the return type is for this expression.
*
* @param fromList The FROM list for the query this
* expression is in, for binding columns.
* @param subqueryList The subquery list being built as we find SubqueryNodes
* @param aggregates The aggregate list being built as we find AggregateNodes
* @return The new top of the expression tree.
* @throws StandardException Thrown on error
*/
@Override
ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates, boolean forQueryRewrite) throws StandardException {
//
if (sequenceDescriptor != null) {
return this;
}
CompilerContext cc = getCompilerContext();
if ((cc.getReliability() & CompilerContext.NEXT_VALUE_FOR_ILLEGAL) != 0) {
throw StandardException.newException(SQLState.LANG_NEXT_VALUE_FOR_ILLEGAL);
}
// lookup sequence object in the data dictionary
sequenceName.bind();
SchemaDescriptor sd = getSchemaDescriptor(sequenceName.getSchemaName());
sequenceDescriptor = getDataDictionary().getSequenceDescriptor(sd, sequenceName.getTableName());
if (sequenceDescriptor == null) {
throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, "SEQUENCE", sequenceName.getFullTableName());
}
//
if (sd.isSystemSchema()) {
throw StandardException.newException(SQLState.LANG_SYSTEM_SEQUENCE);
}
// set the datatype of the value node
this.setType(sequenceDescriptor.getDataType());
//
if (cc.isReferenced(sequenceDescriptor)) {
throw StandardException.newException(SQLState.LANG_SEQUENCE_REFERENCED_TWICE, sequenceName.getFullTableName());
}
cc.addReferencedSequence(sequenceDescriptor);
ValueNode returnNode = this;
// set up dependency on sequence and compile a check for USAGE
// priv if needed
getCompilerContext().createDependency(sequenceDescriptor);
if (isPrivilegeCollectionRequired()) {
getCompilerContext().addRequiredUsagePriv(sequenceDescriptor);
}
return returnNode;
}
Aggregations