[jboss-cvs] JBossAS SVN: r85209 - in projects/webbeans-ri-int/trunk: ejb/src/main/java/org/jboss/webbeans/integration and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Mar 4 04:32:20 EST 2009
Author: alesj
Date: 2009-03-04 04:32:19 -0500 (Wed, 04 Mar 2009)
New Revision: 85209
Added:
projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/transaction/
projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/transaction/JBossTransactionServices.java
projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/transaction/TransactionSynchronizedRunnable.java
Modified:
projects/webbeans-ri-int/trunk/deployer/src/main/resources/META-INF/webbeans-ejb-jboss-beans.xml
projects/webbeans-ri-int/trunk/microcontainer/src/main/java/org/jboss/webbeans/integration/microcontainer/deployer/env/WebBeansBootstrapDeployer.java
Log:
Apply David's patch (+ small fixes).
Modified: projects/webbeans-ri-int/trunk/deployer/src/main/resources/META-INF/webbeans-ejb-jboss-beans.xml
===================================================================
--- projects/webbeans-ri-int/trunk/deployer/src/main/resources/META-INF/webbeans-ejb-jboss-beans.xml 2009-03-04 08:12:55 UTC (rev 85208)
+++ projects/webbeans-ri-int/trunk/deployer/src/main/resources/META-INF/webbeans-ejb-jboss-beans.xml 2009-03-04 09:32:19 UTC (rev 85209)
@@ -18,4 +18,8 @@
<property name="resolver"><inject bean="WBJBossEjb" property="resolver"/></property>
</beanfactory>
+ <bean name="JBossTransactionServices" class="org.jboss.webbeans.integration.transaction.JBossTransactionServices">
+ <property name="transactionManager"><inject bean="RealTransactionManager" option="callback" /></property>
+ </bean>
+
</deployment>
Added: projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/transaction/JBossTransactionServices.java
===================================================================
--- projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/transaction/JBossTransactionServices.java (rev 0)
+++ projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/transaction/JBossTransactionServices.java 2009-03-04 09:32:19 UTC (rev 85209)
@@ -0,0 +1,123 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.webbeans.integration.transaction;
+
+import javax.inject.ExecutionException;
+import static javax.transaction.Status.STATUS_ACTIVE;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+
+import org.jboss.webbeans.transaction.spi.TransactionServices;
+
+/**
+ * JBoss AS implementation of TransactionServices. The transaction manager
+ * for the application server is injected directly into this bean and
+ * used to provide the services.
+ *
+ * @author David Allen
+ * @author ales.justin at jboss.org
+ *
+ */
+public class JBossTransactionServices implements TransactionServices
+{
+ /** The TM */
+ protected TransactionManager transactionManager;
+
+ /* (non-Javadoc)
+ * @see org.jboss.webbeans.transaction.spi.TransactionServices#executeAfterTransactionCompletion(java.lang.Runnable)
+ */
+ public void executeAfterTransactionCompletion(Runnable task)
+ {
+ try
+ {
+ getTransactionManager().getTransaction().registerSynchronization(new TransactionSynchronizedRunnable(task, false));
+ }
+ catch (Exception e)
+ {
+ throw new ExecutionException("Failed to register task " + task + " for after transaction completion", e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.webbeans.transaction.spi.TransactionServices#executeAfterTransactionCompletion(java.lang.Runnable, org.jboss.webbeans.transaction.spi.TransactionServices.Status)
+ */
+ public void executeAfterTransactionCompletion(Runnable task, Status desiredStatus)
+ {
+ try
+ {
+ getTransactionManager().getTransaction().registerSynchronization(new TransactionSynchronizedRunnable(task, desiredStatus));
+ }
+ catch (Exception e)
+ {
+ throw new ExecutionException("Failed to register task " + task + " for after transaction completion, status " + desiredStatus, e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.webbeans.transaction.spi.TransactionServices#executeBeforeTransactionCompletion(java.lang.Runnable)
+ */
+ public void executeBeforeTransactionCompletion(Runnable task)
+ {
+ try
+ {
+ getTransactionManager().getTransaction().registerSynchronization(new TransactionSynchronizedRunnable(task, true));
+ }
+ catch (Exception e)
+ {
+ throw new ExecutionException("Failed to register task " + task + " for before transaction completion", e);
+ }
+ }
+
+ public boolean isTransactionActive()
+ {
+ try
+ {
+ return getTransactionManager().getStatus() == STATUS_ACTIVE;
+ }
+ catch (SystemException e)
+ {
+ throw new ExecutionException("Failed to determine transaction status", e);
+ }
+ }
+
+ /**
+ * Get transaction manager. \
+ *
+ * It might throw IllegalArgumentException if it's not yet configured
+ * as we inject it via callback - only available in deploy/ when TM gets deployed.
+ *
+ * @return the transaction manager
+ */
+ protected TransactionManager getTransactionManager()
+ {
+ if (transactionManager == null)
+ throw new IllegalArgumentException("Transaction manager is not yet set.");
+
+ return transactionManager;
+ }
+
+ /**
+ * Set transaction manager.
+ *
+ * @param transactionManager the transaction manager
+ */
+ public void setTransactionManager(TransactionManager transactionManager)
+ {
+ this.transactionManager = transactionManager;
+ }
+}
Added: projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/transaction/TransactionSynchronizedRunnable.java
===================================================================
--- projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/transaction/TransactionSynchronizedRunnable.java (rev 0)
+++ projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/transaction/TransactionSynchronizedRunnable.java 2009-03-04 09:32:19 UTC (rev 85209)
@@ -0,0 +1,78 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.webbeans.integration.transaction;
+
+import static javax.transaction.Status.STATUS_COMMITTED;
+
+import javax.transaction.Synchronization;
+
+import org.jboss.webbeans.transaction.spi.TransactionServices;
+
+/**
+ * A JTA transaction sychronization which wraps a Runnable.
+ *
+ * @author David Allen
+ *
+ */
+public class TransactionSynchronizedRunnable implements Synchronization
+{
+ private final TransactionServices.Status desiredStatus;
+ private final Runnable task;
+ private final boolean before;
+
+ public TransactionSynchronizedRunnable(Runnable task, boolean before)
+ {
+ this.task = task;
+ this.desiredStatus = TransactionServices.Status.ALL;
+ this.before = before;
+ }
+
+ public TransactionSynchronizedRunnable(Runnable task, TransactionServices.Status desiredStatus)
+ {
+ this.task = task;
+ this.desiredStatus = desiredStatus;
+ this.before = false; // Status is only applicable after the transaction
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.transaction.Synchronization#afterCompletion(int)
+ */
+ public void afterCompletion(int status)
+ {
+ if ((desiredStatus == TransactionServices.Status.SUCCESS && status == STATUS_COMMITTED) || (desiredStatus == TransactionServices.Status.FAILURE && status != STATUS_COMMITTED) || (desiredStatus == TransactionServices.Status.ALL))
+ {
+ task.run();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.transaction.Synchronization#beforeCompletion()
+ */
+ public void beforeCompletion()
+ {
+ if (before)
+ {
+ task.run();
+ }
+ }
+
+}
Modified: projects/webbeans-ri-int/trunk/microcontainer/src/main/java/org/jboss/webbeans/integration/microcontainer/deployer/env/WebBeansBootstrapDeployer.java
===================================================================
--- projects/webbeans-ri-int/trunk/microcontainer/src/main/java/org/jboss/webbeans/integration/microcontainer/deployer/env/WebBeansBootstrapDeployer.java 2009-03-04 08:12:55 UTC (rev 85208)
+++ projects/webbeans-ri-int/trunk/microcontainer/src/main/java/org/jboss/webbeans/integration/microcontainer/deployer/env/WebBeansBootstrapDeployer.java 2009-03-04 09:32:19 UTC (rev 85209)
@@ -59,10 +59,12 @@
BeanMetaDataBuilder bootstrap = BeanMetaDataBuilder.createBuilder(bootstrapName, "org.jboss.webbeans.bootstrap.WebBeansBootstrap");
bootstrap.addPropertyMetaData("webBeanDiscovery", bootstrap.createInject(envName));
bootstrap.addPropertyMetaData("ejbDiscovery", createEjbConnector("JBossEjbDiscovery", "org.jboss.webbeans.integration.ejb.JBossEjbDiscovery", unit));
- bootstrap.addPropertyMetaData("ejbResolver", createEjbConnector("JBossEjbResolver", "org.jboss.webbeans.integration.ejb.JBossEjbResolver", unit));
+ bootstrap.addPropertyMetaData("ejbResolver", createEjbConnector("JBossEjbResolver", "org.jboss.webbeans.integration.ejb.JBossEjbResolver", unit));
+ bootstrap.addPropertyMetaData("transactionServices", bootstrap.createInject("JBossTransactionServices"));
bootstrap.addPropertyMetaData("applicationContext", createBeanStore());
bootstrap.setCreate("initialize");
bootstrap.setStart("boot");
+ bootstrap.addDependency("RealTransactionManager"); // so we know TM is present in JBossTransactionServices
//bootstrap.setDestroy("shutdown");
unit.addAttachment(bootstrapName + "_" + BeanMetaData.class.getSimpleName(), bootstrap.getBeanMetaData());
}
More information about the jboss-cvs-commits
mailing list