Search in sources :

Example 1 with LanguageContext

use of org.jooq.LanguageContext in project jOOQ by jOOQ.

the class BlockImpl method accept0.

private final void accept0(Context<?> ctx) {
    boolean wrapInBeginEnd = alwaysWrapInBeginEnd;
    if (wrapInBeginEnd) {
        boolean topLevel = ctx.scopeLevel() == -1;
        LanguageContext language = ctx.languageContext();
        if (topLevel && language == LanguageContext.QUERY)
            ctx.languageContext(LanguageContext.BLOCK);
        {
            begin(ctx, topLevel);
            scopeDeclarations(ctx, c -> accept1(c));
            end(ctx, topLevel);
        }
        if (topLevel && language == LanguageContext.QUERY)
            ctx.languageContext(language);
    } else
        accept1(ctx);
}
Also used : K_BEGIN(org.jooq.impl.Keywords.K_BEGIN) BiFunction(java.util.function.BiFunction) K_TRUE(org.jooq.impl.Keywords.K_TRUE) UnmodifiableList(org.jooq.impl.QOM.UnmodifiableList) POSTGRES(org.jooq.SQLDialect.POSTGRES) Map(java.util.Map) Tools.decrement(org.jooq.impl.Tools.decrement) SQLDialect(org.jooq.SQLDialect) K_DROP(org.jooq.impl.Keywords.K_DROP) K_NOT(org.jooq.impl.Keywords.K_NOT) DATA_FORCE_STATIC_STATEMENT(org.jooq.impl.Tools.BooleanDataKey.DATA_FORCE_STATIC_STATEMENT) LanguageContext(org.jooq.LanguageContext) Predicate(java.util.function.Predicate) Name(org.jooq.Name) Collection(java.util.Collection) Keyword(org.jooq.Keyword) K_IF(org.jooq.impl.Keywords.K_IF) Tools.toplevel(org.jooq.impl.Tools.toplevel) Set(java.util.Set) DataExtendedKey(org.jooq.impl.Tools.DataExtendedKey) DATA_BLOCK_NESTING(org.jooq.impl.Tools.DataKey.DATA_BLOCK_NESTING) K_ATOMIC(org.jooq.impl.Keywords.K_ATOMIC) QueryPart(org.jooq.QueryPart) Statement(org.jooq.Statement) Block(org.jooq.Block) HSQLDB(org.jooq.SQLDialect.HSQLDB) K_CALL(org.jooq.impl.Keywords.K_CALL) K_AS(org.jooq.impl.Keywords.K_AS) Context(org.jooq.Context) K_END(org.jooq.impl.Keywords.K_END) Query(org.jooq.Query) K_EXECUTE_STATEMENT(org.jooq.impl.Keywords.K_EXECUTE_STATEMENT) DDLQuery(org.jooq.DDLQuery) K_EXECUTE_IMMEDIATE(org.jooq.impl.Keywords.K_EXECUTE_IMMEDIATE) INLINED(org.jooq.conf.ParamType.INLINED) K_EXECUTE_BLOCK(org.jooq.impl.Keywords.K_EXECUTE_BLOCK) ParamType(org.jooq.conf.ParamType) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) K_ALIAS(org.jooq.impl.Keywords.K_ALIAS) Function1(org.jooq.Function1) MYSQL(org.jooq.SQLDialect.MYSQL) K_DO(org.jooq.impl.Keywords.K_DO) FIREBIRD(org.jooq.SQLDialect.FIREBIRD) K_CREATE(org.jooq.impl.Keywords.K_CREATE) ScopeContent(org.jooq.impl.ScopeMarker.ScopeContent) Consumer(java.util.function.Consumer) Configuration(org.jooq.Configuration) YUGABYTEDB(org.jooq.SQLDialect.YUGABYTEDB) H2(org.jooq.SQLDialect.H2) MARIADB(org.jooq.SQLDialect.MARIADB) K_THEN(org.jooq.impl.Keywords.K_THEN) Tools.increment(org.jooq.impl.Tools.increment) LanguageContext(org.jooq.LanguageContext)

