Search in sources :

Example 1 with ReferenceModelClause

use of com.alibaba.druid.sql.dialect.oracle.ast.clause.ModelClause.ReferenceModelClause in project druid by alibaba.

the class OracleOutputVisitor method visit.

@Override
public boolean visit(ModelClause x) {
    print0(ucase ? "MODEL" : "model");
    incrementIndent();
    for (CellReferenceOption opt : x.getCellReferenceOptions()) {
        print(' ');
        print0(opt.name);
    }
    if (x.getReturnRowsClause() != null) {
        print(' ');
        x.getReturnRowsClause().accept(this);
    }
    for (ReferenceModelClause item : x.getReferenceModelClauses()) {
        print(' ');
        item.accept(this);
    }
    x.getMainModel().accept(this);
    decrementIndent();
    return false;
}
Also used : CellReferenceOption(com.alibaba.druid.sql.dialect.oracle.ast.clause.ModelClause.CellReferenceOption) ReferenceModelClause(com.alibaba.druid.sql.dialect.oracle.ast.clause.ModelClause.ReferenceModelClause)

Example 2 with ReferenceModelClause

use of com.alibaba.druid.sql.dialect.oracle.ast.clause.ModelClause.ReferenceModelClause in project druid by alibaba.

the class OracleSelectParser method parseModelClause.

private void parseModelClause(OracleSelectQueryBlock queryBlock) {
    if (lexer.token() != Token.MODEL) {
        return;
    }
    lexer.nextToken();
    ModelClause model = new ModelClause();
    parseCellReferenceOptions(model.getCellReferenceOptions());
    if (identifierEquals("RETURN")) {
        lexer.nextToken();
        ReturnRowsClause returnRowsClause = new ReturnRowsClause();
        if (lexer.token() == Token.ALL) {
            lexer.nextToken();
            returnRowsClause.setAll(true);
        } else {
            acceptIdentifier("UPDATED");
        }
        acceptIdentifier("ROWS");
        model.setReturnRowsClause(returnRowsClause);
    }
    while (identifierEquals("REFERENCE")) {
        ReferenceModelClause referenceModelClause = new ReferenceModelClause();
        lexer.nextToken();
        SQLExpr name = expr();
        referenceModelClause.setName(name);
        accept(Token.ON);
        accept(Token.LPAREN);
        OracleSelect subQuery = this.select();
        accept(Token.RPAREN);
        referenceModelClause.setSubQuery(subQuery);
        parseModelColumnClause(referenceModelClause);
        parseCellReferenceOptions(referenceModelClause.getCellReferenceOptions());
        model.getReferenceModelClauses().add(referenceModelClause);
    }
    parseMainModelClause(model);
    queryBlock.setModelClause(model);
}
Also used : ModelClause(com.alibaba.druid.sql.dialect.oracle.ast.clause.ModelClause) ReferenceModelClause(com.alibaba.druid.sql.dialect.oracle.ast.clause.ModelClause.ReferenceModelClause) MainModelClause(com.alibaba.druid.sql.dialect.oracle.ast.clause.ModelClause.MainModelClause) ReturnRowsClause(com.alibaba.druid.sql.dialect.oracle.ast.clause.ModelClause.ReturnRowsClause) OracleSelect(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSelect) ReferenceModelClause(com.alibaba.druid.sql.dialect.oracle.ast.clause.ModelClause.ReferenceModelClause) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Aggregations

ReferenceModelClause (com.alibaba.druid.sql.dialect.oracle.ast.clause.ModelClause.ReferenceModelClause)2 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)1 ModelClause (com.alibaba.druid.sql.dialect.oracle.ast.clause.ModelClause)1 CellReferenceOption (com.alibaba.druid.sql.dialect.oracle.ast.clause.ModelClause.CellReferenceOption)1 MainModelClause (com.alibaba.druid.sql.dialect.oracle.ast.clause.ModelClause.MainModelClause)1 ReturnRowsClause (com.alibaba.druid.sql.dialect.oracle.ast.clause.ModelClause.ReturnRowsClause)1 OracleSelect (com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSelect)1