Mercurial > dive4elements > framework
comparison 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 |
comparison
equal
deleted
inserted
replaced
13:0d6badf6af42 | 14:0d16d1bb2df0 |
---|---|
1 package de.intevation.artifactdatabase; | |
2 | |
3 import java.util.Properties; | |
4 | |
5 import java.io.IOException; | |
6 import java.io.InputStream; | |
7 | |
8 /** | |
9 * @author Sascha L. Teichmann | |
10 */ | |
11 public final class SQL | |
12 { | |
13 private SQL() { | |
14 } | |
15 | |
16 private static Properties statements; | |
17 | |
18 public static final synchronized Properties getStatements() { | |
19 if (statements == null) { | |
20 statements = loadStatements(); | |
21 } | |
22 return statements; | |
23 } | |
24 | |
25 private static final Properties loadStatements() { | |
26 String driver = Config.getStringXPath( | |
27 DBConnection.DB_DRIVER, DBConnection.DEFAULT_DRIVER); | |
28 | |
29 Properties properties = new Properties(); | |
30 | |
31 InputStream in = null; | |
32 try { | |
33 String res = "/sql/" + driver.replace('.', '-').toLowerCase() | |
34 + ".properties"; | |
35 in = SQL.class.getResourceAsStream(res); | |
36 | |
37 if (in == null) { | |
38 System.err.println("WARNING: no SQL file for driver '" | |
39 + driver + "' found."); | |
40 res = "/sql/" + DBConnection.DEFAULT_DRIVER.replace('.', '-').toLowerCase() | |
41 + ".properties"; | |
42 if ((in = SQL.class.getResourceAsStream(res)) == null) { | |
43 System.err.println("ERROR: no SQL file found"); | |
44 } | |
45 } | |
46 | |
47 properties.load(in); | |
48 } | |
49 catch (IOException ioe) { | |
50 ioe.printStackTrace(System.err); | |
51 } | |
52 finally { | |
53 if (in != null) { | |
54 try { in.close(); } catch (IOException ioe) {} | |
55 } | |
56 } | |
57 | |
58 return properties; | |
59 } | |
60 | |
61 public static final String get(String key) { | |
62 return getStatements().getProperty(key); | |
63 } | |
64 } | |
65 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: |