1 /**
2 * Copyright 2005-2013 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.eclipselink;
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. A portable sequence generator may be specified on the entity
27 * class or on the primary key field or property. The scope of the generator name is global to the persistence unit
28 * (across all generator types).
29 *
30 * <p>The term "portable" in this case indicates that native sequences will be used if the target database platform
31 * supports them. However, if it does not have native sequence support, then sequence-like behavior will be emulated
32 * using an appropriate strategy for the target platform.</p>
33 *
34 * <pre>
35 * Examples:
36 *
37 * @PortableSequenceGenerator(name="EMP_SEQ")
38 *
39 * @PortableSequenceGenerator(name="EMP_SEQ", sequenceName="EMP_SEQ", initialValue = 1)
40 * </pre>
41 *
42 * <p>Current, in order for this annotation to work properly, the {@link KradEclipseLinkCustomizer} must be configured
43 * for the EclipseLink persistence unit. This can be done manually using
44 * {@link org.eclipse.persistence.config.PersistenceUnitProperties#SESSION_CUSTOMIZER}, or it will be done automatically
45 * when using {@link KradEclipseLinkEntityManagerFactoryBean}</p>
46 *
47 * @author Kuali Rice Team (rice.collab@kuali.org)
48 */
49 @Target({TYPE, METHOD, FIELD})
50 @Retention(RUNTIME)
51 public @interface PortableSequenceGenerator {
52
53 /**
54 * (Required) A unique generator name that can be referenced by one or more classes to be the generator for primary
55 * key values.
56 */
57 String name();
58
59 /**
60 * (Optional) The name of the database sequence object from which to obtain primary key values. If not specified,
61 * will default to the name of this generator.
62 */
63 String sequenceName() default "";
64
65 /**
66 * (Optional) The value from which the sequence object is to start generating. Only used for generation of the
67 * sequence in the schema. If the sequence construct already exists in the database or schema generation is not
68 * enabled, then this value is effectively ignored.
69 */
70 int initialValue() default 1000;
71
72 }