Mercurial > dive4elements > river
changeset 5193:fb9dcc68b9c2
Possible fix for flys/1202. Initial SQL statements can now be issued at connection creation.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 07 Mar 2013 17:39:25 +0100 |
parents | 1b6d4edeeb4c |
children | 92c8f8d1a3ba |
files | flys-artifacts/doc/conf/seddb-db.xml flys-backend/src/main/java/de/intevation/flys/backend/Credentials.java flys-backend/src/main/java/de/intevation/flys/backend/FLYSCredentials.java flys-backend/src/main/java/de/intevation/flys/backend/SedDBCredentials.java flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java flys-backend/src/main/java/de/intevation/flys/utils/DBCPConnectionProvider.java |
diffstat | 6 files changed, 64 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/doc/conf/seddb-db.xml Thu Mar 07 16:06:44 2013 +0100 +++ b/flys-artifacts/doc/conf/seddb-db.xml Thu Mar 07 17:39:25 2013 +0100 @@ -6,4 +6,7 @@ <dialect>org.hibernate.dialect.PostgreSQLDialect</dialect> <driver>org.postgresql.Driver</driver> <url>jdbc:postgresql://localhost:5432/seddb</url> + <!-- + <connection-init-sqls>ALTER SESSION SET CURRENT_SCHEMA=SEDDB</connection-init-sqls> + --> </seddb-database>
--- a/flys-backend/src/main/java/de/intevation/flys/backend/Credentials.java Thu Mar 07 16:06:44 2013 +0100 +++ b/flys-backend/src/main/java/de/intevation/flys/backend/Credentials.java Thu Mar 07 17:39:25 2013 +0100 @@ -7,6 +7,7 @@ protected String dialect; protected String driver; protected String url; + protected String connectionInitSqls; protected Class [] classes; public Credentials() { @@ -18,14 +19,16 @@ String dialect, String driver, String url, + String connectionInitSqls, Class [] classes ) { - this.user = user; - this.password = password; - this.dialect = dialect; - this.driver = driver; - this.url = url; - this.classes = classes; + this.user = user; + this.password = password; + this.dialect = dialect; + this.driver = driver; + this.url = url; + this.connectionInitSqls = connectionInitSqls; + this.classes = classes; } public String getUser() { @@ -68,6 +71,14 @@ this.url = url; } + public String getConnectionInitSqls() { + return connectionInitSqls; + } + + public void setConnectionInitSqls(String connectionInitSqls) { + this.connectionInitSqls = connectionInitSqls; + } + public Class [] getClasses() { return classes; }
--- a/flys-backend/src/main/java/de/intevation/flys/backend/FLYSCredentials.java Thu Mar 07 16:06:44 2013 +0100 +++ b/flys-backend/src/main/java/de/intevation/flys/backend/FLYSCredentials.java Thu Mar 07 17:39:25 2013 +0100 @@ -96,6 +96,9 @@ public static final String XPATH_URL = "/artifact-database/backend-database/url/text()"; + public static final String XPATH_CONNECTION_INIT_SQLS = + "/artifact-database/backend-database/connection-init-sqls/text()"; + public static final String DEFAULT_USER = System.getProperty("flys.backend.user", "flys"); @@ -117,6 +120,10 @@ "flys.backend.url", "jdbc:postgresql://localhost:5432/flys"); + public static final String DEFAULT_CONNECTION_INIT_SQLS = + System.getProperty( + "flys.backend.connection.init.sqls"); + public static final Class [] CLASSES = { Annotation.class, AnnotationType.class, @@ -203,9 +210,11 @@ String password, String dialect, String driver, - String url + String url, + String connectionInitSqls ) { - super(user, password, dialect, driver, url, CLASSES); + super( + user, password, dialect, driver, url, connectionInitSqls, CLASSES); } private static Credentials instance; @@ -222,9 +231,13 @@ Config.getStringXPath(XPATH_DRIVER, DEFAULT_DRIVER); String url = Config.getStringXPath(XPATH_URL, DEFAULT_URL); + String connectionInitSqls = + Config.getStringXPath( + XPATH_CONNECTION_INIT_SQLS, + DEFAULT_CONNECTION_INIT_SQLS); instance = new FLYSCredentials( - user, password, dialect, driver, url); + user, password, dialect, driver, connectionInitSqls, url); } return instance; } @@ -235,7 +248,8 @@ DEFAULT_PASSWORD, DEFAULT_DIALECT, DEFAULT_DRIVER, - DEFAULT_URL); + DEFAULT_URL, + DEFAULT_CONNECTION_INIT_SQLS); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-backend/src/main/java/de/intevation/flys/backend/SedDBCredentials.java Thu Mar 07 16:06:44 2013 +0100 +++ b/flys-backend/src/main/java/de/intevation/flys/backend/SedDBCredentials.java Thu Mar 07 17:39:25 2013 +0100 @@ -73,6 +73,9 @@ public static final String XPATH_URL = "/artifact-database/seddb-database/url/text()"; + public static final String XPATH_CONNECTION_INIT_SQLS = + "/artifact-database/seddb-database/connection-init-sqls/text()"; + public static final String DEFAULT_USER = System.getProperty("flys.seddb.user", "seddb"); @@ -94,6 +97,10 @@ "flys.seddb.url", "jdbc:postgresql://localhost:5432/seddb"); + public static final String DEFAULT_CONNECTION_INIT_SQLS = + System.getProperty( + "flys.seddb.connection.init.sqls"); + public static final Class [] CLASSES = { BezugspegelgewId.class, Bezugspegelgew.class, @@ -159,9 +166,10 @@ String password, String dialect, String driver, + String connectionInitSqls, String url ) { - super(user, password, dialect, driver, url, CLASSES); + super(user, password, dialect, driver, url, connectionInitSqls, CLASSES); } public static synchronized Credentials getInstance() { @@ -176,9 +184,13 @@ Config.getStringXPath(XPATH_DRIVER, DEFAULT_DRIVER); String url = Config.getStringXPath(XPATH_URL, DEFAULT_URL); + String connectionInitSqls = + Config.getStringXPath( + XPATH_CONNECTION_INIT_SQLS, + DEFAULT_CONNECTION_INIT_SQLS); instance = new SedDBCredentials( - user, password, dialect, driver, url); + user, password, dialect, driver, connectionInitSqls, url); } return instance; } @@ -189,7 +201,8 @@ DEFAULT_PASSWORD, DEFAULT_DIALECT, DEFAULT_DRIVER, - DEFAULT_URL); + DEFAULT_URL, + DEFAULT_CONNECTION_INIT_SQLS); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java Thu Mar 07 16:06:44 2013 +0100 +++ b/flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java Thu Mar 07 17:39:25 2013 +0100 @@ -137,6 +137,11 @@ props.setProperty(Environment.DRIVER, credentials.getDriver()); props.setProperty(Environment.URL, credentials.getUrl()); + String connectionInitSqls = credentials.getConnectionInitSqls(); + if (connectionInitSqls != null) { + props.setProperty("connectionInitSqls", connectionInitSqls); + } + cfg.mergeProperties(props); return cfg;
--- a/flys-backend/src/main/java/de/intevation/flys/utils/DBCPConnectionProvider.java Thu Mar 07 16:06:44 2013 +0100 +++ b/flys-backend/src/main/java/de/intevation/flys/utils/DBCPConnectionProvider.java Thu Mar 07 17:39:25 2013 +0100 @@ -179,6 +179,11 @@ props.getProperty(DBCP_PS_MAXACTIVE)); } + String connectionInitSqls = props.getProperty("connectionInitSqls"); + if (connectionInitSqls != null) { + dbcpProperties.put("connectionInitSqls", connectionInitSqls); + } + // Some debug info /* // commented out, because it leaks the password if (log.isDebugEnabled()) {