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.jca.ejb;
023:
024: import javax.ejb.EJBException;
025: import javax.ejb.SessionBean;
026: import javax.ejb.SessionContext;
027: import javax.naming.InitialContext;
028: import javax.transaction.UserTransaction;
029:
030: import org.jboss.logging.Logger;
031: import org.jboss.test.jca.adapter.TestConnection;
032: import org.jboss.test.jca.adapter.TestConnectionFactory;
033:
034: /**
035: * UserTxSessionBean.java
036: *
037: * @author <a href="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
038: * @version <tt>$Revision: 57211 $</tt>
039: *
040: * @ejb.bean name="UserTxSession"
041: * jndi-name="UserTxSession"
042: * local-jndi-name="LocalUserTxSession"
043: * view-type="both"
044: * type="Stateless"
045: * transaction-type="Bean"
046: * @ejb.transaction type="NotSupported"
047: */
048: public class UserTxSessionBean implements SessionBean {
049:
050: /** The serialVersionUID */
051: private static final long serialVersionUID = 1L;
052: private SessionContext ctx;
053: private Logger log = Logger.getLogger(getClass());
054:
055: public UserTxSessionBean() {
056:
057: }
058:
059: /**
060: * Describe <code>testUserTxJndi</code> method here.
061: *
062: * @return a <code>boolean</code> value
063: *
064: * @ejb:interface-method
065: */
066: public boolean testUserTxJndi() {
067: try {
068: TestConnectionFactory tcf = (TestConnectionFactory) new InitialContext()
069: .lookup("java:/JBossTestCF");
070: TestConnection tc = (TestConnection) tcf.getConnection();
071: UserTransaction ut = (UserTransaction) new InitialContext()
072: .lookup("UserTransaction");
073: ut.begin();
074: boolean result = tc.isInTx();
075: log.info("Jndi test, inTx: " + result);
076: ut.commit();
077: tc.close();
078: return result;
079: } catch (Exception e) {
080: throw new EJBException(e.getMessage());
081: }
082:
083: }
084:
085: /**
086: * Describe <code>testUserTxSessionCtx</code> method here.
087: *
088: * @return a <code>boolean</code> value
089: *
090: * @ejb:interface-method
091: */
092: public boolean testUserTxSessionCtx() {
093: try {
094: TestConnectionFactory tcf = (TestConnectionFactory) new InitialContext()
095: .lookup("java:/JBossTestCF");
096: TestConnection tc = (TestConnection) tcf.getConnection();
097: UserTransaction ut = ctx.getUserTransaction();
098: ut.begin();
099: boolean result = tc.isInTx();
100: log.info("ctx test, inTx: " + result);
101: ut.commit();
102: tc.close();
103: return result;
104: } catch (Exception e) {
105: throw new EJBException(e.getMessage());
106: }
107:
108: }
109:
110: /**
111: * @ejb:interface-method
112: */
113: public void testUnclosedError() throws Exception {
114: TestConnectionFactory tcf = (TestConnectionFactory) new InitialContext()
115: .lookup("java:/JBossTestCF");
116: tcf.getConnection(); // DONT CLOSE
117: }
118:
119: public void ejbCreate() {
120: }
121:
122: public void ejbActivate() {
123: }
124:
125: public void ejbPassivate() {
126: }
127:
128: public void ejbRemove() {
129: }
130:
131: public void setSessionContext(SessionContext ctx) {
132: this .ctx = ctx;
133: }
134:
135: public void unsetSessionContext() {
136: this.ctx = null;
137: }
138:
139: }
|