Author: pete.muir(a)jboss.org
Date: 2008-12-14 16:52:56 -0500 (Sun, 14 Dec 2008)
New Revision: 524
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/AbstractUserTransaction.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/Transaction.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/UTTransaction.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/UserTransaction.java
Removed:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/LocalTransactionListener.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/TransactionListener.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractFacadeBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/DeploymentProperties.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java
Log:
More TODOs, rewrite UT lookup
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-12-14
21:32:14 UTC (rev 523)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-12-14
21:52:56 UTC (rev 524)
@@ -505,7 +505,7 @@
public <T> T getMostSpecializedInstance(Bean<T> bean, boolean create)
{
- // TODO!!!!!
+ // TODO Implement specialization
return getInstance(bean);
}
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractFacadeBean.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractFacadeBean.java 2008-12-14
21:32:14 UTC (rev 523)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractFacadeBean.java 2008-12-14
21:52:56 UTC (rev 524)
@@ -158,8 +158,7 @@
}
catch (ClassCastException e)
{
- // TODO: Expand error
- throw new IllegalArgumentException("Type mismatch");
+ throw new IllegalArgumentException("Cannot create an instance of " +
toString() + " with " + getAnnotatedItem());
}
}
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/DeploymentProperties.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/DeploymentProperties.java 2008-12-14
21:32:14 UTC (rev 523)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/DeploymentProperties.java 2008-12-14
21:52:56 UTC (rev 524)
@@ -116,8 +116,6 @@
catch (IOException e)
{
// No - op, file is optional
- // TODO: Isn't this more of a open/read/close error? If the file wasn't
- // there in the first place you wouldn't be in the loop?
}
}
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2008-12-14
21:32:14 UTC (rev 523)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2008-12-14
21:52:56 UTC (rev 524)
@@ -55,7 +55,6 @@
import org.jboss.webbeans.bean.ManagerBean;
import org.jboss.webbeans.bean.ProducerFieldBean;
import org.jboss.webbeans.bean.ProducerMethodBean;
-import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.bindings.InitializedBinding;
import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
import org.jboss.webbeans.contexts.DependentContext;
@@ -66,6 +65,8 @@
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.transaction.Transaction;
+import org.jboss.webbeans.util.BeanFactory;
import org.jboss.webbeans.util.JNDI;
import org.jboss.webbeans.util.Reflections;
@@ -120,7 +121,6 @@
public void registerBeans(Iterable<Class<?>> classes)
{
Set<Bean<?>> beans = (Set) createBeans(classes);
- beans.add(new
SimpleBean<DefaultEnterpriseBeanLookup>(DefaultEnterpriseBeanLookup.class,
manager));
beans.add(new ManagerBean(manager));
manager.setBeans(beans);
}
@@ -150,6 +150,8 @@
createBean(createSimpleBean(clazz, manager), beans);
}
}
+ createBean(BeanFactory.createSimpleBean(Transaction.class, manager), beans);
+ createBean(BeanFactory.createSimpleBean(DefaultEnterpriseBeanLookup.class,
manager), beans);
return beans;
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java 2008-12-14
21:32:14 UTC (rev 523)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java 2008-12-14
21:52:56 UTC (rev 524)
@@ -27,12 +27,10 @@
import javax.transaction.Status;
import javax.transaction.SystemException;
-import javax.transaction.UserTransaction;
import javax.webbeans.Observer;
import org.jboss.webbeans.ManagerImpl;
-import org.jboss.webbeans.transaction.TransactionListener;
-import org.jboss.webbeans.util.JNDI;
+import org.jboss.webbeans.transaction.UserTransaction;
import org.jboss.webbeans.util.Reflections;
import org.jboss.webbeans.util.Strings;
@@ -138,7 +136,7 @@
// The map of registered observers for a give
private final RegisteredObserversMap registeredObservers;
// The current UserTransaction
- UserTransaction userTransaction;
+ private UserTransaction userTransaction;
/**
* Initializes a new instance of the EventManager.
@@ -149,8 +147,7 @@
{
this.manager = manager;
registeredObservers = new RegisteredObserversMap();
- // TODO. Check where to *really* get this from
- userTransaction = (UserTransaction)
JNDI.lookup("java:/UserTransaction");
+ userTransaction = manager.getInstanceByType(UserTransaction.class);
}
/**
@@ -243,9 +240,8 @@
*/
private <T> void deferEvent(T event, Observer<T> observer)
{
- TransactionListener transactionListener =
manager.getInstanceByType(TransactionListener.class);
DeferredEventNotification<T> deferredEvent = new
DeferredEventNotification<T>(event, observer);
- transactionListener.registerSynhronization(deferredEvent);
+ userTransaction.registerSynchronization(deferredEvent);
}
/**
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/AbstractUserTransaction.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/AbstractUserTransaction.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/AbstractUserTransaction.java 2008-12-14
21:52:56 UTC (rev 524)
@@ -0,0 +1,74 @@
+package org.jboss.webbeans.transaction;
+
+import static javax.transaction.Status.STATUS_ACTIVE;
+import static javax.transaction.Status.STATUS_COMMITTED;
+import static javax.transaction.Status.STATUS_MARKED_ROLLBACK;
+import static javax.transaction.Status.STATUS_NO_TRANSACTION;
+import static javax.transaction.Status.STATUS_ROLLEDBACK;
+
+import javax.persistence.EntityManager;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+
+/**
+ * Base implementation of UserTransaction
+ *
+ * @author Gavin King
+ *
+ */
+public abstract class AbstractUserTransaction implements UserTransaction
+{
+
+ public boolean isActive() throws SystemException
+ {
+ return getStatus() == STATUS_ACTIVE;
+ }
+
+ public boolean isActiveOrMarkedRollback() throws SystemException
+ {
+ int status = getStatus();
+ return status == STATUS_ACTIVE || status == STATUS_MARKED_ROLLBACK;
+ }
+
+ public boolean isRolledBackOrMarkedRollback() throws SystemException
+ {
+ int status = getStatus();
+ return status == STATUS_ROLLEDBACK || status == STATUS_MARKED_ROLLBACK;
+ }
+
+ public boolean isMarkedRollback() throws SystemException
+ {
+ return getStatus() == STATUS_MARKED_ROLLBACK;
+ }
+
+ public boolean isNoTransaction() throws SystemException
+ {
+ return getStatus() == STATUS_NO_TRANSACTION;
+ }
+
+ public boolean isRolledBack() throws SystemException
+ {
+ return getStatus() == STATUS_ROLLEDBACK;
+ }
+
+ public boolean isCommitted() throws SystemException
+ {
+ return getStatus() == STATUS_COMMITTED;
+ }
+
+ public boolean isConversationContextRequired()
+ {
+ return false;
+ }
+
+ public abstract void registerSynchronization(Synchronization sync);
+
+ public void enlist(EntityManager entityManager) throws SystemException
+ {
+ if ( isActiveOrMarkedRollback() )
+ {
+ entityManager.joinTransaction();
+ }
+ }
+
+}
Property changes on:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/AbstractUserTransaction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/LocalTransactionListener.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/LocalTransactionListener.java 2008-12-14
21:32:14 UTC (rev 523)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/LocalTransactionListener.java 2008-12-14
21:52:56 UTC (rev 524)
@@ -1,35 +0,0 @@
-/*
- * 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.transaction;
-
-import javax.ejb.Local;
-
-/**
- * The local EJB interface for the TransactionListener
- *
- * @author Nicklas Karlsson
- *
- */
-@Local
-public interface LocalTransactionListener
-{
- /**
- * The destroy method
- */
- public void destroy();
-}
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/Transaction.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/Transaction.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/Transaction.java 2008-12-14
21:52:56 UTC (rev 524)
@@ -0,0 +1,59 @@
+package org.jboss.webbeans.transaction;
+
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+import javax.webbeans.Produces;
+
+public class Transaction
+{
+
+ @Produces
+ public UserTransaction getCurrentTransaction()
+ {
+ return new UTTransaction(new javax.transaction.UserTransaction()
+ {
+
+ public void begin() throws NotSupportedException, SystemException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void commit() throws RollbackException, HeuristicMixedException,
HeuristicRollbackException, SecurityException, IllegalStateException, SystemException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public int getStatus() throws SystemException
+ {
+ return javax.transaction.Status.STATUS_UNKNOWN;
+ }
+
+ public void rollback() throws IllegalStateException, SecurityException,
SystemException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setRollbackOnly() throws IllegalStateException, SystemException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setTransactionTimeout(int arg0) throws SystemException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+
+
+ });
+ }
+
+}
Property changes on:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/Transaction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/TransactionListener.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/TransactionListener.java 2008-12-14
21:32:14 UTC (rev 523)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/TransactionListener.java 2008-12-14
21:52:56 UTC (rev 524)
@@ -1,106 +0,0 @@
-/*
- * 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.transaction;
-
-import java.rmi.RemoteException;
-import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-import javax.ejb.EJBException;
-import javax.ejb.Remove;
-import javax.ejb.SessionSynchronization;
-import javax.transaction.Status;
-import javax.transaction.Synchronization;
-import javax.webbeans.RequestScoped;
-
-/**
- * An EJB used for transaction synchronization (e.g. transactional observers)
- *
- * @author Nicklas Karlsson
- *
- */
-//@Stateful
-@RequestScoped
-//(a)TransactionAttribute(TransactionAttributeType.SUPPORTS)
-public class TransactionListener implements LocalTransactionListener,
SessionSynchronization
-{
- // The registered synchronizations
- private List<Synchronization> synchronizations = new
CopyOnWriteArrayList<Synchronization>();
-
- /**
- * Fired after the current transaction have begun
- *
- * @see javax.ejb.SessionSynchronization
- */
- public void afterBegin() throws EJBException, RemoteException
- {
- }
-
- /**
- * Fired after the transaction has completed
- *
- * Notifies any registered synchronizations
- *
- * @param success Did the transaction succeed?
- *
- * @see javax.ejb.SessionSynchronization
- */
- public void afterCompletion(boolean success) throws EJBException, RemoteException
- {
- for (Synchronization synchronization : synchronizations)
- {
- synchronization.afterCompletion(success ? Status.STATUS_COMMITTED :
Status.STATUS_ROLLEDBACK);
- }
- synchronizations.clear();
- }
-
- /**
- * Fired before the transaction completed
- *
- * Notifies any registered synchronizations
- *
- * @see javax.ejb.SessionSynchronization
- */
- public void beforeCompletion() throws EJBException, RemoteException
- {
- for (Synchronization synchronization : synchronizations)
- {
- synchronization.beforeCompletion();
- }
- }
-
- /**
- * Registers a synchronization
- *
- * @param synchronization The synchronization to register
- */
- public void registerSynhronization(Synchronization synchronization)
- {
- synchronizations.add(synchronization);
- }
-
- /**
- * The remove method
- */
- @Remove
- public void destroy()
- {
- synchronizations.clear();
- synchronizations = null;
- }
-}
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/UTTransaction.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/UTTransaction.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/UTTransaction.java 2008-12-14
21:52:56 UTC (rev 524)
@@ -0,0 +1,89 @@
+package org.jboss.webbeans.transaction;
+
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
+
+/**
+ * Wraps JTA transaction management in a Seam UserTransaction
+ * interface.
+ *
+ * @author Mike Youngstrom
+ * @author Gavin King
+ *
+ */
+public class UTTransaction extends AbstractUserTransaction
+{
+ private static final LogProvider log = Logging.getLogProvider(UTTransaction.class);
+
+ private final javax.transaction.UserTransaction delegate;
+
+ UTTransaction(javax.transaction.UserTransaction delegate)
+ {
+ this.delegate = delegate;
+ if (delegate==null)
+ {
+ throw new IllegalArgumentException("null UserTransaction");
+ }
+ }
+
+ public void begin() throws NotSupportedException, SystemException
+ {
+ log.debug("beginning JTA transaction");
+ delegate.begin();
+ }
+
+ public void commit() throws RollbackException, HeuristicMixedException,
+ HeuristicRollbackException, SecurityException, IllegalStateException,
SystemException
+ {
+ log.debug("committing JTA transaction");
+ boolean success = false;
+ try
+ {
+ delegate.commit();
+ success = true;
+ }
+ finally
+ {
+ }
+ }
+
+ public void rollback() throws IllegalStateException, SecurityException,
SystemException
+ {
+ log.debug("rolling back JTA transaction");
+ try
+ {
+ delegate.rollback();
+ }
+ finally
+ {
+ }
+ }
+
+ public int getStatus() throws SystemException
+ {
+ return delegate.getStatus();
+ }
+
+ public void setRollbackOnly() throws IllegalStateException, SystemException
+ {
+ delegate.setRollbackOnly();
+ }
+
+ public void setTransactionTimeout(int timeout) throws SystemException
+ {
+ delegate.setTransactionTimeout(timeout);
+ }
+
+ @Override
+ public void registerSynchronization(Synchronization sync)
+ {
+ }
+
+}
Property changes on:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/UTTransaction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/UserTransaction.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/UserTransaction.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/UserTransaction.java 2008-12-14
21:52:56 UTC (rev 524)
@@ -0,0 +1,29 @@
+package org.jboss.webbeans.transaction;
+
+import javax.persistence.EntityManager;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+
+/**
+ * Extends the standard UserTransaction interface with a couple
+ * of helpful methods.
+ *
+ * @author Gavin King
+ *
+ */
+public interface UserTransaction extends javax.transaction.UserTransaction
+{
+
+ public boolean isActive() throws SystemException;
+ public boolean isActiveOrMarkedRollback() throws SystemException;
+ public boolean isRolledBackOrMarkedRollback() throws SystemException;
+ public boolean isMarkedRollback() throws SystemException;
+ public boolean isNoTransaction() throws SystemException;
+ public boolean isRolledBack() throws SystemException;
+ public boolean isCommitted() throws SystemException;
+
+ public boolean isConversationContextRequired();
+ public abstract void registerSynchronization(Synchronization sync);
+
+ public void enlist(EntityManager entityManager) throws SystemException;
+}
Property changes on:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/UserTransaction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain