# HG changeset patch # User Sascha L. Teichmann # Date 1362674365 -3600 # Node ID fb9dcc68b9c2b3135ec83965eef4548afeed97b9 # Parent 1b6d4edeeb4cafce7d105fe0fdce24a2dec75ed5 Possible fix for flys/1202. Initial SQL statements can now be issued at connection creation. diff -r 1b6d4edeeb4c -r fb9dcc68b9c2 flys-artifacts/doc/conf/seddb-db.xml --- 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 @@ org.hibernate.dialect.PostgreSQLDialect org.postgresql.Driver jdbc:postgresql://localhost:5432/seddb + diff -r 1b6d4edeeb4c -r fb9dcc68b9c2 flys-backend/src/main/java/de/intevation/flys/backend/Credentials.java --- 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; } diff -r 1b6d4edeeb4c -r fb9dcc68b9c2 flys-backend/src/main/java/de/intevation/flys/backend/FLYSCredentials.java --- 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 : diff -r 1b6d4edeeb4c -r fb9dcc68b9c2 flys-backend/src/main/java/de/intevation/flys/backend/SedDBCredentials.java --- 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 : diff -r 1b6d4edeeb4c -r fb9dcc68b9c2 flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java --- 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; diff -r 1b6d4edeeb4c -r fb9dcc68b9c2 flys-backend/src/main/java/de/intevation/flys/utils/DBCPConnectionProvider.java --- 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()) {