[jOOQ/jOOQ#16522] Add alternative setNonKeyToExcluded(),

setNonPrimaryKeyToExcluded(), and setNonConflictingKeyToExcluded()
methods to UPSERT syntax
This commit is contained in:
Lukas Eder 2024-11-13 15:53:39 +01:00
parent 10002ebd93
commit a44eca8eb7
2 changed files with 47 additions and 2 deletions

View File

@ -183,4 +183,35 @@ public interface InsertOnDuplicateSetStep<R extends Record> {
@Support({ CUBRID, DERBY, DUCKDB, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB })
InsertOnDuplicateSetMoreStep<R> setAllToExcluded();
/**
* Sets all non-key columns from the insert column list to
* {@link DSL#excluded(Field)}.
* <p>
* This excludes any {@link Table#getKeys()} columns.
*/
@NotNull @CheckReturnValue
@Support({ CUBRID, DERBY, DUCKDB, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB })
InsertOnDuplicateSetMoreStep<R> setNonKeyToExcluded();
/**
* Sets all non-primary key columns from the insert column list to
* {@link DSL#excluded(Field)}.
* <p>
* This excludes any {@link Table#getPrimaryKey()} columns.
*/
@NotNull @CheckReturnValue
@Support({ CUBRID, DERBY, DUCKDB, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB })
InsertOnDuplicateSetMoreStep<R> setNonPrimaryKeyToExcluded();
/**
* Sets all non-conflicting key columns from the insert column list to
* {@link DSL#excluded(Field)}.
* <p>
* This excludes any {@link InsertOnDuplicateStep#onConflict(Field...)}
* columns.
*/
@NotNull @CheckReturnValue
@Support({ CUBRID, DERBY, DUCKDB, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB })
InsertOnDuplicateSetMoreStep<R> setNonConflictingKeyToExcluded();
}

View File

@ -2452,8 +2452,15 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
parseKeywordIf("SET");
// Cast is necessary, see https://github.com/eclipse-jdt/eclipse.jdt.core/issues/99
InsertOnConflictWhereStep<?> where = parseKeywordIf("ALL TO EXCLUDED")
InsertOnConflictWhereStep<?> where =
parseKeywordIf("ALL TO EXCLUDED")
? onDuplicate.onDuplicateKeyUpdate().setAllToExcluded()
: parseKeywordIf("NON KEY TO EXCLUDED")
? onDuplicate.onDuplicateKeyUpdate().setNonKeyToExcluded()
: parseKeywordIf("NON PRIMARY KEY TO EXCLUDED")
? onDuplicate.onDuplicateKeyUpdate().setNonPrimaryKeyToExcluded()
: parseKeywordIf("NON CONFLICTING KEY TO EXCLUDED")
? onDuplicate.onDuplicateKeyUpdate().setNonConflictingKeyToExcluded()
: onDuplicate.onDuplicateKeyUpdate().set((Map<?, ?>) data(DATA_PARSE_ON_CONFLICT, true, c -> c.parseSetClauseList()));
if (parseKeywordIf("WHERE"))
@ -2489,8 +2496,15 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
else if (parseKeywordIf("UPDATE SET")) {
// Cast is necessary, see https://github.com/eclipse-jdt/eclipse.jdt.core/issues/99
InsertOnConflictWhereStep<?> where = parseKeywordIf("ALL TO EXCLUDED")
InsertOnConflictWhereStep<?> where =
parseKeywordIf("ALL TO EXCLUDED")
? doUpdate.doUpdate().setAllToExcluded()
: parseKeywordIf("NON KEY TO EXCLUDED")
? doUpdate.doUpdate().setNonKeyToExcluded()
: parseKeywordIf("NON PRIMARY KEY TO EXCLUDED")
? doUpdate.doUpdate().setNonPrimaryKeyToExcluded()
: parseKeywordIf("NON CONFLICTING KEY TO EXCLUDED")
? doUpdate.doUpdate().setNonConflictingKeyToExcluded()
: doUpdate.doUpdate().set((Map<?, ?>) data(DATA_PARSE_ON_CONFLICT, true, c -> c.parseSetClauseList()));
if (parseKeywordIf("WHERE"))