001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.cmp2.cmr.ejb;
023:
024: import java.util.Collection;
025:
026: import javax.ejb.CreateException;
027: import javax.ejb.EJBException;
028: import javax.ejb.EntityBean;
029: import javax.ejb.EntityContext;
030:
031: import org.jboss.test.cmp2.cmr.interfaces.CMRBugEJBLocal;
032:
033: /**
034: * class <code>CMRBugBean</code> demonstrates bug 523627. CMR fields may get changed
035: * in ejbPostCreate, so newly created entities must be marked as needing ejbSave.
036: * Currently this is done by putting them in GlobalTxEntityMap.
037: *
038: * @author <a href="mailto:MNewcomb@tacintel.com">Michael Newcomb</a>
039: * @author <a href="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
040: * @version 1.0
041: *
042: * @ejb:bean name="CMRBugEJB"
043: * local-jndi-name="LocalReadOnly"
044: * view-type="local"
045: * type="CMP"
046: * cmp-version="2.x"
047: * primkey-field="id"
048: * reentrant="true"
049: * schema="CMRBug"
050: * @ejb:pk class="java.lang.String"
051: * @ejb:finder signature="java.util.Collection findAll()"
052: * query="select object(cmr_bug) from CMRBug as cmr_bug"
053: * @jboss:create-table create="true"
054: * @jboss:remove-table remove="true"
055: */
056: public abstract class CMRBugBean implements EntityBean {
057: private EntityContext context;
058:
059: /**
060: * Describe <code>getId</code> method here.
061: *
062: * @return a <code>String</code> value
063: * @ejb:persistent-field
064: * @ejb:interface-method
065: */
066: public abstract String getId();
067:
068: /**
069: * Describe <code>setId</code> method here.
070: *
071: * @param id a <code>String</code> value
072: * @ejb:interface-method
073: */
074: public abstract void setId(String id);
075:
076: /**
077: * Describe <code>getDescription</code> method here.
078: *
079: * @return a <code>String</code> value
080: * @ejb:persistent-field
081: * @ejb:interface-method
082: */
083: public abstract String getDescription();
084:
085: /**
086: * Describe <code>setDescription</code> method here.
087: *
088: * @param description a <code>String</code> value
089: * @ejb:interface-method
090: */
091: public abstract void setDescription(String description);
092:
093: /**
094: * Describe <code>getParent</code> method here.
095: *
096: * @return a <code>CMRBugEJBLocal</code> value
097: * @ejb:interface-method
098: * @ejb:relation name="CMRBug-CMRBug"
099: * role-name="parent"
100: * cascade-delete="yes"
101: * @jboss:auto-key-fields
102: */
103: public abstract CMRBugEJBLocal getParent();
104:
105: /**
106: * Describe <code>setParent</code> method here.
107: *
108: * @param parent a <code>CMRBugEJBLocal</code> value
109: * @ejb:interface-method
110: */
111: public abstract void setParent(CMRBugEJBLocal parent);
112:
113: /**
114: * Describe <code>getChildren</code> method here.
115: *
116: * @return a <code>Collection</code> value
117: * @ejb:interface-method
118: * @ejb:relation name="CMRBug-CMRBug"
119: * role-name="children"
120: * multiple="yes"
121: * @jboss:auto-key-fields
122: */
123: public abstract Collection getChildren();
124:
125: /**
126: * Describe <code>setChildren</code> method here.
127: *
128: * @param children a <code>Collection</code> value
129: * @ejb:interface-method
130: */
131: public abstract void setChildren(Collection children);
132:
133: /**
134: * Describe <code>addChild</code> method here.
135: *
136: * @param child a <code>CMRBugEJBLocal</code> value
137: * @return a <code>boolean</code> value
138: * @ejb:interface-method
139: */
140: public boolean addChild(CMRBugEJBLocal child) {
141: try {
142: Collection children = getChildren();
143: return children.add(child);
144: } catch (Exception e) {
145: throw new EJBException(e);
146: }
147: }
148:
149: /**
150: * Describe <code>removeChild</code> method here.
151: *
152: * @param child a <code>CMRBugEJBLocal</code> value
153: * @return a <code>boolean</code> value
154: * @ejb:interface-method
155: */
156: public boolean removeChild(CMRBugEJBLocal child) {
157: try {
158: Collection children = getChildren();
159: return children.remove(child);
160: } catch (Exception e) {
161: throw new EJBException(e);
162: }
163: }
164:
165: //
166: // The following is the linked list implementation. It is implemented with unidirectional CMRs.
167: // These are used to test correct foreign key state initialization when the foreign key
168: // loaded is not a valid value, i.e. the relationship was already changed in the tx.
169: //
170:
171: /**
172: * @ejb:interface-method view-type="local"
173: * @ejb:relation
174: * name="viewcomponent-prevnode"
175: * role-name="one-viewcomponent-has-one-previous-node"
176: * target-role-name="one-prev-belogs-to-one-viewcomponent"
177: * target-ejb="CMRBugEJB"
178: * target-multiple="no"
179: * @jboss:relation
180: * related-pk-field="id"
181: * fk-column="prev_id_fk"
182: */
183: public abstract CMRBugEJBLocal getPrevNode();
184:
185: /**
186: * @ejb:interface-method view-type="local"
187: */
188: public abstract void setPrevNode(CMRBugEJBLocal a_ViewComponent);
189:
190: /**
191: * @ejb:interface-method view-type="local"
192: * @ejb:relation
193: * name="viewcomponent-nextnode"
194: * role-name="one-viewcomponent-has-one-following-node"
195: * target-role-name="one-following-node-belogs-to-one-viewcomponent"
196: * target-ejb="CMRBugEJB"
197: * target-multiple="no"
198: * @jboss:relation
199: * related-pk-field="id"
200: * fk-column="next_id_fk"
201: */
202: public abstract CMRBugEJBLocal getNextNode();
203:
204: /**
205: * @ejb:interface-method view-type="local"
206: */
207: public abstract void setNextNode(CMRBugEJBLocal a_ViewComponent);
208:
209: // --------------------------------------------------------------------------
210: // EntityBean methods
211: //
212:
213: /**
214: * Describe <code>ejbCreate</code> method here.
215: *
216: * @param id a <code>String</code> value
217: * @param description a <code>String</code> value
218: * @param parent a <code>CMRBugEJBLocal</code> value
219: * @return an <code>Integer</code> value
220: * @exception CreateException if an error occurs
221: * @ejb:create-method
222: */
223: public String ejbCreate(String id, String description,
224: CMRBugEJBLocal parent) throws CreateException {
225: setId(id);
226: setDescription(description);
227:
228: // CMP beans return null for this method
229: //
230: return null;
231: }
232:
233: /**
234: * Describe <code>ejbPostCreate</code> method here.
235: *
236: * @param id a <code>String</code> value
237: * @param description a <code>String</code> value
238: * @param parent a <code>CMRBugEJBLocal</code> value
239: * @exception CreateException if an error occurs
240: */
241: public void ejbPostCreate(String id, String description,
242: CMRBugEJBLocal parent) throws CreateException {
243: // must set the CMR fields in the post create
244: //
245: setParent(parent);
246: }
247:
248: public void setEntityContext(EntityContext context) {
249: this .context = context;
250: }
251:
252: public void unsetEntityContext() {
253: context = null;
254: }
255:
256: public void ejbRemove() {
257: }
258:
259: public void ejbLoad() {
260: }
261:
262: public void ejbStore() {
263: }
264:
265: public void ejbActivate() {
266: }
267:
268: public void ejbPassivate() {
269: }
270: }
|