sascha@14: package de.intevation.artifactdatabase; sascha@14: sascha@14: import java.util.Properties; sascha@14: sascha@14: import java.io.IOException; sascha@14: import java.io.InputStream; sascha@14: sascha@17: import org.apache.log4j.Logger; sascha@17: sascha@14: /** sascha@14: * @author Sascha L. Teichmann sascha@14: */ sascha@14: public final class SQL sascha@14: { sascha@17: private static Logger logger = Logger.getLogger(SQL.class); sascha@17: sascha@14: private SQL() { sascha@14: } sascha@14: sascha@14: private static Properties statements; sascha@14: sascha@14: public static final synchronized Properties getStatements() { sascha@14: if (statements == null) { sascha@14: statements = loadStatements(); sascha@14: } sascha@14: return statements; sascha@14: } sascha@14: sascha@14: private static final Properties loadStatements() { sascha@14: String driver = Config.getStringXPath( sascha@14: DBConnection.DB_DRIVER, DBConnection.DEFAULT_DRIVER); sascha@14: sascha@14: Properties properties = new Properties(); sascha@14: sascha@14: InputStream in = null; sascha@14: try { sascha@47: String res = "/sql/" + driver.replace('.', '-').toLowerCase() sascha@14: + ".properties"; sascha@14: in = SQL.class.getResourceAsStream(res); sascha@14: sascha@14: if (in == null) { sascha@17: logger.warn("No SQL file for driver '" + driver + "' found."); sascha@14: res = "/sql/" + DBConnection.DEFAULT_DRIVER.replace('.', '-').toLowerCase() sascha@14: + ".properties"; sascha@14: if ((in = SQL.class.getResourceAsStream(res)) == null) { sascha@17: logger.error("No SQL file found"); sascha@14: } sascha@14: } sascha@14: sascha@14: properties.load(in); sascha@14: } sascha@14: catch (IOException ioe) { sascha@17: logger.error(ioe.getLocalizedMessage(), ioe); sascha@14: } sascha@14: finally { sascha@14: if (in != null) { sascha@14: try { in.close(); } catch (IOException ioe) {} sascha@14: } sascha@14: } sascha@14: sascha@14: return properties; sascha@14: } sascha@14: sascha@14: public static final String get(String key) { sascha@14: return getStatements().getProperty(key); sascha@14: } sascha@14: } sascha@14: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: