Fix and fine-tune suppress_nulls.
[squelch.git] / src / main / java / net / jaekl / squelch / db / DbDriver.java
index 72472de3c2a0992825c535f6183ccb41afb0fc50..cf116de5b8f3ba39c9c73cfb6553ed7d6a320592 100644 (file)
@@ -3,10 +3,14 @@ package net.jaekl.squelch.db;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.SQLException;
+import java.util.HashMap;
 import java.util.Locale;
 
 public abstract class DbDriver {
-       private boolean m_suppressNulls = false;
+       // Well-known setting names
+       public static final String SUPPRESS_NULLS = "suppress_nulls";
+       
+       private HashMap<String, Setting> m_settings;
        
        // Returns true iff. this DbDriver knows how to connect to the given JDBC URL
        abstract public boolean handles(String jdbcUrl);
@@ -14,13 +18,38 @@ public abstract class DbDriver {
        // Execute line as a statement of this type
        abstract String getJdbcDriverClassName();
 
+       DbDriver() {
+               m_settings = new HashMap<String, Setting>();
+               m_settings.put(SUPPRESS_NULLS, new Setting(SUPPRESS_NULLS, Boolean.class, Boolean.valueOf(false)));
+       }
+       
        // -------------------
        // Getters and setters
+       public Setting[] getSettings() 
+       {
+               return m_settings.values().toArray(new Setting[m_settings.size()]);
+       }
        
-       public boolean isSuppressNulls() { return m_suppressNulls; }
-       public void setSuppressNulls(boolean value) { m_suppressNulls = value; }
-       
-       
+       public boolean isSet(String name) 
+       {
+               Setting setting = m_settings.get(name);
+               if (null != setting) {
+                       return setting.getBoolean();
+               }
+               return false;
+       }
+       public void set(String name, Object value) 
+       {
+               String lcName = name.toLowerCase(Locale.CANADA);
+               Setting setting = m_settings.get(lcName);
+               if (null != setting) {
+                       setting.set(value);
+               }
+               else {
+                       throw new IllegalArgumentException("Setting \"" + name + "\" not found.");
+               }
+       }
+               
        // Open a new Connection to the database.  Note that the caller must close() this at some point.
        public Connection connect(String jdbcUrl, String userName, String password) throws ClassNotFoundException, SQLException 
        {