KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > persistence > DiscriminatorColumn


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.TYPE JavaDoc;
28 import static java.lang.annotation.RetentionPolicy.RUNTIME JavaDoc;
29 import static javax.persistence.DiscriminatorType.STRING;
30
31 /**
32  * Is used to define the discriminator column for the
33  * {@link InheritanceType#SINGLE_TABLE SINGLE_TABLE} and
34  * {@link InheritanceType#JOINED JOINED} inheritance mapping strategies.
35  *
36  * <p> The strategy and the discriminator column are only
37  * specified in the root of an entity class hierarchy or
38  * subhierarchy in which a different inheritance strategy is applied
39  *
40  * <p> If the <code>DiscriminatorColumn</code> annotation is missing,
41  * and a discriminator column is required, the name of the
42  * discriminator column defaults to <code>"DTYPE"</code> and the discriminator
43  * type to {@link DiscriminatorType#STRING DiscriminatorType.STRING}.
44  *
45  * <pre>
46  * Example:
47  * &#064;Entity
48  * &#064;Table(name="CUST")
49  * &#064;Inheritance(strategy=SINGLE_TABLE)
50  * &#064;DiscriminatorColumn(name="DISC", discriminatorType=STRING,length=20)
51  * public class Customer { ... }
52  *
53  * &#064;Entity
54  * public class ValuedCustomer extends Customer { ... }
55  * </pre>
56  *
57  * @since Java Persistence 1.0
58  */

59 @Target JavaDoc({TYPE})
60 @Retention JavaDoc(RUNTIME)
61
62 public @interface DiscriminatorColumn {
63
64     /**
65      * (Optional) The name of column to be used for the discriminator.
66      */

67     String JavaDoc name() default "DTYPE";
68
69     /**
70      * (Optional) The type of object/column to use as a class discriminator.
71      * Defaults to {@link DiscriminatorType#STRING DiscriminatorType.STRING}.
72      */

73     DiscriminatorType discriminatorType() default STRING;
74
75     /**
76      * (Optional) The SQL fragment that is used when generating the DDL
77      * for the discriminator column.
78      * <p> Defaults to the provider-generated SQL to create a column
79      * of the specified discriminator type.
80      */

81     String JavaDoc columnDefinition() default "";
82
83     /**
84      * (Optional) The column length for String-based discriminator types.
85      * Ignored for other discriminator types.
86      */

87     int length() default 31;
88 }
89
Popular Tags