Search in sources :

Example 6 with Context

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

the class RowCondition method accept.

@Override
public final void accept(Context<?> ctx) {
    // Regular comparison predicate emulation
    if ((comparator == EQUALS || comparator == NOT_EQUALS) && (forceEmulation || EMULATE_EQ_AND_NE.contains(ctx.dialect()))) {
        Field<?>[] rightFields = right.fields();
        Condition result = DSL.and(map(left.fields(), (f, i) -> f.equal((Field) rightFields[i])));
        if (comparator == NOT_EQUALS)
            result = result.not();
        ctx.visit(result);
    } else // Ordering comparison predicate emulation
    if ((comparator == GREATER || comparator == GREATER_OR_EQUAL || comparator == LESS || comparator == LESS_OR_EQUAL) && (forceEmulation || EMULATE_RANGES.contains(ctx.dialect()))) {
        // The order component of the comparator (stripping the equal component)
        Comparator order = (comparator == GREATER) ? GREATER : (comparator == GREATER_OR_EQUAL) ? GREATER : (comparator == LESS) ? LESS : (comparator == LESS_OR_EQUAL) ? LESS : null;
        // [#2658] The factored order component of the comparator (enforcing the equal component)
        Comparator factoredOrder = (comparator == GREATER) ? GREATER_OR_EQUAL : (comparator == GREATER_OR_EQUAL) ? GREATER_OR_EQUAL : (comparator == LESS) ? LESS_OR_EQUAL : (comparator == LESS_OR_EQUAL) ? LESS_OR_EQUAL : null;
        // Whether the comparator has an equal component
        boolean equal = (comparator == GREATER_OR_EQUAL) || (comparator == LESS_OR_EQUAL);
        Field<?>[] leftFields = left.fields();
        Field<?>[] rightFields = right.fields();
        // The following algorithm emulates the equivalency of these expressions:
        // (A, B, C) > (X, Y, Z)
        // (A > X) OR (A = X AND B > Y) OR (A = X AND B = Y AND C > Z)
        List<Condition> outer = new ArrayList<>(1 + leftFields.length);
        for (int i = 0; i < leftFields.length; i++) {
            List<Condition> inner = new ArrayList<>(1 + i);
            for (int j = 0; j < i; j++) inner.add(leftFields[j].equal((Field) rightFields[j]));
            inner.add(leftFields[i].compare(equal && i == leftFields.length - 1 ? comparator : order, (Field) rightFields[i]));
            outer.add(DSL.and(inner));
        }
        Condition result = DSL.or(outer);
        // (A >= X) AND ((A > X) OR (A = X AND B > Y) OR (A = X AND B = Y AND C > Z))
        if (leftFields.length > 1)
            result = leftFields[0].compare(factoredOrder, (Field) rightFields[0]).and(result);
        ctx.visit(result);
    } else {
        // Some dialects do not support != comparison with rows
        {
            // Some databases need extra parentheses around the RHS
            boolean extraParentheses = false;
            ctx.visit(left).sql(' ').sql(comparator.toSQL()).sql(' ').sql(extraParentheses ? "(" : "").visit(right).sql(extraParentheses ? ")" : "");
        }
    }
}
Also used : Condition(org.jooq.Condition) DERBY(org.jooq.SQLDialect.DERBY) LESS(org.jooq.Comparator.LESS) Row(org.jooq.Row) Tools.map(org.jooq.impl.Tools.map) UNotYetImplemented(org.jooq.impl.QOM.UNotYetImplemented) GREATER_OR_EQUAL(org.jooq.Comparator.GREATER_OR_EQUAL) Condition(org.jooq.Condition) ArrayList(java.util.ArrayList) CONDITION_COMPARISON(org.jooq.Clause.CONDITION_COMPARISON) Clause(org.jooq.Clause) SQLDialect(org.jooq.SQLDialect) NOT_EQUALS(org.jooq.Comparator.NOT_EQUALS) LESS_OR_EQUAL(org.jooq.Comparator.LESS_OR_EQUAL) K_NOT(org.jooq.impl.Keywords.K_NOT) QueryPartInternal(org.jooq.QueryPartInternal) Comparator(org.jooq.Comparator) CONDITION(org.jooq.Clause.CONDITION) Set(java.util.Set) Field(org.jooq.Field) FIREBIRD(org.jooq.SQLDialect.FIREBIRD) DSL.select(org.jooq.impl.DSL.select) CUBRID(org.jooq.SQLDialect.CUBRID) EQUALS(org.jooq.Comparator.EQUALS) Configuration(org.jooq.Configuration) List(java.util.List) Context(org.jooq.Context) GREATER(org.jooq.Comparator.GREATER) Field(org.jooq.Field) ArrayList(java.util.ArrayList) List(java.util.List) Comparator(org.jooq.Comparator)

Example 7 with Context

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

the class DefaultParseContext method parseTerm.

