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 ta...@apache.org on 2006/02/11 00:00:36 UTC

svn commit: r376885 - in /portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/util/interceptors: MethodReplayDecisionMaker.java MethodReplayInterceptor.java TransactionalMethodReplayDecisionMaker.java

Author: taylor
Date: Fri Feb 10 15:00:34 2006
New Revision: 376885

URL: http://svn.apache.org/viewcvs?rev=376885&view=rev
Log:
cleanup, bug fixes, licenses

Modified:
    portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/util/interceptors/MethodReplayDecisionMaker.java
    portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/util/interceptors/MethodReplayInterceptor.java
    portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/util/interceptors/TransactionalMethodReplayDecisionMaker.java

Modified: portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/util/interceptors/MethodReplayDecisionMaker.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/util/interceptors/MethodReplayDecisionMaker.java?rev=376885&r1=376884&r2=376885&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/util/interceptors/MethodReplayDecisionMaker.java (original)
+++ portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/util/interceptors/MethodReplayDecisionMaker.java Fri Feb 10 15:00:34 2006
@@ -1,22 +1,39 @@
+/*
+ * Copyright 2000-2004 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.util.interceptors;
 
 import org.aopalliance.intercept.MethodInvocation;
 
 /**
- * A interface which is akin to a <B>gateway</B>
- * in BPMN notation. Concrete implementations can make a decision
- * as to whether or not a method invocation should be replayed.
+ * A interface which is akin to a <B>gateway</B> in BPMN notation. Concrete
+ * implementations can make a decision as to whether or not a method invocation
+ * should be replayed.
  * 
  * @author a336317
  */
-public interface MethodReplayDecisionMaker {
-	
-	/**
-	 * 
-	 * @param invocation The MethodInvocation object
-	 * @param exception Exception thrown on previous invocation attempt
-	 * @return True if we should replay the method, false otherwise
-	 */
-	public boolean shouldReplay(MethodInvocation invocation, Exception exception);
-	
+public interface MethodReplayDecisionMaker
+{
+    /**
+     * 
+     * @param invocation
+     *            The MethodInvocation object
+     * @param exception
+     *            Exception thrown on previous invocation attempt
+     * @return True if we should replay the method, false otherwise
+     */
+    public boolean shouldReplay(MethodInvocation invocation, Exception exception);
+
 }

Modified: portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/util/interceptors/MethodReplayInterceptor.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/util/interceptors/MethodReplayInterceptor.java?rev=376885&r1=376884&r2=376885&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/util/interceptors/MethodReplayInterceptor.java (original)
+++ portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/util/interceptors/MethodReplayInterceptor.java Fri Feb 10 15:00:34 2006
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2000-2004 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.util.interceptors;
 
 import org.aopalliance.intercept.MethodInterceptor;

Modified: portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/util/interceptors/TransactionalMethodReplayDecisionMaker.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/util/interceptors/TransactionalMethodReplayDecisionMaker.java?rev=376885&r1=376884&r2=376885&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/util/interceptors/TransactionalMethodReplayDecisionMaker.java (original)
+++ portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/util/interceptors/TransactionalMethodReplayDecisionMaker.java Fri Feb 10 15:00:34 2006
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2000-2004 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.util.interceptors;
 
 import java.sql.SQLException;
@@ -11,6 +26,7 @@
  * content of the underlying exception from the resource.
  * 
  * @author a336317
+ * @author a202225
  */
 public class TransactionalMethodReplayDecisionMaker implements
         MethodReplayDecisionMaker
@@ -20,42 +36,39 @@
 
     public boolean shouldReplay(MethodInvocation invocation, Exception exception)
     {
-        // TODO This needs to be a lot more elegant than it currently is - see
-        // Spring code
-        // for exception translators to see what we can do here.
-
-        // exception must be of type SQLException and have an error code value,
-        // else we keep
-        // walking down the root cause tree to a maximum depth of 3
-        if (exception.getCause() instanceof SQLException)
+        SQLException sqlException = findSQLException(exception);
+        if (sqlException != null)
         {
-            SQLException sqlExp = (SQLException) exception.getCause();
-
-            int errorCode = sqlExp.getErrorCode();
+            int errorCode = sqlException.getErrorCode();
 
             if (errorCode != 0) { return isErrorCodeListed(errorCode); }
         }
 
-        if (exception.getCause().getCause() instanceof SQLException)
-        {
-
-            SQLException sqlExp = (SQLException) exception.getCause()
-                    .getCause();
-            int errorCode = sqlExp.getErrorCode();
-
-            if (errorCode != 0) { return isErrorCodeListed(errorCode); }
-        }
+        return false;
+    }
 
-        if (exception.getCause().getCause().getCause() instanceof SQLException)
+    // Recursively search the exception tree looking for the first SQLException
+    protected SQLException findSQLException(Exception exception)
+    {
+        SQLException foundException = null;
+        if (exception != null)
         {
-            SQLException sqlExp = (SQLException) exception.getCause()
-                    .getCause().getCause();
-            int errorCode = sqlExp.getErrorCode();
-
-            if (errorCode != 0) { return isErrorCodeListed(errorCode); }
+            if (exception instanceof SQLException)
+            {
+                foundException = (SQLException) exception;
+            } 
+            else
+            {
+                // Look at the cause
+                Throwable throwable = exception.getCause();
+                if (throwable != null && throwable instanceof Exception)
+                {
+                    foundException = findSQLException((Exception) throwable);
+                }
+            }
         }
 
-        return false;
+        return foundException;
     }
 
     public void setSqlErrorCodes(String sqlErrorCodesString)
@@ -67,8 +80,8 @@
 
         for (int i = 0; tokenizer.hasMoreTokens(); i++)
         {
-            String token = tokenizer.nextToken();
-            this.sqlErrorCodes[i] = new Integer(token.trim()).intValue();
+            this.sqlErrorCodes[i] = new Integer(tokenizer.nextToken())
+                    .intValue();
         }
     }
 
@@ -76,11 +89,9 @@
     {
         for (int i = 0; i < this.sqlErrorCodes.length; i++)
         {
-
             if (this.sqlErrorCodes[i] == errorCode) return true;
-
         }
+
         return false;
     }
-
-}
+}
\ 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