KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > amber > type > SubEntityType


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free Software Foundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.amber.type;
30
31 import com.caucho.amber.field.Id;
32 import com.caucho.amber.manager.AmberPersistenceUnit;
33 import com.caucho.amber.table.Column;
34 import com.caucho.util.L10N;
35
36 /**
37  * Represents an application persistent bean type
38  */

39 public class SubEntityType extends EntityType {
40   private static final L10N L = new L10N(SubEntityType.class);
41
42   private RelatedType _root;
43   private RelatedType _parent;
44
45   private Id _id;
46
47   public SubEntityType(AmberPersistenceUnit amberPersistenceUnit,
48                        RelatedType parent)
49   {
50     super(amberPersistenceUnit);
51
52     _parent = parent;
53     _root = parent.getRootType();
54
55     _loadGroupIndex = -1;
56     _defaultLoadGroupIndex = -1;
57     _dirtyIndex = -1;
58   }
59
60   /**
61    * Returns the id.
62    */

63   public Id getId()
64   {
65     if (_id != null)
66       return _id;
67     else
68       return _parent.getId();
69   }
70
71   /**
72    * Sts the id.
73    */

74   public void setId(Id id)
75   {
76     _id = id;
77   }
78
79   /**
80    * Returns the root type.
81    */

82   public RelatedType getRootType()
83   {
84     return _root;
85   }
86
87   /**
88    * Returns the parent class.
89    */

90   public RelatedType getParentType()
91   {
92     return _parent;
93   }
94
95   /**
96    * Returns the discriminator.
97    */

98   public Column getDiscriminator()
99   {
100     return getRootType().getDiscriminator();
101   }
102
103   /**
104    * Returns the load group index, overriding the parent.
105    */

106   public int getLoadGroupIndex()
107   {
108     if (_loadGroupIndex < 0) {
109       _loadGroupIndex = _parent.getLoadGroupIndex() + 1;
110       _defaultLoadGroupIndex = _loadGroupIndex;
111     }
112
113     return _loadGroupIndex;
114   }
115
116   /**
117    * Returns the current load group.
118    */

119   public int getDefaultLoadGroupIndex()
120   {
121     if (_defaultLoadGroupIndex < 0) {
122       // initialized by getLoadGroupIndex()
123
getLoadGroupIndex();
124     }
125
126     return _defaultLoadGroupIndex;
127   }
128
129   /**
130    * Returns the dirty index, overriding the parent.
131    */

132   public int getDirtyIndex()
133   {
134     if (_dirtyIndex < 0) {
135       _dirtyIndex = _parent.getDirtyIndex();
136       _minDirtyIndex = _dirtyIndex;
137     }
138
139     return _dirtyIndex;
140   }
141
142
143   /**
144    * Printable version of the entity.
145    */

146   public String JavaDoc toString()
147   {
148     return "SubEntityType[" + getBeanClass().getName() + "]";
149   }
150 }
151
Popular Tags