portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r380296 - in /portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl: DatabasePageManager.java DatabasePageManagerCache.java TransactionedOperation.java
Date Fri, 24 Feb 2006 01:51:53 GMT
Author: taylor
Date: Thu Feb 23 17:51:51 2006
New Revision: 380296

URL: http://svn.apache.org/viewcvs?rev=380296&view=rev
Log:
http://issues.apache.org/jira/browse/JS2-495
Using Spring method interceptor to clear OJB cache for Page Manager
After an object is added, 
OJB seems to be holding on to objects in the cache after rollback
Sometimes I really wonder if iBatis or even JDBC would suite us better than this endless stream
of bugs

The really fucked up thing is that this works fine in my unit test
But in production, a commit sneaks in before the rollback
No idea where that one is coming from

Added:
    portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/TransactionedOperation.java
Modified:
    portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/DatabasePageManager.java
    portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/DatabasePageManagerCache.java

Modified: portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/DatabasePageManager.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/DatabasePageManager.java?rev=380296&r1=380295&r2=380296&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/DatabasePageManager.java
(original)
+++ portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/DatabasePageManager.java
Thu Feb 23 17:51:51 2006
@@ -651,7 +651,7 @@
                 FolderImpl parent = null;
                 try
                 {
-                    parent = (FolderImpl)getFolder(parentPath);
+                    parent = (FolderImpl)getFolder(parentPath);                    
                 }
                 catch (FolderNotFoundException fnfe)
                 {
@@ -664,10 +664,14 @@
 
                 try
                 {
+                    
                     // update parent folder with added page
                     parent.addPage((PageImpl)page);
                     page.setParent(parent);
+                                        
                     getPersistenceBrokerTemplate().store(parent);
+                    DatabasePageManagerCache.addTransaction(new TransactionedOperation(pagePath,
TransactionedOperation.ADD_OPERATION));
+                    
                 }
                 catch (Exception e)
                 {
@@ -675,7 +679,7 @@
                     parent.removePage((PageImpl)page);
                     throw e;
                 }
-
+                                
                 // notify page manager listeners
                 delegator.notifyNewNode(page);
             }
@@ -685,8 +689,9 @@
                 page.checkAccess(JetspeedActions.EDIT);
 
                 // update page
-                getPersistenceBrokerTemplate().store(page);
-
+                getPersistenceBrokerTemplate().store(page);                
+                DatabasePageManagerCache.addTransaction(new TransactionedOperation(page.getPath(),
TransactionedOperation.UPDATE_OPERATION));
+                
                 // notify page manager listeners
                 delegator.notifyUpdatedNode(page);
             }
@@ -702,8 +707,9 @@
         catch (Exception e)
         {
             throw new PageNotUpdatedException("Page " + page.getPath() + " not updated.",
e);
-        }
+        }        
     }
+    
 
     /* (non-Javadoc)
      * @see org.apache.jetspeed.page.PageManager#removePage(org.apache.jetspeed.om.page.Page)
@@ -1255,13 +1261,22 @@
     
     public int addPages(Page[] pages)
     throws JetspeedException
-    {
-        System.out.println("Adding first page");
-        this.updatePage(pages[0]);
-        System.out.println("Adding second page");
-        this.updatePage(pages[1]);
-        System.out.println("About to throw ex");
-        throw new JetspeedException("Its gonna blow captain!");
+    {   
+        if (pages.length > 0 && pages[0].getPath().equals("/tx__test1.psml"))
+        {
+            // for tx testing
+            System.out.println("Adding first page");
+            this.updatePage(pages[0]);
+            System.out.println("Adding second page");
+            this.updatePage(pages[1]);
+            System.out.println("About to throw ex");
+            throw new JetspeedException("Its gonna blow captain!");
+        }
+        for (int ix = 0; ix < pages.length; ix++)
+        {
+            this.updatePage(pages[ix]);
+        }
+        return pages.length;
     }
     
 }

Modified: portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/DatabasePageManagerCache.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/DatabasePageManagerCache.java?rev=380296&r1=380295&r2=380296&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/DatabasePageManagerCache.java
(original)
+++ portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/DatabasePageManagerCache.java
Thu Feb 23 17:51:51 2006
@@ -15,10 +15,10 @@
  */
 package org.apache.jetspeed.page.impl;
 
-import java.util.HashMap;
 import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Properties;
-import java.util.Map;
 
 import org.apache.commons.collections.map.LRUMap;
 import org.apache.jetspeed.page.document.impl.NodeImpl;
@@ -152,6 +152,12 @@
             }
         }
     }
+    public synchronized static void cacheRemove(String path)
+    {
+        Identity id = (Identity)cacheByPath.get(path);
+        cacheRemove(id);
+    }
+    
 
     /**
      * resetCachedSecurityConstraints
@@ -257,5 +263,60 @@
     public void remove(Identity oid)
     {
         cacheRemove(oid);
+    }
+
+    public static void dump()
+    {
+        System.out.println("--------------------------1");        
+        synchronized (cacheByPath)
+        {
+            Object[] entries = new Object[100];
+            int count = 0;
+            Iterator paths = cacheByPath.orderedMapIterator();
+            while (paths.hasNext())
+            {
+                entries[count] = paths.next();
+                count++;
+            }
+            for (int ix = 0; ix < count; ix++)
+            {
+                System.out.println("entry = " + entries[ix] + ", " + cacheByPath.get(entries[ix]));
+            }
+        }
+        System.out.println("--------------------------2");
+    }
+    
+    protected static ThreadLocal transactionedOperations = new ThreadLocal();
+    
+    public static List getTransactions()
+    {
+        List operations = (List)transactionedOperations.get();
+        if (operations == null)
+        {
+            operations = new LinkedList();
+            transactionedOperations.set(operations);
+        }
+        
+        return operations;
+    }
+
+    /**
+     * @param principal
+     *            The principal to set.
+     */
+    public static void addTransaction(TransactionedOperation operation)
+    {
+        List transactions = getTransactions();        
+        transactions.add(operation);
+    }
+    
+    public static void rollbackTransactions()
+    {
+        Iterator transactions = getTransactions().iterator();
+        while (transactions.hasNext())
+        {
+            TransactionedOperation operation = (TransactionedOperation)transactions.next();
+            cacheRemove(operation.getPath());
+        }
     }
 }

Added: portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/TransactionedOperation.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/TransactionedOperation.java?rev=380296&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/TransactionedOperation.java
(added)
+++ portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/TransactionedOperation.java
Thu Feb 23 17:51:51 2006
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * 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.apache.jetspeed.page.impl;
+
+
+/**
+ * A transactioned operation is a single Page Manager DML operation that was applied
+ * to the OJB cache. Im finding that OJB is not properly synchronizing its cache
+ * upon rollback of database transactions. This code may not be needed in future
+ * versions of OJB which have fixed this bug.
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: $
+ */
+public class TransactionedOperation 
+{
+    public static final int ADD_OPERATION = 0;
+    public static final int UPDATE_OPERATION = 1;
+    private String path;
+    private int transactionType;
+    
+    public TransactionedOperation(String path, int type)
+    {
+        this.path = path;
+        this.transactionType = type;
+    }
+
+    
+    public String getPath()
+    {
+        return path;
+    }
+
+    
+    public void setPath(String path)
+    {
+        this.path = path;
+    }
+
+    
+    public int getTransactionType()
+    {
+        return transactionType;
+    }
+
+    
+    public void setTransactionType(int transactionType)
+    {
+        this.transactionType = transactionType;
+    }
+}
\ No newline at end of file



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


Mime
View raw message