Example 2 with LanguageContext

use of org.jooq.LanguageContext in project jOOQ by jOOQ.

the class DefaultParseContext method parseQuery.

private final Query parseQuery(boolean parseResultQuery, boolean parseSelect) {
    if (done())
        return null;
    scopeStart();
    boolean previousMetaLookupsForceIgnore = metaLookupsForceIgnore();
    Query result = null;
    LanguageContext previous = languageContext;
    try {
        languageContext = LanguageContext.QUERY;
        switch(characterUpper()) {
            case 'A':
                if (!parseResultQuery && peekKeyword("ALTER"))
                    return result = metaLookupsForceIgnore(true).parseAlter();
                break;
            case 'B':
                if (!parseResultQuery && peekKeyword("BEGIN")) {
                    languageContext = previous;
                    return result = parseBlock(false);
                }
                break;
            case 'C':
                if (!parseResultQuery && peekKeyword("CREATE"))
                    return result = metaLookupsForceIgnore(true).parseCreate();
                else if (!parseResultQuery && peekKeyword("COMMENT ON"))
                    return result = metaLookupsForceIgnore(true).parseCommentOn();
                else if (!parseResultQuery && parseKeywordIf("CT"))
                    return result = metaLookupsForceIgnore(true).parseCreateTable(false);
                else if (!parseResultQuery && parseKeywordIf("CV"))
                    return result = metaLookupsForceIgnore(true).parseCreateView(false);
                else if (!ignoreProEdition() && peekKeyword("CALL") && requireProEdition())
                    ;
                else if (parseKeywordIf("COMMIT"))
                    throw notImplemented("COMMIT");
                else if (parseKeywordIf("CONNECT"))
                    throw notImplemented("CONNECT");
                break;
            case 'D':
                if (!parseResultQuery && !ignoreProEdition() && peekKeyword("DECLARE") && requireProEdition())
                    return result = parseBlock(true);
                else if (!parseSelect && (peekKeyword("DELETE") || peekKeyword("DEL")))
                    return result = parseDelete(null, parseResultQuery);
                else if (!parseResultQuery && peekKeyword("DROP"))
                    return result = metaLookupsForceIgnore(true).parseDrop();
                else if (!parseResultQuery && peekKeyword("DO"))
                    return result = parseDo();
                break;
            case 'E':
                if (!parseResultQuery && peekKeyword("EXECUTE BLOCK AS"))
                    return result = parseBlock(true);
                else if (!parseResultQuery && peekKeyword("EXEC"))
                    return result = parseExec();
                else if (!ignoreProEdition() && peekKeyword("EXECUTE PROCEDURE") && requireProEdition())
                    ;
                break;
            case 'G':
                if (!parseResultQuery && peekKeyword("GRANT"))
                    return result = metaLookupsForceIgnore(true).parseGrant();
                break;
            case 'I':
                if (!parseSelect && (peekKeyword("INSERT") || peekKeyword("INS")))
                    return result = parseInsert(null, parseResultQuery);
                break;
            case 'L':
                if (parseKeywordIf("LOAD"))
                    throw notImplemented("LOAD");
                break;
            case 'M':
                if (!parseResultQuery && peekKeyword("MERGE"))
                    return result = parseMerge(null);
                break;
            case 'O':
                if (!parseResultQuery && peekKeyword("OPEN"))
                    return result = parseOpen();
                break;
            case 'R':
                if (!parseResultQuery && peekKeyword("RENAME"))
                    return result = metaLookupsForceIgnore(true).parseRename();
                else if (!parseResultQuery && peekKeyword("REVOKE"))
                    return result = metaLookupsForceIgnore(true).parseRevoke();
                else if (parseKeywordIf("REPLACE"))
                    throw notImplemented("REPLACE");
                else if (parseKeywordIf("ROLLBACK"))
                    throw notImplemented("ROLLBACK");
                break;
            case 'S':
                if (peekSelect(false))
                    return result = parseSelect();
                else if (!parseResultQuery && peekKeyword("SET"))
                    return result = parseSet();
                else if (parseKeywordIf("SAVEPOINT"))
                    throw notImplemented("SAVEPOINT");
                break;
            case 'T':
                if (!parseSelect && peekKeyword("TABLE"))
                    return result = parseSelect();
                else if (!parseResultQuery && peekKeyword("TRUNCATE"))
                    return result = parseTruncate();
                break;
            case 'U':
                if (!parseSelect && (peekKeyword("UPDATE") || peekKeyword("UPD")))
                    return result = parseUpdate(null, parseResultQuery);
                else if (!parseResultQuery && peekKeyword("USE"))
                    return result = parseUse();
                else if (parseKeywordIf("UPSERT"))
                    throw notImplemented("UPSERT");
                break;
            case 'V':
                if (!parseSelect && peekKeyword("VALUES"))
                    return result = parseSelect();
            case 'W':
                if (peekKeyword("WITH"))
                    return result = parseWith(parseSelect);
                break;
            case '(':
                // TODO are there other possible statement types?
                if (peekKeyword("WITH", false, true, false))
                    return result = parseWith(true);
                else
                    return result = parseSelect();
            case '{':
                if (!ignoreProEdition() && peekKeyword("{ CALL") && requireProEdition())
                    ;
                break;
            default:
                break;
        }
        throw exception("Unsupported query type");
    } catch (ParserException e) {
        // [#9061] Don't hide this pre-existing exceptions in scopeResolve()
        scopeClear();
        throw e;
    } finally {
        scopeEnd(result);
        scopeResolve();
        metaLookupsForceIgnore(previousMetaLookupsForceIgnore);
        languageContext = previous;
    }
}
Also used : ResultQuery(org.jooq.ResultQuery) Query(org.jooq.Query) DDLQuery(org.jooq.DDLQuery) LanguageContext(org.jooq.LanguageContext)

