sascha@4068: package de.intevation.db; sascha@4068: sascha@4068: import java.util.Properties; sascha@4068: sascha@4068: import java.io.IOException; sascha@4068: import java.io.InputStream; sascha@4068: sascha@4068: import org.apache.log4j.Logger; sascha@4068: sascha@4068: public class Statements sascha@4068: { sascha@4068: private static Logger log = Logger.getLogger(Statements.class); sascha@4068: sascha@4068: public static final String RESOURCE_PATH = "/sql/"; sascha@4068: public static final String COMMON_PROPERTIES = "-common.properties"; sascha@4068: sascha@4068: protected String type; sascha@4068: protected String driver; sascha@4068: sascha@4068: protected Properties properties; sascha@4068: sascha@4068: public Statements(String type, String driver) { sascha@4068: this.type = type; sascha@4068: this.driver = driver; sascha@4068: } sascha@4068: sascha@4068: protected String driverToProperties() { sascha@4068: return sascha@4068: type + "-" + sascha@4068: driver.replace('.', '-').toLowerCase() + ".properties"; sascha@4068: } sascha@4068: sascha@4068: protected Properties loadCommon() { sascha@4068: Properties common = new Properties(); sascha@4068: sascha@4068: String path = RESOURCE_PATH + type + COMMON_PROPERTIES; sascha@4068: sascha@4068: InputStream in = Statements.class.getResourceAsStream(path); sascha@4068: sascha@4068: if (in != null) { sascha@4068: try { sascha@4068: common.load(in); sascha@4068: } sascha@4068: catch (IOException ioe) { sascha@4068: log.error("cannot load defaults: " + path, ioe); sascha@4068: } sascha@4068: finally { sascha@4068: try { sascha@4068: in.close(); sascha@4068: } sascha@4068: catch (IOException ioe) { sascha@4068: } sascha@4068: } sascha@4068: } sascha@4068: else { sascha@4068: log.warn("cannot find: " + path); sascha@4068: } sascha@4068: sascha@4068: return common; sascha@4068: } sascha@4068: sascha@4068: protected Properties getProperties() { sascha@4068: sascha@4068: if (properties != null) { sascha@4068: return properties; sascha@4068: } sascha@4068: sascha@4068: Properties common = loadCommon(); sascha@4068: sascha@4068: properties = new Properties(common); sascha@4068: sascha@4068: String path = RESOURCE_PATH + driverToProperties(); sascha@4068: sascha@4068: InputStream in = Statements.class.getResourceAsStream(path); sascha@4068: sascha@4068: if (in != null) { sascha@4068: try { sascha@4068: properties.load(in); sascha@4068: } sascha@4068: catch (IOException ioe) { sascha@4068: log.error("cannot load statements: " + path, ioe); sascha@4068: } sascha@4068: finally { sascha@4068: try { sascha@4068: in.close(); sascha@4068: } sascha@4068: catch (IOException ioe) { sascha@4068: } sascha@4068: } sascha@4068: } sascha@4068: else { sascha@4068: log.warn("cannot find: " + path); sascha@4068: } sascha@4068: sascha@4068: return properties; sascha@4068: } sascha@4068: } sascha@4068: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :