[jboss-cvs] jboss-seam/src/ioc/org/jboss/seam/ioc/spring ...

Michael Youngstrom youngm at gmail.com
Tue Jul 3 16:36:29 EDT 2007


  User: myoungstrom
  Date: 07/07/03 16:36:29

  Modified:    src/ioc/org/jboss/seam/ioc/spring      spring-2.0.xsd
                        SeamManagedEntityManagerFactory.java
                        SeamLifecycleUtils.java spring-seam-2.0.xsd
  Added:       src/ioc/org/jboss/seam/ioc/spring     
                        SpringTransaction.java
  Log:
  Fixes for:
  JBSEAM-1575
  JBSEAM-1583
  
  Revision  Changes    Path
  1.2       +62 -36    jboss-seam/src/ioc/org/jboss/seam/ioc/spring/spring-2.0.xsd
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: spring-2.0.xsd
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/ioc/org/jboss/seam/ioc/spring/spring-2.0.xsd,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- spring-2.0.xsd	26 Jun 2007 23:02:36 -0000	1.1
  +++ spring-2.0.xsd	3 Jul 2007 20:36:29 -0000	1.2
  @@ -2,15 +2,17 @@
   <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
       targetNamespace="http://jboss.com/products/seam/spring" xmlns:spring="http://jboss.com/products/seam/spring"
       xmlns:components="http://jboss.com/products/seam/components" attributeFormDefault="unqualified">
  -    <xs:import namespace="http://jboss.com/products/seam/components" schemaLocation="http://jboss.com/products/seam/components-2.0.xsd"/>
  +	<xs:import namespace="http://jboss.com/products/seam/components"
  +		schemaLocation="http://jboss.com/products/seam/components-2.0.xsd" />
   
       <xs:element name="context-loader">
           <xs:complexType mixed="true">
               <xs:choice minOccurs="0" maxOccurs="unbounded">
  -                <xs:element minOccurs="0" maxOccurs="1" ref="spring:config-locations"/>
  +				<xs:element minOccurs="0" maxOccurs="1" ref="spring:config-locations" />
               </xs:choice>
  -            <xs:attributeGroup ref="components:attlist.component"/>
  -            <xs:attribute name="config-locations" type="xs:string" use="optional" default="/WEB-INF/applicationContext.xml">
  +			<xs:attributeGroup ref="components:attlist.component" />
  +			<xs:attribute name="config-locations" type="xs:string" use="optional"
  +				default="/WEB-INF/applicationContext.xml">
                   <xs:annotation>
                       <xs:documentation>
                           <![CDATA[
  @@ -33,12 +35,36 @@
       
       <xs:element name="task-executor-dispatcher">
           <xs:complexType mixed="true">
  -            <xs:attributeGroup ref="components:attlist.component"/>
  -            <xs:attributeGroup ref="core:attlist.taskExecutorDispatcher"/>
  +			<xs:attributeGroup ref="components:attlist.component" />
  +			<xs:attributeGroup ref="core:attlist.taskExecutorDispatcher" />
           </xs:complexType>
       </xs:element>
       <xs:attributeGroup name="core:attlist.taskExecutorDispatcher">
  -        <xs:attribute name="task-executor" use="required"/>
  -        <xs:attribute name="schedule-dispatcher"/>
  +		<xs:attribute name="task-executor" use="required" />
  +		<xs:attribute name="schedule-dispatcher" />
       </xs:attributeGroup>
  +	<xs:element name="spring-transaction">
  +		<xs:complexType mixed="true">
  +			<xs:attributeGroup ref="components:attlist.component" />
  +			<xs:attribute name="platform-transaction-manager">
  +				<xs:annotation>
  +					<xs:documentation>
  +						<![CDATA[
  +                        	An expression evalutating to the spring platform transaction manager
  +                        ]]>
  +					</xs:documentation>
  +				</xs:annotation>
  +			</xs:attribute>
  +			<xs:attribute name="conversation-context-required" type="xs:boolean" use="required" default="true">
  +				<xs:annotation>
  +					<xs:annotation>
  +						<xs:documentation>
  +							Specify if this transaction manager requires a conversation context to be available or not.
  +							Set to true if you're using a JpaTransactionManager with a conversation scoped persistence
  +							context.
  +						</xs:documentation>
  +					</xs:annotation>
  +			</xs:attribute>
  +		</xs:complexType>
  +	</xs:element>
   </xs:schema>
  
  
  
  1.4       +1 -1      jboss-seam/src/ioc/org/jboss/seam/ioc/spring/SeamManagedEntityManagerFactory.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SeamManagedEntityManagerFactory.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/ioc/org/jboss/seam/ioc/spring/SeamManagedEntityManagerFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- SeamManagedEntityManagerFactory.java	30 May 2007 17:28:23 -0000	1.3
  +++ SeamManagedEntityManagerFactory.java	3 Jul 2007 20:36:29 -0000	1.4
  @@ -31,7 +31,6 @@
   
      public SeamManagedEntityManagerFactory(String seamPersistenceContextName)
      {
  -      super();
         if (seamPersistenceContextName == null || "".equals(seamPersistenceContextName))
         {
            throw new IllegalArgumentException("persistenceContextName cannot be null");
  @@ -125,6 +124,7 @@
               closed = true;
               return null;
            }
  +         
            try
            {
               return method.invoke(delegate, args);
  
  
  
  1.2       +2 -2      jboss-seam/src/ioc/org/jboss/seam/ioc/spring/SeamLifecycleUtils.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SeamLifecycleUtils.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/ioc/org/jboss/seam/ioc/spring/SeamLifecycleUtils.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- SeamLifecycleUtils.java	28 Mar 2007 22:46:50 -0000	1.1
  +++ SeamLifecycleUtils.java	3 Jul 2007 20:36:29 -0000	1.2
  @@ -44,8 +44,8 @@
         throw new IllegalStateException(
                  "Seam application context not available and cannot be started.  "
                           + "Seam Managed Persistence Context not available.  "
  -                        + "Try placing the spring bean call inside of a spring transaction or making the spring bean "
  -                        + "a Seam Component.");
  +                        + "Try placing the spring bean call inside of a spring transaction or try making the spring bean "
  +                        + "a Seam Component using <seam:component/>.");
      }
   
      /**
  
  
  
  1.2       +2 -3      jboss-seam/src/ioc/org/jboss/seam/ioc/spring/spring-seam-2.0.xsd
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: spring-seam-2.0.xsd
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/ioc/org/jboss/seam/ioc/spring/spring-seam-2.0.xsd,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- spring-seam-2.0.xsd	26 Jun 2007 23:02:36 -0000	1.1
  +++ spring-seam-2.0.xsd	3 Jul 2007 20:36:29 -0000	1.2
  @@ -160,9 +160,8 @@
                   <xsd:annotation>
                       <xsd:documentation>
                           <![CDATA[
  -                                 Determines whether Seam interceptors should be wrapped around a bean, by overriding Seam's default rules. 
  -                                 Seldom do you want the seam interceptors wrapped around a sprig singleton.  Auto will use choose no
  -                                 interception for a singleton and use Seam standard rules otherwise.
  +                                 Determines whether Seam interceptors should be wrapped around a bean, overriding
  +                                 Seam's default which is currently "true". 
                           ]]>
                       </xsd:documentation>
                   </xsd:annotation>
  
  
  
  1.1      date: 2007/07/03 20:36:29;  author: myoungstrom;  state: Exp;jboss-seam/src/ioc/org/jboss/seam/ioc/spring/SpringTransaction.java
  
  Index: SpringTransaction.java
  ===================================================================
  package org.jboss.seam.ioc.spring;
  
  import static org.jboss.seam.annotations.Install.FRAMEWORK;
  
  import javax.transaction.HeuristicMixedException;
  import javax.transaction.HeuristicRollbackException;
  import javax.transaction.NotSupportedException;
  import javax.transaction.RollbackException;
  import javax.transaction.Status;
  import javax.transaction.Synchronization;
  import javax.transaction.SystemException;
  
  import org.jboss.seam.ScopeType;
  import org.jboss.seam.annotations.Install;
  import org.jboss.seam.annotations.Name;
  import org.jboss.seam.annotations.Scope;
  import org.jboss.seam.annotations.intercept.BypassInterceptors;
  import org.jboss.seam.core.Expressions.ValueExpression;
  import org.jboss.seam.log.LogProvider;
  import org.jboss.seam.log.Logging;
  import org.jboss.seam.transaction.AbstractUserTransaction;
  import org.springframework.transaction.HeuristicCompletionException;
  import org.springframework.transaction.PlatformTransactionManager;
  import org.springframework.transaction.TransactionException;
  import org.springframework.transaction.TransactionStatus;
  import org.springframework.transaction.TransactionSystemException;
  import org.springframework.transaction.UnexpectedRollbackException;
  import org.springframework.transaction.support.DefaultTransactionDefinition;
  import org.springframework.transaction.support.TransactionSynchronization;
  import org.springframework.transaction.support.TransactionSynchronizationManager;
  
  @Name("org.jboss.seam.transaction.transaction")
  @Scope(ScopeType.EVENT)
  @Install(value = false, precedence = FRAMEWORK)
  @BypassInterceptors
  public class SpringTransaction extends AbstractUserTransaction
  {
     private static final LogProvider log = Logging.getLogProvider(SpringTransaction.class);
     private ValueExpression<PlatformTransactionManager> platformTransactionManager;
     private DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
     private boolean conversationContextRequired = true;
     private TransactionStatus currentTransaction;
  
     @Override
     public void registerSynchronization(final Synchronization sync)
     {
        if(TransactionSynchronizationManager.isSynchronizationActive()) {
           TransactionSynchronizationManager.registerSynchronization(new JtaSpringSynchronizationAdapter(sync));
        } else {
           throw new IllegalStateException("TransactionSynchronization not available with this Spring Transaction Manager");
        }
     }
  
     public void begin() throws NotSupportedException, SystemException
     {
        if (TransactionSynchronizationManager.isActualTransactionActive())
        {
           throw new NotSupportedException("A Spring transaction is already active.");
        }
        currentTransaction = platformTransactionManager.getValue().getTransaction(definition);
     }
  
     public void commit() throws RollbackException, HeuristicMixedException,
              HeuristicRollbackException, SecurityException, IllegalStateException, SystemException
     {
        assertActive();
        try
        {
           platformTransactionManager.getValue().commit(currentTransaction);
        }
        catch (HeuristicCompletionException e)
        {
           
           switch(e.getOutcomeState()) {
              case HeuristicCompletionException.STATE_ROLLED_BACK :
                 log.error("Exception cause:", e);
                 throw new HeuristicRollbackException(e.getMessage());
              default :
                 log.error("Exception cause:", e);
                 throw new HeuristicMixedException(e.getMessage());
           }
        } catch (TransactionSystemException e) {
           log.error("Exception cause:", e);
           throw new SystemException(e.getMessage());
        } catch(UnexpectedRollbackException e) {
           log.error("Exception cause:", e);
           throw new RollbackException(e.getMessage());
        } finally {
           currentTransaction = null;
        }
     }
  
     public int getStatus() throws SystemException
     {
        if(TransactionSynchronizationManager.isActualTransactionActive()) {
           TransactionStatus transaction = null;
           try {
              if(currentTransaction == null) {
                 transaction = platformTransactionManager.getValue().getTransaction(definition);
              } else {
                 transaction = currentTransaction;
              }
              if(transaction.isCompleted()) {
                 if(transaction.isRollbackOnly()) {
                    return Status.STATUS_ROLLEDBACK;
                 }
                 return Status.STATUS_COMMITTED;
              } else {
                 if(transaction.isRollbackOnly()) {
                    return Status.STATUS_MARKED_ROLLBACK;
                 }
                 return Status.STATUS_ACTIVE;
              }
           } finally {
              if(currentTransaction == null) {
                 if(transaction.isNewTransaction()) {
                    throw new IllegalStateException("Our transactions are in a bad state");
                 } else {
                    platformTransactionManager.getValue().commit(transaction);
                 }
              }
           }
        }
        return Status.STATUS_NO_TRANSACTION;
     }
  
     public void rollback() throws IllegalStateException, SecurityException, SystemException
     {
        assertActive();
        try
        {
           TransactionStatus transaction = platformTransactionManager.getValue().getTransaction(definition);
           platformTransactionManager.getValue().rollback(transaction);
        }
        catch (TransactionException e)
        {
           log.error("Exception cause:", e);
           throw new SystemException(e.getMessage());
        } finally {
           currentTransaction = null;
        }
     }
  
     /**
      * 
      */
     private void assertActive()
     {
        if(!TransactionSynchronizationManager.isActualTransactionActive() || currentTransaction == null) {
           throw new IllegalStateException("No transaction currently active that Seam started." +
           		"Seam should only be able to committ or rollback transactions it started.");
        }
     }
  
     public void setRollbackOnly() throws IllegalStateException, SystemException
     {
        if(!TransactionSynchronizationManager.isActualTransactionActive()) {
           throw new IllegalStateException("No Spring Transaction is currently available.");
        }
        TransactionStatus transaction = null;
        try
        {
           if(currentTransaction == null) {
              transaction = platformTransactionManager.getValue().getTransaction(definition);
           } else {
              transaction = currentTransaction;
           }
           transaction.setRollbackOnly();
        }
        catch (TransactionException e)
        {
           log.error("Exception cause:", e);
           throw new SystemException(e.getMessage());
        } finally {
           if(currentTransaction == null) {
              if(transaction.isNewTransaction()) {
                 throw new IllegalStateException("Our transactions are in a bad state");
              } else {
                 platformTransactionManager.getValue().commit(transaction);
              }
           }
        }
     }
  
     public void setTransactionTimeout(int timeout) throws SystemException
     {
        if(TransactionSynchronizationManager.isActualTransactionActive()) {
           //cannot set timeout on already running transaction
           return;
        }
        definition.setTimeout(timeout);
     }
     
     public void setPlatformTransactionManager(
              ValueExpression<PlatformTransactionManager> platformTransactionManager)
     {
        this.platformTransactionManager = platformTransactionManager;
     }
     
     @Override
     public boolean isConversationContextRequired()
     {
        return conversationContextRequired;
     }
     
     public void setConversationContextRequired(boolean conversationContextRequired)
     {
        this.conversationContextRequired = conversationContextRequired;
     }
     
     
     public class JtaSpringSynchronizationAdapter implements TransactionSynchronization
     {
        private final Synchronization sync;
  
        public JtaSpringSynchronizationAdapter(Synchronization sync)
        {
           this.sync = sync;
        }
  
        public void afterCommit() { }
  
        public void afterCompletion(int status)
        {
           sync.afterCompletion(status);
        }
  
        public void beforeCommit(boolean arg0) { }
  
        public void beforeCompletion()
        {
           sync.beforeCompletion();
        }
  
        public void resume() { }
  
        public void suspend() { }
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list