diff artifact-database/src/main/java/de/intevation/artifactdatabase/SQL.java @ 14:0d16d1bb2df0

Initial checkin of artigact persistents back by database. artifacts/trunk@29 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 07 Sep 2009 08:41:05 +0000
parents
children 5a6b6a3debc7
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/SQL.java	Mon Sep 07 08:41:05 2009 +0000
@@ -0,0 +1,65 @@
+package de.intevation.artifactdatabase;
+
+import java.util.Properties;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ *  @author Sascha L. Teichmann
+ */
+public final class SQL
+{
+    private SQL() {
+    }
+
+    private static Properties statements;
+
+    public static final synchronized Properties getStatements() {
+        if (statements == null) {
+            statements = loadStatements();
+        }
+        return statements;
+    }
+
+    private static final Properties loadStatements() {
+        String driver = Config.getStringXPath(
+            DBConnection.DB_DRIVER, DBConnection.DEFAULT_DRIVER);
+
+        Properties properties = new Properties();
+
+        InputStream in = null;
+        try {
+            String res = "/sql/" + driver.replace('.', '-').toLowerCase() 
+                + ".properties";
+            in = SQL.class.getResourceAsStream(res);
+
+            if (in == null) {
+                System.err.println("WARNING: no SQL file for driver '"
+                    + driver + "' found.");
+                res = "/sql/" + DBConnection.DEFAULT_DRIVER.replace('.', '-').toLowerCase()
+                    + ".properties";
+                if ((in = SQL.class.getResourceAsStream(res)) == null) {
+                    System.err.println("ERROR: no SQL file found");
+                }
+            }
+
+            properties.load(in);
+        }
+        catch (IOException ioe) {
+            ioe.printStackTrace(System.err);
+        }
+        finally {
+            if (in != null) {
+                try { in.close(); } catch (IOException ioe) {}
+            }
+        }
+
+        return properties;
+    }
+
+    public static final String get(String key) {
+        return getStatements().getProperty(key);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org