Skip to content

Commit

Permalink
introduce comment and check, @CheckConstraint annotation
Browse files Browse the repository at this point in the history
see #381
  • Loading branch information
gavinking committed Aug 8, 2023
1 parent 4daf494 commit 9c4078d
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 0 deletions.
31 changes: 31 additions & 0 deletions api/src/main/java/jakarta/persistence/CheckConstraint.java
Original file line number Diff line number Diff line change
@@ -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 native SQL expression to be checked.
*/
String constraint();

}
16 changes: 16 additions & 0 deletions api/src/main/java/jakarta/persistence/Column.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
}
16 changes: 16 additions & 0 deletions api/src/main/java/jakarta/persistence/JoinColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
}
16 changes: 16 additions & 0 deletions api/src/main/java/jakarta/persistence/JoinTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
}
16 changes: 16 additions & 0 deletions api/src/main/java/jakarta/persistence/SecondaryTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
}
16 changes: 16 additions & 0 deletions api/src/main/java/jakarta/persistence/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
}
1 change: 1 addition & 0 deletions spec/src/main/asciidoc/appendixes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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_
70 changes: 70 additions & 0 deletions spec/src/main/asciidoc/ch11-metadata-for-or-mapping.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
}
----

Expand Down Expand Up @@ -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:*
Expand Down Expand Up @@ -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 "";
}
----

Expand Down Expand Up @@ -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:*
Expand Down Expand Up @@ -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 "";
}
----

Expand Down Expand Up @@ -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:*
Expand Down Expand Up @@ -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 "";
}
----

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -4811,6 +4867,8 @@ public @interface Table {
String schema() default "";
UniqueConstraint[] uniqueConstraints() default {};
Index[] indexes() default {};
CheckConstraint[] check() default {}
String comment() default "";
}
----

Expand Down Expand Up @@ -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:*
Expand Down

0 comments on commit 9c4078d

Please sign in to comment.