KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > persistence > TableGenerator


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package javax.persistence;
24
25 import java.lang.annotation.Target JavaDoc;
26 import java.lang.annotation.Retention JavaDoc;
27 import static java.lang.annotation.ElementType.FIELD JavaDoc;
28 import static java.lang.annotation.ElementType.METHOD JavaDoc;
29 import static java.lang.annotation.ElementType.TYPE JavaDoc;
30 import static java.lang.annotation.RetentionPolicy.RUNTIME JavaDoc;
31
32 /**
33  * This annotation defines a primary key generator that may be
34  * referenced by name when a generator element is specified for
35  * the {@link GeneratedValue} annotation. A table generator
36  * may be specified on the entity class or on the primary key
37  * field or property. The scope of the generator name is global
38  * to the persistence unit (across all generator types).
39  *
40  * <pre>
41  * Example 1:
42  *
43  * &#064;Entity public class Employee {
44  * ...
45  * &#064;TableGenerator(
46  * name="empGen",
47  * table="ID_GEN",
48  * pkColumnName="GEN_KEY",
49  * valueColumnName="GEN_VALUE",
50  * pkColumnValue="EMP_ID",
51  * allocationSize=1)
52  * &#064;Id
53  * &#064;GeneratedValue(strategy=TABLE, generator="empGen")
54  * public int id;
55  * ...
56  * }
57  *
58  * Example 2:
59  *
60  * &#064;Entity public class Address {
61  * ...
62  * &#064;TableGenerator(
63  * name="addressGen",
64  * table="ID_GEN",
65  * pkColumnName="GEN_KEY",
66  * valueColumnName="GEN_VALUE",
67  * pkColumnValue="ADDR_ID")
68  * &#064;Id
69  * &#064;GeneratedValue(strategy=TABLE, generator="addressGen")
70  * public int id;
71  * ...
72  * }
73  * </pre>
74  *
75  * @since Java Persistence 1.0
76  */

77 @Target JavaDoc({TYPE, METHOD, FIELD})
78 @Retention JavaDoc(RUNTIME)
79
80 public @interface TableGenerator {
81
82     /**
83      * (Required) A unique generator name that can be referenced
84      * by one or more classes to be the generator for id values.
85      */

86     String JavaDoc name();
87
88     /**
89      * (Optional) Name of table that stores the generated id values.
90      * <p> Defaults to a name chosen by persistence provider.
91      */

92     String JavaDoc table() default "";
93
94     /** (Optional) The catalog of the table.
95      * <p> Defaults to the default catalog.
96      */

97     String JavaDoc catalog() default "";
98
99     /** (Optional) The schema of the table.
100      * <p> Defaults to the default schema for user.
101      */

102     String JavaDoc schema() default "";
103
104     /**
105      * (Optional) Name of the primary key column in the table.
106      * <p> Defaults to a provider-chosen name.
107      */

108     String JavaDoc pkColumnName() default "";
109
110     /**
111      * (Optional) Name of the column that stores the last value generated.
112      * <p> Defaults to a provider-chosen name.
113      */

114     String JavaDoc valueColumnName() default "";
115
116     /**
117      * (Optional) The primary key value in the generator table
118      * that distinguishes this set of generated values from others
119      * that may be stored in the table.
120      * <p> Defaults to a provider-chosen value to store in the
121      * primary key column of the generator table
122      */

123     String JavaDoc pkColumnValue() default "";
124
125     /**
126      * (Optional) The initial value to be used when allocating id
127      * numbers from the generator.
128      */

129     int initialValue() default 0;
130
131     /**
132      * (Optional) The amount to increment by when allocating id
133      * numbers from the generator.
134      */

135     int allocationSize() default 50;
136
137     /**
138      * (Optional) Unique constraints that are to be placed on the
139      * table. These are only used if table generation is in effect.
140      * These constraints apply in addition to primary key constraints.
141      * <p> Defaults to no additional constraints.
142      */

143     UniqueConstraint[] uniqueConstraints() default {};
144 }
145
Popular Tags