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.txtimer.ejb;
023:
024: import java.rmi.RemoteException;
025:
026: import javax.ejb.CreateException;
027: import javax.ejb.EJBException;
028: import javax.ejb.SessionBean;
029: import javax.ejb.SessionContext;
030: import javax.naming.InitialContext;
031:
032: import org.apache.log4j.Logger;
033: import org.jboss.test.txtimer.interfaces.TimerEntity;
034: import org.jboss.test.txtimer.interfaces.TimerEntityHome;
035: import org.jboss.test.txtimer.interfaces.TimerSession;
036: import org.jboss.test.txtimer.interfaces.TimerSessionHome;
037:
038: /**
039: * Session Bean Timer Test
040: */
041: public class TimerFacadeBean implements SessionBean {
042: private static Logger log = Logger.getLogger(TimerFacadeBean.class);
043:
044: private SessionContext context;
045:
046: /**
047: * @ejb.interface-method view-type="both"
048: */
049: public void rollbackAfterCreateSession(long duration)
050: throws Exception {
051: InitialContext iniCtx = new InitialContext();
052: TimerSessionHome home = (TimerSessionHome) iniCtx
053: .lookup(TimerSessionHome.JNDI_NAME);
054: TimerSession bean = home.create();
055: bean.createTimer(duration, 0, null);
056: context.setRollbackOnly();
057: }
058:
059: /**
060: * @ejb.interface-method view-type="both"
061: */
062: public void rollbackAfterCancelSession() throws Exception {
063: InitialContext iniCtx = new InitialContext();
064: TimerSessionHome home = (TimerSessionHome) iniCtx
065: .lookup(TimerSessionHome.JNDI_NAME);
066: TimerSession bean = home.create();
067: bean.cancelFirstTimer();
068: context.setRollbackOnly();
069: }
070:
071: /**
072: * @ejb.interface-method view-type="both"
073: */
074: public void rollbackAfterCreateEntity(long duration)
075: throws Exception {
076: InitialContext iniCtx = new InitialContext();
077: TimerEntityHome home = (TimerEntityHome) iniCtx
078: .lookup(TimerEntityHome.JNDI_NAME);
079: TimerEntity bean = home.findByPrimaryKey(new Integer(1));
080: bean.createTimer(duration, 0, null);
081: context.setRollbackOnly();
082: }
083:
084: /**
085: * @ejb.interface-method view-type="both"
086: */
087: public void rollbackAfterCancelEntity() throws Exception {
088: InitialContext iniCtx = new InitialContext();
089: TimerEntityHome home = (TimerEntityHome) iniCtx
090: .lookup(TimerEntityHome.JNDI_NAME);
091: TimerEntity bean = home.findByPrimaryKey(new Integer(1));
092: bean.cancelFirstTimer();
093: context.setRollbackOnly();
094: }
095:
096: // -------------------------------------------------------------------------
097: // Framework Callbacks
098: // -------------------------------------------------------------------------
099:
100: public void setSessionContext(SessionContext ctx)
101: throws EJBException, RemoteException {
102: this .context = ctx;
103: }
104:
105: /**
106: * @ejb.create-method view-type="both"
107: */
108: public void ejbCreate() throws CreateException {
109: }
110:
111: public void ejbRemove() throws EJBException, RemoteException {
112: }
113:
114: public void ejbActivate() throws EJBException, RemoteException {
115: }
116:
117: public void ejbPassivate() throws EJBException, RemoteException {
118: }
119: }
|