KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cmp2 > cmr > ejb > CMRBugBean


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.cmp2.cmr.ejb;
23
24
25 import java.util.Collection JavaDoc;
26
27 import javax.ejb.CreateException JavaDoc;
28 import javax.ejb.EJBException JavaDoc;
29 import javax.ejb.EntityBean JavaDoc;
30 import javax.ejb.EntityContext JavaDoc;
31
32 import org.jboss.test.cmp2.cmr.interfaces.CMRBugEJBLocal;
33
34 /**
35  * class <code>CMRBugBean</code> demonstrates bug 523627. CMR fields may get changed
36  * in ejbPostCreate, so newly created entities must be marked as needing ejbSave.
37  * Currently this is done by putting them in GlobalTxEntityMap.
38  *
39  * @author <a HREF="mailto:MNewcomb@tacintel.com">Michael Newcomb</a>
40  * @author <a HREF="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
41  * @version 1.0
42  *
43  * @ejb:bean name="CMRBugEJB"
44  * local-jndi-name="LocalReadOnly"
45  * view-type="local"
46  * type="CMP"
47  * cmp-version="2.x"
48  * primkey-field="id"
49  * reentrant="true"
50  * schema="CMRBug"
51  * @ejb:pk class="java.lang.String"
52  * @ejb:finder signature="java.util.Collection findAll()"
53  * query="select object(cmr_bug) from CMRBug as cmr_bug"
54  * @jboss:create-table create="true"
55  * @jboss:remove-table remove="true"
56  */

