KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > txtimer > ejb > TimerFacadeBean


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.txtimer.ejb;
23
24 import java.rmi.RemoteException JavaDoc;
25
26 import javax.ejb.CreateException JavaDoc;
27 import javax.ejb.EJBException JavaDoc;
28 import javax.ejb.SessionBean JavaDoc;
29 import javax.ejb.SessionContext JavaDoc;
30 import javax.naming.InitialContext JavaDoc;
31
32 import org.jboss.logging.Logger;
33 import org.jboss.test.txtimer.interfaces.TimerEntity;
34 import org.jboss.test.txtimer.interfaces.TimerEntityHome;
35 import org.jboss.test.txtimer.interfaces.TimerSession;
36 import org.jboss.test.txtimer.interfaces.TimerSessionHome;
37
38 /**
39  * Session Bean Timer Test
40  */

41 public class TimerFacadeBean implements SessionBean JavaDoc
42 {
43    private static Logger log = Logger.getLogger(TimerFacadeBean.class);
44
45    private SessionContext JavaDoc context;
46
47    /**
48     * @ejb.interface-method view-type="both"
49     */

50    public void rollbackAfterCreateSession(long duration)
51            throws Exception JavaDoc
52    {
53       InitialContext JavaDoc iniCtx = new InitialContext JavaDoc();
54       TimerSessionHome home = (TimerSessionHome) iniCtx.lookup(TimerSessionHome.JNDI_NAME);
55       TimerSession bean = home.create();
56       bean.createTimer(duration, 0, null);
57       context.setRollbackOnly();
58    }
59
60    /**
61     * @ejb.interface-method view-type="both"
62     */

63    public void rollbackAfterCancelSession()
64            throws Exception JavaDoc
65    {
66       InitialContext JavaDoc iniCtx = new InitialContext JavaDoc();
67       TimerSessionHome home = (TimerSessionHome) iniCtx.lookup(TimerSessionHome.JNDI_NAME);
68       TimerSession bean = home.create();
69       bean.cancelFirstTimer();
70       context.setRollbackOnly();
71    }
72
73    /**
74     * @ejb.interface-method view-type="both"
75     */

76    public void rollbackAfterCreateEntity(long duration)
77            throws Exception JavaDoc
78    {
79       InitialContext JavaDoc iniCtx = new InitialContext JavaDoc();
80       TimerEntityHome home = (TimerEntityHome) iniCtx.lookup(TimerEntityHome.JNDI_NAME);
81       TimerEntity bean = home.findByPrimaryKey(new Integer JavaDoc(1));
82       bean.createTimer(duration, 0, null);
83       context.setRollbackOnly();
84    }
85
86    /**
87     * @ejb.interface-method view-type="both"
88     */

89    public void rollbackAfterCancelEntity()
90            throws Exception JavaDoc
91    {
92       InitialContext JavaDoc iniCtx = new InitialContext JavaDoc();
93       TimerEntityHome home = (TimerEntityHome) iniCtx.lookup(TimerEntityHome.JNDI_NAME);
94       TimerEntity bean = home.findByPrimaryKey(new Integer JavaDoc(1));
95       bean.cancelFirstTimer();
96       context.setRollbackOnly();
97    }
98
99
100    // -------------------------------------------------------------------------
101
// Framework Callbacks
102
// -------------------------------------------------------------------------
103

104    public void setSessionContext(SessionContext JavaDoc ctx) throws EJBException JavaDoc, RemoteException JavaDoc
105    {
106       this.context = ctx;
107    }
108
109    /**
110     * @ejb.create-method view-type="both"
111     */

112    public void ejbCreate() throws CreateException JavaDoc
113    {
114    }
115
116    public void ejbRemove() throws EJBException JavaDoc, RemoteException JavaDoc
117    {
118    }
119
120    public void ejbActivate() throws EJBException JavaDoc, RemoteException JavaDoc
121    {
122    }
123
124    public void ejbPassivate() throws EJBException JavaDoc, RemoteException JavaDoc
125    {
126    }
127 }
128
Popular Tags