Search in sources :

Example 6 with Visitable

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);
    }
}
Also used : Visitable(org.apache.derby.iapi.sql.compile.Visitable)

Example 7 with Visitable

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;
}
Also used : LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) CompilerContext(org.apache.derby.iapi.sql.compile.CompilerContext) Visitable(org.apache.derby.iapi.sql.compile.Visitable) Parser(org.apache.derby.iapi.sql.compile.Parser)

Example 8 with Visitable

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;
}
Also used : CompilerContext(org.apache.derby.iapi.sql.compile.CompilerContext) Visitable(org.apache.derby.iapi.sql.compile.Visitable) Parser(org.apache.derby.iapi.sql.compile.Parser)

Aggregations

Visitable (org.apache.derby.iapi.sql.compile.Visitable)8 CompilerContext (org.apache.derby.iapi.sql.compile.CompilerContext)6 Parser (org.apache.derby.iapi.sql.compile.Parser)6 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)3 UUID (org.apache.derby.catalog.UUID)1 SPSDescriptor (org.apache.derby.iapi.sql.dictionary.SPSDescriptor)1 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)1 StatementNode (org.apache.derby.impl.sql.compile.StatementNode)1 StandardException (org.apache.derby.shared.common.error.StandardException)1