### Eclipse Workspace Patch 1.0 #P jboss-ejb3-core Index: src/test/java/org/jboss/ejb3/core/test/ejbthree1738/unit/TransactionTestCase.java =================================================================== --- src/test/java/org/jboss/ejb3/core/test/ejbthree1738/unit/TransactionTestCase.java (revision 0) +++ src/test/java/org/jboss/ejb3/core/test/ejbthree1738/unit/TransactionTestCase.java (revision 0) @@ -0,0 +1,51 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2009, Red Hat Middleware LLC, and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.ejb3.core.test.ejbthree1738.unit; + +import org.jboss.ejb3.core.test.common.AbstractEJB3TestCase; +import org.jboss.ejb3.core.test.ejbthree1738.TransactionalServiceBean; +import org.jboss.ejb3.core.test.ejbthree1738.TransactionalServiceLocal; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * @author Carlo de Wolf + * @version $Revision: $ + */ +public class TransactionTestCase extends AbstractEJB3TestCase +{ + @BeforeClass + public static void beforeClass() throws Exception + { + AbstractEJB3TestCase.beforeClass(); + + deploySessionEjb(TransactionalServiceBean.class); + } + + @Test + public void test1() throws Exception + { + TransactionalServiceLocal bean = lookup("TransactionalServiceBean/local", TransactionalServiceLocal.class); + + System.out.println(bean); + } +} Index: src/main/resources/ejb3-interceptors-aop.xml =================================================================== --- src/main/resources/ejb3-interceptors-aop.xml (revision 91369) +++ src/main/resources/ejb3-interceptors-aop.xml (working copy) @@ -383,6 +383,17 @@ + + + + + + + + Index: src/test/java/org/jboss/ejb3/core/test/ejbthree1738/TransactionalServiceBean.java =================================================================== --- src/test/java/org/jboss/ejb3/core/test/ejbthree1738/TransactionalServiceBean.java (revision 0) +++ src/test/java/org/jboss/ejb3/core/test/ejbthree1738/TransactionalServiceBean.java (revision 0) @@ -0,0 +1,74 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2009, Red Hat Middleware LLC, and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.ejb3.core.test.ejbthree1738; + +import javax.annotation.PostConstruct; +import javax.annotation.Resource; +import javax.transaction.SystemException; +import javax.transaction.Transaction; +import javax.transaction.TransactionManager; + +import org.jboss.ejb3.annotation.Service; +import org.jboss.logging.Logger; + +/** + * @author Carlo de Wolf + * @version $Revision: $ + */ +@Service +public class TransactionalServiceBean implements TransactionalServiceLocal +{ + private static final Logger log = Logger.getLogger(TransactionalServiceBean.class); + + @Resource(mappedName="java:/TransactionManager") + private TransactionManager tm; + + public static int postConstructs = 0; + + @PostConstruct + public void postConstruct() + { + log.info("postConstruct"); + //new Exception("postConstruct").printStackTrace(); + postConstructs++; + } + + /** + * magic start + */ + public void start() + { + log.info("start"); + //new Exception("start").printStackTrace(); + try + { + Transaction tx = tm.getTransaction(); + log.info("tx = " + tx); + if(tx == null) + throw new IllegalStateException("EJBTHREE-1738: was expecting a tx to be present"); + } + catch(SystemException e) + { + throw new RuntimeException(e); + } + } +} Index: src/main/java/org/jboss/ejb3/service/ServiceContainer.java =================================================================== --- src/main/java/org/jboss/ejb3/service/ServiceContainer.java (revision 91369) +++ src/main/java/org/jboss/ejb3/service/ServiceContainer.java (working copy) @@ -260,8 +260,9 @@ injectDependencies(beanContext); + invokePostConstruct(beanContext); + timerServiceFactory.restoreTimerService(timerService); - invokeOptionalMethod(METHOD_NAME_LIFECYCLE_CALLBACK_START); } catch (Exception e) { @@ -281,9 +282,8 @@ @Override protected void lockedStop() throws Exception { - // Make the lifecycle callback - invokeOptionalMethod(METHOD_NAME_LIFECYCLE_CALLBACK_STOP); - + invokePreDestroy(beanContext); + if (timerService != null) { timerServiceFactory.suspendTimerService(timerService); @@ -338,6 +338,31 @@ }); } + private Object invokeOptionalBusinessMethod(String methodName) throws Exception + { + try + { + Method method = getBeanClass().getMethod(methodName); + try + { + return localInvoke(method, null); + } + catch(Throwable t) + { + throw sanitize(t); + } + } + catch (SecurityException e) + { + throw new RuntimeException(e); + } + catch (NoSuchMethodException e) + { + // ignore + return null; + } + } + /** * Invoke a method on the singleton without a specific security or transaction context. * @@ -400,16 +425,6 @@ } - public void invokePostConstruct(BeanContext beanContext, Object[] params) - { - //Ignore - } - - public void invokePreDestroy(BeanContext beanContext) - { - //Ignore - } - public Object localInvoke(Object id, Method method, Object[] args) throws Throwable { return localInvoke(method, args); @@ -797,9 +812,35 @@ throw new RuntimeException("Don't do this"); } + private Exception sanitize(Throwable t) + { + if(t instanceof Error) + throw (Error) t; + return (Exception) t; + } + @Inject public void setTimerServiceFactory(TimerServiceFactory factory) { this.timerServiceFactory = factory; } + + @Override + public void start() throws Exception + { + super.start(); + + // EJBTHREE-1738: method start/stop need to have a tx context + invokeOptionalBusinessMethod(METHOD_NAME_LIFECYCLE_CALLBACK_START); + } + + @Override + public void stop() throws Exception + { + // Make the lifecycle callback + // EJBTHREE-1738: method start/stop need to have a tx context + invokeOptionalBusinessMethod(METHOD_NAME_LIFECYCLE_CALLBACK_STOP); + + super.stop(); + } } Index: src/main/java/org/jboss/ejb3/EJBContainer.java =================================================================== --- src/main/java/org/jboss/ejb3/EJBContainer.java (revision 91369) +++ src/main/java/org/jboss/ejb3/EJBContainer.java (working copy) @@ -890,7 +890,10 @@ */ } - public final void start() throws Exception + /** + * This should have been final, but ServiceContainer wants to butt in. + */ + public void start() throws Exception { this.lockedStart(); @@ -926,7 +929,10 @@ log.info("STARTED EJB: " + beanClass.getName() + " ejbName: " + ejbName); } - public final void stop() throws Exception + /** + * This should have been final, but ServiceContainer wants to butt in. + */ + public void stop() throws Exception { // Wait for active invocations to complete - and block new invocations this.blockInvocations(); Index: src/test/java/org/jboss/ejb3/core/test/ejbthree1738/TransactionalServiceLocal.java =================================================================== --- src/test/java/org/jboss/ejb3/core/test/ejbthree1738/TransactionalServiceLocal.java (revision 0) +++ src/test/java/org/jboss/ejb3/core/test/ejbthree1738/TransactionalServiceLocal.java (revision 0) @@ -0,0 +1,34 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2009, Red Hat Middleware LLC, and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.ejb3.core.test.ejbthree1738; + +import javax.ejb.Local; + +/** + * @author Carlo de Wolf + * @version $Revision: $ + */ +@Local +public interface TransactionalServiceLocal +{ + +}