KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cmp2 > cmrtree > ejb > FacadeSessionBean


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.cmrtree.ejb;
23
24 import java.util.Collection JavaDoc;
25 import org.jboss.logging.Logger;
26
27 import javax.ejb.SessionBean JavaDoc;
28 import javax.ejb.SessionContext JavaDoc;
29 import javax.ejb.CreateException JavaDoc;
30
31 /**
32  * @ejb:bean type="Stateless"
33  * name="Facade"
34  * view-type="remote"
35  * @ejb.util generate="physical"
36  * @ejb:transaction type="Required"
37  * @ejb:transaction-type type="Container"
38  *
39  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
40  * @version <tt>$Revision: 58115 $</tt>
41  */

42 public class FacadeSessionBean
43    implements SessionBean JavaDoc
44 {
45    private static Logger log = Logger.getLogger(FacadeSessionBean.class);
46
47    SessionContext JavaDoc ctx;
48
49    // Business methods
50

51    /**
52     * @ejb.interface-method
53     * @ejb.transaction type="RequiresNew"
54     */

55    public void setup() throws Exception JavaDoc
56    {
57       final long startTime = System.currentTimeMillis();
58       log.debug("SETUP>");
59
60       ALocal a = AUtil.getLocalHome().create(1, "A", "1.A");
61       BLocal b1 = BUtil.getLocalHome().create(1, "B1", "1.B1");
62       b1.setAMinorId("A");
63
64       BLocal b2 = BUtil.getLocalHome().create(1, "B2", "1.B2");
65       b2.setParent(b1);
66
67       log.debug("SETUP> done in " + (System.currentTimeMillis() - startTime) + " ms.");
68    }
69
70    /**
71     * @ejb.interface-method
72     * @ejb.transaction type="RequiresNew"
73     */

74    public void test(long sleep) throws Exception JavaDoc
75    {
76       final long startTime = System.currentTimeMillis();
77       log.debug("RUN>");
78
79       AUtil.getLocalHome().remove(new APK(1, "A"));
80
81       log.debug("RUN> done in " + (System.currentTimeMillis() - startTime) + " ms.");
82    }
83
84    /**
85     * @ejb.interface-method
86     * @ejb.transaction type="RequiresNew"
87     */

88    public void tearDown() throws Exception JavaDoc
89    {
90       final long startTime = System.currentTimeMillis();
91       log.debug("TEAR DOWN>");
92
93       log.debug("TEAR DOWN> done in " + (System.currentTimeMillis() - startTime) + " ms.");
94    }
95
96    /**
97     * @ejb.interface-method
98     * @ejb.transaction type="RequiresNew"
99     */

100    public void setup2() throws Exception JavaDoc
101    {
102       final long startTime = System.currentTimeMillis();
103       log.debug("SETUP2>");
104
105       ALocal a = AUtil.getLocalHome().create(1, "A", "1.A");
106       BLocal b1 = BUtil.getLocalHome().create(1, "B1", "some name");
107       b1.setA(a);
108
109       log.debug("SETUP2> done in " + (System.currentTimeMillis() - startTime) + " ms.");
110    }
111
112    /**
113     * @ejb.interface-method
114     * @ejb.transaction type="RequiresNew"
115     */

116    public void setBNameToNull() throws Exception JavaDoc
117    {
118       ALocal a = AUtil.getLocalHome().findByPrimaryKey(new APK(1, "A"));
119       Collection JavaDoc bs = a.getB();
120       if(bs.size() != 1)
121       {
122          throw new IllegalStateException JavaDoc("Expected only one B but got " + bs);
123       }
124
125       BLocal b = (BLocal)bs.iterator().next();
126       b.setName(null);
127    }
128
129    /**
130     * @ejb.interface-method
131     * @ejb.transaction type="RequiresNew"
132     */

133    public String JavaDoc getBName() throws Exception JavaDoc
134    {
135       BLocal b = BUtil.getLocalHome().findByPrimaryKey(new BPK(1, "B1"));
136       return b.getName();
137    }
138
139    // SessionBean implementation
140

141    /**
142     * @throws CreateException Description of Exception
143     * @ejb.create-method
144     */

145    public void ejbCreate() throws CreateException JavaDoc
146    {
147    }
148
149    public void ejbActivate()
150    {
151    }
152
153    public void ejbPassivate()
154    {
155    }
156
157    public void ejbRemove()
158    {
159    }
160
161    public void setSessionContext(SessionContext JavaDoc ctx)
162    {
163       this.ctx = ctx;
164    }
165 }
166
Popular Tags