001: /**
002: * EasyBeans
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: MDBBMTransaction.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.tests.common.ejbs.mdb.beanmanaged.transaction;
025:
026: import javax.annotation.Resource;
027: import javax.ejb.ActivationConfigProperty;
028: import javax.ejb.EJB;
029: import javax.ejb.EJBException;
030: import javax.ejb.MessageDriven;
031: import javax.ejb.TransactionManagement;
032: import javax.ejb.TransactionManagementType;
033: import javax.jms.Message;
034: import javax.jms.MessageListener;
035: import javax.transaction.UserTransaction;
036:
037: import org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.CallbackType;
038: import org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.BaseInsertCallbackEvent;
039: import org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.inheritance.ItfCMTInheritance;
040: import org.ow2.easybeans.tests.common.jms.JMSManager;
041: import org.ow2.util.log.Log;
042: import org.ow2.util.log.LogFactory;
043:
044: /**
045: * This message-driven bean is used to test the container-managed transaction
046: * demarcation with transaction attribute NOT_SUPPORTED.
047: * @author Eduardo Studzinski Estima de Castro
048: * @author Gisele Pinheiro Souza
049: */
050: @MessageDriven(activationConfig={@ActivationConfigProperty(propertyName="destination",propertyValue=JMSManager.DEFAULT_QUEUE),@ActivationConfigProperty(propertyName="destinationType",propertyValue="javax.jms.Queue"),@ActivationConfigProperty(propertyName="messageSelector",propertyValue="TYPE = 'org.ow2.easybeans.tests.common.ejbs.mdb.beanmanaged.transaction.MDBBMTransaction'")})
051: @TransactionManagement(value=TransactionManagementType.BEAN)
052: public class MDBBMTransaction extends BaseInsertCallbackEvent implements
053: MessageListener {
054:
055: /**
056: * Message type.
057: */
058: public static final String MESSAGE_TYPE = "org.ow2.easybeans.tests.common.ejbs."
059: + "mdb.beanmanaged.transaction.MDBBMTransaction";
060:
061: /**
062: * Logger.
063: */
064: private static Log logger = LogFactory
065: .getLog(MDBBMTransaction.class);
066:
067: /**
068: * Bean.
069: */
070: @EJB(beanName="SLSBCMTInheritance")
071: private ItfCMTInheritance bean;
072:
073: /**
074: * UserTransaction.
075: */
076: @Resource
077: private UserTransaction utx;
078:
079: /**
080: * Manages a message.
081: * @param message msg
082: */
083: public void onMessage(final Message message) {
084: try {
085: // The dummyMethod1 is NEVER, so an exception must be thrown.
086: logger.debug("Invoking dummyMethod1.");
087: utx.begin();
088: bean.dummyMethod1();
089: utx.commit();
090: logger
091: .debug("Invoking dummyMethod1 should throw an EJBException.");
092: } catch (EJBException e) {
093: logger.debug("MDB is OK.");
094: super .log(MDBBMTransaction.class, CallbackType.ON_MESSAGE,
095: MDBBMTransaction.class);
096: } catch (Exception e) {
097: logger.error("Error. Exception = {0}", e.getCause());
098: }
099: }
100:
101: }
|