Example 3 with LanguageContext

use of org.jooq.LanguageContext in project jOOQ by jOOQ.

the class DefaultParseContext method parseBlock.

private final Block parseBlock(boolean allowDeclareSection) {
    LanguageContext previous = languageContext;
    try {
        if (languageContext == LanguageContext.QUERY)
            languageContext = LanguageContext.BLOCK;
        List<Statement> statements = new ArrayList<>();
        if (allowDeclareSection && !ignoreProEdition() && parseKeywordIf("DECLARE") && requireProEdition())
            ;
        else
            parseKeywordIf("EXECUTE BLOCK AS");
        parseKeyword("BEGIN");
        parseKeywordIf("ATOMIC", "NOT ATOMIC");
        statements.addAll(parseStatementsAndPeek("END"));
        parseKeyword("END");
        parseIf(';');
        return dsl.begin(statements);
    } finally {
        languageContext = previous;
    }
}
Also used : Statement(org.jooq.Statement) ArrayList(java.util.ArrayList) LanguageContext(org.jooq.LanguageContext)

Aggregations

LanguageContext (org.jooq.LanguageContext)3 ArrayList (java.util.ArrayList)2 DDLQuery (org.jooq.DDLQuery)2 Query (org.jooq.Query)2 Statement (org.jooq.Statement)2 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 BiFunction (java.util.function.BiFunction)1 Consumer (java.util.function.Consumer)1 Predicate (java.util.function.Predicate)1 Block (org.jooq.Block)1 Configuration (org.jooq.Configuration)1 Context (org.jooq.Context)1 Function1 (org.jooq.Function1)1 Keyword (org.jooq.Keyword)1 Name (org.jooq.Name)1 QueryPart (org.jooq.QueryPart)1 ResultQuery (org.jooq.ResultQuery)1