KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cmp2 > cmrstress > ejb > ParentBean


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.cmrstress.ejb;
23
24 import java.util.HashMap JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.Map JavaDoc;
27 import java.util.Set JavaDoc;
28
29 import javax.ejb.CreateException JavaDoc;
30 import javax.ejb.EJBException JavaDoc;
31 import javax.ejb.EntityBean JavaDoc;
32 import javax.ejb.EntityContext JavaDoc;
33 import javax.ejb.RemoveException JavaDoc;
34 import javax.naming.NamingException JavaDoc;
35
36 import org.jboss.logging.Logger;
37 import org.jboss.test.cmp2.cmrstress.interfaces.ChildLocal;
38 import org.jboss.test.cmp2.cmrstress.interfaces.ChildUtil;
39
40 /**
41  * This class implements the "parent" side of 1..many unidirectional relationship.
42  * It doesn't do anything particularly interesting besides provide the CMR getter
43  * and a method (@see #getPropertyMap()) that provides a transactional context for
44  * iterating over the CMR collection.
45  *
46  * This code is based upon the original test case provided by Andrew May.
47  *
48  * @version <tt>$Revision: 58115 $</tt>
49  * @author <a HREF="mailto:steve@resolvesw.com">Steve Coy</a>.
50  *
51  * @ejb.bean name="Parent"
52  * type="CMP"
53  * cmp-version="2.x"
54  * view-type="both"
55  * jndi-name="cmrstress/Parent"
56  * primkey-field="id"
57  *
58  * @ejb.pk class="java.lang.String"
59  * generate="false"
60  *
61  * @ejb.persistence table-name="StressedParent"
62  *
63  * @@ejb.home generate="both"
64  * @@ejb.interface generate="both"
65  *
66  * @ejb.ejb-ref ejb-name="Child"
67  * view-type="local"
68  *
69  * @ejb.transaction type="Supports"
70  *
71  * @jboss.persistence
72  * create-table="true"
73  * remove-table="true"
74  * @jboss.tuned-updates tune="true"
75  */

76 public abstract class ParentBean implements EntityBean JavaDoc
77 {
78    /**
79     * CMP get method for Id attribute.
80     * @ejb.interface-method view-type="remote"
81     * @ejb.persistent-field
82     * @jboss.column-name name="id"
83     * @jboss.method-attributes read-only="true"
84     */

85    public abstract String JavaDoc getId();
86
87    /**
88     * CMP set method for Id attribute.
89     * @ejb.interface-method view-type="remote"
90     * @ejb.transaction type="Mandatory"
91     */

92    public abstract void setId(String JavaDoc id);
93
94    /**
95     * Get Children that apply to this Parent.
96     *
97     * @ejb.interface-method view-type="remote"
98     * @ejb.relation name="Parent-Child"
99     * role-name="Parent-has-Children"
100     * cascade-delete="no"
101     * target-ejb="Child"
102     * target-role-name="Child-of-Parent"
103     * target-cascade-delete="yes"
104     * @jboss.target-relation related-pk-field="id"
105     * fk-column="parentid"
106     * jboss.method-attributes read-only="true"
107     */

108    public abstract Set JavaDoc getChildren();
109
110    /**
111     * Set Children.
112     * @ejb.interface-method view-type="remote"
113     * @ejb.transaction type="Mandatory"
114     */

115    public abstract void setChildren(Set JavaDoc children);
116
117    /**
118     * Get a map of Child values.
119     * This is the current axis of evil.
120     *
121     * @ejb.interface-method view-type="remote"
122     * @ejb.transaction type="Required"
123     * @jboss.method-attributes read-only="true"
124     */

125    public Map JavaDoc getPropertyMap()
126    {
127       Map JavaDoc result = new HashMap JavaDoc();
128       Set JavaDoc children = getChildren();
129       for (Iterator JavaDoc i = children.iterator(); i.hasNext(); )
130       {
131          ChildLocal c = (ChildLocal) i.next();
132          result.put(c.getName(), c.getValue());
133       }
134
135       return result;
136    }
137
138    /**
139     * Adds a child bean with the given attributes to this bean.
140     * @ejb.interface-method view-type="remote"
141     * @ejb.transaction type="RequiresNew"
142     */

143    public void addChild(int k, String JavaDoc field1, String JavaDoc field2) throws CreateException JavaDoc
144    {
145       msLog.debug("Adding child with pk: " + k);
146       try
147       {
148          getChildren().add(ChildUtil.getLocalHome().create(Integer.toString(k), field1, field2));
149       }
150       catch (NamingException JavaDoc e)
151       {
152          throw new EJBException JavaDoc(e);
153       }
154    }
155    
156    
157    /**
158     * Create method for Entity.
159     * @ejb.create-method view-type="remote"
160     * @ejb.transaction type="RequiresNew"
161     */

162    public String JavaDoc ejbCreate(String JavaDoc id) throws javax.ejb.CreateException JavaDoc
163    {
164       msLog.debug("Created '" + id + "'");
165       setId(id);
166       return null;
167    }
168
169    public void ejbPostCreate(String JavaDoc id)
170    {
171    }
172    
173    /**
174     * @see javax.ejb.EntityBean#ejbActivate()
175     */

176    public void ejbActivate()
177    {
178    }
179
180    /**
181     * @see javax.ejb.EntityBean#ejbLoad()
182     */

183    public void ejbLoad()
184    {
185    }
186
187    /**
188     * @see javax.ejb.EntityBean#ejbPassivate()
189     */

190    public void ejbPassivate()
191    {
192    }
193
194    /**
195     * @see javax.ejb.EntityBean#ejbRemove()
196     */

197    public void ejbRemove() throws RemoveException JavaDoc
198    {
199       msLog.debug("Removed");
200    }
201
202    /**
203     * @see javax.ejb.EntityBean#ejbStore()
204     */

205    public void ejbStore()
206    {
207    }
208
209    /**
210     * @see javax.ejb.EntityBean#setEntityContext(javax.ejb.EntityContext)
211     */

212    public void setEntityContext(EntityContext JavaDoc arg0)
213    {
214    }
215
216    /**
217     * @see javax.ejb.EntityBean#unsetEntityContext()
218     */

219    public void unsetEntityContext()
220    {
221    }
222
223    private static final Logger msLog = Logger.getLogger(ParentBean.class);
224
225 }
226
Popular Tags