57 public abstract class CMRBugBean
58    implements EntityBean JavaDoc
59 {
60    private EntityContext JavaDoc context;
61
62    /**
63     * Describe <code>getId</code> method here.
64     *
65     * @return a <code>String</code> value
66     * @ejb:persistent-field
67     * @ejb:interface-method
68     */

69    public abstract String JavaDoc getId();
70
71    /**
72     * Describe <code>setId</code> method here.
73     *
74     * @param id a <code>String</code> value
75     * @ejb:interface-method
76     */

77    public abstract void setId(String JavaDoc id);
78
79    /**
80     * Describe <code>getDescription</code> method here.
81     *
82     * @return a <code>String</code> value
83     * @ejb:persistent-field
84     * @ejb:interface-method
85     */

86    public abstract String JavaDoc getDescription();
87
88    /**
89     * Describe <code>setDescription</code> method here.
90     *
91     * @param description a <code>String</code> value
92     * @ejb:interface-method
93     */

94    public abstract void setDescription(String JavaDoc description);
95
96    /**
97     * Describe <code>getParent</code> method here.
98     *
99     * @return a <code>CMRBugEJBLocal</code> value
100     * @ejb:interface-method
101     * @ejb:relation name="CMRBug-CMRBug"
102     * role-name="parent"
103     * cascade-delete="yes"
104     * @jboss:auto-key-fields
105     */

106    public abstract CMRBugEJBLocal getParent();
107
108    /**
109     * Describe <code>setParent</code> method here.
110     *
111     * @param parent a <code>CMRBugEJBLocal</code> value
112     * @ejb:interface-method
113     */

114    public abstract void setParent(CMRBugEJBLocal parent);
115
116    /**
117     * Describe <code>getChildren</code> method here.
118     *
119     * @return a <code>Collection</code> value
120     * @ejb:interface-method
121     * @ejb:relation name="CMRBug-CMRBug"
122     * role-name="children"
123     * multiple="yes"
124     * @jboss:auto-key-fields
125     */

126    public abstract Collection JavaDoc getChildren();
127
128    /**
129     * Describe <code>setChildren</code> method here.
130     *
131     * @param children a <code>Collection</code> value
132     * @ejb:interface-method
133     */

134    public abstract void setChildren(Collection JavaDoc children);
135
136    /**
137     * Describe <code>addChild</code> method here.
138     *
139     * @param child a <code>CMRBugEJBLocal</code> value
140     * @return a <code>boolean</code> value
141     * @ejb:interface-method
142     */

143    public boolean addChild(CMRBugEJBLocal child)
144    {
145       try
146       {
147          Collection JavaDoc children = getChildren();
148          return children.add(child);
149       }
150       catch(Exception JavaDoc e)
151       {
152          throw new EJBException JavaDoc(e);
153       }
154    }
155
156    /**
157     * Describe <code>removeChild</code> method here.
158     *
159     * @param child a <code>CMRBugEJBLocal</code> value
160     * @return a <code>boolean</code> value
161     * @ejb:interface-method
162     */

163    public boolean removeChild(CMRBugEJBLocal child)
164    {
165       try
166       {
167          Collection JavaDoc children = getChildren();
168          return children.remove(child);
169       }
170       catch(Exception JavaDoc e)
171       {
172          throw new EJBException JavaDoc(e);
173       }
174    }
175
176    //
177
// The following is the linked list implementation. It is implemented with unidirectional CMRs.
178
// These are used to test correct foreign key state initialization when the foreign key
179
// loaded is not a valid value, i.e. the relationship was already changed in the tx.
180
//
181

182    /**
183     * @ejb:interface-method view-type="local"
184     * @ejb:relation
185     * name="viewcomponent-prevnode"
186     * role-name="one-viewcomponent-has-one-previous-node"
187     * target-role-name="one-prev-belogs-to-one-viewcomponent"
188     * target-ejb="CMRBugEJB"
189     * target-multiple="no"
190     * @jboss:relation
191     * related-pk-field="id"
192     * fk-column="prev_id_fk"
193     */

194    public abstract CMRBugEJBLocal getPrevNode();
195    /**
196     * @ejb:interface-method view-type="local"
197     */

198    public abstract void setPrevNode(CMRBugEJBLocal a_ViewComponent);
199
200    /**
201     * @ejb:interface-method view-type="local"
202     * @ejb:relation
203     * name="viewcomponent-nextnode"
204     * role-name="one-viewcomponent-has-one-following-node"
205     * target-role-name="one-following-node-belogs-to-one-viewcomponent"
206     * target-ejb="CMRBugEJB"
207     * target-multiple="no"
208     * @jboss:relation
209     * related-pk-field="id"
210     * fk-column="next_id_fk"
211     */

212    public abstract CMRBugEJBLocal getNextNode();
213    /**
214     * @ejb:interface-method view-type="local"
215     */

216    public abstract void setNextNode(CMRBugEJBLocal a_ViewComponent);
217
218    // --------------------------------------------------------------------------
219
// EntityBean methods
220
//
221

222    /**
223     * Describe <code>ejbCreate</code> method here.
224     *
225     * @param id a <code>String</code> value
226     * @param description a <code>String</code> value
227     * @param parent a <code>CMRBugEJBLocal</code> value
228     * @return an <code>Integer</code> value
229     * @exception CreateException if an error occurs
230     * @ejb:create-method
231     */

232    public String JavaDoc ejbCreate(String JavaDoc id, String JavaDoc description, CMRBugEJBLocal parent)
233       throws CreateException JavaDoc
234    {
235       setId(id);
236       setDescription(description);
237
238       // CMP beans return null for this method
239
//
240
return null;
241    }
242
243    /**
244     * Describe <code>ejbPostCreate</code> method here.
245     *
246     * @param id a <code>String</code> value
247     * @param description a <code>String</code> value
248     * @param parent a <code>CMRBugEJBLocal</code> value
249     * @exception CreateException if an error occurs
250     */

251    public void ejbPostCreate(String JavaDoc id, String JavaDoc description, CMRBugEJBLocal parent)
252       throws CreateException JavaDoc
253    {
254       // must set the CMR fields in the post create
255
//
256
setParent(parent);
257    }
258
259    public void setEntityContext(EntityContext JavaDoc context)
260    {
261       this.context = context;
262    }
263
264    public void unsetEntityContext()
265    {
266       context = null;
267    }
268
269    public void ejbRemove()
270    {
271    }
272
273    public void ejbLoad()
274    {
275    }
276
277    public void ejbStore()
278    {
279    }
280
281    public void ejbActivate()
282    {
283    }
284
285    public void ejbPassivate()
286    {
287    }
288 }
289
Popular Tags