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);
}
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;
}
}
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;
}
}
Aggregations