1 /**
2 * Copyright 2005-2015 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.rice.krad.data.jpa;
17
18 import java.lang.annotation.Retention;
19 import java.lang.annotation.Target;
20
21 import static java.lang.annotation.ElementType.*;
22 import static java.lang.annotation.RetentionPolicy.RUNTIME;
23
24 /**
25 * Defines a primary key generator that may be referenced by name when a generator element is specified for the
26 * {@link javax.persistence.GeneratedValue} annotation.
27 *
28 * <p>
29 * A portable sequence generator may be specified on the entity class or on the primary key field or property. The scope
30 * of the generator name is global to the persistence unit (across all generator types).
31 * </p>
32 *
33 * <p>
34 * The term "portable" in this case indicates that native sequences will be used if the target database platform
35 * supports them. However, if it does not have native sequence support, then sequence-like behavior will be emulated
36 * using an appropriate strategy for the target platform.
37 * </p>
38 *
39 * <pre>
40 * Examples:
41 *
42 * @PortableSequenceGenerator(name="EMP_SEQ")
43 *
44 * @PortableSequenceGenerator(name="EMP_SEQ", sequenceName="EMP_SEQ", initialValue = 1)
45 * </pre>
46 *
47 * <p>
48 * Current, in order for this annotation to work properly, the
49 * {@link org.kuali.rice.krad.data.jpa.eclipselink.KradEclipseLinkCustomizer} must be configured for the EclipseLink
50 * persistence unit. This can be done manually using
51 * {@link org.eclipse.persistence.config.PersistenceUnitProperties#SESSION_CUSTOMIZER}, or it will be done automatically
52 * when using {@link org.kuali.rice.krad.data.jpa.eclipselink.KradEclipseLinkEntityManagerFactoryBean}.</p>
53 *
54 * @author Kuali Rice Team (rice.collab@kuali.org)
55 */
56 @Target({TYPE, METHOD, FIELD})
57 @Retention(RUNTIME)
58 public @interface PortableSequenceGenerator {
59
60 /**
61 * (Required) A unique generator name that can be referenced by one or more classes to be the generator for primary
62 * key values.
63 *
64 * @return the name of the sequence generator.
65 */
66 String name();
67
68 /**
69 * (Optional) The name of the database sequence object from which to obtain primary key values. If not specified,
70 * will default to the name of this generator.
71 *
72 * @return the sequence name associated with the sequence generator.
73 */
74 String sequenceName() default "";
75
76 /**
77 * (Optional) The value from which the sequence object is to start generating. Only used for generation of the
78 * sequence in the schema.
79 *
80 * <p>
81 * If the sequence construct already exists in the database or schema generation is not enabled, then this value is
82 * effectively ignored.
83 * </p>
84 *
85 * @return the initial value of the sequence.
86 */
87 int initialValue() default 1000;
88
89 }