diff --git a/api/src/main/java/jakarta/persistence/CheckConstraint.java b/api/src/main/java/jakarta/persistence/CheckConstraint.java new file mode 100644 index 00000000..0e504813 --- /dev/null +++ b/api/src/main/java/jakarta/persistence/CheckConstraint.java @@ -0,0 +1,31 @@ +package jakarta.persistence; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * Used to specify a SQL check constraint on a column or table + * when schema generation is in effect. + * + * @see Table#check() + * @see Column#check() + * + * @since 3.2 + */ +@Target({}) +@Retention(RUNTIME) +public @interface CheckConstraint { + + /** + * (Optional) The name of the constraint; defaults to a provider-generated name. + */ + String name() default ""; + + /** + * (Required) The expression to be checked. + */ + String constraint(); + +} diff --git a/api/src/main/java/jakarta/persistence/Column.java b/api/src/main/java/jakarta/persistence/Column.java index 561d834f..ca6e0b0d 100644 --- a/api/src/main/java/jakarta/persistence/Column.java +++ b/api/src/main/java/jakarta/persistence/Column.java @@ -121,4 +121,20 @@ * (Applies only if a decimal column is used.) */ int scale() default 0; + + /** + * (Optional) Check constraints to be applied to the column. + * These are only used if table generation is in effect. + * + * @since 3.2 + */ + CheckConstraint[] check() default {}; + + /** + * (Optional) A comment to be applied to the column. + * This is only used if table generation is in effect. + * + * @since 3.2 + */ + String comment() default ""; } diff --git a/api/src/main/java/jakarta/persistence/JoinColumn.java b/api/src/main/java/jakarta/persistence/JoinColumn.java index 3ec2142e..6cb8d937 100644 --- a/api/src/main/java/jakarta/persistence/JoinColumn.java +++ b/api/src/main/java/jakarta/persistence/JoinColumn.java @@ -183,4 +183,20 @@ * @since 2.1 */ ForeignKey foreignKey() default @ForeignKey(PROVIDER_DEFAULT); + + /** + * (Optional) Check constraints to be applied to the column. + * These are only used if table generation is in effect. + * + * @since 3.2 + */ + CheckConstraint[] check() default {}; + + /** + * (Optional) A comment to be applied to the column. + * This is only used if table generation is in effect. + * + * @since 3.2 + */ + String comment() default ""; } diff --git a/api/src/main/java/jakarta/persistence/JoinTable.java b/api/src/main/java/jakarta/persistence/JoinTable.java index d4b8a880..55b42db9 100644 --- a/api/src/main/java/jakarta/persistence/JoinTable.java +++ b/api/src/main/java/jakarta/persistence/JoinTable.java @@ -152,4 +152,20 @@ * @since 2.1 */ Index[] indexes() default {}; + + /** + * (Optional) Check constraints to be applied to the table. + * These are only used if table generation is in effect. + * + * @since 3.2 + */ + CheckConstraint[] check() default {}; + + /** + * (Optional) A comment to be applied to the table. + * This is only used if table generation is in effect. + * + * @since 3.2 + */ + String comment() default ""; } diff --git a/api/src/main/java/jakarta/persistence/SecondaryTable.java b/api/src/main/java/jakarta/persistence/SecondaryTable.java index ae2ed557..03442608 100644 --- a/api/src/main/java/jakarta/persistence/SecondaryTable.java +++ b/api/src/main/java/jakarta/persistence/SecondaryTable.java @@ -118,4 +118,20 @@ * @since 2.1 */ Index[] indexes() default {}; + + /** + * (Optional) Check constraints to be applied to the table. + * These are only used if table generation is in effect. + * + * @since 3.2 + */ + CheckConstraint[] check() default {}; + + /** + * (Optional) A comment to be applied to the table. + * This is only used if table generation is in effect. + * + * @since 3.2 + */ + String comment() default ""; } diff --git a/api/src/main/java/jakarta/persistence/Table.java b/api/src/main/java/jakarta/persistence/Table.java index 667f2d5f..ea2eca5f 100644 --- a/api/src/main/java/jakarta/persistence/Table.java +++ b/api/src/main/java/jakarta/persistence/Table.java @@ -78,4 +78,20 @@ * @since 2.1 */ Index[] indexes() default {}; + + /** + * (Optional) Check constraints to be applied to the table. + * These are only used if table generation is in effect. + * + * @since 3.2 + */ + CheckConstraint[] check() default {}; + + /** + * (Optional) A comment to be applied to the table. + * This is only used if table generation is in effect. + * + * @since 3.2 + */ + String comment() default ""; } diff --git a/spec/src/main/asciidoc/appendixes.adoc b/spec/src/main/asciidoc/appendixes.adoc index 6e2ab49e..facb4aae 100644 --- a/spec/src/main/asciidoc/appendixes.adoc +++ b/spec/src/main/asciidoc/appendixes.adoc @@ -114,3 +114,4 @@ Added _concat()_ overload accepting list of expressions to _CriteriaBuilder_ Made the _name_ member of _TableGenerator_ and _SequenceGenerator_ optional +Introduced _comment_ and _check_ members to table and column annotations, along with _CheckConstraint_ \ No newline at end of file diff --git a/spec/src/main/asciidoc/ch11-metadata-for-or-mapping.adoc b/spec/src/main/asciidoc/ch11-metadata-for-or-mapping.adoc index 76a39bb9..944af262 100644 --- a/spec/src/main/asciidoc/ch11-metadata-for-or-mapping.adoc +++ b/spec/src/main/asciidoc/ch11-metadata-for-or-mapping.adoc @@ -852,6 +852,8 @@ public @interface Column { int length() default 255; int precision() default 0; // decimal precision int scale() default 0; // decimal scale + CheckConstraint[] check() default {} + String comment() default ""; } ---- @@ -925,6 +927,18 @@ if a string-valued column is used.) |(Optional) The scale for a decimal (exact numeric) column. (Applies only if a decimal column is used.) |0 + +|CheckConstraint[] +|check +|(Optional) Check constraints for the column. These are +only used if table generation is in effect. +|No check constraint + +|String +|comment +|(Optional) Comment for the column. This is +only used if table generation is in effect. +|No comment |=== *Example 1:* @@ -2178,6 +2192,8 @@ public @interface JoinColumn { String columnDefinition() default ""; String table() default ""; ForeignKey foreignKey() default @ForeignKey(PROVIDER_DEFAULT); + CheckConstraint[] check() default {} + String comment() default ""; } ---- @@ -2272,6 +2288,18 @@ join is for an element collection, the name of the collection table. |(Optional) The foreign key constraint for the join column. This is used only if table generation is in effect. |Provider's default + +|CheckConstraint[] +|check +|(Optional) Check constraints for the column. These are +only used if table generation is in effect. +|No check constraint + +|String +|comment +|(Optional) Comment for the column. This is +only used if table generation is in effect. +|No comment |=== *Example 1:* @@ -2407,6 +2435,8 @@ public @interface JoinTable { ForeignKey inverseForeignKey() default @ForeignKey(PROVIDER_DEFAULT); UniqueConstraint[] uniqueConstraints() default {}; Index[] indexes() default {}; + CheckConstraint[] check() default {} + String comment() default ""; } ---- @@ -2471,6 +2501,18 @@ effect. |(Optional) Indexes for the table. These are only used if table generation is in effect. |No additional indexes + +|CheckConstraint[] +|check +|(Optional) Check constraints for the table. These are +only used if table generation is in effect. +|No check constraint + +|String +|comment +|(Optional) Comment for the table. This is +only used if table generation is in effect. +|No comment |=== *Example:* @@ -4541,6 +4583,8 @@ public @interface SecondaryTable { ForeignKey foreignKey() default @ForeignKey(PROVIDER_DEFAULT); UniqueConstraint[] uniqueConstraints() default {}; Index[] indexes() default {}; + CheckConstraint[] check() default {} + String comment() default ""; } ---- @@ -4589,6 +4633,18 @@ entailed by primary key mappings. |(Optional) Indexes for the table. These are only used if table generation is in effect. |No additional indexes + +|CheckConstraint[] +|check +|(Optional) Check constraints for the table. These are +only used if table generation is in effect. +|No check constraint + +|String +|comment +|(Optional) Comment for the table. This is +only used if table generation is in effect. +|No comment |=== *Example 1:* Single secondary table with a single primary key column. @@ -4811,6 +4867,8 @@ public @interface Table { String schema() default ""; UniqueConstraint[] uniqueConstraints() default {}; Index[] indexes() default {}; + CheckConstraint[] check() default {} + String comment() default ""; } ---- @@ -4849,6 +4907,18 @@ constraints |(Optional) Indexes for the table. These are only used if table generation is in effect. |No additional indexes + +|CheckConstraint[] +|check +|(Optional) Check constraints for the table. These are +only used if table generation is in effect. +|No check constraint + +|String +|comment +|(Optional) Comment for the table. This is +only used if table generation is in effect. +|No comment |=== *Example:*