private final FieldOrRow parseTerm() {
    FieldOrRow field;
    Object value;
    switch(characterUpper()) {
        // [#8821] Known prefixes so far:
        case ':':
        case '@':
        case '?':
            if ((field = parseBindVariableIf()) != null)
                return field;
            break;
        case '\'':
            return inline(parseStringLiteral());
        case '$':
            if ((field = parseBindVariableIf()) != null)
                return field;
            else if ((value = parseDollarQuotedStringLiteralIf()) != null)
                return inline((String) value);
            break;
        case 'A':
            if (parseFunctionNameIf("ABS"))
                return abs((Field) parseFieldNumericOpParenthesised());
            else if (parseFunctionNameIf("ASC", "ASCII", "ASCII_VAL"))
                return ascii((Field) parseFieldParenthesised());
            else if (parseFunctionNameIf("ACOS"))
                return acos((Field) parseFieldNumericOpParenthesised());
            else if (parseFunctionNameIf("ASIN"))
                return asin((Field) parseFieldNumericOpParenthesised());
            else if (parseFunctionNameIf("ATAN", "ATN"))
                return atan((Field) parseFieldNumericOpParenthesised());
            else if (parseFunctionNameIf("ATN2", "ATAN2"))
                return parseFunctionArgs2(() -> toField(parseNumericOp()), DSL::atan2);
            else if (parseFunctionNameIf("ASCII_CHAR"))
                return chr((Field) parseFieldParenthesised());
            else if ((field = parseArrayValueConstructorIf()) != null)
                return field;
            else if (parseFunctionNameIf("ADD_YEARS"))
                return parseFieldAddDatePart(YEAR);
            else if (parseFunctionNameIf("ADD_MONTHS"))
                return parseFieldAddDatePart(MONTH);
            else if (parseFunctionNameIf("ADD_DAYS"))
                return parseFieldAddDatePart(DAY);
            else if (parseFunctionNameIf("ADD_HOURS"))
                return parseFieldAddDatePart(HOUR);
            else if (parseFunctionNameIf("ADD_MINUTES"))
                return parseFieldAddDatePart(MINUTE);
            else if (parseFunctionNameIf("ADD_SECONDS"))
                return parseFieldAddDatePart(SECOND);
            else if (parseFunctionNameIf("ARRAY_GET"))
                return parseFunctionArgs2((f1, f2) -> arrayGet(f1, f2));
            break;
        case 'B':
            if (parseFunctionNameIf("BIT_LENGTH"))
                return bitLength((Field) parseFieldParenthesised());
            else if (parseFunctionNameIf("BITCOUNT", "BIT_COUNT"))
                return bitCount((Field) parseFieldNumericOpParenthesised());
            else if (parseFunctionNameIf("BYTE_LENGTH"))
                return octetLength((Field) parseFieldParenthesised());
            else if ((field = parseFieldBitwiseFunctionIf()) != null)
                return field;
            else if ((value = parseBitLiteralIf()) != null)
                return DSL.inline((Boolean) value);
            break;
        case 'C':
            if ((field = parseFieldConcatIf()) != null)
                return field;
            else if ((parseFunctionNameIf("CURRENT_CATALOG") && parseEmptyParens()))
                return currentCatalog();
            else if ((parseFunctionNameIf("CURRENT_DATABASE") && parseEmptyParens()))
                return currentCatalog();
            else if ((parseKeywordIf("CURRENT_SCHEMA", "CURRENT SCHEMA")) && parseEmptyParensIf())
                return currentSchema();
            else if ((parseKeywordIf("CURRENT_USER", "CURRENT USER", "CURRENTUSER")) && parseEmptyParensIf())
                return currentUser();
            else if (parseFunctionNameIf("CHR", "CHAR"))
                return chr((Field) parseFieldParenthesised());
            else if (parseFunctionNameIf("CHARINDEX"))
                return parseFunctionArgs3((f1, f2) -> DSL.position(f2, f1), (f1, f2, f3) -> DSL.position(f2, f1, f3));
            else if (parseFunctionNameIf("CHAR_LENGTH"))
                return charLength((Field) parseFieldParenthesised());
            else if (parseFunctionNameIf("CARDINALITY"))
                return cardinality((Field) parseFieldParenthesised());
            else if (parseFunctionNameIf("CEILING", "CEIL"))
                return ceil((Field) parseFieldNumericOpParenthesised());
            else if (parseFunctionNameIf("COSH"))
                return cosh((Field) parseFieldNumericOpParenthesised());
            else if (parseFunctionNameIf("COS"))
                return cos((Field) parseFieldNumericOpParenthesised());
            else if (parseFunctionNameIf("COTH"))
                return coth((Field) parseFieldNumericOpParenthesised());
            else if (parseFunctionNameIf("COT"))
                return cot((Field) parseFieldNumericOpParenthesised());
            else if ((field = parseNextvalCurrvalIf(SequenceMethod.CURRVAL)) != null)
                return field;
            else if (parseFunctionNameIf("CENTURY"))
                return century(parseFieldParenthesised());
            else if ((parseKeywordIf("CURRENT_DATE") || parseKeywordIf("CURRENT DATE")) && parseEmptyParensIf())
                return currentDate();
            else if (parseKeywordIf("CURRENT_TIMESTAMP") || parseKeywordIf("CURRENT TIMESTAMP")) {
                Field<Integer> precision = null;
                if (parseIf('('))
                    if (!parseIf(')')) {
                        precision = (Field<Integer>) parseField();
                        parse(')');
                    }
                return precision != null ? currentTimestamp(precision) : currentTimestamp();
            } else if ((parseKeywordIf("CURRENT_TIME") || parseKeywordIf("CURRENT TIME")) && parseEmptyParensIf())
                return currentTime();
            else if (parseFunctionNameIf("CURDATE") && parseEmptyParens())
                return currentDate();
            else if (parseFunctionNameIf("CURTIME") && parseEmptyParens())
                return currentTime();
            else if ((field = parseFieldCaseIf()) != null)
                return field;
            else if ((field = parseFieldCastIf()) != null)
                return field;
            else if ((field = parseFieldCoalesceIf()) != null)
                return field;
            else if ((field = parseFieldCumeDistIf()) != null)
                return field;
            else if ((field = parseFieldConvertIf()) != null)
                return field;
            else if ((field = parseFieldChooseIf()) != null)
                return field;
            else if (!ignoreProEdition() && parseKeywordIf("CONNECT_BY_ISCYCLE") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseKeywordIf("CONNECT_BY_ISLEAF") && requireProEdition()) {
            }
            break;
        case 'D':
            if ((parseFunctionNameIf("DATABASE") && parseEmptyParens()))
                return currentCatalog();
            else if ((parseFunctionNameIf("DB_NAME") && parseEmptyParens()))
                return currentCatalog();
            else if ((parseFunctionNameIf("DBINFO") && parse('(') && parseStringLiteral("dbname") != null && parse(')')))
                return currentCatalog();
            else if (parseFunctionNameIf("DIGITS"))
                return digits((Field) parseFieldParenthesised());
            else if ((field = parseFieldDateLiteralIf()) != null)
                return field;
            else if ((field = parseFieldDateTruncIf()) != null)
                return field;
            else if ((field = parseFieldDateAddIf()) != null)
                return field;
            else if ((field = parseFieldDateDiffIf()) != null)
                return field;
            else if ((field = parseFieldDatePartIf()) != null)
                return field;
            else if ((field = parseFieldDenseRankIf()) != null)
                return field;
            else if (parseFunctionNameIf("DECADE"))
                return decade(parseFieldParenthesised());
            else if (parseFunctionNameIf("DAY") || parseFunctionNameIf("DAYOFMONTH"))
                return day(parseFieldParenthesised());
            else // DB2 and MySQL support the non-ISO version where weeks go from Sunday = 1 to Saturday = 7
            if (parseFunctionNameIf("DAYOFWEEK_ISO"))
                return isoDayOfWeek(parseFieldParenthesised());
            else if (parseFunctionNameIf("DAYOFWEEK") || parseFunctionNameIf("DAY_OF_WEEK"))
                return dayOfWeek(parseFieldParenthesised());
            else if (parseFunctionNameIf("DAYOFYEAR") || parseFunctionNameIf("DAY_OF_YEAR"))
                return dayOfYear(parseFieldParenthesised());
            else if (parseFunctionNameIf("DEGREES") || parseFunctionNameIf("DEGREE") || parseFunctionNameIf("DEG"))
                return deg((Field) parseFieldNumericOpParenthesised());
            else if (parseFunctionNameIf("DATALENGTH"))
                return octetLength((Field) parseFieldParenthesised());
            else if ((field = parseFieldDecodeIf()) != null)
                return field;
            else if (parseKeywordIf("DEFAULT"))
                return default_();
            break;
        case 'E':
            // [#6704] PostgreSQL E'...' escaped string literals
            if (characterNext() == '\'')
                return inline(parseStringLiteral());
            else if ((field = parseFieldExtractIf()) != null)
                return field;
            else if (parseFunctionNameIf("EXP"))
                return exp((Field) parseFieldNumericOpParenthesised());
            else if (parseFunctionNameIf("EPOCH"))
                return epoch(parseFieldParenthesised());
            break;
        case 'F':
            if (parseFunctionNameIf("FLOOR"))
                return floor((Field) parseFieldNumericOpParenthesised());
            else if ((field = parseFieldFirstValueIf()) != null)
                return field;
            else if ((field = parseFieldFieldIf()) != null)
                return field;
            break;
        case 'G':
            if (parseKeywordIf("GETDATE") && parseEmptyParens())
                return currentTimestamp();
            else if (parseFunctionNameIf("GENGUID", "GENERATE_UUID", "GEN_RANDOM_UUID") && parseEmptyParens())
                return uuid();
            else if ((field = parseFieldGreatestIf()) != null)
                return field;
            else if (!ignoreProEdition() && parseFunctionNameIf("GROUP_ID") && requireProEdition() && parseEmptyParens()) {
            } else if ((field = parseFieldGroupingIdIf()) != null)
                return field;
            else if (parseFunctionNameIf("GROUPING"))
                return grouping(parseFieldParenthesised());
            else if (!ignoreProEdition() && (parseFunctionNameIf("GEOMETRY::STGEOMFROMWKB") || parseFunctionNameIf("GEOGRAPHY::STGEOMFROMWKB")) && requireProEdition()) {
            } else if (!ignoreProEdition() && (parseFunctionNameIf("GEOMETRY::STGEOMFROMTEXT") || parseFunctionNameIf("GEOGRAPHY::STGEOMFROMTEXT")) && requireProEdition()) {
            } else
                break;
        case 'H':
            if (parseFunctionNameIf("HOUR"))
                return hour(parseFieldParenthesised());
            else if (parseFunctionNameIf("HASH_MD5"))
                return md5((Field) parseFieldParenthesised());
            else if (parseFunctionNameIf("HEX"))
                return toHex((Field) parseFieldParenthesised());
            break;
        case 'I':
            if ((field = parseFieldIntervalLiteralIf()) != null)
                return field;
            else if (parseFunctionNameIf("ISO_DAY_OF_WEEK"))
                return isoDayOfWeek(parseFieldParenthesised());
            else if (parseFunctionNameIf("INSTR"))
                return parseFunctionArgs3(DSL::position, DSL::position);
            else if (parseFunctionNameIf("INSERT"))
                return parseFunctionArgs4(DSL::insert);
            else if (parseFunctionNameIf("IFNULL"))
                return parseFunctionArgs2((f1, f2) -> ifnull((Field<?>) f1, (Field<?>) f2));
            else if (parseFunctionNameIf("ISNULL"))
                return parseFunctionArgs2(f -> field(f.isNull()), (f1, f2) -> isnull((Field<?>) f1, (Field<?>) f2));
            else if ((field = parseFieldIfIf()) != null)
                return field;
            else
                break;
        case 'J':
            if ((field = parseFieldJSONArrayConstructorIf()) != null)
                return field;
            else if ((field = parseFieldJSONObjectConstructorIf()) != null)
                return field;
            else if ((field = parseFieldJSONValueIf()) != null)
                return field;
            else if ((field = parseFieldJSONLiteralIf()) != null)
                return field;
            break;
        case 'L':
            if (parseFunctionNameIf("LOWER", "LCASE"))
                return lower((Field) parseFieldParenthesised());
            else if (parseFunctionNameIf("LPAD"))
                return parseFunctionArgs3(DSL::lpad, DSL::lpad);
            else if (parseFunctionNameIf("LTRIM"))
                return parseFunctionArgs2(DSL::ltrim, DSL::ltrim);
            else if (parseFunctionNameIf("LEFT"))
                return parseFunctionArgs2(DSL::left);
            else if (parseFunctionNameIf("LENGTH", "LEN"))
                return length((Field) parseFieldParenthesised());
            else if (parseFunctionNameIf("LENGTHB"))
                return octetLength((Field) parseFieldParenthesised());
            else if (parseFunctionNameIf("LN", "LOGN"))
                return ln((Field) parseFieldNumericOpParenthesised());
            else if (parseFunctionNameIf("LOG10"))
                return log10((Field) parseFieldNumericOpParenthesised());
            else if ((field = parseFieldLogIf()) != null)
                return field;
            else if ((field = parseFieldLocateIf()) != null)
                return field;
            else if (!ignoreProEdition() && parseKeywordIf("LEVEL") && requireProEdition()) {
            } else if (parseKeywordIf("LSHIFT"))
                return parseFunctionArgs2(() -> toField(parseNumericOp()), (f1, f2) -> shl(f1, f2));
            else if ((field = parseFieldLeastIf()) != null)
                return field;
            else if ((field = parseFieldLeadLagIf()) != null)
                return field;
            else if ((field = parseFieldLastValueIf()) != null)
                return field;
            break;
        case 'M':
            if (parseFunctionNameIf("MOD"))
                return parseFunctionArgs2(Field::mod);
            else if (parseFunctionNameIf("MICROSECOND"))
                return microsecond(parseFieldParenthesised());
            else if (parseFunctionNameIf("MILLENNIUM"))
                return millennium(parseFieldParenthesised());
            else if (parseFunctionNameIf("MILLISECOND"))
                return millisecond(parseFieldParenthesised());
            else if (parseFunctionNameIf("MINUTE"))
                return minute(parseFieldParenthesised());
            else if (parseFunctionNameIf("MONTH"))
                return month(parseFieldParenthesised());
            else if (parseFunctionNameIf("MID"))
                return parseFunctionArgs3(DSL::mid);
            else if (parseFunctionNameIf("MD5"))
                return md5((Field) parseFieldParenthesised());
            else if ((field = parseMultisetValueConstructorIf()) != null)
                return field;
            else if ((field = parseFieldGreatestIf()) != null)
                return field;
            else if ((field = parseFieldLeastIf()) != null)
                return field;
            else if ((field = parseFieldDecodeIf()) != null)
                return field;
            break;
        case 'N':
            // [#9540] N'...' NVARCHAR literals
            if (characterNext() == '\'')
                return inline(parseStringLiteral(), NVARCHAR);
            else if ((field = parseFieldNewIdIf()) != null)
                return field;
            else if (parseFunctionNameIf("NVL2"))
                return parseFunctionArgs3((f1, f2, f3) -> nvl2((Field<?>) f1, (Field<?>) f2, (Field<?>) f3));
            else if (parseFunctionNameIf("NVL"))
                return parseFunctionArgs2((f1, f2) -> nvl((Field<?>) f1, (Field<?>) f2));
            else if (parseFunctionNameIf("NULLIF"))
                return parseFunctionArgs2((f1, f2) -> nullif((Field<?>) f1, (Field<?>) f2));
            else if ((field = parseFieldNtileIf()) != null)
                return field;
            else if ((field = parseFieldNthValueIf()) != null)
                return field;
            else if ((field = parseNextValueIf()) != null)
                return field;
            else if ((field = parseNextvalCurrvalIf(SequenceMethod.NEXTVAL)) != null)
                return field;
            else if (parseFunctionNameIf("NOW") && parse('(')) {
                if (parseIf(')'))
                    return now();
                Field<Integer> precision = (Field<Integer>) parseField();
                parse(')');
                return now(precision);
            }
            break;
        case 'O':
            if (parseFunctionNameIf("OREPLACE"))
                return parseFunctionArgs3(DSL::replace, DSL::replace);
            else if ((field = parseFieldOverlayIf()) != null)
                return field;
            else if ((field = parseFieldTranslateIf()) != null)
                return field;
            else if (parseFunctionNameIf("OCTET_LENGTH"))
                return octetLength((Field) parseFieldParenthesised());
            break;
        case 'P':
            if ((field = parseFieldPositionIf()) != null)
                return field;
            else if ((field = parseFieldPercentRankIf()) != null)
                return field;
            else if (parseFunctionNameIf("POWER", "POW"))
                return parseFunctionArgs2(() -> toField(parseNumericOp()), DSL::power);
            else if (parseFunctionNameIf("PI") && parseEmptyParens())
                return pi();
            else if (!ignoreProEdition() && parseKeywordIf("PRIOR") && requireProEdition()) {
            }
            break;
        case 'Q':
            if (characterNext() == '\'')
                return inline(parseStringLiteral());
            else if (parseFunctionNameIf("QUARTER"))
                return quarter(parseFieldParenthesised());
        case 'R':
            if (parseFunctionNameIf("REPLACE"))
                return parseFunctionArgs3(DSL::replace, DSL::replace);
            else if ((field = parseFieldRegexpReplaceIf()) != null)
                return field;
            else if (parseFunctionNameIf("REPEAT", "REPLICATE"))
                return parseFunctionArgs2(DSL::repeat);
            else if (parseFunctionNameIf("REVERSE"))
                return reverse((Field) parseFieldParenthesised());
            else if (parseFunctionNameIf("RPAD"))
                return parseFunctionArgs3(DSL::rpad, DSL::rpad);
            else if (parseFunctionNameIf("RTRIM"))
                return parseFunctionArgs2(DSL::rtrim, DSL::rtrim);
            else if (parseFunctionNameIf("RIGHT"))
                return parseFunctionArgs2(DSL::right);
            else if (parseFunctionNameIf("RANDOM_UUID") && parseEmptyParens())
                return uuid();
            else if (parseFunctionNameIf("ROW_NUMBER") && parseEmptyParens())
                return parseWindowFunction(null, null, rowNumber());
            else if ((field = parseFieldRankIf()) != null)
                return field;
            else if ((field = parseFieldRoundIf()) != null)
                return field;
            else if (!ignoreProEdition() && parseKeywordIf("ROWNUM") && requireProEdition()) {
            } else if (parseFunctionNameIf("RADIANS") || parseFunctionNameIf("RADIAN") || parseFunctionNameIf("RAD"))
                return rad((Field) parseFieldNumericOpParenthesised());
            else if (parseFunctionNameIf("RAND", "RANDOM") && parseEmptyParens())
                return rand();
            else if (parseFunctionNameIf("RATIO_TO_REPORT"))
                return parseFunctionArgs1(f -> parseWindowFunction(null, null, ratioToReport(f)));
            else if (parseKeywordIf("RSHIFT"))
                return parseFunctionArgs2(() -> toField(parseNumericOp()), (f1, f2) -> shr(f1, f2));
            else if (parseFunctionNameIf("ROW"))
                return parseTuple();
            break;
        case 'S':
            if ((field = parseFieldSubstringIf()) != null)
                return field;
            else if (parseFunctionNameIf("SUBSTRING_INDEX"))
                return parseFunctionArgs3(DSL::substringIndex);
            else if (parseFunctionNameIf("SPACE"))
                return space((Field) parseFieldParenthesised());
            else if (parseFunctionNameIf("SPLIT_PART"))
                return parseFunctionArgs3(DSL::splitPart);
            else if (parseFunctionNameIf("STR_REPLACE"))
                return parseFunctionArgs3(DSL::replace, DSL::replace);
            else if (parseFunctionNameIf("SCHEMA") && parseEmptyParensIf())
                return currentSchema();
            else if (parseFunctionNameIf("STRREVERSE"))
                return reverse((Field) parseFieldParenthesised());
            else if (parseFunctionNameIf("SYSUUID") && parseEmptyParensIf())
                return uuid();
            else if (parseFunctionNameIf("SECOND"))
                return second(parseFieldParenthesised());
            else if (!ignoreProEdition() && parseFunctionNameIf("SEQ4", "SEQ8") && parseEmptyParens() && requireProEdition()) {
            } else if (parseFunctionNameIf("SIGN", "SGN"))
                return sign((Field) parseFieldParenthesised());
            else if (parseFunctionNameIf("SQRT", "SQR"))
                return sqrt((Field) parseFieldNumericOpParenthesised());
            else if (parseFunctionNameIf("SQUARE"))
                return square((Field) parseFieldNumericOpParenthesised());
            else if (parseFunctionNameIf("SINH"))
                return sinh((Field) parseFieldNumericOpParenthesised());
            else if (parseFunctionNameIf("SIN"))
                return sin((Field) parseFieldNumericOpParenthesised());
            else if (parseKeywordIf("SHL", "SHIFTLEFT"))
                return parseFunctionArgs2(() -> toField(parseNumericOp()), (f1, f2) -> shl(f1, f2));
            else if (parseKeywordIf("SHR", "SHIFTRIGHT"))
                return parseFunctionArgs2(() -> toField(parseNumericOp()), (f1, f2) -> shr(f1, f2));
            else if ((field = parseFieldSysConnectByPathIf()) != null)
                return field;
            else if (!ignoreProEdition() && parseFunctionNameIf("ST_AREA") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("SDO_GEOM.SDO_AREA") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("ST_ASBINARY") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("ST_ASTEXT") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("ST_CENTROID") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("SDO_GEOM.SDO_CENTROID") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("ST_DIFFERENCE") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("SDO_GEOM.SDO_DIFFERENCE") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("ST_DISTANCE") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("SDO_GEOM.SDO_DISTANCE") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("ST_ENDPOINT") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("ST_EXTERIORRING") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("ST_GEOMETRYN") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("ST_GEOMETRYTYPE") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("ST_GEOMFROMWKB") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("ST_GEOMFROMTEXT", "SDO_GEOMETRY") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("ST_INTERIORRINGN") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("ST_INTERSECTION") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("SDO_GEOM.SDO_INTERSECTION") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("ST_LENGTH") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("SDO_GEOM.SDO_LENGTH") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("ST_NUMINTERIORRING", "ST_NUMINTERIORRINGS") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("ST_NUMGEOMETRIES", "SDO_UTIL.GETNUMELEM") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("ST_NUMPOINTS") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("ST_POINTN") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("ST_SRID") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("ST_STARTPOINT") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("ST_UNION") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("SDO_GEOM.SDO_UNION") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("ST_X") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("ST_Y") && requireProEdition()) {
            } else if (!ignoreProEdition() && parseFunctionNameIf("ST_Z") && requireProEdition()) {
            }
            break;
        case 'T':
            if ((field = parseBooleanValueExpressionIf()) != null)
                return field;
            else if ((field = parseFieldTrimIf()) != null)
                return field;
            else if ((field = parseFieldTranslateIf()) != null)
                return field;
            else if (parseFunctionNameIf("TO_CHAR"))
                return parseFunctionArgs2(DSL::toChar, DSL::toChar);
            else if (parseFunctionNameIf("TO_HEX"))
                return toHex((Field) parseFieldParenthesised());
            else if (parseFunctionNameIf("TANH"))
                return tanh((Field) parseFieldNumericOpParenthesised());
            else if (parseFunctionNameIf("TAN"))
                return tan((Field) parseFieldNumericOpParenthesised());
            else if (parseFunctionNameIf("TO_NUMBER"))
                return parseFunctionArgs1(f -> cast(f, NUMERIC));
            else if (parseFunctionNameIf("TIMEZONE_HOUR"))
                return timezoneHour(parseFieldParenthesised());
            else if (parseFunctionNameIf("TIMEZONE_MINUTE"))
                return timezoneMinute(parseFieldParenthesised());
            else if (parseFunctionNameIf("TIMEZONE"))
                return timezone(parseFieldParenthesised());
            else if ((field = parseFieldTimestampLiteralIf()) != null)
                return field;
            else if ((field = parseFieldTimeLiteralIf()) != null)
                return field;
            else if (parseFunctionNameIf("TO_DATE"))
                return parseFunctionArgs2(f1 -> toDate(f1, inline(settings().getParseDateFormat())), DSL::toDate);
            else if (parseFunctionNameIf("TO_TIMESTAMP"))
                return parseFunctionArgs2(f1 -> toTimestamp(f1, inline(settings().getParseTimestampFormat())), DSL::toTimestamp);
            else if (parseFunctionNameIf("TIMESTAMPDIFF"))
                return parseFunctionArgs2((f1, f2) -> DSL.timestampDiff(f1, f2));
            else if ((field = parseFieldTruncIf()) != null)
                return field;
            break;
        case 'U':
            if (parseFunctionNameIf("UPPER", "UCASE"))
                return DSL.upper((Field) parseFieldParenthesised());
            else if (parseFunctionNameIf("UUID", "UUID_GENERATE", "UUID_STRING") && parseEmptyParens())
                return uuid();
            else if (parseFunctionNameIf("UNIX_TIMESTAMP"))
                return epoch(parseFieldParenthesised());
            break;
        case 'W':
            if (parseFunctionNameIf("WIDTH_BUCKET"))
                return parseFunctionArgs4((f1, f2, f3, f4) -> widthBucket(f1, f2, f3, f4));
            else if (parseFunctionNameIf("WEEK"))
                return week(parseFieldParenthesised());
            break;
        case 'X':
            if ((value = parseBinaryLiteralIf()) != null)
                return inline((byte[]) value);
            else if (parseFunctionNameIf("XMLCOMMENT"))
                return xmlcomment((Field) parseField());
            else if ((field = parseFieldXMLConcatIf()) != null)
                return field;
            else if ((field = parseFieldXMLElementIf()) != null)
                return field;
            else if ((field = parseFieldXMLPIIf()) != null)
                return field;
            else if ((field = parseFieldXMLForestIf()) != null)
                return field;
            else if ((field = parseFieldXMLParseIf()) != null)
                return field;
            else if ((field = parseFieldXMLDocumentIf()) != null)
                return field;
            else if ((field = parseFieldXMLQueryIf()) != null)
                return field;
            else if ((field = parseFieldXMLSerializeIf()) != null)
                return field;
            break;
        case 'Y':
            if (parseFunctionNameIf("YEAR"))
                return year(parseFieldParenthesised());
            break;
        case 'Z':
            if (parseFunctionNameIf("ZEROIFNULL"))
                return coalesce(parseFieldParenthesised(), zero());
            break;
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
        case '-':
        case '.':
            if ((field = parseFieldUnsignedNumericLiteralIf(Sign.NONE)) != null)
                return field;
            break;
        case '{':
            parse('{', false);
            switch(characterUpper()) {
                case 'D':
                    parseKeyword("D");
                    field = inline(parseDateLiteral());
                    break;
                case 'F':
                    parseKeyword("FN");
                    // TODO: Limit the supported expressions in this context to the ones specified here:
                    // http://download.oracle.com/otn-pub/jcp/jdbc-4_2-mrel2-eval-spec/jdbc4.2-fr-spec.pdf
                    field = parseTerm();
                    break;
                case 'T':
                    if (parseKeywordIf("TS")) {
                        field = inline(parseTimestampLiteral());
                    } else {
                        parseKeyword("T");
                        field = inline(parseTimeLiteral());
                    }
                    break;
                default:
                    throw exception("Unsupported JDBC escape literal");
            }
            parse('}');
            return field;
        case '(':
            // A term parenthesis can mark the beginning of any of:
            // - ROW expression without ROW keyword:        E.g. (1, 2)
            // - Parenthesised field expression:            E.g. (1 + 2)
            // - A correlated subquery:                     E.g. (select 1)
            // - A correlated subquery with nested set ops: E.g. ((select 1) except (select 2))
            // - A combination of the above:                E.g. ((select 1) + 2, ((select 1) except (select 2)) + 2)
            int p = position();
            EnumSet fk = forbidden;
            try {
                if (!forbidden.isEmpty())
                    forbidden = EnumSet.noneOf(FunctionKeyword.class);
                FieldOrRow r = parseScalarSubqueryIf();
                if (r != null)
                    return r;
                parse('(');
                r = parseFieldOrRow();
                List<Field<?>> list = null;
                if (r instanceof Field) {
                    Field<?> f = (Field<?>) r;
                    while (parseIf(',')) {
                        if (list == null) {
                            list = new ArrayList<>();
                            list.add(f);
                        }
                        // TODO Allow for nesting ROWs
                        list.add(parseField());
                    }
                }
                parse(')');
                return list != null ? row(list) : r;
            } finally {
                forbidden = fk;
            }
    }
    if ((field = parseAggregateFunctionIf()) != null)
        return field;
    else if ((field = parseBooleanValueExpressionIf()) != null)
        return field;
    else
        return parseFieldNameOrSequenceExpression();
}
Also used : SECOND(org.jooq.DatePart.SECOND) DSL.newTable(org.jooq.impl.DSL.newTable) DSL.rtrim(org.jooq.impl.DSL.rtrim) Truncate(org.jooq.Truncate) DSL.defaultValue(org.jooq.impl.DSL.defaultValue) K_UPDATE(org.jooq.impl.Keywords.K_UPDATE) CONFIG(org.jooq.impl.Tools.CONFIG) Arrays.asList(java.util.Arrays.asList) DSL.rowsPreceding(org.jooq.impl.DSL.rowsPreceding) Select(org.jooq.Select) DSL.shl(org.jooq.impl.DSL.shl) DSL.currentTimestamp(org.jooq.impl.DSL.currentTimestamp) DSL.product(org.jooq.impl.DSL.product) Keyword(org.jooq.Keyword) Meta(org.jooq.Meta) DSL.choose(org.jooq.impl.DSL.choose) Update(org.jooq.Update) DSL.shr(org.jooq.impl.DSL.shr) DSL.century(org.jooq.impl.DSL.century) DSL.chr(org.jooq.impl.DSL.chr) OrderedAggregateFunction(org.jooq.OrderedAggregateFunction) TRUE(java.lang.Boolean.TRUE) DSL.bitNand(org.jooq.impl.DSL.bitNand) DSL.sin(org.jooq.impl.DSL.sin) ByteArrayOutputStream(java.io.ByteArrayOutputStream) InsertOnConflictWhereIndexPredicateStep(org.jooq.InsertOnConflictWhereIndexPredicateStep) DSL.groupsPreceding(org.jooq.impl.DSL.groupsPreceding) GrantOnStep(org.jooq.GrantOnStep) DSL.catalog(org.jooq.impl.DSL.catalog) InsertOnConflictDoUpdateStep(org.jooq.InsertOnConflictDoUpdateStep) DSL.hour(org.jooq.impl.DSL.hour) DSL.jsonArrayAgg(org.jooq.impl.DSL.jsonArrayAgg) Supplier(java.util.function.Supplier) Sequence(org.jooq.Sequence) LinkedHashMap(java.util.LinkedHashMap) DeleteUsingStep(org.jooq.DeleteUsingStep) DSL.groupsBetweenUnboundedFollowing(org.jooq.impl.DSL.groupsBetweenUnboundedFollowing) CommentOnIsStep(org.jooq.CommentOnIsStep) REAL(org.jooq.impl.SQLDataType.REAL) DSL.xmlquery(org.jooq.impl.DSL.xmlquery) MONTH(org.jooq.DatePart.MONTH) MINUTE(org.jooq.DatePart.MINUTE) Comparator(org.jooq.Comparator) DSL.pi(org.jooq.impl.DSL.pi) DOUBLE(org.jooq.impl.SQLDataType.DOUBLE) AlterSchemaStep(org.jooq.AlterSchemaStep) Param(org.jooq.Param) JoinType(org.jooq.JoinType) ArrayAggOrderByStep(org.jooq.ArrayAggOrderByStep) DSL.rollup(org.jooq.impl.DSL.rollup) TIMESTAMP(org.jooq.impl.SQLDataType.TIMESTAMP) MARIADB(org.jooq.SQLDialect.MARIADB) DECIMAL(org.jooq.impl.SQLDataType.DECIMAL) DropDomainCascadeStep(org.jooq.DropDomainCascadeStep) DSL.timezoneMinute(org.jooq.impl.DSL.timezoneMinute) ParseUnsupportedSyntax(org.jooq.conf.ParseUnsupportedSyntax) DSL.table(org.jooq.impl.DSL.table) DSL.concat(org.jooq.impl.DSL.concat) Row(org.jooq.Row) InsertValuesStepN(org.jooq.InsertValuesStepN) Table(org.jooq.Table) DSL.domain(org.jooq.impl.DSL.domain) SQL(org.jooq.SQL) DSL.varPop(org.jooq.impl.DSL.varPop) INTERVALDAYTOSECOND(org.jooq.impl.SQLDataType.INTERVALDAYTOSECOND) DSL.ln(org.jooq.impl.DSL.ln) ResultQuery(org.jooq.ResultQuery) DSL.zero(org.jooq.impl.DSL.zero) DSLContext(org.jooq.DSLContext) DSL.rowsBetweenFollowing(org.jooq.impl.DSL.rowsBetweenFollowing) DSL.groupsBetweenPreceding(org.jooq.impl.DSL.groupsBetweenPreceding) DSL.stddevSamp(org.jooq.impl.DSL.stddevSamp) GroupField(org.jooq.GroupField) DSL.anyValue(org.jooq.impl.DSL.anyValue) DSL.sinh(org.jooq.impl.DSL.sinh) DataType(org.jooq.DataType) DSL.name(org.jooq.impl.DSL.name) EMPTY_QUERYPART(org.jooq.impl.Tools.EMPTY_QUERYPART) Name(org.jooq.Name) Tools.deleteQueryImpl(org.jooq.impl.Tools.deleteQueryImpl) Timestamp(java.sql.Timestamp) DropIndexCascadeStep(org.jooq.DropIndexCascadeStep) DSL.millennium(org.jooq.impl.DSL.millennium) JSON(org.jooq.impl.SQLDataType.JSON) DSL.rangePreceding(org.jooq.impl.DSL.rangePreceding) FLOAT(org.jooq.impl.SQLDataType.FLOAT) EMPTY_STRING(org.jooq.impl.Tools.EMPTY_STRING) CreateIndexStep(org.jooq.CreateIndexStep) FK_IN(org.jooq.impl.DefaultParseContext.FunctionKeyword.FK_IN) DSL.rowsUnboundedFollowing(org.jooq.impl.DSL.rowsUnboundedFollowing) K_SELECT(org.jooq.impl.Keywords.K_SELECT) EMPTY_BYTE(org.jooq.impl.Tools.EMPTY_BYTE) AlterTableDropStep(org.jooq.AlterTableDropStep) DSL.lateral(org.jooq.impl.DSL.lateral) Merge(org.jooq.Merge) UpdateOrderByStep(org.jooq.UpdateOrderByStep) DSL.unnest(org.jooq.impl.DSL.unnest) Function(java.util.function.Function) DSL.currentCatalog(org.jooq.impl.DSL.currentCatalog) CaseConditionStep(org.jooq.CaseConditionStep) MergeMatchedDeleteStep(org.jooq.MergeMatchedDeleteStep) Comment(org.jooq.Comment) DSL.rowsBetweenUnboundedFollowing(org.jooq.impl.DSL.rowsBetweenUnboundedFollowing) DropTypeStep(org.jooq.DropTypeStep) Interval(org.jooq.types.Interval) AlterDomainRenameConstraintStep(org.jooq.AlterDomainRenameConstraintStep) DSL.md5(org.jooq.impl.DSL.md5) DSL.currentTime(org.jooq.impl.DSL.currentTime) Consumer(java.util.function.Consumer) DSL.rangeBetweenUnboundedPreceding(org.jooq.impl.DSL.rangeBetweenUnboundedPreceding) AlterDatabaseStep(org.jooq.AlterDatabaseStep) Catalog(org.jooq.Catalog) DSL.greatest(org.jooq.impl.DSL.greatest) DSL.octetLength(org.jooq.impl.DSL.octetLength) DSL.max(org.jooq.impl.DSL.max) TINYINT(org.jooq.impl.SQLDataType.TINYINT) DSL.collation(org.jooq.impl.DSL.collation) DSL.inOut(org.jooq.impl.DSL.inOut) INTERVALYEARTOMONTH(org.jooq.impl.SQLDataType.INTERVALYEARTOMONTH) Arrays(java.util.Arrays) UpdateWhereStep(org.jooq.UpdateWhereStep) InsertOnConflictWhereStep(org.jooq.InsertOnConflictWhereStep) DAY(org.jooq.DatePart.DAY) ParseWithMetaLookups(org.jooq.conf.ParseWithMetaLookups) DSL.day(org.jooq.impl.DSL.day) DSL.orderBy(org.jooq.impl.DSL.orderBy) DSL.charLength(org.jooq.impl.DSL.charLength) DSL.tan(org.jooq.impl.DSL.tan) DSL.xmltable(org.jooq.impl.DSL.xmltable) DSL.condition(org.jooq.impl.DSL.condition) ConstraintTypeStep(org.jooq.ConstraintTypeStep) BooleanSupplier(java.util.function.BooleanSupplier) BigDecimal(java.math.BigDecimal) DSL.sqrt(org.jooq.impl.DSL.sqrt) DSL.xmlforest(org.jooq.impl.DSL.xmlforest) DSL.rangeBetweenFollowing(org.jooq.impl.DSL.rangeBetweenFollowing) AlterTypeStep(org.jooq.AlterTypeStep) Index(org.jooq.Index) DSL.timezone(org.jooq.impl.DSL.timezone) JSONArrayAggReturningStep(org.jooq.JSONArrayAggReturningStep) DSL.cardinality(org.jooq.impl.DSL.cardinality) DSL.digits(org.jooq.impl.DSL.digits) DSL.bitCount(org.jooq.impl.DSL.bitCount) WindowIgnoreNullsStep(org.jooq.WindowIgnoreNullsStep) DSL.groupingSets(org.jooq.impl.DSL.groupingSets) LanguageContext(org.jooq.LanguageContext) DSL.log10(org.jooq.impl.DSL.log10) GrantWithGrantOptionStep(org.jooq.GrantWithGrantOptionStep) DSL.nthValue(org.jooq.impl.DSL.nthValue) DSL.ceil(org.jooq.impl.DSL.ceil) DSL.in(org.jooq.impl.DSL.in) BOOLEAN(org.jooq.impl.SQLDataType.BOOLEAN) DSL.nvl(org.jooq.impl.DSL.nvl) DSL.denseRank(org.jooq.impl.DSL.denseRank) DSL.finalTable(org.jooq.impl.DSL.finalTable) StringUtils.defaultIfNull(org.jooq.tools.StringUtils.defaultIfNull) CreateTableElementListStep(org.jooq.CreateTableElementListStep) DSL.nvl2(org.jooq.impl.DSL.nvl2) DSL.minDistinct(org.jooq.impl.DSL.minDistinct) DSL.xmlagg(org.jooq.impl.DSL.xmlagg) WindowSpecificationRowsAndStep(org.jooq.WindowSpecificationRowsAndStep) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) BIT(org.jooq.impl.SQLDataType.BIT) DSL.sequence(org.jooq.impl.DSL.sequence) DSL.dateAdd(org.jooq.impl.DSL.dateAdd) Tools.asInt(org.jooq.impl.Tools.asInt) TIME(org.jooq.impl.SQLDataType.TIME) DSL.bitOrAgg(org.jooq.impl.DSL.bitOrAgg) Schema(org.jooq.Schema) DSL.tanh(org.jooq.impl.DSL.tanh) CTX(org.jooq.impl.Tools.CTX) MergeUsingStep(org.jooq.MergeUsingStep) LinkedHashSet(java.util.LinkedHashSet) RevokeOnStep(org.jooq.RevokeOnStep) DSL.groupsBetweenCurrentRow(org.jooq.impl.DSL.groupsBetweenCurrentRow) DSL.bitAndAgg(org.jooq.impl.DSL.bitAndAgg) NVARCHAR(org.jooq.impl.SQLDataType.NVARCHAR) JSONObjectReturningStep(org.jooq.JSONObjectReturningStep) DSL.unique(org.jooq.impl.DSL.unique) ConstraintEnforcementStep(org.jooq.ConstraintEnforcementStep) RenderQuotedNames(org.jooq.conf.RenderQuotedNames) DSL.asin(org.jooq.impl.DSL.asin) DSL.regexpReplaceFirst(org.jooq.impl.DSL.regexpReplaceFirst) NOT_IN(org.jooq.Comparator.NOT_IN) DSL.systemName(org.jooq.impl.DSL.systemName) CreateDomainDefaultStep(org.jooq.CreateDomainDefaultStep) DSL.ntile(org.jooq.impl.DSL.ntile) DSL.widthBucket(org.jooq.impl.DSL.widthBucket) EMPTY_FIELD(org.jooq.impl.Tools.EMPTY_FIELD) TableOnStep(org.jooq.TableOnStep) DSL.percentileDisc(org.jooq.impl.DSL.percentileDisc) Time(java.sql.Time) UEmpty(org.jooq.impl.QOM.UEmpty) DSL.rad(org.jooq.impl.DSL.rad) DSL.jsonbObject(org.jooq.impl.DSL.jsonbObject) DSL.mode(org.jooq.impl.DSL.mode) DSL.length(org.jooq.impl.DSL.length) DSL.sign(org.jooq.impl.DSL.sign) DSL.regexpReplaceAll(org.jooq.impl.DSL.regexpReplaceAll) DSL.xmlexists(org.jooq.impl.DSL.xmlexists) DSL.deg(org.jooq.impl.DSL.deg) SortOrder(org.jooq.SortOrder) DSL.bitXor(org.jooq.impl.DSL.bitXor) DSL.acos(org.jooq.impl.DSL.acos) DSL.xmlpi(org.jooq.impl.DSL.xmlpi) AlterTableStep(org.jooq.AlterTableStep) Row2(org.jooq.Row2) Predicate(java.util.function.Predicate) XMLTablePassingStep(org.jooq.XMLTablePassingStep) JSONEntry(org.jooq.JSONEntry) DSL.jsonObjectAgg(org.jooq.impl.DSL.jsonObjectAgg) DSL.arrayGet(org.jooq.impl.DSL.arrayGet) JSONArrayReturningStep(org.jooq.JSONArrayReturningStep) DSL.groupsUnboundedPreceding(org.jooq.impl.DSL.groupsUnboundedPreceding) List(java.util.List) K_INSERT(org.jooq.impl.Keywords.K_INSERT) SettingsTools.parseLocale(org.jooq.conf.SettingsTools.parseLocale) DSL.rangeUnboundedPreceding(org.jooq.impl.DSL.rangeUnboundedPreceding) TablePartitionByStep(org.jooq.TablePartitionByStep) Pattern(java.util.regex.Pattern) DSL.productDistinct(org.jooq.impl.DSL.productDistinct) Query(org.jooq.Query) DSL.avgDistinct(org.jooq.impl.DSL.avgDistinct) DayToSecond(org.jooq.types.DayToSecond) BY_REF(org.jooq.impl.QOM.XMLPassingMechanism.BY_REF) YEAR(org.jooq.DatePart.YEAR) DSL.currentDate(org.jooq.impl.DSL.currentDate) DSL.check(org.jooq.impl.DSL.check) DSL.count(org.jooq.impl.DSL.count) DSL.default_(org.jooq.impl.DSL.default_) DSL.toDate(org.jooq.impl.DSL.toDate) WindowSpecificationOrderByStep(org.jooq.WindowSpecificationOrderByStep) DSL.sumDistinct(org.jooq.impl.DSL.sumDistinct) NUMERIC(org.jooq.impl.SQLDataType.NUMERIC) JSONTableColumnPathStep(org.jooq.JSONTableColumnPathStep) XMLPassingMechanism(org.jooq.impl.QOM.XMLPassingMechanism) Function2(org.jooq.Function2) Function1(org.jooq.Function1) Function4(org.jooq.Function4) RenderNameCase(org.jooq.conf.RenderNameCase) Function3(org.jooq.Function3) DSL.rangeBetweenCurrentRow(org.jooq.impl.DSL.rangeBetweenCurrentRow) ParseSearchSchema(org.jooq.conf.ParseSearchSchema) EMPTY_OBJECT(org.jooq.impl.Tools.EMPTY_OBJECT) FALSE(java.lang.Boolean.FALSE) DSL.abs(org.jooq.impl.DSL.abs) DSL.isoDayOfWeek(org.jooq.impl.DSL.isoDayOfWeek) DSL.currentUser(org.jooq.impl.DSL.currentUser) Configuration(org.jooq.Configuration) DSL.ifnull(org.jooq.impl.DSL.ifnull) DSL.generateSeries(org.jooq.impl.DSL.generateSeries) CreateDomainConstraintStep(org.jooq.CreateDomainConstraintStep) OTHER(org.jooq.impl.SQLDataType.OTHER) DSL.timezoneHour(org.jooq.impl.DSL.timezoneHour) DSL.jsonTable(org.jooq.impl.DSL.jsonTable) DSL.bitXNor(org.jooq.impl.DSL.bitXNor) Tools.aliased(org.jooq.impl.Tools.aliased) DSL.bitNot(org.jooq.impl.DSL.bitNot) DropSchemaStep(org.jooq.DropSchemaStep) DSL.field(org.jooq.impl.DSL.field) WindowOverStep(org.jooq.WindowOverStep) DSL.bitNor(org.jooq.impl.DSL.bitNor) ParamMode(org.jooq.ParamMode) DSL.year(org.jooq.impl.DSL.year) DSL.groupsBetweenUnboundedPreceding(org.jooq.impl.DSL.groupsBetweenUnboundedPreceding) DSL.jsonbArray(org.jooq.impl.DSL.jsonbArray) DSL.round(org.jooq.impl.DSL.round) DSL.trunc(org.jooq.impl.DSL.trunc) DSL.begin(org.jooq.impl.DSL.begin) CreateTableOnCommitStep(org.jooq.CreateTableOnCommitStep) DSL.trim(org.jooq.impl.DSL.trim) DSL.rand(org.jooq.impl.DSL.rand) Map(java.util.Map) QualifiedAsterisk(org.jooq.QualifiedAsterisk) DSL.median(org.jooq.impl.DSL.median) JSONTableColumnsStep(org.jooq.JSONTableColumnsStep) DSL.rowsBetweenUnboundedPreceding(org.jooq.impl.DSL.rowsBetweenUnboundedPreceding) BigInteger(java.math.BigInteger) DropTableStep(org.jooq.DropTableStep) SQLDialect(org.jooq.SQLDialect) DSL.cube(org.jooq.impl.DSL.cube) DSL.rank(org.jooq.impl.DSL.rank) EnumSet(java.util.EnumSet) Quoted(org.jooq.Name.Quoted) VisitListener.onVisitStart(org.jooq.VisitListener.onVisitStart) DSL.exists(org.jooq.impl.DSL.exists) CHAR(org.jooq.impl.SQLDataType.CHAR) DocumentOrContent(org.jooq.impl.QOM.DocumentOrContent) DSL.partitionBy(org.jooq.impl.DSL.partitionBy) DSL.reverse(org.jooq.impl.DSL.reverse) DSL.xmlserializeContent(org.jooq.impl.DSL.xmlserializeContent) RevokeFromStep(org.jooq.RevokeFromStep) JSONOnNull(org.jooq.impl.QOM.JSONOnNull) GrantToStep(org.jooq.GrantToStep) Queries(org.jooq.Queries) Collation(org.jooq.Collation) TableField(org.jooq.TableField) DSL.oldTable(org.jooq.impl.DSL.oldTable) DSL.now(org.jooq.impl.DSL.now) DSL.avg(org.jooq.impl.DSL.avg) DSL.week(org.jooq.impl.DSL.week) DSL.values0(org.jooq.impl.DSL.values0) JSONValueOnStep(org.jooq.JSONValueOnStep) TruncateCascadeStep(org.jooq.TruncateCascadeStep) Parameter(org.jooq.Parameter) LONGVARCHAR(org.jooq.impl.SQLDataType.LONGVARCHAR) DSL.coth(org.jooq.impl.DSL.coth) JSONValueDefaultStep(org.jooq.JSONValueDefaultStep) INTERVAL(org.jooq.impl.SQLDataType.INTERVAL) JSONObjectAggNullStep(org.jooq.JSONObjectAggNullStep) DSL.grouping(org.jooq.impl.DSL.grouping) VARCHAR(org.jooq.impl.SQLDataType.VARCHAR) MergeMatchedStep(org.jooq.MergeMatchedStep) DSL.decade(org.jooq.impl.DSL.decade) GEOMETRY(org.jooq.impl.SQLDataType.GEOMETRY) DSL.rowsFollowing(org.jooq.impl.DSL.rowsFollowing) MYSQL(org.jooq.SQLDialect.MYSQL) DSL.percentileCont(org.jooq.impl.DSL.percentileCont) DSL.epoch(org.jooq.impl.DSL.epoch) MergeMatchedWhereStep(org.jooq.MergeMatchedWhereStep) Transformations.transformAppendMissingTableReferences(org.jooq.impl.Transformations.transformAppendMissingTableReferences) SelectFieldOrAsterisk(org.jooq.SelectFieldOrAsterisk) DSL.jsonbArrayAgg(org.jooq.impl.DSL.jsonbArrayAgg) DSL.cosh(org.jooq.impl.DSL.cosh) BLOB(org.jooq.impl.SQLDataType.BLOB) Constraint(org.jooq.Constraint) YearToMonth(org.jooq.types.YearToMonth) DSL.jsonExists(org.jooq.impl.DSL.jsonExists) DSL.xmlattributes(org.jooq.impl.DSL.xmlattributes) DSL.microsecond(org.jooq.impl.DSL.microsecond) DeleteWhereStep(org.jooq.DeleteWhereStep) User(org.jooq.User) DSL.user(org.jooq.impl.DSL.user) DSL.overlay(org.jooq.impl.DSL.overlay) DSL.rowsCurrentRow(org.jooq.impl.DSL.rowsCurrentRow) DATE(org.jooq.impl.SQLDataType.DATE) UpdateReturningStep(org.jooq.UpdateReturningStep) XMLAggOrderByStep(org.jooq.XMLAggOrderByStep) DSL.millisecond(org.jooq.impl.DSL.millisecond) RenderKeywordCase(org.jooq.conf.RenderKeywordCase) TIMESTAMPWITHTIMEZONE(org.jooq.impl.SQLDataType.TIMESTAMPWITHTIMEZONE) CreateTableAsStep(org.jooq.CreateTableAsStep) BiFunction(java.util.function.BiFunction) DSL.rowNumber(org.jooq.impl.DSL.rowNumber) WindowBeforeOverStep(org.jooq.WindowBeforeOverStep) DSL.list(org.jooq.impl.DSL.list) DSL.boolOr(org.jooq.impl.DSL.boolOr) DSL.dayOfYear(org.jooq.impl.DSL.dayOfYear) DSL.currentSchema(org.jooq.impl.DSL.currentSchema) DSL.listAgg(org.jooq.impl.DSL.listAgg) Locale(java.util.Locale) CreateTableWithDataStep(org.jooq.CreateTableWithDataStep) Value(org.jooq.impl.ScopeStack.Value) JSONB(org.jooq.impl.SQLDataType.JSONB) DSL.lastValue(org.jooq.impl.DSL.lastValue) DSL.rowsBetweenPreceding(org.jooq.impl.DSL.rowsBetweenPreceding) GroupConcatOrderByStep(org.jooq.GroupConcatOrderByStep) DSL.groupsBetweenFollowing(org.jooq.impl.DSL.groupsBetweenFollowing) CreateTableCommentStep(org.jooq.CreateTableCommentStep) DSL.primaryKey(org.jooq.impl.DSL.primaryKey) Collection(java.util.Collection) EMPTY_COLLECTION(org.jooq.impl.Tools.EMPTY_COLLECTION) AlterDomainStep(org.jooq.AlterDomainStep) Field(org.jooq.Field) DSL.space(org.jooq.impl.DSL.space) DSL.rangeBetweenUnboundedFollowing(org.jooq.impl.DSL.rangeBetweenUnboundedFollowing) CreateIndexIncludeStep(org.jooq.CreateIndexIncludeStep) TableElement(org.jooq.TableElement) Tools.anyMatch(org.jooq.impl.Tools.anyMatch) DSL.minute(org.jooq.impl.DSL.minute) DSL.dayOfWeek(org.jooq.impl.DSL.dayOfWeek) EMPTY_NAME(org.jooq.impl.Tools.EMPTY_NAME) DSL.multisetAgg(org.jooq.impl.DSL.multisetAgg) ParseUnknownFunctions(org.jooq.conf.ParseUnknownFunctions) DropIndexOnStep(org.jooq.DropIndexOnStep) DSL.iif(org.jooq.impl.DSL.iif) HashSet(java.util.HashSet) ABSENT_ON_NULL(org.jooq.impl.QOM.JSONOnNull.ABSENT_ON_NULL) BIGINT(org.jooq.impl.SQLDataType.BIGINT) InsertReturningStep(org.jooq.InsertReturningStep) TableLike(org.jooq.TableLike) DSL.rangeCurrentRow(org.jooq.impl.DSL.rangeCurrentRow) DSL.log(org.jooq.impl.DSL.log) DSL.out(org.jooq.impl.DSL.out) ConstraintForeignKeyOnStep(org.jooq.ConstraintForeignKeyOnStep) DSL.inline(org.jooq.impl.DSL.inline) EMPTY_COMMON_TABLE_EXPRESSION(org.jooq.impl.Tools.EMPTY_COMMON_TABLE_EXPRESSION) EMPTY_TABLE(org.jooq.impl.Tools.EMPTY_TABLE) Delete(org.jooq.Delete) DSL.groupsFollowing(org.jooq.impl.DSL.groupsFollowing) DSL.bitLength(org.jooq.impl.DSL.bitLength) AlterSequenceFlagsStep(org.jooq.AlterSequenceFlagsStep) Date(java.sql.Date) Insert(org.jooq.Insert) InsertSetStep(org.jooq.InsertSetStep) DSL.rowsUnboundedPreceding(org.jooq.impl.DSL.rowsUnboundedPreceding) SortField(org.jooq.SortField) InsertOnDuplicateStep(org.jooq.InsertOnDuplicateStep) DSL.floor(org.jooq.impl.DSL.floor) IN(org.jooq.Comparator.IN) DSL.rangeFollowing(org.jooq.impl.DSL.rangeFollowing) DSL.bitAnd(org.jooq.impl.DSL.bitAnd) Tools.updateQueryImpl(org.jooq.impl.Tools.updateQueryImpl) AlterIndexStep(org.jooq.AlterIndexStep) XMLAttributes(org.jooq.XMLAttributes) FK_AND(org.jooq.impl.DefaultParseContext.FunctionKeyword.FK_AND) DSL.lag(org.jooq.impl.DSL.lag) CaseValueStep(org.jooq.CaseValueStep) DSL.all(org.jooq.impl.DSL.all) ParseContext(org.jooq.ParseContext) JOIN(org.jooq.JoinType.JOIN) DSL.when(org.jooq.impl.DSL.when) Condition(org.jooq.Condition) DSL.extract(org.jooq.impl.DSL.extract) Matcher(java.util.regex.Matcher) DSL.cot(org.jooq.impl.DSL.cot) DSL.rangeBetweenPreceding(org.jooq.impl.DSL.rangeBetweenPreceding) SelectField(org.jooq.SelectField) DSL.cos(org.jooq.impl.DSL.cos) WindowSpecification(org.jooq.WindowSpecification) DSL.ratioToReport(org.jooq.impl.DSL.ratioToReport) DSL.square(org.jooq.impl.DSL.square) Domain(org.jooq.Domain) JSONObjectNullStep(org.jooq.JSONObjectNullStep) NULL_ON_NULL(org.jooq.impl.QOM.JSONOnNull.NULL_ON_NULL) SMALLINT(org.jooq.impl.SQLDataType.SMALLINT) DSL.arrayAggDistinct(org.jooq.impl.DSL.arrayAggDistinct) DSL.constraint(org.jooq.impl.DSL.constraint) YearToSecond(org.jooq.types.YearToSecond) DSL.least(org.jooq.impl.DSL.least) DSL.second(org.jooq.impl.DSL.second) DSL.toHex(org.jooq.impl.DSL.toHex) DSL.xmlconcat(org.jooq.impl.DSL.xmlconcat) Set(java.util.Set) DSL.function(org.jooq.impl.DSL.function) DSL.month(org.jooq.impl.DSL.month) AggregateFunction(org.jooq.AggregateFunction) DeleteReturningStep(org.jooq.DeleteReturningStep) QueryPart(org.jooq.QueryPart) Block(org.jooq.Block) HOUR(org.jooq.DatePart.HOUR) DSL.xmlparseContent(org.jooq.impl.DSL.xmlparseContent) JSONArrayAggOrderByStep(org.jooq.JSONArrayAggOrderByStep) JSONObjectAggReturningStep(org.jooq.JSONObjectAggReturningStep) AlterSequenceStep(org.jooq.AlterSequenceStep) NCLOB(org.jooq.impl.SQLDataType.NCLOB) DSL.jsonObject(org.jooq.impl.DSL.jsonObject) DSL.jsonValue(org.jooq.impl.DSL.jsonValue) JSONArrayAggNullStep(org.jooq.JSONArrayAggNullStep) XML(org.jooq.XML) OrderedAggregateFunctionOfDeferredType(org.jooq.OrderedAggregateFunctionOfDeferredType) DSL.row(org.jooq.impl.DSL.row) DSL.cumeDist(org.jooq.impl.DSL.cumeDist) DSL.xmlelement(org.jooq.impl.DSL.xmlelement) LONGNVARCHAR(org.jooq.impl.SQLDataType.LONGNVARCHAR) DSL.rowsBetweenCurrentRow(org.jooq.impl.DSL.rowsBetweenCurrentRow) DSL.stddevPop(org.jooq.impl.DSL.stddevPop) UpdateSetFirstStep(org.jooq.UpdateSetFirstStep) LikeEscapeStep(org.jooq.LikeEscapeStep) VARBINARY(org.jooq.impl.SQLDataType.VARBINARY) DSL.keyword(org.jooq.impl.DSL.keyword) DSL.sql(org.jooq.impl.DSL.sql) DSL.translate(org.jooq.impl.DSL.translate) DSL.xmlcomment(org.jooq.impl.DSL.xmlcomment) Record(org.jooq.Record) TruncateIdentityStep(org.jooq.TruncateIdentityStep) DSL.varSamp(org.jooq.impl.DSL.varSamp) CreateSequenceFlagsStep(org.jooq.CreateSequenceFlagsStep) WindowSpecificationExcludeStep(org.jooq.WindowSpecificationExcludeStep) StringUtils(org.jooq.tools.StringUtils) WindowSpecificationRowsStep(org.jooq.WindowSpecificationRowsStep) AlterTableAddStep(org.jooq.AlterTableAddStep) DSL.jsonArray(org.jooq.impl.DSL.jsonArray) DSL.groupsCurrentRow(org.jooq.impl.DSL.groupsCurrentRow) DSL.bitOr(org.jooq.impl.DSL.bitOr) DSL.any(org.jooq.impl.DSL.any) EMULATE_SELECT_INTO_AS_CTAS(org.jooq.impl.SelectQueryImpl.EMULATE_SELECT_INTO_AS_CTAS) DeleteOrderByStep(org.jooq.DeleteOrderByStep) XMLTableColumnPathStep(org.jooq.XMLTableColumnPathStep) DSL.time(org.jooq.impl.DSL.time) DSL.foreignKey(org.jooq.impl.DSL.foreignKey) DSL.exp(org.jooq.impl.DSL.exp) WindowDefinition(org.jooq.WindowDefinition) DSL.atan(org.jooq.impl.DSL.atan) DSL.uuid(org.jooq.impl.DSL.uuid) CLOB(org.jooq.impl.SQLDataType.CLOB) GEOGRAPHY(org.jooq.impl.SQLDataType.GEOGRAPHY) CreateTableStorageStep(org.jooq.CreateTableStorageStep) Parser(org.jooq.Parser) NCHAR(org.jooq.impl.SQLDataType.NCHAR) EMPTY_ROW(org.jooq.impl.Tools.EMPTY_ROW) DSL.schema(org.jooq.impl.DSL.schema) DSL.xmlserializeDocument(org.jooq.impl.DSL.xmlserializeDocument) FieldOrRow(org.jooq.FieldOrRow) XMLTableColumnsStep(org.jooq.XMLTableColumnsStep) DSL.date(org.jooq.impl.DSL.date) DSL.firstValue(org.jooq.impl.DSL.firstValue) UpdateFromStep(org.jooq.UpdateFromStep) DSL.coalesce(org.jooq.impl.DSL.coalesce) K_DELETE(org.jooq.impl.Keywords.K_DELETE) DSL.characterSet(org.jooq.impl.DSL.characterSet) Tools.selectQueryImpl(org.jooq.impl.Tools.selectQueryImpl) CharacterSet(org.jooq.CharacterSet) DSL.timestamp(org.jooq.impl.DSL.timestamp) CaseWhenStep(org.jooq.CaseWhenStep) Collections.emptyList(java.util.Collections.emptyList) DSL.xmlparseDocument(org.jooq.impl.DSL.xmlparseDocument) DSL.select(org.jooq.impl.DSL.select) NO_SUPPORT_FOR_UPDATE_OF_FIELDS(org.jooq.impl.SelectQueryImpl.NO_SUPPORT_FOR_UPDATE_OF_FIELDS) DSL.coerce(org.jooq.impl.DSL.coerce) Statement(org.jooq.Statement) Reflect(org.jooq.tools.reflect.Reflect) DSL.toTimestamp(org.jooq.impl.DSL.toTimestamp) Context(org.jooq.Context) IGNORE_ON_FAILURE(org.jooq.conf.ParseWithMetaLookups.IGNORE_ON_FAILURE) INTEGER(org.jooq.impl.SQLDataType.INTEGER) CreateIndexWhereStep(org.jooq.CreateIndexWhereStep) DSL.isnull(org.jooq.impl.DSL.isnull) DSL.lower(org.jooq.impl.DSL.lower) DSL.quarter(org.jooq.impl.DSL.quarter) JSONArrayNullStep(org.jooq.JSONArrayNullStep) DDLQuery(org.jooq.DDLQuery) DSL.min(org.jooq.impl.DSL.min) BY_VALUE(org.jooq.impl.QOM.XMLPassingMechanism.BY_VALUE) DSL.ltrim(org.jooq.impl.DSL.ltrim) DSL.privilege(org.jooq.impl.DSL.privilege) EMPTY_SORTFIELD(org.jooq.impl.Tools.EMPTY_SORTFIELD) DSL.key(org.jooq.impl.DSL.key) DSL.nullif(org.jooq.impl.DSL.nullif) UpdateLimitStep(org.jooq.UpdateLimitStep) DeleteLimitStep(org.jooq.DeleteLimitStep) LONGVARBINARY(org.jooq.impl.SQLDataType.LONGVARBINARY) Privilege(org.jooq.Privilege) DSL.countDistinct(org.jooq.impl.DSL.countDistinct) DSL.bitXorAgg(org.jooq.impl.DSL.bitXorAgg) DSL.sum(org.jooq.impl.DSL.sum) DSL.ascii(org.jooq.impl.DSL.ascii) TIMEWITHTIMEZONE(org.jooq.impl.SQLDataType.TIMEWITHTIMEZONE) DSL.asterisk(org.jooq.impl.DSL.asterisk) AggregateFilterStep(org.jooq.AggregateFilterStep) DSL.rangeUnboundedFollowing(org.jooq.impl.DSL.rangeUnboundedFollowing) DatePart(org.jooq.DatePart) DSL.cast(org.jooq.impl.DSL.cast) GroupConcatSeparatorStep(org.jooq.GroupConcatSeparatorStep) THROW_ON_FAILURE(org.jooq.conf.ParseWithMetaLookups.THROW_ON_FAILURE) DSL.percentRank(org.jooq.impl.DSL.percentRank) DSL.maxDistinct(org.jooq.impl.DSL.maxDistinct) DSL.one(org.jooq.impl.DSL.one) NO_NAME(org.jooq.impl.AbstractName.NO_NAME) DSL.every(org.jooq.impl.DSL.every) DSL.groupsUnboundedFollowing(org.jooq.impl.DSL.groupsUnboundedFollowing) Tools.normaliseNameCase(org.jooq.impl.Tools.normaliseNameCase) TableOptionalOnStep(org.jooq.TableOptionalOnStep) DSL.jsonbObjectAgg(org.jooq.impl.DSL.jsonbObjectAgg) DSL.lead(org.jooq.impl.DSL.lead) DSL.arrayAgg(org.jooq.impl.DSL.arrayAgg) BINARY(org.jooq.impl.SQLDataType.BINARY) DerivedColumnList(org.jooq.DerivedColumnList) WindowFromFirstLastStep(org.jooq.WindowFromFirstLastStep) CommonTableExpression(org.jooq.CommonTableExpression) AlterDomainDropConstraintCascadeStep(org.jooq.AlterDomainDropConstraintCascadeStep) BigInteger(java.math.BigInteger) GroupField(org.jooq.GroupField) TableField(org.jooq.TableField) Field(org.jooq.Field) SortField(org.jooq.SortField) SelectField(org.jooq.SelectField) EnumSet(java.util.EnumSet) DSL.jsonbObject(org.jooq.impl.DSL.jsonbObject) DSL.jsonObject(org.jooq.impl.DSL.jsonObject) FieldOrRow(org.jooq.FieldOrRow) Constraint(org.jooq.Constraint) DSL.constraint(org.jooq.impl.DSL.constraint)

