use of org.apache.derby.iapi.services.context.ContextManager in project derby by apache.
the class JoinNode method deferredBindExpressions.
private void deferredBindExpressions(FromList fromListParam) throws StandardException {
ContextManager cm = getContextManager();
CompilerContext cc = getCompilerContext();
/* Bind the expressions in the join clause */
subqueryList = new SubqueryList(cm);
aggregates = new ArrayList<AggregateNode>();
/* ON clause */
if (joinClause != null) {
joinClause = bindExpression(joinClause, true, true, "ON");
} else /* USING clause */
if (usingClause != null) {
/* Build a join clause from the usingClause, using the
* exposed names in the left and right RSNs.
* For each column in the list, we generate 2 ColumnReferences,
* 1 for the left and 1 for the right. We bind each of these
* to the appropriate side and build an equality predicate
* between the 2. We bind the = and AND nodes by hand because
* we have to bind the ColumnReferences a side at a time.
* We need to bind the CRs a side at a time to ensure that
* we don't find an bogus ambiguous column reference. (Bug 377)
*/
joinClause = new BooleanConstantNode(true, cm);
for (ResultColumn rc : usingClause) {
BinaryComparisonOperatorNode equalsNode;
ColumnReference leftCR;
ColumnReference rightCR;
/* Create and bind the left CR */
fromListParam.insertElementAt(leftResultSet, 0);
leftCR = new ColumnReference(rc.getName(), ((FromTable) leftResultSet).getTableName(), cm);
leftCR = (ColumnReference) leftCR.bindExpression(fromListParam, subqueryList, aggregates);
fromListParam.removeElementAt(0);
/* Create and bind the right CR */
fromListParam.insertElementAt(rightResultSet, 0);
rightCR = new ColumnReference(rc.getName(), ((FromTable) rightResultSet).getTableName(), cm);
rightCR = (ColumnReference) rightCR.bindExpression(fromListParam, subqueryList, aggregates);
fromListParam.removeElementAt(0);
/* Create and insert the new = condition */
equalsNode = new BinaryRelationalOperatorNode(BinaryRelationalOperatorNode.K_EQUALS, leftCR, rightCR, false, cm);
equalsNode.bindComparisonOperator();
// Create a new join clause by ANDing the new = condition and
// the old join clause.
AndNode newJoinClause = new AndNode(equalsNode, joinClause, cm);
newJoinClause.postBindFixup();
joinClause = newJoinClause;
}
}
if (joinClause != null) {
/* If joinClause is a parameter, (where ?), then we assume
* it will be a nullable boolean.
*/
if (joinClause.requiresTypeFromContext()) {
joinClause.setType(new DataTypeDescriptor(TypeId.BOOLEAN_ID, true));
}
/*
** Is the datatype of the JOIN clause BOOLEAN?
**
** NOTE: This test is not necessary in SQL92 entry level, because
** it is syntactically impossible to have a non-Boolean JOIN clause
** in that level of the standard. But we intend to extend the
** language to allow Boolean user functions in the JOIN clause,
** so we need to test for the error condition.
*/
TypeId joinTypeId = joinClause.getTypeId();
/* If the where clause is not a built-in type, then generate a bound
* conversion tree to a built-in type.
*/
if (joinTypeId.userType()) {
joinClause = joinClause.genSQLJavaSQLTree();
}
if (!joinClause.getTypeServices().getTypeId().equals(TypeId.BOOLEAN_ID)) {
throw StandardException.newException(SQLState.LANG_NON_BOOLEAN_JOIN_CLAUSE, joinClause.getTypeServices().getTypeId().getSQLTypeName());
}
}
}
use of org.apache.derby.iapi.services.context.ContextManager in project derby by apache.
the class JoinNode method bindExpression.
/**
* Bind an expression against the child tables of the JoinNode. May
* update the subquery and aggregate lists in the JoinNode. Assumes that
* the subquery and aggregate lists for the JoinNode have already been created.
*
* @return the bound expression
*/
public ValueNode bindExpression(ValueNode expression, boolean useLeftChild, boolean useRightChild, String expressionType) throws StandardException {
ContextManager cm = getContextManager();
CompilerContext cc = getCompilerContext();
/* Create a new fromList with only left and right children before
* binding the join clause. Valid column references in the join clause
* are limited to columns from the 2 tables being joined. This
* algorithm enforces that.
*/
FromList fromList = makeFromList(useLeftChild, useRightChild);
int previousReliability = orReliability(CompilerContext.ON_CLAUSE_RESTRICTION);
expression = expression.bindExpression(fromList, subqueryList, aggregates);
cc.setReliability(previousReliability);
// SQL 2003, section 7.7 SR 5
SelectNode.checkNoWindowFunctions(expression, expressionType);
/*
** We cannot have aggregates in the ON clause.
** In the future, if we relax this, we'll need
** to be able to pass the list of aggregates up
** the tree.
*/
if (!aggregates.isEmpty()) {
throw StandardException.newException(SQLState.LANG_NO_AGGREGATES_IN_ON_CLAUSE);
}
return expression;
}
use of org.apache.derby.iapi.services.context.ContextManager in project derby by apache.
the class InternalDriver method getConnectionContext.
private ConnectionContext getConnectionContext() {
/*
** The current connection is the one in the current
** connection context, so get the context.
*/
ContextManager cm = getCurrentContextManager();
ConnectionContext localCC = null;
/*
cm is null the very first time, and whenever
we aren't actually nested.
*/
if (cm != null) {
localCC = (ConnectionContext) (cm.getContext(ConnectionContext.CONTEXT_ID));
}
return localCC;
}
use of org.apache.derby.iapi.services.context.ContextManager in project derby by apache.
the class BaseMonitor method shutdown.
public void shutdown() {
// allow only one caller to shut the monitor down
synchronized (this) {
if (inShutdown)
return;
inShutdown = true;
}
Monitor.getStream().println(LINE);
// Make a note of Engine shutdown in the log file
Monitor.getStream().println(MessageService.getTextMessage(MessageId.CONN_SHUT_DOWN_ENGINE, new Date().toString()));
if (SanityManager.DEBUG && reportOn) {
report("Shutdown request");
}
// Shutdown all threads by iterrupting them
contextService.notifyAllActiveThreads((Context) null);
for (; ; ) {
TopService ts;
int position;
synchronized (this) {
position = services.size() - 1;
if (position == 0)
break;
ts = services.get(position);
}
// push a new context manager
ContextManager cm = contextService.newContextManager();
try {
// pop the default shutdown context, we are shutting down
cm.popContext();
contextService.setCurrentContextManager(cm);
shutdown(ts.getService());
} finally {
contextService.resetCurrentContextManager(cm);
}
}
Monitor.getStream().println(LINE);
(services.get(0)).shutdown();
stopContextService();
}
use of org.apache.derby.iapi.services.context.ContextManager in project derby by apache.
the class FromTable method getResultColumnsForList.
/**
* Return a ResultColumnList with all of the columns in this table.
* (Used in expanding '*'s.)
* NOTE: Since this method is for expanding a "*" in the SELECT list,
* ResultColumn.expression will be a ColumnReference.
*
* @param allTableName The qualifier on the "*"
*
* @return ResultColumnList List of result columns from this table.
*
* @exception StandardException Thrown on error
*/
ResultColumnList getResultColumnsForList(TableName allTableName, ResultColumnList inputRcl, TableName tableName) throws StandardException {
TableName exposedName;
TableName toCompare;
if (correlationName == null)
toCompare = tableName;
else {
if (allTableName != null)
toCompare = makeTableName(allTableName.getSchemaName(), correlationName);
else
toCompare = makeTableName(null, correlationName);
}
if (allTableName != null && !allTableName.equals(toCompare)) {
return null;
}
/* Cache exposed name for this table.
* The exposed name becomes the qualifier for each column
* in the expanded list.
*/
if (correlationName == null) {
exposedName = tableName;
} else {
exposedName = makeTableName(null, correlationName);
}
final ContextManager cm = getContextManager();
ResultColumnList rcList = new ResultColumnList(cm);
/* Build a new result column list based off of resultColumns.
* NOTE: This method will capture any column renaming due to
* a derived column list.
*/
for (ResultColumn rc : inputRcl) {
ColumnReference oldCR = rc.getReference();
if (oldCR != null) {
// this is necessary in order to correctly bind the column list of the dummy SELECT.
if (oldCR.getMergeTableID() != ColumnReference.MERGE_UNKNOWN) {
exposedName = oldCR.getQualifiedTableName();
}
}
ColumnReference newCR = new ColumnReference(rc.getName(), exposedName, cm);
if ((oldCR != null) && (oldCR.getMergeTableID() != ColumnReference.MERGE_UNKNOWN)) {
newCR.setMergeTableID(oldCR.getMergeTableID());
}
ResultColumn newRc = new ResultColumn(rc.getName(), newCR, cm);
rcList.addResultColumn(newRc);
}
return rcList;
}
Aggregations