use of org.apache.derby.iapi.sql.compile.Visitable in project derby by apache.
the class QueryTreeNodeVector method acceptChildren.
/**
* Accept the visitor for all visitable children of this node.
*
* @param v the visitor
*
* @exception StandardException on error
*/
@Override
void acceptChildren(Visitor v) throws StandardException {
super.acceptChildren(v);
int size = size();
for (int index = 0; index < size; index++) {
Visitable vbl = elementAt(index).accept(v);
setElementAt(eltClass.cast(vbl), index);
}
}
use of org.apache.derby.iapi.sql.compile.Visitable in project derby by apache.
the class DMLModStatementNode method parseGenerationClause.
/**
* Parse the generation clause for a column.
*
* @param clauseText Text of the generation clause
*
* @return The parsed expression as a query tree.
*
* @exception StandardException Thrown on failure
*/
public ValueNode parseGenerationClause(String clauseText, TableDescriptor td) throws StandardException {
Parser p;
ValueNode clauseTree;
LanguageConnectionContext lcc = getLanguageConnectionContext();
/* Get a Statement to pass to the parser */
/* We're all set up to parse. We have to build a compilable SQL statement
* before we can parse - So, we goober up a VALUES defaultText.
*/
String select = "SELECT " + clauseText + " FROM " + td.getQualifiedName();
/*
** Get a new compiler context, so the parsing of the select statement
** doesn't mess up anything in the current context (it could clobber
** the ParameterValueSet, for example).
*/
CompilerContext newCC = lcc.pushCompilerContext();
p = newCC.getParser();
/* Finally, we can call the parser */
// Since this is always nested inside another SQL statement, so topLevel flag
// should be false
Visitable qt = p.parseStatement(select);
if (SanityManager.DEBUG) {
if (!(qt instanceof CursorNode)) {
SanityManager.THROWASSERT("qt expected to be instanceof CursorNode, not " + qt.getClass().getName());
}
CursorNode cn = (CursorNode) qt;
if (!(cn.getResultSetNode() instanceof SelectNode)) {
SanityManager.THROWASSERT("cn.getResultSetNode() expected to be instanceof SelectNode, not " + cn.getResultSetNode().getClass().getName());
}
}
clauseTree = ((CursorNode) qt).getResultSetNode().getResultColumns().elementAt(0).getExpression();
lcc.popCompilerContext(newCC);
return clauseTree;
}
use of org.apache.derby.iapi.sql.compile.Visitable in project derby by apache.
the class DefaultNode method parseDefault.
/**
* Parse a default and turn it into a query tree.
*
* @param defaultText Text of Default.
* @param lcc LanguageConnectionContext
* @param cc CompilerContext
*
* @return The parsed default as a query tree.
*
* @exception StandardException Thrown on failure
*/
public static ValueNode parseDefault(String defaultText, LanguageConnectionContext lcc, CompilerContext cc) throws StandardException {
Parser p;
ValueNode defaultTree;
/* Get a Statement to pass to the parser */
/* We're all set up to parse. We have to build a compilable SQL statement
* before we can parse - So, we goober up a VALUES defaultText.
*/
String values = "VALUES " + defaultText;
/*
** Get a new compiler context, so the parsing of the select statement
** doesn't mess up anything in the current context (it could clobber
** the ParameterValueSet, for example).
*/
CompilerContext newCC = lcc.pushCompilerContext();
p = newCC.getParser();
/* Finally, we can call the parser */
// Since this is always nested inside another SQL statement, so topLevel flag
// should be false
Visitable qt = p.parseStatement(values);
if (SanityManager.DEBUG) {
if (!(qt instanceof CursorNode)) {
SanityManager.THROWASSERT("qt expected to be instanceof CursorNode, not " + qt.getClass().getName());
}
CursorNode cn = (CursorNode) qt;
if (!(cn.getResultSetNode() instanceof RowResultSetNode)) {
SanityManager.THROWASSERT("cn.getResultSetNode() expected to be instanceof RowResultSetNode, not " + cn.getResultSetNode().getClass().getName());
}
}
defaultTree = ((CursorNode) qt).getResultSetNode().getResultColumns().elementAt(0).getExpression();
lcc.popCompilerContext(newCC);
return defaultTree;
}
Aggregations