Skip to content

Commit

Permalink
package-level @SequenceGenerator and @TableGenerator
Browse files Browse the repository at this point in the history
see #511
  • Loading branch information
gavinking authored and lukasj committed Sep 4, 2023
1 parent 07ac75e commit a1c9c1e
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 16 deletions.
13 changes: 12 additions & 1 deletion api/src/main/java/jakarta/persistence/SequenceGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.lang.annotation.Retention;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

Expand All @@ -39,6 +40,16 @@
* on an entity class or primary key attribute of an entity class,
* then the name defaults to the name of the entity.
*
* <p>If no name is explicitly specified, and the annotation occurs
* on a package descriptor, then the annotation defines a recipe for
* producing a default generator when a {@link GeneratedValue}
* annotation of any program element in the annotated package has
* {@link GeneratedValue#strategy strategy=SEQUENCE} and a defaulted
* {@linkplain GeneratedValue#generator generator name}. The name of
* this default generator is the defaulted generator name, and its
* other properties are determined by the members of the package
* {@code SequenceGenerator} annotation.
*
* <p>Example:
* <pre>
* &#064;SequenceGenerator(name="EMP_SEQ", allocationSize=25)
Expand All @@ -47,7 +58,7 @@
* @since 1.0
*/
@Repeatable(SequenceGenerators.class)
@Target({TYPE, METHOD, FIELD})
@Target({TYPE, METHOD, FIELD, PACKAGE})
@Retention(RUNTIME)
public @interface SequenceGenerator {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

Expand All @@ -29,7 +30,7 @@
* @see SequenceGenerator
* @since 2.2
*/
@Target({TYPE, METHOD, FIELD})
@Target({TYPE, METHOD, FIELD, PACKAGE})
@Retention(RUNTIME)
public @interface SequenceGenerators {

Expand Down
13 changes: 12 additions & 1 deletion api/src/main/java/jakarta/persistence/TableGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.lang.annotation.Retention;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

Expand All @@ -41,6 +42,16 @@
* entity class, then the name defaults to the name of the
* entity.
*
* <p>If no name is explicitly specified, and the annotation occurs
* on a package descriptor, then the annotation defines a recipe for
* producing a default generator when a {@link GeneratedValue}
* annotation of any program element in the annotated package has
* {@link GeneratedValue#strategy strategy=TABLE} and a defaulted
* {@linkplain GeneratedValue#generator generator name}. The name of
* this default generator is the defaulted generator name, and its
* other properties are determined by the members of the package
* {@code TableGenerator} annotation.
*
* <p>Example 1:
* <pre>
* &#064;Entity public class Employee {
Expand Down Expand Up @@ -80,7 +91,7 @@
* @since 1.0
*/
@Repeatable(TableGenerators.class)
@Target({TYPE, METHOD, FIELD})
@Target({TYPE, METHOD, FIELD, PACKAGE})
@Retention(RUNTIME)
public @interface TableGenerator {

Expand Down
3 changes: 2 additions & 1 deletion api/src/main/java/jakarta/persistence/TableGenerators.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

Expand All @@ -29,7 +30,7 @@
* @see TableGenerator
* @since 2.2
*/
@Target({TYPE, METHOD, FIELD})
@Target({TYPE, METHOD, FIELD, PACKAGE})
@Retention(RUNTIME)
public @interface TableGenerators {

Expand Down
36 changes: 26 additions & 10 deletions spec/src/main/asciidoc/ch11-metadata-for-or-mapping.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4900,13 +4900,21 @@ and the annotation occurs on an entity class or primary key attribute of
an entity class, then the name defaults to the name of the entity.
Otherwise, if the annotation occurs elsewhere, the behavior is undefined.

<<a16179>> lists the annotation elements
that may be specified for the _SequenceGenerator_ annotation and their
default values.
If no name is explicitly specified by the _SequenceGenerator_ annotation,
and the annotation occurs on a package descriptor, then the annotation
defines a recipe for producing a default generator when a _GeneratedValue_
annotation of any program element in the annotated package has
_strategy=SEQUENCE_ and a defaulted _generator_ name. The name of this
default generator is the defaulted generator name, and its other properties
are determined by the members of the package-level _SequenceGenerator_
annotation.

<<a16179>> lists the annotation elements that may be specified for the
_SequenceGenerator_ annotation and their default values.

[source,java]
----
@Target({TYPE, METHOD, FIELD})
@Target({TYPE, METHOD, FIELD, PACKAGE})
@Retention(RUNTIME)
@Repeatable(SequenceGenerators.class)
public @interface SequenceGenerator {
Expand Down Expand Up @@ -4979,7 +4987,7 @@ to specify multiple sequence generators.

[source,java]
----
@Target({TYPE, METHOD, FIELD})
@Target({TYPE, METHOD, FIELD, PACKAGE})
@Retention(RUNTIME)
public @interface SequenceGenerators {
SequenceGenerator[] value();
Expand Down Expand Up @@ -5107,9 +5115,17 @@ and the annotation occurs on an entity class or primary key attribute
of an entity class, then the name defaults to the name of the entity.
Otherwise, if the annotation occurs elsewhere, the behavior is undefined.

<<a162771>> lists the annotation elements that
may be specified for the _TableGenerator_ annotation and their default
values.
If no name is explicitly specified by the _TableGenerator_ annotation,
and the annotation occurs on a package descriptor, then the annotation
defines a recipe for producing a default generator when a _GeneratedValue_
annotation of any program element in the annotated package has
_strategy=TABLE_ and a defaulted _generator_ name. The name of this
default generator is the defaulted generator name, and its other properties
are determined by the members of the package-level _TableGenerator_
annotation.

<<a162771>> lists the annotation elements that may be specified for the
_TableGenerator_ annotation and their default values.

The _table_ element specifies the name of the
table that is used by the persistence provider to store generated
Expand All @@ -5119,7 +5135,7 @@ primary key values are normally positive integers.

[source,java]
----
@Target({TYPE, METHOD, FIELD})
@Target({TYPE, METHOD, FIELD, PACKAGE})
@Retention(RUNTIME)
@Repeatable(TableGenerators.class)
public @interface TableGenerator {
Expand Down Expand Up @@ -5265,7 +5281,7 @@ specify multiple table generators.

[source,java]
----
@Target({TYPE, METHOD, FIELD})
@Target({TYPE, METHOD, FIELD, PACKAGE})
@Retention(RUNTIME)
public @interface TableGenerators {
TableGenerator[] value();
Expand Down
4 changes: 2 additions & 2 deletions spec/src/main/asciidoc/ch12-xml-or-mapping-descriptor.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3046,7 +3046,7 @@ object/relational mapping schema for use with the persistence API.
<xsd:annotation>
<xsd:documentation>
@Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME)
@Target({TYPE, METHOD, FIELD, PACKAGE}) @Retention(RUNTIME)
public @interface SequenceGenerator {
String name() default "";
String sequenceName() default "";
Expand Down Expand Up @@ -3155,7 +3155,7 @@ object/relational mapping schema for use with the persistence API.
<xsd:annotation>
<xsd:documentation>
@Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME)
@Target({TYPE, METHOD, FIELD, PACKAGE}) @Retention(RUNTIME)
public @interface TableGenerator {
String name() default "";
String table() default "";
Expand Down

0 comments on commit a1c9c1e

Please sign in to comment.