You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by rw...@apache.org on 2009/02/25 15:29:27 UTC

svn commit: r747795 - in /portals/jetspeed-2/portal/branches/JPA_BRANCH: components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/ jetspeed-portal-resources/src/main/resources/assembly/

Author: rwatler
Date: Wed Feb 25 14:29:27 2009
New Revision: 747795

URL: http://svn.apache.org/viewvc?rev=747795&view=rev
Log:
strengthen conversational txn valve implementation as suggested by Ate

Added:
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/JPAConversationalTxnValveImpl.java
      - copied, changed from r747457, portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/JPAConversationalTxnStartValveImpl.java
Removed:
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/JPAConversationalTxnEndValveImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/JPAConversationalTxnStartValveImpl.java
Modified:
    portals/jetspeed-2/portal/branches/JPA_BRANCH/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml

Copied: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/JPAConversationalTxnValveImpl.java (from r747457, portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/JPAConversationalTxnStartValveImpl.java)
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/JPAConversationalTxnValveImpl.java?p2=portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/JPAConversationalTxnValveImpl.java&p1=portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/JPAConversationalTxnStartValveImpl.java&r1=747457&r2=747795&rev=747795&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/JPAConversationalTxnStartValveImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/JPAConversationalTxnValveImpl.java Wed Feb 25 14:29:27 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.jetspeed.pipeline.valve.impl;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -28,12 +29,12 @@
 import org.apache.jetspeed.request.RequestContext;
 
 /**
- * JPAConversationalTxnStartValveImpl
+ * JPAConversationalTxnValveImpl
  * 
  * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
  * @version $Id:$
  */
-public class JPAConversationalTxnStartValveImpl extends AbstractValve implements JPAConversationalTxnValve
+public class JPAConversationalTxnValveImpl extends AbstractValve implements JPAConversationalTxnValve
 {
     private List<String> contextBeanNames;
     
@@ -41,7 +42,7 @@
      * Default constructor used for place holder in pipelines not
      * requiring conversational transaction manager contexts.
      */
-    public JPAConversationalTxnStartValveImpl()
+    public JPAConversationalTxnValveImpl()
     {
     }
     
@@ -51,7 +52,7 @@
      * 
      * @param contextBeanNames list of context bean names.
      */
-    public JPAConversationalTxnStartValveImpl(List<String> contextBeanNames)
+    public JPAConversationalTxnValveImpl(List<String> contextBeanNames)
     {
         this.contextBeanNames = contextBeanNames;
     }
@@ -63,6 +64,7 @@
     public void invoke(RequestContext request, ValveContext context) throws PipelineException
     {
         // create contexts and save in request
+        List<String> putContextBeanNames = null;
         if ((contextBeanNames != null) && !contextBeanNames.isEmpty())
         {
             Map<String,Object> contexts = (Map<String,Object>)request.getAttribute(JPA_CONVERSATIONAL_TXN_CONTEXTS_ATTR_KEY);
@@ -72,13 +74,47 @@
             }
             for (String contextBeanName : contextBeanNames)
             {
-                Object contextBean = Jetspeed.getComponentManager().createPrototypeComponent(contextBeanName);
-                contexts.put(contextBeanName, contextBean);
+                if (!contexts.containsKey(contextBeanName))
+                {
+                    Object contextBean = Jetspeed.getComponentManager().createPrototypeComponent(contextBeanName);
+                    contexts.put(contextBeanName, contextBean);
+                    if (putContextBeanNames == null)
+                    {
+                        putContextBeanNames = new ArrayList<String>();
+                    }
+                    putContextBeanNames.add(contextBeanName);
+                }
             }
             request.setAttribute(JPA_CONVERSATIONAL_TXN_CONTEXTS_ATTR_KEY, contexts);
         }
         
-        // continue pipeline
-        context.invokeNext(request);
+        try
+        {
+            // continue pipeline
+            context.invokeNext(request);
+        }
+        finally
+        {
+            // get put contexts from request and destroy
+            if (putContextBeanNames != null)
+            {
+                Map<String,Object> contexts = (Map<String,Object>)request.getAttribute(JPA_CONVERSATIONAL_TXN_CONTEXTS_ATTR_KEY);
+                if ((contexts != null) && !contexts.isEmpty())
+                {
+                    for (String contextBeanName : putContextBeanNames)
+                    {
+                        Object contextBean = contexts.remove(contextBeanName);
+                        if (contextBean != null)
+                        {
+                            Jetspeed.getComponentManager().destroyPrototypeComponent(contextBeanName, contextBean);
+                        }
+                    }
+                    if (contexts.isEmpty())
+                    {
+                        request.setAttribute(JPA_CONVERSATIONAL_TXN_CONTEXTS_ATTR_KEY, null);
+                    }
+                }
+            }
+        }
     }
 }

