KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > cfg > InheritanceState


1 //$Id: InheritanceState.java,v 1.4 2005/06/17 09:15:14 epbernard Exp $
2
package org.hibernate.cfg;
3
4 import java.lang.reflect.AnnotatedElement JavaDoc;
5 import javax.persistence.Inheritance;
6 import javax.persistence.InheritanceType;
7 import javax.persistence.EmbeddableSuperclass;
8 import javax.persistence.AccessType;
9
10 /**
11  * Some extra data to the inheritance position of a class
12  *
13  * @author Emmanuel Bernard
14  */

15 public class InheritanceState {
16     public boolean hasSons = false;
17     public boolean hasParents = false;
18     public boolean hasEmbeddedSuperclass = false;
19     public InheritanceType type;
20     public boolean isEmbeddableSuperclass = false;
21     /** only defined on embedded superclasses */
22     public AccessType accessType = null;
23
24     public void setInheritanceType(AnnotatedElement JavaDoc clazz) {
25         Inheritance inhAnn = clazz.getAnnotation(Inheritance.class);
26         EmbeddableSuperclass superclassAnn = clazz.getAnnotation( EmbeddableSuperclass.class );
27         if ( superclassAnn != null ) {
28             isEmbeddableSuperclass = true;
29             type = inhAnn == null ? null : inhAnn.strategy();
30             accessType = superclassAnn.access();
31         }
32         else {
33             type = inhAnn == null ? InheritanceType.SINGLE_TABLE : inhAnn.strategy();
34         }
35     }
36
37     boolean hasTable() {
38         return !hasParents || !InheritanceType.SINGLE_TABLE.equals(type);
39     }
40
41     boolean hasDenormalizedTable() {
42         return hasParents && InheritanceType.TABLE_PER_CLASS.equals(type);
43     }
44 }
45
Popular Tags