Example 8 with Context

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

the class MergeImpl method toSQLStandard.

private final void toSQLStandard(Context<?> ctx) {
    ctx.start(MERGE_MERGE_INTO).visit(K_MERGE_INTO).sql(' ').declareTables(true, c -> c.visit(table)).end(MERGE_MERGE_INTO).formatSeparator().start(MERGE_USING).visit(K_USING).sql(' ');
    ctx.declareTables(true, c1 -> c1.data(DATA_WRAP_DERIVED_TABLES_IN_PARENTHESES, true, c2 -> {
        // in its MERGE statement.
        if (usingDual) {
            switch(c2.family()) {
                case DERBY:
                    c2.visit(new Dual());
                    break;
                default:
                    c2.visit(DSL.selectOne());
                    break;
            }
        } else
            c2.visit(using);
    }));
    boolean onParentheses = false;
    ctx.end(MERGE_USING).formatSeparator().start(MERGE_ON).visit(K_ON).sql(onParentheses ? " (" : " ").visit(on).sql(onParentheses ? ")" : "").end(MERGE_ON).start(MERGE_WHEN_MATCHED_THEN_UPDATE).start(MERGE_SET);
    // [#7291] Multi MATCHED emulation
    boolean emulate = false;
    boolean requireMatchedConditions = false;
    // [#10054] TODO: Skip all WHEN MATCHED clauses after a WHEN MATCHED clause with no search condition
    if (NO_SUPPORT_CONDITION_AFTER_NO_CONDITION.contains(ctx.dialect())) {
        boolean withoutMatchedConditionFound = false;
        for (MatchedClause m : matched) {
            if (requireMatchedConditions |= withoutMatchedConditionFound)
                break;
            withoutMatchedConditionFound |= m.condition instanceof NoCondition;
        }
    }
    emulateCheck: if ((NO_SUPPORT_MULTI.contains(ctx.dialect()) && matched.size() > 1)) {
        boolean matchUpdate = false;
        boolean matchDelete = false;
        for (MatchedClause m : matched) {
            if (m.delete) {
                if (emulate |= matchDelete)
                    break emulateCheck;
                matchDelete = true;
            } else {
                if (emulate |= matchUpdate)
                    break emulateCheck;
                matchUpdate = true;
            }
        }
    }
    if (emulate) {
        MatchedClause update = null;
        MatchedClause delete = null;
        Condition negate = noCondition();
        for (MatchedClause m : matched) {
            Condition condition = negate.and(m.condition);
            if (m.delete) {
                if (delete == null)
                    delete = new MatchedClause(noCondition(), true);
                delete.condition = delete.condition.or(condition);
            } else {
                if (update == null)
                    update = new MatchedClause(noCondition());
                for (Entry<Field<?>, Field<?>> e : m.updateMap.entrySet()) {
                    Field<?> exp = update.updateMap.get(e.getKey());
                    if (exp instanceof CaseConditionStepImpl)
                        ((CaseConditionStepImpl) exp).when(negate.and(condition), e.getValue());
                    else
                        update.updateMap.put(e.getKey(), when(negate.and(condition), (Field) e.getValue()).else_(e.getKey()));
                }
                update.condition = update.condition.or(condition);
            }
            if (REQUIRE_NEGATION.contains(ctx.dialect()))
                negate = negate.andNot(m.condition instanceof NoCondition ? trueCondition() : m.condition);
        }
        {
            if (delete != null)
                toSQLMatched(ctx, delete, requireMatchedConditions);
            if (update != null)
                toSQLMatched(ctx, update, requireMatchedConditions);
        }
    } else // [#7291] Workaround for https://github.com/h2database/h2database/issues/2552
    if (REQUIRE_NEGATION.contains(ctx.dialect())) {
        Condition negate = noCondition();
        for (MatchedClause m : matched) {
            toSQLMatched(ctx, new MatchedClause(negate.and(m.condition), m.delete, m.updateMap), requireMatchedConditions);
            negate = negate.andNot(m.condition instanceof NoCondition ? trueCondition() : m.condition);
        }
    } else {
        for (MatchedClause m : matched) toSQLMatched(ctx, m, requireMatchedConditions);
    }
    ctx.end(MERGE_SET).end(MERGE_WHEN_MATCHED_THEN_UPDATE).start(MERGE_WHEN_NOT_MATCHED_THEN_INSERT);
    for (NotMatchedClause m : notMatched) toSQLNotMatched(ctx, m);
    ctx.end(MERGE_WHEN_NOT_MATCHED_THEN_INSERT);
}
Also used : QueryPartListView.wrap(org.jooq.impl.QueryPartListView.wrap) THROW(org.jooq.conf.WriteIfReadonly.THROW) Arrays(java.util.Arrays) DSL.condition(org.jooq.impl.DSL.condition) DSL.when(org.jooq.impl.DSL.when) Condition(org.jooq.Condition) DSL.trueCondition(org.jooq.impl.DSL.trueCondition) K_UPDATE(org.jooq.impl.Keywords.K_UPDATE) Record1(org.jooq.Record1) Map(java.util.Map) MERGE_SET_ASSIGNMENT(org.jooq.Clause.MERGE_SET_ASSIGNMENT) MergeMatchedSetMoreStep(org.jooq.MergeMatchedSetMoreStep) SQLDialect(org.jooq.SQLDialect) Select(org.jooq.Select) DSL.exists(org.jooq.impl.DSL.exists) K_NOT(org.jooq.impl.Keywords.K_NOT) MERGE(org.jooq.Clause.MERGE) Set(java.util.Set) DataExtendedKey(org.jooq.impl.Tools.DataExtendedKey) K_MATCHED(org.jooq.impl.Keywords.K_MATCHED) Serializable(java.io.Serializable) QueryPart(org.jooq.QueryPart) Tools.filter(org.jooq.impl.Tools.filter) K_AS(org.jooq.impl.Keywords.K_AS) DSL.noCondition(org.jooq.impl.DSL.noCondition) MergeMatchedThenStep(org.jooq.MergeMatchedThenStep) K_AND(org.jooq.impl.Keywords.K_AND) MergeKeyStep9(org.jooq.MergeKeyStep9) MergeKeyStep8(org.jooq.MergeKeyStep8) MERGE_WHEN_MATCHED_THEN_UPDATE(org.jooq.Clause.MERGE_WHEN_MATCHED_THEN_UPDATE) MergeKeyStep1(org.jooq.MergeKeyStep1) MergeKeyStep3(org.jooq.MergeKeyStep3) MergeKeyStep2(org.jooq.MergeKeyStep2) MergeKeyStep5(org.jooq.MergeKeyStep5) MergeKeyStep4(org.jooq.MergeKeyStep4) MergeKeyStep7(org.jooq.MergeKeyStep7) ArrayList(java.util.ArrayList) MergeKeyStep6(org.jooq.MergeKeyStep6) LinkedHashMap(java.util.LinkedHashMap) MERGE_MERGE_INTO(org.jooq.Clause.MERGE_MERGE_INTO) MergeNotMatchedValuesStepN(org.jooq.MergeNotMatchedValuesStepN) MergeUsingStep(org.jooq.MergeUsingStep) DSL.notExists(org.jooq.impl.DSL.notExists) MERGE_ON(org.jooq.Clause.MERGE_ON) Record(org.jooq.Record) IGNORE(org.jooq.conf.WriteIfReadonly.IGNORE) FIREBIRD(org.jooq.SQLDialect.FIREBIRD) K_ON(org.jooq.impl.Keywords.K_ON) StringUtils(org.jooq.tools.StringUtils) MERGE_SET(org.jooq.Clause.MERGE_SET) K_WHERE(org.jooq.impl.Keywords.K_WHERE) EMPTY_FIELD(org.jooq.impl.Tools.EMPTY_FIELD) MergeNotMatchedValuesStep10(org.jooq.MergeNotMatchedValuesStep10) K_VALUES(org.jooq.impl.Keywords.K_VALUES) UniqueKey(org.jooq.UniqueKey) MergeNotMatchedValuesStep12(org.jooq.MergeNotMatchedValuesStep12) Tools.map(org.jooq.impl.Tools.map) MergeNotMatchedValuesStep11(org.jooq.MergeNotMatchedValuesStep11) MergeKeyStep19(org.jooq.MergeKeyStep19) MergeNotMatchedValuesStep14(org.jooq.MergeNotMatchedValuesStep14) UNotYetImplemented(org.jooq.impl.QOM.UNotYetImplemented) MergeNotMatchedValuesStep13(org.jooq.MergeNotMatchedValuesStep13) MergeNotMatchedValuesStep16(org.jooq.MergeNotMatchedValuesStep16) MergeNotMatchedValuesStep15(org.jooq.MergeNotMatchedValuesStep15) MergeKeyStep15(org.jooq.MergeKeyStep15) MergeKeyStep16(org.jooq.MergeKeyStep16) Table(org.jooq.Table) MergeKeyStep17(org.jooq.MergeKeyStep17) MergeOnConditionStep(org.jooq.MergeOnConditionStep) MergeKeyStep18(org.jooq.MergeKeyStep18) Operator(org.jooq.Operator) MergeKeyStep11(org.jooq.MergeKeyStep11) DATA_WRAP_DERIVED_TABLES_IN_PARENTHESES(org.jooq.impl.Tools.BooleanDataKey.DATA_WRAP_DERIVED_TABLES_IN_PARENTHESES) MergeKeyStep12(org.jooq.MergeKeyStep12) MergeKeyStep13(org.jooq.MergeKeyStep13) SQL(org.jooq.SQL) MergeKeyStep14(org.jooq.MergeKeyStep14) MergeKeyStep10(org.jooq.MergeKeyStep10) Clause(org.jooq.Clause) K_DELETE(org.jooq.impl.Keywords.K_DELETE) DataTypeException(org.jooq.exception.DataTypeException) MergeNotMatchedValuesStep21(org.jooq.MergeNotMatchedValuesStep21) MergeNotMatchedValuesStep20(org.jooq.MergeNotMatchedValuesStep20) MergeOnStep(org.jooq.MergeOnStep) MergeNotMatchedValuesStep22(org.jooq.MergeNotMatchedValuesStep22) MergeNotMatchedSetMoreStep(org.jooq.MergeNotMatchedSetMoreStep) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Field(org.jooq.Field) MergeKeyStep22(org.jooq.MergeKeyStep22) MergeNotMatchedValuesStep9(org.jooq.MergeNotMatchedValuesStep9) HSQLDB(org.jooq.SQLDialect.HSQLDB) MergeNotMatchedValuesStep8(org.jooq.MergeNotMatchedValuesStep8) List(java.util.List) MergeKeyStep20(org.jooq.MergeKeyStep20) MergeNotMatchedValuesStep7(org.jooq.MergeNotMatchedValuesStep7) K_INSERT(org.jooq.impl.Keywords.K_INSERT) MergeKeyStep21(org.jooq.MergeKeyStep21) MergeNotMatchedValuesStep6(org.jooq.MergeNotMatchedValuesStep6) Context(org.jooq.Context) MergeNotMatchedValuesStep5(org.jooq.MergeNotMatchedValuesStep5) K_SET(org.jooq.impl.Keywords.K_SET) MergeNotMatchedValuesStep4(org.jooq.MergeNotMatchedValuesStep4) K_KEY(org.jooq.impl.Keywords.K_KEY) MergeNotMatchedValuesStep3(org.jooq.MergeNotMatchedValuesStep3) MergeNotMatchedValuesStep2(org.jooq.MergeNotMatchedValuesStep2) Entry(java.util.Map.Entry) MergeNotMatchedValuesStep1(org.jooq.MergeNotMatchedValuesStep1) MergeNotMatchedValuesStep18(org.jooq.MergeNotMatchedValuesStep18) MergeNotMatchedValuesStep17(org.jooq.MergeNotMatchedValuesStep17) MergeNotMatchedValuesStep19(org.jooq.MergeNotMatchedValuesStep19) MERGE_WHEN_NOT_MATCHED_THEN_INSERT(org.jooq.Clause.MERGE_WHEN_NOT_MATCHED_THEN_INSERT) K_UPSERT(org.jooq.impl.Keywords.K_UPSERT) Tools.nullSafe(org.jooq.impl.Tools.nullSafe) K_USING(org.jooq.impl.Keywords.K_USING) HashSet(java.util.HashSet) MergeMatchedDeleteStep(org.jooq.MergeMatchedDeleteStep) DSL.insertInto(org.jooq.impl.DSL.insertInto) TableLike(org.jooq.TableLike) K_WHEN(org.jooq.impl.Keywords.K_WHEN) FALSE(java.lang.Boolean.FALSE) MERGE_VALUES(org.jooq.Clause.MERGE_VALUES) MERGE_USING(org.jooq.Clause.MERGE_USING) Tools.collect(org.jooq.impl.Tools.collect) K_WITH_PRIMARY_KEY(org.jooq.impl.Keywords.K_WITH_PRIMARY_KEY) Configuration(org.jooq.Configuration) H2(org.jooq.SQLDialect.H2) K_MERGE_INTO(org.jooq.impl.Keywords.K_MERGE_INTO) K_THEN(org.jooq.impl.Keywords.K_THEN) Condition(org.jooq.Condition) DSL.trueCondition(org.jooq.impl.DSL.trueCondition) DSL.noCondition(org.jooq.impl.DSL.noCondition) Field(org.jooq.Field)