Modified: portals/jetspeed-2/portal/branches/JPA_BRANCH/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml?rev=747795&r1=747794&r2=747795&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml (original)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml Wed Feb 25 14:29:27 2009
@@ -435,15 +435,15 @@
     </constructor-arg>
   </bean>
 
-  <bean class="org.apache.jetspeed.pipeline.valve.impl.JPAConversationalTxnStartValveImpl">
+  <bean class="org.apache.jetspeed.pipeline.valve.impl.JPAConversationalTxnValveImpl">
     <meta key="j2:cat" value="ojb and default"/>
-    <meta key="j2:alias" value="jpaConversationalTxnStartValve"/>
+    <meta key="j2:alias" value="jpaConversationalTxnValve"/>
     <!-- no JPA manager contexts -->
   </bean>
 
-  <bean class="org.apache.jetspeed.pipeline.valve.impl.JPAConversationalTxnStartValveImpl">
+  <bean class="org.apache.jetspeed.pipeline.valve.impl.JPAConversationalTxnValveImpl">
     <meta key="j2:cat" value="jpa and default"/>
-    <meta key="j2:alias" value="jpaConversationalTxnStartValve"/>
+    <meta key="j2:alias" value="jpaConversationalTxnValve"/>
     <constructor-arg index="0">
       <list>
         <!-- JPA manager context bean names -->
@@ -456,10 +456,6 @@
     </constructor-arg>
   </bean>
 
-  <bean id="jpaConversationalTxnEndValve" class="org.apache.jetspeed.pipeline.valve.impl.JPAConversationalTxnEndValveImpl">
-    <meta key="j2:cat" value="default"/>
-  </bean>
-
   <bean id="databaseValidator"
     class="org.apache.jetspeed.healthcheck.validators.DatasourceAvailableHealthCheckValidator">
     <meta key="j2:cat" value="default" />
@@ -517,7 +513,7 @@
     </constructor-arg>
     <constructor-arg>
       <list>
-        <ref bean="jpaConversationalTxnStartValve" />
+        <ref bean="jpaConversationalTxnValve" />
         <ref bean="capabilityValve" />
         <ref bean="portalURLValve" />
         <ref bean="securityValve" />
@@ -539,7 +535,6 @@
         <ref bean="DecorationValve" />
         <ref bean="headerAggregatorValvePortal" />
         <ref bean="aggregatorValve" />
-        <ref bean="jpaConversationalTxnEndValve" />
         <ref bean="cleanUpValve" />
       </list>
     </constructor-arg>
@@ -552,7 +547,7 @@
     </constructor-arg>
     <constructor-arg>
       <list>
-        <ref bean="jpaConversationalTxnStartValve" />
+        <ref bean="jpaConversationalTxnValve" />
         <ref bean="capabilityValve" />
         <ref bean="portalURLValve" />
         <ref bean="securityValve" />
@@ -566,7 +561,6 @@
         <ref bean="DecorationValve" />
         <ref bean="headerAggregatorValvePortal" />
         <ref bean="aggregatorValve" />
-        <ref bean="jpaConversationalTxnEndValve" />
         <ref bean="cleanUpValve" />
       </list>
     </constructor-arg>
@@ -579,11 +573,10 @@
     </constructor-arg>
     <constructor-arg>
       <list>
-        <ref bean="jpaConversationalTxnStartValve" />
+        <ref bean="jpaConversationalTxnValve" />
         <ref bean="capabilityValve" />
         <ref bean="localizationValve" />
         <ref bean="loginViewValve" />
-        <ref bean="jpaConversationalTxnEndValve" />
       </list>
     </constructor-arg>
   </bean>
@@ -595,13 +588,12 @@
     </constructor-arg>
     <constructor-arg>
       <list>
-        <ref bean="jpaConversationalTxnStartValve" />
+        <ref bean="jpaConversationalTxnValve" />
         <ref bean="localizationValve" />
         <ref bean="capabilityValve" />
         <ref bean="portalURLValve" />
         <ref bean="containerValve" />
         <ref bean="actionValve" />
-        <ref bean="jpaConversationalTxnEndValve" />
       </list>
     </constructor-arg>
   </bean>
@@ -613,7 +605,7 @@
     </constructor-arg>
     <constructor-arg>
       <list>
-        <ref bean="jpaConversationalTxnStartValve" />
+        <ref bean="jpaConversationalTxnValve" />
         <ref bean="securityValve" />
         <ref bean="localizationValve" />
         <ref bean="capabilityValve" />
