[jboss-cvs] JBossAS SVN: r104897 - in projects/ejb-book/trunk: chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/ejb and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon May 17 21:40:37 EDT 2010
Author: ALRubinger
Date: 2010-05-17 21:40:37 -0400 (Mon, 17 May 2010)
New Revision: 104897
Added:
projects/ejb-book/trunk/testsupport/src/main/java/org/jboss/ejb3/examples/testsupport/txwrap/
projects/ejb-book/trunk/testsupport/src/main/java/org/jboss/ejb3/examples/testsupport/txwrap/ForcedTestException.java
projects/ejb-book/trunk/testsupport/src/main/java/org/jboss/ejb3/examples/testsupport/txwrap/TaskExecutionException.java
projects/ejb-book/trunk/testsupport/src/main/java/org/jboss/ejb3/examples/testsupport/txwrap/TxWrappingBean.java
projects/ejb-book/trunk/testsupport/src/main/java/org/jboss/ejb3/examples/testsupport/txwrap/TxWrappingLocalBusiness.java
Removed:
projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/ejb/ForcedTestException.java
projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/ejb/TaskExecutionException.java
projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/ejb/TxWrappingBean.java
projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/ejb/TxWrappingLocalBusiness.java
Modified:
projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/TransactionalPokerGameIntegrationTest.java
Log:
[EJBBOOK-25] Move the TxWrappingBean to common support
Modified: projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/TransactionalPokerGameIntegrationTest.java
===================================================================
--- projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/TransactionalPokerGameIntegrationTest.java 2010-05-18 01:26:43 UTC (rev 104896)
+++ projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/TransactionalPokerGameIntegrationTest.java 2010-05-18 01:40:37 UTC (rev 104897)
@@ -39,9 +39,6 @@
import org.jboss.ejb3.examples.chxx.transactions.api.PokerGameLocalBusiness;
import org.jboss.ejb3.examples.chxx.transactions.ejb.DbInitializerBean;
import org.jboss.ejb3.examples.chxx.transactions.ejb.ExampleUserData;
-import org.jboss.ejb3.examples.chxx.transactions.ejb.ForcedTestException;
-import org.jboss.ejb3.examples.chxx.transactions.ejb.TaskExecutionException;
-import org.jboss.ejb3.examples.chxx.transactions.ejb.TxWrappingLocalBusiness;
import org.jboss.ejb3.examples.chxx.transactions.entity.Account;
import org.jboss.ejb3.examples.chxx.transactions.entity.User;
import org.jboss.ejb3.examples.chxx.transactions.impl.BankBean;
@@ -49,6 +46,9 @@
import org.jboss.ejb3.examples.testsupport.dbinit.DbInitializerLocalBusiness;
import org.jboss.ejb3.examples.testsupport.dbquery.DbQueryBean;
import org.jboss.ejb3.examples.testsupport.dbquery.DbQueryLocalBusiness;
+import org.jboss.ejb3.examples.testsupport.txwrap.ForcedTestException;
+import org.jboss.ejb3.examples.testsupport.txwrap.TaskExecutionException;
+import org.jboss.ejb3.examples.testsupport.txwrap.TxWrappingLocalBusiness;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.After;
@@ -94,8 +94,9 @@
{
final JavaArchive archive = ShrinkWrap.create("test.jar", JavaArchive.class).addPackages(true,
BankLocalBusiness.class.getPackage(), User.class.getPackage()).addManifestResource("persistence.xml")
- .addPackages(false, DbInitializerBean.class.getPackage(), BankBean.class.getPackage(),
- DbInitializerLocalBusiness.class.getPackage(), DbQueryBean.class.getPackage());
+ .addPackages(false, DbInitializerBean.class.getPackage(), TxWrappingLocalBusiness.class.getPackage(),
+ BankBean.class.getPackage(), DbInitializerLocalBusiness.class.getPackage(),
+ DbQueryBean.class.getPackage());
log.info(archive.toString(true));
return archive;
}
@@ -159,7 +160,7 @@
{
// Fake injection by doing manual lookups for the time being
dbInitializer = (DbInitializerLocalBusiness) jndiContext.lookup("DbInitializerBean/local");
- txWrapper = (TxWrappingLocalBusiness) jndiContext.lookup(TxWrappingLocalBusiness.JNDI_NAME);
+ txWrapper = (TxWrappingLocalBusiness) jndiContext.lookup("TxWrappingBean/local");
db = (DbQueryLocalBusiness) jndiContext.lookup("DbQueryBean/local");
bank = (BankLocalBusiness) jndiContext.lookup(BankLocalBusiness.JNDI_NAME);
pokerGame = (PokerGameLocalBusiness) jndiContext.lookup(PokerGameLocalBusiness.JNDI_NAME);
Deleted: projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/ejb/ForcedTestException.java
===================================================================
--- projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/ejb/ForcedTestException.java 2010-05-18 01:26:43 UTC (rev 104896)
+++ projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/ejb/ForcedTestException.java 2010-05-18 01:40:37 UTC (rev 104897)
@@ -1,62 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, 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.examples.chxx.transactions.ejb;
-
-import javax.ejb.ApplicationException;
-
-/**
- * May be thrown manually by the test to force a transactional
- * rollback condition
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
- at ApplicationException(rollback = true)
-public class ForcedTestException extends Exception
-{
- //-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * serialVersionUID
- */
- private static final long serialVersionUID = 1L;
-
- /**
- * Message to be thrown
- */
- private static final String MESSAGE = "Intentional Test Exception";
-
- //-------------------------------------------------------------------------------------||
- // Constructor ------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Creates a new instance
- */
- public ForcedTestException()
- {
- super(MESSAGE);
- }
-
-}
Deleted: projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/ejb/TaskExecutionException.java
===================================================================
--- projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/ejb/TaskExecutionException.java 2010-05-18 01:26:43 UTC (rev 104896)
+++ projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/ejb/TaskExecutionException.java 2010-05-18 01:40:37 UTC (rev 104897)
@@ -1,68 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, 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.examples.chxx.transactions.ejb;
-
-import javax.ejb.ApplicationException;
-import javax.ejb.EJBException;
-
-/**
- * Indicates that an exception has occurred while submitting
- * a task to {@link TxWrappingLocalBusiness#wrapInTx(java.util.concurrent.Callable...)}.
- * Not wrapped in {@link EJBException} because this is an {@link ApplicationException}
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
- at ApplicationException(rollback = true)
-public class TaskExecutionException extends Exception
-{
- //-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * serialVersionUID
- */
- private static final long serialVersionUID = 1L;
-
- //-------------------------------------------------------------------------------------||
- // Constructor ------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Creates a new instance with the specified root cause
- */
- public TaskExecutionException(final Throwable cause)
- {
- super(cause);
- }
-
- /**
- * Creates a new instance with the specified message
- * @param message
- */
- public TaskExecutionException(String message)
- {
- super(message);
- }
-
-}
Deleted: projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/ejb/TxWrappingBean.java
===================================================================
--- projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/ejb/TxWrappingBean.java 2010-05-18 01:26:43 UTC (rev 104896)
+++ projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/ejb/TxWrappingBean.java 2010-05-18 01:40:37 UTC (rev 104897)
@@ -1,80 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, 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.examples.chxx.transactions.ejb;
-
-import java.util.concurrent.Callable;
-
-import javax.ejb.Local;
-import javax.ejb.Stateless;
-import javax.ejb.TransactionAttribute;
-import javax.ejb.TransactionAttributeType;
-
-import org.jboss.ejb3.annotation.LocalBinding;
-
-/**
- * EJB which wraps a specified series of {@link Callable}
- * tasks within the context of a new Transaction
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
- at Stateless
- at Local(TxWrappingLocalBusiness.class)
- at TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
-// We always require a new Tx here, so we ensure to wrap
- at LocalBinding(jndiBinding = TxWrappingLocalBusiness.JNDI_NAME)
-public class TxWrappingBean implements TxWrappingLocalBusiness
-{
- //-------------------------------------------------------------------------------------||
- // Required Implementations -----------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * {@inheritDoc}
- * @see org.jboss.ejb3.examples.chxx.transactions.ejb.TxWrappingLocalBusiness#wrapInTx(java.util.concurrent.Callable<V>[])
- */
- @Override
- public void wrapInTx(final Callable<?>... tasks) throws IllegalArgumentException, TaskExecutionException
- {
- // Precondition check
- if (tasks == null)
- {
- throw new IllegalArgumentException("task must be specified");
- }
-
- // Just delegate along to the tasks in order; now it's executed inside of a Tx
- for (final Callable<?> task : tasks)
- {
- try
- {
- task.call();
- }
- // Every problem we encounter here becomes an ApplicationException
- // to be unwrapped later by the caller (so the container doesn't wrap
- // in EJBException
- catch (final Throwable e)
- {
- throw new TaskExecutionException(e);
- }
- }
- }
-}
Deleted: projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/ejb/TxWrappingLocalBusiness.java
===================================================================
--- projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/ejb/TxWrappingLocalBusiness.java 2010-05-18 01:26:43 UTC (rev 104896)
+++ projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/ejb/TxWrappingLocalBusiness.java 2010-05-18 01:40:37 UTC (rev 104897)
@@ -1,58 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, 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.examples.chxx.transactions.ejb;
-
-import java.util.concurrent.Callable;
-
-/**
- * Contract of an EJB which wraps arbitrary {@link Callable}
- * tasks inside of a new Tx.
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public interface TxWrappingLocalBusiness
-{
-
- //-------------------------------------------------------------------------------------||
- // Constants --------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Name we'll ind to in JNDI
- */
- String JNDI_NAME = "TxWrappingLocal";
-
- //-------------------------------------------------------------------------------------||
- // Contracts --------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Wraps the specified tasks in a new Transaction
- *
- * @param task
- * @throws IllegalArgumentException If no tasks are specified
- * @throws TaskExecutionException If an error occurred in invoking {@link Callable#call()}
- */
- void wrapInTx(Callable<?>... tasks) throws IllegalArgumentException, TaskExecutionException;
-
-}
Copied: projects/ejb-book/trunk/testsupport/src/main/java/org/jboss/ejb3/examples/testsupport/txwrap/ForcedTestException.java (from rev 104788, projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/ejb/ForcedTestException.java)
===================================================================
--- projects/ejb-book/trunk/testsupport/src/main/java/org/jboss/ejb3/examples/testsupport/txwrap/ForcedTestException.java (rev 0)
+++ projects/ejb-book/trunk/testsupport/src/main/java/org/jboss/ejb3/examples/testsupport/txwrap/ForcedTestException.java 2010-05-18 01:40:37 UTC (rev 104897)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.examples.testsupport.txwrap;
+
+import javax.ejb.ApplicationException;
+
+/**
+ * May be thrown manually by the test to force a transactional
+ * rollback condition
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at ApplicationException(rollback = true)
+public class ForcedTestException extends Exception
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Message to be thrown
+ */
+ private static final String MESSAGE = "Intentional Test Exception";
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates a new instance
+ */
+ public ForcedTestException()
+ {
+ super(MESSAGE);
+ }
+
+}
Copied: projects/ejb-book/trunk/testsupport/src/main/java/org/jboss/ejb3/examples/testsupport/txwrap/TaskExecutionException.java (from rev 104788, projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/ejb/TaskExecutionException.java)
===================================================================
--- projects/ejb-book/trunk/testsupport/src/main/java/org/jboss/ejb3/examples/testsupport/txwrap/TaskExecutionException.java (rev 0)
+++ projects/ejb-book/trunk/testsupport/src/main/java/org/jboss/ejb3/examples/testsupport/txwrap/TaskExecutionException.java 2010-05-18 01:40:37 UTC (rev 104897)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.examples.testsupport.txwrap;
+
+import javax.ejb.ApplicationException;
+import javax.ejb.EJBException;
+
+/**
+ * Indicates that an exception has occurred while submitting
+ * a task to {@link TxWrappingLocalBusiness#wrapInTx(java.util.concurrent.Callable...)}.
+ * Not wrapped in {@link EJBException} because this is an {@link ApplicationException}
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at ApplicationException(rollback = true)
+public class TaskExecutionException extends Exception
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = 1L;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates a new instance with the specified root cause
+ */
+ public TaskExecutionException(final Throwable cause)
+ {
+ super(cause);
+ }
+
+ /**
+ * Creates a new instance with the specified message
+ * @param message
+ */
+ public TaskExecutionException(String message)
+ {
+ super(message);
+ }
+
+}
Copied: projects/ejb-book/trunk/testsupport/src/main/java/org/jboss/ejb3/examples/testsupport/txwrap/TxWrappingBean.java (from rev 104828, projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/ejb/TxWrappingBean.java)
===================================================================
--- projects/ejb-book/trunk/testsupport/src/main/java/org/jboss/ejb3/examples/testsupport/txwrap/TxWrappingBean.java (rev 0)
+++ projects/ejb-book/trunk/testsupport/src/main/java/org/jboss/ejb3/examples/testsupport/txwrap/TxWrappingBean.java 2010-05-18 01:40:37 UTC (rev 104897)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.examples.testsupport.txwrap;
+
+import java.util.concurrent.Callable;
+
+import javax.ejb.Local;
+import javax.ejb.Stateless;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+
+/**
+ * EJB which wraps a specified series of {@link Callable}
+ * tasks within the context of a new Transaction
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Stateless
+ at Local(TxWrappingLocalBusiness.class)
+ at TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
+// We always require a new Tx here, so we ensure to wrap
+public class TxWrappingBean implements TxWrappingLocalBusiness
+{
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.ejb3.examples.chxx.transactions.ejb.TxWrappingLocalBusiness#wrapInTx(java.util.concurrent.Callable<V>[])
+ */
+ @Override
+ public void wrapInTx(final Callable<?>... tasks) throws IllegalArgumentException, TaskExecutionException
+ {
+ // Precondition check
+ if (tasks == null)
+ {
+ throw new IllegalArgumentException("task must be specified");
+ }
+
+ // Just delegate along to the tasks in order; now it's executed inside of a Tx
+ for (final Callable<?> task : tasks)
+ {
+ try
+ {
+ task.call();
+ }
+ // Every problem we encounter here becomes an ApplicationException
+ // to be unwrapped later by the caller (so the container doesn't wrap
+ // in EJBException
+ catch (final Throwable e)
+ {
+ throw new TaskExecutionException(e);
+ }
+ }
+ }
+}
Copied: projects/ejb-book/trunk/testsupport/src/main/java/org/jboss/ejb3/examples/testsupport/txwrap/TxWrappingLocalBusiness.java (from rev 104788, projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/ejb/TxWrappingLocalBusiness.java)
===================================================================
--- projects/ejb-book/trunk/testsupport/src/main/java/org/jboss/ejb3/examples/testsupport/txwrap/TxWrappingLocalBusiness.java (rev 0)
+++ projects/ejb-book/trunk/testsupport/src/main/java/org/jboss/ejb3/examples/testsupport/txwrap/TxWrappingLocalBusiness.java 2010-05-18 01:40:37 UTC (rev 104897)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.examples.testsupport.txwrap;
+
+import java.util.concurrent.Callable;
+
+/**
+ * Contract of an EJB which wraps arbitrary {@link Callable}
+ * tasks inside of a new Tx.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface TxWrappingLocalBusiness
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Contracts --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Wraps the specified tasks in a new Transaction
+ *
+ * @param task
+ * @throws IllegalArgumentException If no tasks are specified
+ * @throws TaskExecutionException If an error occurred in invoking {@link Callable#call()}
+ */
+ void wrapInTx(Callable<?>... tasks) throws IllegalArgumentException, TaskExecutionException;
+
+}
More information about the jboss-cvs-commits
mailing list