Example 9 with Context

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

the class SelectQueryImpl method toSQLReference0.

/**
 * This method renders the main part of a query without the LIMIT clause.
 * This part is common to any type of limited query
 */
@SuppressWarnings("unchecked")
private final void toSQLReference0(Context<?> context, List<Field<?>> originalFields, List<Field<?>> alternativeFields) {
    SQLDialect family = context.family();
    boolean qualify = context.qualify();
    int unionOpSize = unionOp.size();
    boolean unionParensRequired = false;
    boolean unionOpNesting = false;
    // The SQL standard specifies:
    // 
    // <query expression> ::=
    // [ <with clause> ] <query expression body>
    // [ <order by clause> ] [ <result offset clause> ] [ <fetch first clause> ]
    // 
    // Depending on the dialect and on various syntax elements, parts of the above must be wrapped in
    // synthetic parentheses
    boolean wrapQueryExpressionInDerivedTable;
    boolean wrapQueryExpressionBodyInDerivedTable;
    boolean applySeekOnDerivedTable = applySeekOnDerivedTable();
    wrapQueryExpressionInDerivedTable = false;
    if (wrapQueryExpressionInDerivedTable)
        context.visit(K_SELECT).sql(" *").formatSeparator().visit(K_FROM).sql(" (").formatIndentStart().formatNewLine();
    wrapQueryExpressionBodyInDerivedTable = false || // predicate must be applied on a derived table, not on the individual subqueries
    applySeekOnDerivedTable;
    if (wrapQueryExpressionBodyInDerivedTable) {
        context.visit(K_SELECT).sql(' ');
        context.formatIndentStart().formatNewLine().sql("t.*");
        if (alternativeFields != null && originalFields.size() < alternativeFields.size())
            context.sql(", ").formatSeparator().declareFields(true, c -> c.visit(alternativeFields.get(alternativeFields.size() - 1)));
        context.formatIndentEnd().formatSeparator().visit(K_FROM).sql(" (").formatIndentStart().formatNewLine();
    }
    // all databases, we need to wrap relevant subqueries in parentheses.
    if (unionOpSize > 0) {
        if (!TRUE.equals(context.data(DATA_NESTED_SET_OPERATIONS)))
            context.data(DATA_NESTED_SET_OPERATIONS, unionOpNesting = unionOpNesting());
        for (int i = unionOpSize - 1; i >= 0; i--) {
            switch(unionOp.get(i)) {
                case EXCEPT:
                    context.start(SELECT_EXCEPT);
                    break;
                case EXCEPT_ALL:
                    context.start(SELECT_EXCEPT_ALL);
                    break;
                case INTERSECT:
                    context.start(SELECT_INTERSECT);
                    break;
                case INTERSECT_ALL:
                    context.start(SELECT_INTERSECT_ALL);
                    break;
                case UNION:
                    context.start(SELECT_UNION);
                    break;
                case UNION_ALL:
                    context.start(SELECT_UNION_ALL);
                    break;
            }
            // [#3676] There might be cases where nested set operations do not
            // imply required parentheses in some dialects, but better
            // play safe than sorry
            unionParenthesis(context, '(', alternativeFields != null ? alternativeFields : getSelect(), derivedTableRequired(context, this), unionParensRequired = unionOpNesting || unionParensRequired(context));
        }
    }
    traverseJoins(getFrom(), t -> {
        if (t instanceof TableImpl)
            context.scopeRegister(t, true);
    });
    for (Entry<QueryPart, QueryPart> entry : localQueryPartMapping.entrySet()) context.scopeRegister(entry.getKey(), true, entry.getValue());
    // SELECT clause
    // -------------
    context.start(SELECT_SELECT).visit(K_SELECT).separatorRequired(true);
    // [#1493] Oracle hints come directly after the SELECT keyword
    if (!StringUtils.isBlank(hint))
        context.sql(' ').sql(hint).separatorRequired(true);
    if (Tools.isNotEmpty(distinctOn))
        context.visit(K_DISTINCT_ON).sql(" (").visit(distinctOn).sql(')').separatorRequired(true);
    else if (distinct)
        context.visit(K_DISTINCT).separatorRequired(true);
    if (TRUE.equals(context.data(BooleanDataKey.DATA_RENDERING_DATA_CHANGE_DELTA_TABLE)))
        context.qualify(false);
    context.declareFields(true);
    // non-ambiguous column names as ambiguous column names are not allowed in subqueries
    if (alternativeFields != null)
        if (wrapQueryExpressionBodyInDerivedTable && originalFields.size() < alternativeFields.size())
            context.visit(new SelectFieldList<>(alternativeFields.subList(0, originalFields.size())));
        else
            context.visit(new SelectFieldList<>(alternativeFields));
    else
        // The default behaviour
        context.visit(getSelectResolveUnsupportedAsterisks(context.configuration()));
    if (TRUE.equals(context.data(BooleanDataKey.DATA_RENDERING_DATA_CHANGE_DELTA_TABLE)))
        context.qualify(qualify);
    context.declareFields(false).end(SELECT_SELECT);
    // only in top level SELECTs
    if (!context.subquery()) {
        context.start(SELECT_INTO);
        QueryPart actualIntoTable = (QueryPart) context.data(DATA_SELECT_INTO_TABLE);
        if (actualIntoTable == null)
            actualIntoTable = intoTable;
        if (actualIntoTable != null && !TRUE.equals(context.data(DATA_OMIT_INTO_CLAUSE)) && (SUPPORT_SELECT_INTO_TABLE.contains(context.dialect()) || !(actualIntoTable instanceof Table))) {
            context.formatSeparator().visit(K_INTO).sql(' ').visit(actualIntoTable);
        }
        context.end(SELECT_INTO);
    }
    // FROM and JOIN clauses
    // ---------------------
    context.start(SELECT_FROM).declareTables(true);
    // [#....] Some SQL dialects do not require a FROM clause. Others do and
    // jOOQ generates a "DUAL" table or something equivalent.
    // See also org.jooq.impl.Dual for details.
    boolean hasFrom = !getFrom().isEmpty() || !OPTIONAL_FROM_CLAUSE.contains(context.dialect());
    List<Condition> semiAntiJoinPredicates = null;
    ConditionProviderImpl where = getWhere(context);
    if (hasFrom) {
        Object previousCollect = context.data(DATA_COLLECT_SEMI_ANTI_JOIN, true);
        Object previousCollected = context.data(DATA_COLLECTED_SEMI_ANTI_JOIN, null);
        TableList tablelist = getFrom();
        tablelist = transformInlineDerivedTables(tablelist, where);
        context.formatSeparator().visit(K_FROM).separatorRequired(true).visit(tablelist);
        semiAntiJoinPredicates = (List<Condition>) context.data(DATA_COLLECTED_SEMI_ANTI_JOIN, previousCollected);
        context.data(DATA_COLLECT_SEMI_ANTI_JOIN, previousCollect);
    }
    context.declareTables(false).end(SELECT_FROM);
    // WHERE clause
    // ------------
    context.start(SELECT_WHERE);
    if (TRUE.equals(context.data().get(BooleanDataKey.DATA_SELECT_NO_DATA)))
        context.formatSeparator().visit(K_WHERE).sql(' ').visit(falseCondition());
    else if (!where.hasWhere() && semiAntiJoinPredicates == null)
        ;
    else {
        ConditionProviderImpl actual = new ConditionProviderImpl();
        if (semiAntiJoinPredicates != null)
            actual.addConditions(semiAntiJoinPredicates);
        if (where.hasWhere())
            actual.addConditions(where.getWhere());
        context.formatSeparator().visit(K_WHERE).sql(' ').visit(actual);
    }
    context.end(SELECT_WHERE);
    // GROUP BY and HAVING clause
    // --------------------------
    context.start(SELECT_GROUP_BY);
    if (!getGroupBy().isEmpty()) {
        context.formatSeparator().visit(K_GROUP_BY);
        if (groupByDistinct)
            context.sql(' ').visit(K_DISTINCT);
        context.separatorRequired(true);
        context.visit(groupBy);
    }
    context.end(SELECT_GROUP_BY);
    // HAVING clause
    // -------------
    context.start(SELECT_HAVING);
    if (getHaving().hasWhere())
        context.formatSeparator().visit(K_HAVING).sql(' ').visit(getHaving());
    context.end(SELECT_HAVING);
    // WINDOW clause
    // -------------
    context.start(SELECT_WINDOW);
    if (Tools.isNotEmpty(window) && !NO_SUPPORT_WINDOW_CLAUSE.contains(context.dialect()))
        context.formatSeparator().visit(K_WINDOW).separatorRequired(true).declareWindows(true, c -> c.visit(window));
    context.end(SELECT_WINDOW);
    if (getQualify().hasWhere())
        context.formatSeparator().visit(K_QUALIFY).sql(' ').visit(getQualify());
    // ORDER BY clause for local subselect
    // -----------------------------------
    toSQLOrderBy(context, originalFields, alternativeFields, false, wrapQueryExpressionBodyInDerivedTable, orderBy, limit);
    // --------------------------------------------
    if (unionOpSize > 0) {
        unionParenthesis(context, ')', null, derivedTableRequired(context, this), unionParensRequired);
        for (int i = 0; i < unionOpSize; i++) {
            CombineOperator op = unionOp.get(i);
            for (Select<?> other : union.get(i)) {
                boolean derivedTableRequired = derivedTableRequired(context, other);
                context.formatSeparator().visit(op.toKeyword(family));
                if (unionParensRequired)
                    context.sql(' ');
                else
                    context.formatSeparator();
                unionParenthesis(context, '(', other.getSelect(), derivedTableRequired, unionParensRequired);
                context.visit(other);
                unionParenthesis(context, ')', null, derivedTableRequired, unionParensRequired);
            }
            // [#1658] Close parentheses opened previously
            if (i < unionOpSize - 1)
                unionParenthesis(context, ')', null, derivedTableRequired(context, this), unionParensRequired);
            switch(unionOp.get(i)) {
                case EXCEPT:
                    context.end(SELECT_EXCEPT);
                    break;
                case EXCEPT_ALL:
                    context.end(SELECT_EXCEPT_ALL);
                    break;
                case INTERSECT:
                    context.end(SELECT_INTERSECT);
                    break;
                case INTERSECT_ALL:
                    context.end(SELECT_INTERSECT_ALL);
                    break;
                case UNION:
                    context.end(SELECT_UNION);
                    break;
                case UNION_ALL:
                    context.end(SELECT_UNION_ALL);
                    break;
            }
        }
        if (unionOpNesting)
            context.data().remove(DATA_NESTED_SET_OPERATIONS);
    }
    if (wrapQueryExpressionBodyInDerivedTable) {
        context.formatIndentEnd().formatNewLine().sql(") t");
        if (applySeekOnDerivedTable) {
            context.formatSeparator().visit(K_WHERE).sql(' ').qualify(false, c -> c.visit(getSeekCondition()));
        }
    }
    // ORDER BY clause for UNION
    // -------------------------
    context.qualify(false, c -> toSQLOrderBy(context, originalFields, alternativeFields, wrapQueryExpressionInDerivedTable, wrapQueryExpressionBodyInDerivedTable, unionOrderBy, unionLimit));
}
Also used : Internal.isub(org.jooq.impl.Internal.isub) Tools.aliased(org.jooq.impl.Tools.aliased) UnmodifiableList(org.jooq.impl.QOM.UnmodifiableList) DSL.emptyGroupingSet(org.jooq.impl.DSL.emptyGroupingSet) K_BY(org.jooq.impl.Keywords.K_BY) Arrays.asList(java.util.Arrays.asList) DSL.createTable(org.jooq.impl.DSL.createTable) Map(java.util.Map) QualifiedAsterisk(org.jooq.QualifiedAsterisk) SQLDialect(org.jooq.SQLDialect) Scope(org.jooq.Scope) Select(org.jooq.Select) SELECT_START_WITH(org.jooq.Clause.SELECT_START_WITH) DSL.partitionBy(org.jooq.impl.DSL.partitionBy) QueryPartCollectionView.wrap(org.jooq.impl.QueryPartCollectionView.wrap) Tools.isWindow(org.jooq.impl.Tools.isWindow) DataExtendedKey(org.jooq.impl.Tools.DataExtendedKey) DATA_TRANSFORM_ROWNUM_TO_LIMIT(org.jooq.impl.Tools.DataExtendedKey.DATA_TRANSFORM_ROWNUM_TO_LIMIT) TableField(org.jooq.TableField) SUPPORT_NATIVE_EXCEPT(org.jooq.impl.AsteriskImpl.SUPPORT_NATIVE_EXCEPT) DSL.noCondition(org.jooq.impl.DSL.noCondition) K_START_WITH(org.jooq.impl.Keywords.K_START_WITH) DATA_INSERT_SELECT(org.jooq.impl.Tools.BooleanDataKey.DATA_INSERT_SELECT) TRUE(java.lang.Boolean.TRUE) DERBY(org.jooq.SQLDialect.DERBY) EXCEPT_ALL(org.jooq.impl.CombineOperator.EXCEPT_ALL) DATA_RENDER_TRAILING_LIMIT_IF_APPLICABLE(org.jooq.impl.Tools.BooleanDataKey.DATA_RENDER_TRAILING_LIMIT_IF_APPLICABLE) DSL.jsonArrayAgg(org.jooq.impl.DSL.jsonArrayAgg) K_WITH_READ_ONLY(org.jooq.impl.Keywords.K_WITH_READ_ONLY) LinkedHashMap(java.util.LinkedHashMap) K_ORDER_BY(org.jooq.impl.Keywords.K_ORDER_BY) Tools.autoAlias(org.jooq.impl.Tools.autoAlias) INTERSECT(org.jooq.impl.CombineOperator.INTERSECT) VARCHAR(org.jooq.impl.SQLDataType.VARCHAR) XML(org.jooq.impl.SQLDataType.XML) DATA_OMIT_INTO_CLAUSE(org.jooq.impl.Tools.BooleanDataKey.DATA_OMIT_INTO_CLAUSE) DATA_DML_TARGET_TABLE(org.jooq.impl.Tools.DataKey.DATA_DML_TARGET_TABLE) MYSQL(org.jooq.SQLDialect.MYSQL) DATA_COLLECTED_SEMI_ANTI_JOIN(org.jooq.impl.Tools.DataKey.DATA_COLLECTED_SEMI_ANTI_JOIN) K_WITH_CHECK_OPTION(org.jooq.impl.Keywords.K_WITH_CHECK_OPTION) K_FROM(org.jooq.impl.Keywords.K_FROM) Comparator(org.jooq.Comparator) SelectFieldOrAsterisk(org.jooq.SelectFieldOrAsterisk) DSL.jsonbArrayAgg(org.jooq.impl.DSL.jsonbArrayAgg) DATA_COLLECT_SEMI_ANTI_JOIN(org.jooq.impl.Tools.BooleanDataKey.DATA_COLLECT_SEMI_ANTI_JOIN) FIREBIRD(org.jooq.SQLDialect.FIREBIRD) K_WHERE(org.jooq.impl.Keywords.K_WHERE) SELECT(org.jooq.Clause.SELECT) DSL.xmlattributes(org.jooq.impl.DSL.xmlattributes) JoinType(org.jooq.JoinType) IGNITE(org.jooq.SQLDialect.IGNITE) MARIADB(org.jooq.SQLDialect.MARIADB) NO_SUPPORT_ABSENT_ON_NULL(org.jooq.impl.JSONNull.NO_SUPPORT_ABSENT_ON_NULL) K_DISTINCT_ON(org.jooq.impl.Keywords.K_DISTINCT_ON) SelectQuery(org.jooq.SelectQuery) DSL.table(org.jooq.impl.DSL.table) INTERSECT_ALL(org.jooq.impl.CombineOperator.INTERSECT_ALL) Row(org.jooq.Row) IntStream.range(java.util.stream.IntStream.range) SELECT_WINDOW(org.jooq.Clause.SELECT_WINDOW) BiFunction(java.util.function.BiFunction) Table(org.jooq.Table) DSL.rowNumber(org.jooq.impl.DSL.rowNumber) Operator(org.jooq.Operator) ForLockWaitMode(org.jooq.impl.ForLock.ForLockWaitMode) SelectLimitPercentStep(org.jooq.SelectLimitPercentStep) Clause(org.jooq.Clause) SELECT_SELECT(org.jooq.Clause.SELECT_SELECT) NO_SUPPORT_UNQUALIFIED_COMBINED(org.jooq.impl.AsteriskImpl.NO_SUPPORT_UNQUALIFIED_COMBINED) JSONB(org.jooq.impl.SQLDataType.JSONB) DataKey(org.jooq.impl.Tools.DataKey) Tools.aliasedFields(org.jooq.impl.Tools.aliasedFields) SELECT_FROM(org.jooq.Clause.SELECT_FROM) K_TOP(org.jooq.impl.Keywords.K_TOP) GroupField(org.jooq.GroupField) OR(org.jooq.Operator.OR) DataType(org.jooq.DataType) DSL.name(org.jooq.impl.DSL.name) K_HAVING(org.jooq.impl.Keywords.K_HAVING) SELECT_CONNECT_BY(org.jooq.Clause.SELECT_CONNECT_BY) Name(org.jooq.Name) Collection(java.util.Collection) SelectLimitStep(org.jooq.SelectLimitStep) Field(org.jooq.Field) DATA_INSERT_SELECT_WITHOUT_INSERT_COLUMN_LIST(org.jooq.impl.Tools.BooleanDataKey.DATA_INSERT_SELECT_WITHOUT_INSERT_COLUMN_LIST) CUBRID(org.jooq.SQLDialect.CUBRID) SELECT_UNION(org.jooq.Clause.SELECT_UNION) K_QUALIFY(org.jooq.impl.Keywords.K_QUALIFY) EXCEPT(org.jooq.impl.CombineOperator.EXCEPT) K_INTO(org.jooq.impl.Keywords.K_INTO) Tools.containsUnaliasedTable(org.jooq.impl.Tools.containsUnaliasedTable) SelectWithTiesStep(org.jooq.SelectWithTiesStep) JSON(org.jooq.impl.SQLDataType.JSON) Entry(java.util.Map.Entry) K_DISTINCT(org.jooq.impl.Keywords.K_DISTINCT) Tools.anyMatch(org.jooq.impl.Tools.anyMatch) ResultSetMetaData(java.sql.ResultSetMetaData) K_SELECT(org.jooq.impl.Keywords.K_SELECT) K_SIBLINGS(org.jooq.impl.Keywords.K_SIBLINGS) SELECT_HAVING(org.jooq.Clause.SELECT_HAVING) INLINED(org.jooq.conf.ParamType.INLINED) Function(java.util.function.Function) K_CONNECT_BY(org.jooq.impl.Keywords.K_CONNECT_BY) TableLike(org.jooq.TableLike) Tools.fieldArray(org.jooq.impl.Tools.fieldArray) DSL.inline(org.jooq.impl.DSL.inline) K_PERCENT(org.jooq.impl.Keywords.K_PERCENT) SelectHavingStep(org.jooq.SelectHavingStep) DataAccessException(org.jooq.exception.DataAccessException) DATA_NESTED_SET_OPERATIONS(org.jooq.impl.Tools.BooleanDataKey.DATA_NESTED_SET_OPERATIONS) SELECT_INTERSECT(org.jooq.Clause.SELECT_INTERSECT) Consumer(java.util.function.Consumer) SortField(org.jooq.SortField) Multiset.returningClob(org.jooq.impl.Multiset.returningClob) H2(org.jooq.SQLDialect.H2) Tools.unalias(org.jooq.impl.Tools.unalias) K_WINDOW(org.jooq.impl.Keywords.K_WINDOW) Arrays(java.util.Arrays) DSL.orderBy(org.jooq.impl.DSL.orderBy) POSTGRES(org.jooq.SQLDialect.POSTGRES) DATA_UNALIAS_ALIASED_EXPRESSIONS(org.jooq.impl.Tools.BooleanDataKey.DATA_UNALIAS_ALIASED_EXPRESSIONS) JOIN(org.jooq.JoinType.JOIN) Condition(org.jooq.Condition) DSL.trueCondition(org.jooq.impl.DSL.trueCondition) EMULATE_WITH_GROUP_CONCAT(org.jooq.impl.JSONArrayAgg.EMULATE_WITH_GROUP_CONCAT) SelectField(org.jooq.SelectField) Tools.unqualified(org.jooq.impl.Tools.unqualified) CommonTableExpressionList.markTopLevelCteAndAccept(org.jooq.impl.CommonTableExpressionList.markTopLevelCteAndAccept) JSONObjectNullStep(org.jooq.JSONObjectNullStep) K_NOCYCLE(org.jooq.impl.Keywords.K_NOCYCLE) Set(java.util.Set) Tools.camelCase(org.jooq.impl.Tools.camelCase) QueryPart(org.jooq.QueryPart) Tools.traverseJoins(org.jooq.impl.Tools.traverseJoins) SELECT_UNION_ALL(org.jooq.Clause.SELECT_UNION_ALL) Tools.qualify(org.jooq.impl.Tools.qualify) N_LEVEL(org.jooq.impl.Names.N_LEVEL) Materialized(org.jooq.impl.QOM.Materialized) DSL.jsonObject(org.jooq.impl.DSL.jsonObject) K_AND(org.jooq.impl.Keywords.K_AND) DSL.xmlagg(org.jooq.impl.DSL.xmlagg) DATA_SELECT_INTO_TABLE(org.jooq.impl.Tools.DataKey.DATA_SELECT_INTO_TABLE) XML(org.jooq.XML) K_GROUP_BY(org.jooq.impl.Keywords.K_GROUP_BY) CompareCondition(org.jooq.impl.QOM.CompareCondition) DSL.row(org.jooq.impl.DSL.row) DSL.xmlelement(org.jooq.impl.DSL.xmlelement) ArrayList(java.util.ArrayList) Tools.isNotEmpty(org.jooq.impl.Tools.isNotEmpty) SELECT_INTO(org.jooq.Clause.SELECT_INTO) Transformations.transformRownum(org.jooq.impl.Transformations.transformRownum) SQLITE(org.jooq.SQLDialect.SQLITE) SELECT_WHERE(org.jooq.Clause.SELECT_WHERE) Record(org.jooq.Record) RIGHT_OUTER_JOIN(org.jooq.JoinType.RIGHT_OUTER_JOIN) JSONObjectReturningStep(org.jooq.JSONObjectReturningStep) K_MATERIALIZE(org.jooq.impl.Keywords.K_MATERIALIZE) K_ORDER(org.jooq.impl.Keywords.K_ORDER) DATA_TOP_LEVEL_CTE(org.jooq.impl.Tools.DataKey.DATA_TOP_LEVEL_CTE) SELECT_INTERSECT_ALL(org.jooq.Clause.SELECT_INTERSECT_ALL) StringUtils(org.jooq.tools.StringUtils) YUGABYTEDB(org.jooq.SQLDialect.YUGABYTEDB) UNION_ALL(org.jooq.impl.CombineOperator.UNION_ALL) ArrayDeque(java.util.ArrayDeque) ForLockMode(org.jooq.impl.ForLock.ForLockMode) TableOnStep(org.jooq.TableOnStep) Tools.map(org.jooq.impl.Tools.map) WindowDefinition(org.jooq.WindowDefinition) DSL.jsonbObject(org.jooq.impl.DSL.jsonbObject) Transformations.transformQualify(org.jooq.impl.Transformations.transformQualify) SelectOffsetStep(org.jooq.SelectOffsetStep) DATA_WRAP_DERIVED_TABLES_IN_PARENTHESES(org.jooq.impl.Tools.BooleanDataKey.DATA_WRAP_DERIVED_TABLES_IN_PARENTHESES) K_INLINE(org.jooq.impl.Keywords.K_INLINE) DSL.regexpReplaceAll(org.jooq.impl.DSL.regexpReplaceAll) DATA_SELECT_ALIASES(org.jooq.impl.Tools.DataKey.DATA_SELECT_ALIASES) JSONArrayAgg.patchOracleArrayAggBug(org.jooq.impl.JSONArrayAgg.patchOracleArrayAggBug) SELECT_EXCEPT(org.jooq.Clause.SELECT_EXCEPT) DEFAULT(org.jooq.SQLDialect.DEFAULT) Tools.selectQueryImpl(org.jooq.impl.Tools.selectQueryImpl) SELECT_GROUP_BY(org.jooq.Clause.SELECT_GROUP_BY) JooqLogger(org.jooq.tools.JooqLogger) Collections.emptyList(java.util.Collections.emptyList) DSL.falseCondition(org.jooq.impl.DSL.falseCondition) JSONEntry(org.jooq.JSONEntry) DATA_WINDOW_DEFINITIONS(org.jooq.impl.Tools.DataKey.DATA_WINDOW_DEFINITIONS) HSQLDB(org.jooq.SQLDialect.HSQLDB) List(java.util.List) Context(org.jooq.Context) DATA_OVERRIDE_ALIASES_IN_ORDER_BY(org.jooq.impl.Tools.DataKey.DATA_OVERRIDE_ALIASES_IN_ORDER_BY) TablePartitionByStep(org.jooq.TablePartitionByStep) Tools.recordType(org.jooq.impl.Tools.recordType) DSL.key(org.jooq.impl.DSL.key) ForeignKey(org.jooq.ForeignKey) Deque(java.util.Deque) BooleanDataKey(org.jooq.impl.Tools.BooleanDataKey) UNION(org.jooq.impl.CombineOperator.UNION) DSL.asterisk(org.jooq.impl.DSL.asterisk) SELECT_EXCEPT_ALL(org.jooq.Clause.SELECT_EXCEPT_ALL) Tools.hasAmbiguousNames(org.jooq.impl.Tools.hasAmbiguousNames) DSL.unquotedName(org.jooq.impl.DSL.unquotedName) Tools.isEmpty(org.jooq.impl.Tools.isEmpty) DESC(org.jooq.SortOrder.DESC) N_ROWNUM(org.jooq.impl.Names.N_ROWNUM) DSL.one(org.jooq.impl.DSL.one) Configuration(org.jooq.Configuration) TableOptionalOnStep(org.jooq.TableOptionalOnStep) SELECT_ORDER_BY(org.jooq.Clause.SELECT_ORDER_BY) LEFT_OUTER_JOIN(org.jooq.JoinType.LEFT_OUTER_JOIN) DSL.generateSeries(org.jooq.impl.DSL.generateSeries) OrderField(org.jooq.OrderField) Collections(java.util.Collections) DSL.noCondition(org.jooq.impl.DSL.noCondition) Condition(org.jooq.Condition) DSL.trueCondition(org.jooq.impl.DSL.trueCondition) CompareCondition(org.jooq.impl.QOM.CompareCondition) DSL.falseCondition(org.jooq.impl.DSL.falseCondition) DSL.createTable(org.jooq.impl.DSL.createTable) Table(org.jooq.Table) Tools.containsUnaliasedTable(org.jooq.impl.Tools.containsUnaliasedTable) QueryPart(org.jooq.QueryPart) SQLDialect(org.jooq.SQLDialect) DSL.jsonObject(org.jooq.impl.DSL.jsonObject) DSL.jsonbObject(org.jooq.impl.DSL.jsonbObject)

