Modified:    src/stores/slidestore/j2ee J2EEContentStore.java
  Log:
  Add the database test statements and calls to
connectIfNeededAndPossible()
  to the J2EEContentStore as well - now the store will reconnect to the
  database if the connection stops working (if, for example, the socket
  times out or is otherwise invalidated).

Please see the attachment text file <<J2EEContentStorePatch.txt>> 
Index: J2EEContentStore.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-slide/src/stores/slidestore/j2ee/J2EEContentStore.java,v
retrieving revision 1.3
diff -u -r1.3 J2EEContentStore.java
--- J2EEContentStore.java       7 Jan 2002 00:44:44 -0000       1.3
+++ J2EEContentStore.java       6 Feb 2002 15:37:36 -0000
@@ -247,7 +247,18 @@
         }
     }
 
-
+    /**
+     * Tries to reconnect if needed but doesn't report failure.
+     */
+    protected synchronized void connectIfNeededAndPossible() {
+        try  {
+            connectIfNeeded();
+        }
+        catch (Throwable ex) {
+            // ignore
+        }
+    }
+    
     /**
      * Initializes content store.
      *
@@ -368,9 +379,10 @@
         {
             try {
 //                getLogger().log("start",LOG_CHANNEL,Logger.DEBUG);
+                               connectIfNeeded();
            // discard changes made outside a tranaction
                 connection.rollback();
-            } catch (SQLException e) {
+            } catch (Exception e) {
                 throw new XAException(XAException.XAER_RMERR);
             }
             alreadyEnlisted=true;
@@ -428,6 +440,7 @@
 
         } catch (SQLException e) {
             getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
+            connectIfNeededAndPossible();
             throw new ServiceAccessException(this, e.getMessage());
         } catch (RevisionNotFoundException e) {
             getLogger().log("RevisionNotFoundException encountered for " +
@@ -436,6 +449,7 @@
             throw e; // we do NOT want this caught by next clause.
         } catch (Exception e) {
             getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
+            connectIfNeededAndPossible();
             throw new ServiceAccessException(this, e.getMessage());
         }
 
@@ -484,17 +498,20 @@
 
         } catch (SQLException e) {
             getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
+            connectIfNeededAndPossible();
             throw new ServiceAccessException(this, e.getMessage());
         } catch (IOException e) {
             getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
+            connectIfNeededAndPossible();
             throw new ServiceAccessException(this, e.getMessage());
         } catch(RevisionAlreadyExistException e) {
             getLogger().log("RevisionAlreadyExistException encountered for " + 
                             revisionUri + " revision " + revisionNumber,
-                            LOG_CHANNEL,Logger.WARNING);
+                            LOG_CHANNEL,Logger.WARNING);                            
             throw e; // we do NOT want this caught by next clause.
         } catch (Exception e) {
             getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
+            connectIfNeededAndPossible();
             throw new ServiceAccessException(this, e.getMessage());
         } finally {
             closeStatement(selectStatement);
@@ -544,17 +561,20 @@
 
         } catch (SQLException e) {
             getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
+            connectIfNeededAndPossible();
             throw new ServiceAccessException(this, e.getMessage());
         } catch (IOException e) {
             getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
+            connectIfNeededAndPossible();
             throw new ServiceAccessException(this, e.getMessage());
         } catch(RevisionNotFoundException e) {
-            getLogger().log("RevisionNotFoundException encountered for "+ 
+            getLogger().log("RevisionNotFoundException encountered for " + 
                             revisionUri + " revision " + revisionNumber,
                             LOG_CHANNEL,Logger.WARNING);
             throw e; // we do NOT want this caught by next clause.
         } catch (Exception e) {
             getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
+            connectIfNeededAndPossible();
             throw new ServiceAccessException(this, e.getMessage());
         } finally {
             closeStatement(selectStatement);
@@ -583,6 +603,7 @@
 
         } catch (Exception e) {
             getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
+            connectIfNeededAndPossible();
             throw new ServiceAccessException(this, e.getMessage());
         }
--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to