KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > common > ejbs > mdb > beanmanaged > transaction > MDBBMTransaction


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: MDBBMTransaction.java 823 2006-07-05 12:21:09Z studzine $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.common.ejbs.mdb.beanmanaged.transaction;
26
27 import javax.annotation.Resource;
28 import javax.ejb.ActivationConfigProperty JavaDoc;
29 import javax.ejb.EJB JavaDoc;
30 import javax.ejb.EJBException JavaDoc;
31 import javax.ejb.MessageDriven JavaDoc;
32 import javax.ejb.TransactionManagement JavaDoc;
33 import javax.ejb.TransactionManagementType JavaDoc;
34 import javax.jms.Message JavaDoc;
35 import javax.jms.MessageListener JavaDoc;
36 import javax.transaction.UserTransaction JavaDoc;
37
38 import org.objectweb.easybeans.log.JLog;
39 import org.objectweb.easybeans.log.JLogFactory;
40 import org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.CallbackType;
41 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.BaseInsertCallbackEvent;
42 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.inheritance.ItfCMTInheritance;
43 import org.objectweb.easybeans.tests.common.jms.JMSManager;
44
45 /**
46  * This message-driven bean is used to test the container-managed transaction
47  * demarcation with transaction attribute NOT_SUPPORTED.
48  * @author Eduardo Studzinski Estima de Castro
49  * @author Gisele Pinheiro Souza
50  */

51 @MessageDriven JavaDoc(activationConfig = {
52         @ActivationConfigProperty JavaDoc(propertyName = "destination", propertyValue = JMSManager.DEFAULT_QUEUE),
53         @ActivationConfigProperty JavaDoc(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
54         @ActivationConfigProperty JavaDoc(propertyName = "messageSelector", propertyValue =
55             "TYPE = 'org.objectweb.easybeans.tests.common.ejbs.mdb.beanmanaged.transaction.MDBBMTransaction'")})
56 @TransactionManagement JavaDoc(value = TransactionManagementType.BEAN)
57 public class MDBBMTransaction extends BaseInsertCallbackEvent implements MessageListener JavaDoc {
58
59     /**
60      * Message type.
61      */

62     public static final String JavaDoc MESSAGE_TYPE = "org.objectweb.easybeans.tests.common.ejbs."
63         + "mdb.beanmanaged.transaction.MDBBMTransaction";
64
65     /**
66      * Logger.
67      */

68     private static JLog logger = JLogFactory.getLog(MDBBMTransaction.class);
69
70     /**
71      * Bean.
72      */

73     @EJB JavaDoc(beanName = "SLSBCMTInheritance")
74     private ItfCMTInheritance bean;
75
76     /**
77      * UserTransaction.
78      */

79     @Resource
80     private UserTransaction JavaDoc utx;
81
82     /**
83      * Manages a message.
84      * @param message msg
85      */

86     public void onMessage(final Message JavaDoc message) {
87         try {
88             // The dummyMethod1 is NEVER, so an exception must be thrown.
89
logger.debug("Invoking dummyMethod1.");
90             utx.begin();
91             bean.dummyMethod1();
92             utx.commit();
93             logger.debug("Invoking dummyMethod1 should throw an EJBException.");
94         } catch (EJBException JavaDoc e) {
95             logger.debug("MDB is OK.");
96             super.log(MDBBMTransaction.class, CallbackType.ON_MESSAGE, MDBBMTransaction.class);
97         } catch (Exception JavaDoc e) {
98             logger.error("Error. Exception = {0}", e.getCause());
99         }
100     }
101
102 }
103
Popular Tags