Example 10 with Context

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

the class FieldMapForUpdate method accept.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public final void accept(Context<?> ctx) {
    if (size() > 0) {
        String separator = "";
        // [#989] Some dialects do not support qualified column references
        // in the UPDATE statement's SET clause
        // [#2055] Other dialects require qualified column references to
        // disambiguated columns in queries like
        // UPDATE t1 JOIN t2 .. SET t1.val = ..., t2.val = ...
        boolean supportsQualify = !NO_SUPPORT_QUALIFY.contains(ctx.dialect()) && ctx.qualify();
        // [#2823] [#10034] Few dialects need bind value casts for UPDATE .. SET
        // Some regressions have been observed e.g. in PostgreSQL with JSON types, so let's be careful.
        CastMode previous = ctx.castMode();
        if (!CASTS_NEEDED.contains(ctx.dialect()))
            ctx.castMode(CastMode.NEVER);
        for (Entry<Field<?>, Field<?>> entry : removeReadonly(ctx, flattenEntrySet(entrySet(), true))) {
            if (!"".equals(separator))
                ctx.sql(separator).formatSeparator();
            ctx.start(assignmentClause).qualify(supportsQualify, c -> c.visit(entry.getKey())).sql(" = ");
            // [#8479] Emulate WHERE clause using CASE
            Condition condition = (Condition) ctx.data(DATA_ON_DUPLICATE_KEY_WHERE);
            if (condition != null)
                ctx.visit(when(condition, (Field) entry.getValue()).else_(entry.getKey()));
            else
                ctx.visit(entry.getValue());
            ctx.end(assignmentClause);
            separator = ",";
        }
        if (!CASTS_NEEDED.contains(ctx.dialect()))
            ctx.castMode(previous);
    } else
        ctx.sql("[ no fields are updated ]");
}
Also used : THROW(org.jooq.conf.WriteIfReadonly.THROW) Row(org.jooq.Row) UNotYetImplemented(org.jooq.impl.QOM.UNotYetImplemented) IGNORE(org.jooq.conf.WriteIfReadonly.IGNORE) Tools.collect(org.jooq.impl.Tools.collect) Set(java.util.Set) Table(org.jooq.Table) Tools.row0(org.jooq.impl.Tools.row0) Field(org.jooq.Field) POSTGRES(org.jooq.SQLDialect.POSTGRES) DSL.when(org.jooq.impl.DSL.when) Condition(org.jooq.Condition) Tools.filter(org.jooq.impl.Tools.filter) YUGABYTEDB(org.jooq.SQLDialect.YUGABYTEDB) DATA_ON_DUPLICATE_KEY_WHERE(org.jooq.impl.Tools.DataKey.DATA_ON_DUPLICATE_KEY_WHERE) Clause(org.jooq.Clause) Context(org.jooq.Context) CastMode(org.jooq.RenderContext.CastMode) SQLITE(org.jooq.SQLDialect.SQLITE) Map(java.util.Map) Tools.flattenEntrySet(org.jooq.impl.Tools.flattenEntrySet) DataTypeException(org.jooq.exception.DataTypeException) SQLDialect(org.jooq.SQLDialect) Tools.anyMatch(org.jooq.impl.Tools.anyMatch) Condition(org.jooq.Condition) Field(org.jooq.Field) CastMode(org.jooq.RenderContext.CastMode)

Aggregations

Context (org.jooq.Context)14 Set (java.util.Set)13 SQLDialect (org.jooq.SQLDialect)13 Field (org.jooq.Field)12 Configuration (org.jooq.Configuration)11 List (java.util.List)10 Clause (org.jooq.Clause)10 Collection (java.util.Collection)9 Condition (org.jooq.Condition)9 QueryPart (org.jooq.QueryPart)9 FIREBIRD (org.jooq.SQLDialect.FIREBIRD)9 H2 (org.jooq.SQLDialect.H2)9 Tools.map (org.jooq.impl.Tools.map)9 ArrayList (java.util.ArrayList)8 Arrays (java.util.Arrays)8 Map (java.util.Map)8 Name (org.jooq.Name)8 Record (org.jooq.Record)8 Row (org.jooq.Row)8 DERBY (org.jooq.SQLDialect.DERBY)8