@@ -621,7 +613,6 @@
         <ref bean="profilerValve" />
         <ref bean="containerValve" />
         <ref bean="desktopActionValve" />
-        <ref bean="jpaConversationalTxnEndValve" />
       </list>
     </constructor-arg>
   </bean>
@@ -634,7 +625,7 @@
     </constructor-arg>
     <constructor-arg>
       <list>
-        <ref bean="jpaConversationalTxnStartValve" />
+        <ref bean="jpaConversationalTxnValve" />
         <ref bean="desktopEncoderRedirectValve" />
         <ref bean="portalURLValve" />
         <ref bean="capabilityValve" />
@@ -644,7 +635,6 @@
         <ref bean="containerValve" />
         <ref bean="resourceValve" />
         <ref bean="portletValveTitleInHeader" />
-        <ref bean="jpaConversationalTxnEndValve" />
       </list>
     </constructor-arg>
   </bean>
@@ -656,7 +646,7 @@
     </constructor-arg>
     <constructor-arg>
       <list>
-        <ref bean="jpaConversationalTxnStartValve" />
+        <ref bean="jpaConversationalTxnValve" />
         <ref bean="portalURLValve" />
         <ref bean="capabilityValve" />
         <ref bean="securityValve" />
@@ -664,7 +654,6 @@
         <ref bean="profilerValve" />
         <ref bean="containerValve" />
         <ref bean="portletValveTitleInHeader" />
-        <ref bean="jpaConversationalTxnEndValve" />
       </list>
     </constructor-arg>
   </bean>
@@ -676,7 +665,7 @@
     </constructor-arg>
     <constructor-arg>
       <list>
-        <ref bean="jpaConversationalTxnStartValve" />
+        <ref bean="jpaConversationalTxnValve" />
         <ref bean="capabilityValve" />
         <ref bean="portalURLValve" />
         <ref bean="securityValve" />
@@ -685,7 +674,6 @@
         <ref bean="containerValve" />
         <!--  this is the standard Jetspeed API entry point -->
         <ref bean="layoutValve" />
-        <ref bean="jpaConversationalTxnEndValve" />
       </list>
     </constructor-arg>
   </bean>
@@ -697,7 +685,7 @@
     </constructor-arg>
     <constructor-arg>
       <list>
-        <ref bean="jpaConversationalTxnStartValve" />
+        <ref bean="jpaConversationalTxnValve" />
         <ref bean="capabilityValve" />
         <ref bean="portalURLValve" />
         <ref bean="securityValve" />
@@ -705,7 +693,6 @@
         <ref bean="profilerValve" />
         <ref bean="containerValve" />
         <ref bean="AJAXValve" />
-        <ref bean="jpaConversationalTxnEndValve" />
       </list>
     </constructor-arg>
   </bean>
@@ -717,7 +704,7 @@
     </constructor-arg>
     <constructor-arg>
       <list>
-        <ref bean="jpaConversationalTxnStartValve" />
+        <ref bean="jpaConversationalTxnValve" />
         <ref bean="portalURLValve" />
         <ref bean="securityValve" />
         <ref bean="localizationValve" />
@@ -725,7 +712,6 @@
         <ref bean="containerValve" />
         <ref bean="fileServerValve" />
         <ref bean="portletValve" />
-        <ref bean="jpaConversationalTxnEndValve" />
       </list>
     </constructor-arg>
   </bean>
@@ -737,7 +723,7 @@
     </constructor-arg>
     <constructor-arg>
       <list>
-        <ref bean="jpaConversationalTxnStartValve" />
+        <ref bean="jpaConversationalTxnValve" />
         <ref bean="capabilityValve" />
         <ref bean="portalURLValve" />
         <ref bean="securityValve" />
@@ -745,7 +731,6 @@
         <ref bean="profilerValve" />
         <ref bean="headerAggregatorValveDesktop" />
         <ref bean="desktopValve" />
-        <ref bean="jpaConversationalTxnEndValve" />
       </list>
     </constructor-arg>
   </bean>
@@ -757,7 +742,7 @@
     </constructor-arg>
     <constructor-arg>
       <list>
-        <ref bean="jpaConversationalTxnStartValve" />
+        <ref bean="jpaConversationalTxnValve" />
         <ref bean="capabilityValve" />
         <ref bean="portalURLValve" />
         <ref bean="securityValve" />
@@ -765,7 +750,6 @@
         <ref bean="profilerValve" />
         <ref bean="headerAggregatorValveDesktop" />
         <ref bean="desktopValve" />
-        <ref bean="jpaConversationalTxnEndValve" />
       </list>
     </constructor-arg>
   </bean>



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org