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);
// 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
{