# HG changeset patch
# User cli
# Date 1273401526 -7200
# Node ID 146b3275b792ee1e4e642522fa07a893c94b2ea5
# Parent  60c237bb677afa35e57bed26541cdc7173aa5af0
The StorageBackendException is catched two times so that the user see the "500 internal server error" only at the second catch (probably fixes #5).

diff -r 60c237bb677a -r 146b3275b792 org/sonews/config/Config.java
--- a/org/sonews/config/Config.java	Sat May 01 18:51:57 2010 +0200
+++ b/org/sonews/config/Config.java	Sun May 09 12:38:46 2010 +0200
@@ -128,24 +128,20 @@
     return val;
   }
 
-  public String get(int level, String key, String def)
+  public String get(int maxLevel, String key, String def)
   {
-    switch(level)
+    String val = CommandLineConfig.getInstance().get(key, null);
+
+    if(val == null && maxLevel <= LEVEL_FILE)
     {
-      case LEVEL_CLI:
+      val = FileConfig.getInstance().get(key, null);
+      if(val == null && maxLevel <= LEVEL_BACKEND)
       {
-        return CommandLineConfig.getInstance().get(key, def);
-      }
-      case LEVEL_FILE:
-      {
-        return FileConfig.getInstance().get(key, def);
-      }
-      case LEVEL_BACKEND:
-      {
-        return BackendConfig.getInstance().get(key, def);
+        val = BackendConfig.getInstance().get(key, def);
       }
     }
-    return null;
+
+    return val != null ? val : def;
   }
 
   @Override
diff -r 60c237bb677a -r 146b3275b792 org/sonews/config/FileConfig.java
--- a/org/sonews/config/FileConfig.java	Sat May 01 18:51:57 2010 +0200
+++ b/org/sonews/config/FileConfig.java	Sun May 09 12:38:46 2010 +0200
@@ -161,6 +161,7 @@
    * @param key
    * @param value
    */
+  @Override
   public void set(final String key, final String value)
   {
     settings.setProperty(key, value);
diff -r 60c237bb677a -r 146b3275b792 org/sonews/daemon/NNTPConnection.java
--- a/org/sonews/daemon/NNTPConnection.java	Sat May 01 18:51:57 2010 +0200
+++ b/org/sonews/daemon/NNTPConnection.java	Sun May 09 12:38:46 2010 +0200
@@ -33,6 +33,7 @@
 import org.sonews.daemon.command.Command;
 import org.sonews.storage.Article;
 import org.sonews.storage.Channel;
+import org.sonews.storage.StorageBackendException;
 import org.sonews.util.Log;
 import org.sonews.util.Stats;
 
@@ -275,7 +276,17 @@
     try
     {
       // The command object will process the line we just received
-      command.processLine(this, line, raw);
+      try
+      {
+        command.processLine(this, line, raw);
+      }
+      catch(StorageBackendException ex)
+      {
+        Log.get().info("Retry command processing after StorageBackendException");
+
+        // Try it a second time, so that the backend has time to recover
+        command.processLine(this, line, raw);
+      }
     }
     catch(ClosedChannelException ex0)
     {
@@ -289,7 +300,7 @@
         ex0a.printStackTrace();
       }
     }
-    catch(Exception ex1)
+    catch(Exception ex1) // This will catch a second StorageBackendException
     {
       try
       {
diff -r 60c237bb677a -r 146b3275b792 org/sonews/storage/impl/JDBCDatabase.java
--- a/org/sonews/storage/impl/JDBCDatabase.java	Sat May 01 18:51:57 2010 +0200
+++ b/org/sonews/storage/impl/JDBCDatabase.java	Sun May 09 12:38:46 2010 +0200
@@ -52,7 +52,7 @@
 public class JDBCDatabase implements Storage
 {
 
-  public static final int MAX_RESTARTS = 3;
+  public static final int MAX_RESTARTS = 2;
   
   private Connection        conn = null;
   private PreparedStatement pstmtAddArticle1 = null;
@@ -110,13 +110,13 @@
     {
       // Load database driver
       Class.forName(
-              Config.inst().get(Config.STORAGE_DBMSDRIVER, "java.lang.Object"));
+        Config.inst().get(Config.LEVEL_FILE, Config.STORAGE_DBMSDRIVER, "java.lang.Object"));
 
       // Establish database connection
       this.conn = DriverManager.getConnection(
-              Config.inst().get(Config.STORAGE_DATABASE, "<not specified>"),
-              Config.inst().get(Config.STORAGE_USER, "root"),
-              Config.inst().get(Config.STORAGE_PASSWORD, ""));
+        Config.inst().get(Config.LEVEL_FILE, Config.STORAGE_DATABASE, "<not specified>"),
+        Config.inst().get(Config.LEVEL_FILE, Config.STORAGE_USER, "root"),
+        Config.inst().get(Config.LEVEL_FILE, Config.STORAGE_PASSWORD, ""));
 
       this.conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
       if(this.conn.getTransactionIsolation() != Connection.TRANSACTION_SERIALIZABLE)
diff -r 60c237bb677a -r 146b3275b792 org/sonews/storage/impl/JDBCDatabaseProvider.java
--- a/org/sonews/storage/impl/JDBCDatabaseProvider.java	Sat May 01 18:51:57 2010 +0200
+++ b/org/sonews/storage/impl/JDBCDatabaseProvider.java	Sun May 09 12:38:46 2010 +0200
@@ -18,10 +18,12 @@
 
 package org.sonews.storage.impl;
 
-import org.sonews.storage.*;
 import java.sql.SQLException;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
+import org.sonews.storage.Storage;
+import org.sonews.storage.StorageBackendException;
+import org.sonews.storage.StorageProvider;
 
 /**
  *