From 349b73f540303a7d7146ec97d88b229fbb0429a7 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Thu, 12 Dec 2019 18:13:14 +0100 Subject: [PATCH] [jOOQ/jOOQ#9663] Regenerated test code --- .../java/org/jooq/codegen/JavaGenerator.java | 28 ++++++++++++------ .../src/main/java/org/jooq/impl/Internal.java | 29 ++++++++++++++++--- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/jOOQ-codegen/src/main/java/org/jooq/codegen/JavaGenerator.java b/jOOQ-codegen/src/main/java/org/jooq/codegen/JavaGenerator.java index 04441c96bc..fef3123f9a 100644 --- a/jOOQ-codegen/src/main/java/org/jooq/codegen/JavaGenerator.java +++ b/jOOQ-codegen/src/main/java/org/jooq/codegen/JavaGenerator.java @@ -1103,17 +1103,22 @@ public class JavaGenerator extends AbstractGenerator { private void printCreateUniqueKey(JavaWriter out, UniqueKeyDefinition uniqueKey) { if (scala) - out.print("%s.createUniqueKey(%s, \"%s\", [[%s]])", + out.print("%s.createUniqueKey(%s, \"%s\", Array([[%s]]).asInstanceOf[Array[%s[%s, _] ] ], %s)", Internal.class, out.ref(getStrategy().getFullJavaIdentifier(uniqueKey.getTable()), 2), escapeString(uniqueKey.getOutputName()), - out.ref(getStrategy().getFullJavaIdentifiers(uniqueKey.getKeyColumns()), colRefSegments(null))); + out.ref(getStrategy().getFullJavaIdentifiers(uniqueKey.getKeyColumns()), colRefSegments(null)), + TableField.class, + out.ref(getStrategy().getJavaClassName(uniqueKey.getTable(), Mode.RECORD)), + uniqueKey.enforced()); else - out.print("%s.createUniqueKey(%s, \"%s\", [[%s]])", + out.print("%s.createUniqueKey(%s, \"%s\", new %s[] { [[%s]] }, %s)", Internal.class, out.ref(getStrategy().getFullJavaIdentifier(uniqueKey.getTable()), 2), escapeString(uniqueKey.getOutputName()), - out.ref(getStrategy().getFullJavaIdentifiers(uniqueKey.getKeyColumns()), colRefSegments(null))); + TableField.class, + out.ref(getStrategy().getFullJavaIdentifiers(uniqueKey.getKeyColumns()), colRefSegments(null)), + uniqueKey.enforced()); } protected void printForeignKey(JavaWriter out, int foreignKeyCounter, ForeignKeyDefinition foreignKey) { @@ -1134,7 +1139,7 @@ public class JavaGenerator extends AbstractGenerator { } if (scala) - out.tab(2).println("val %s : %s[%s, %s] = %s.createForeignKey(%s, %s, \"%s\", [[%s]])", + out.tab(2).println("val %s : %s[%s, %s] = %s.createForeignKey(%s, %s, \"%s\", Array([[%s]]).asInstanceOf[Array[%s[%s, _] ] ], %s)", getStrategy().getJavaIdentifier(foreignKey), ForeignKey.class, out.ref(getStrategy().getFullJavaClassName(foreignKey.getKeyTable(), Mode.RECORD)), @@ -1143,9 +1148,12 @@ public class JavaGenerator extends AbstractGenerator { out.ref(getStrategy().getFullJavaIdentifier(foreignKey.getReferencedKey()), 2), out.ref(getStrategy().getFullJavaIdentifier(foreignKey.getKeyTable()), 2), escapeString(foreignKey.getOutputName()), - out.ref(getStrategy().getFullJavaIdentifiers(foreignKey.getKeyColumns()), colRefSegments(null))); + out.ref(getStrategy().getFullJavaIdentifiers(foreignKey.getKeyColumns()), colRefSegments(null)), + TableField.class, + out.ref(getStrategy().getJavaClassName(foreignKey.getTable(), Mode.RECORD)), + foreignKey.enforced()); else - out.tab(2).println("public static final %s<%s, %s> %s = %s.createForeignKey(%s, %s, \"%s\", [[%s]]);", + out.tab(2).println("public static final %s<%s, %s> %s = %s.createForeignKey(%s, %s, \"%s\", new %s[] { [[%s]] }, %s);", ForeignKey.class, out.ref(getStrategy().getFullJavaClassName(foreignKey.getKeyTable(), Mode.RECORD)), out.ref(getStrategy().getFullJavaClassName(foreignKey.getReferencedTable(), Mode.RECORD)), @@ -1154,7 +1162,9 @@ public class JavaGenerator extends AbstractGenerator { out.ref(getStrategy().getFullJavaIdentifier(foreignKey.getReferencedKey()), 2), out.ref(getStrategy().getFullJavaIdentifier(foreignKey.getKeyTable()), 2), escapeString(foreignKey.getOutputName()), - out.ref(getStrategy().getFullJavaIdentifiers(foreignKey.getKeyColumns()), colRefSegments(null))); + TableField.class, + out.ref(getStrategy().getFullJavaIdentifiers(foreignKey.getKeyColumns()), colRefSegments(null)), + foreignKey.enforced()); } protected void generateRecords(SchemaDefinition schema) { @@ -4249,7 +4259,7 @@ public class JavaGenerator extends AbstractGenerator { String separator = " "; for (CheckConstraintDefinition c : cc) { - out.tab(3).println("%s%s.createCheck(this, %s.name(\"%s\"), \"%s\")", separator, Internal.class, DSL.class, c.getName().replace("\"", "\\\""), c.getCheckClause().replace("\"", "\\\"")); + out.tab(3).println("%s%s.createCheck(this, %s.name(\"%s\"), \"%s\", %s)", separator, Internal.class, DSL.class, c.getName().replace("\"", "\\\""), c.getCheckClause().replace("\"", "\\\""), c.enforced()); separator = ", "; } diff --git a/jOOQ/src/main/java/org/jooq/impl/Internal.java b/jOOQ/src/main/java/org/jooq/impl/Internal.java index f7015b1a05..2479614607 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Internal.java +++ b/jOOQ/src/main/java/org/jooq/impl/Internal.java @@ -100,7 +100,7 @@ public final class Internal { @SafeVarargs public static final UniqueKey createUniqueKey(Table table, TableField... fields) { - return new UniqueKeyImpl<>(table, fields, true); + return createUniqueKey(table, null, fields, true); } /** @@ -110,7 +110,14 @@ public final class Internal { @SafeVarargs public static final UniqueKey createUniqueKey(Table table, String name, TableField... fields) { - return new UniqueKeyImpl<>(table, name, fields, true); + return createUniqueKey(table, name, fields, true); + } + + /** + * Factory method for unique keys. + */ + public static final UniqueKey createUniqueKey(Table table, String name, TableField[] fields, boolean enforced) { + return new UniqueKeyImpl<>(table, name, fields, enforced); } /** @@ -130,7 +137,14 @@ public final class Internal { @SafeVarargs public static final ForeignKey createForeignKey(UniqueKey key, Table table, String name, TableField... fields) { - ForeignKey result = new ReferenceImpl<>(key, table, name, fields, true); + return createForeignKey(key, table, name, fields, true); + } + + /** + * Factory method for foreign keys. + */ + public static final ForeignKey createForeignKey(UniqueKey key, Table table, String name, TableField[] fields, boolean enforced) { + ForeignKey result = new ReferenceImpl<>(key, table, name, fields, enforced); if (key instanceof UniqueKeyImpl) ((UniqueKeyImpl) key).references.add(result); @@ -167,7 +181,14 @@ public final class Internal { * Factory method for check constraints. */ public static final Check createCheck(Table table, Name name, String condition) { - return new CheckImpl<>(table, name, DSL.condition(condition), true); + return createCheck(table, name, condition, true); + } + + /** + * Factory method for check constraints. + */ + public static final Check createCheck(Table table, Name name, String condition, boolean enforced) { + return new CheckImpl<>(table, name, DSL.condition(condition), enforced); } /**