[Dive4elements-commits] [PATCH] Directly set the connectionInitSqls on the datasource

Wald Commits scm-commit at wald.intevation.org
Fri Mar 8 11:48:36 CET 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1362739713 -3600
# Node ID 42bb6ff78d1b734341732772ab24db2a913311b0
# Parent  29d79741c2fef466b7b3d9cf0dd86d18bed24566
Directly set the connectionInitSqls on the datasource

    Somehow the factory fails to set the connectionInitSqls if
    we add it to the dbcpProperties. So we now set it directly

diff -r 29d79741c2fe -r 42bb6ff78d1b flys-backend/src/main/java/de/intevation/flys/utils/DBCPConnectionProvider.java
--- a/flys-backend/src/main/java/de/intevation/flys/utils/DBCPConnectionProvider.java	Fri Mar 08 11:18:38 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/utils/DBCPConnectionProvider.java	Fri Mar 08 11:48:33 2013 +0100
@@ -21,6 +21,8 @@
 import java.util.Iterator;
 import java.util.Properties;
 import java.util.Map;
+import java.util.Collections;
+import java.util.StringTokenizer;
 
 import org.apache.commons.dbcp.BasicDataSource;
 import org.apache.commons.dbcp.BasicDataSourceFactory;
@@ -179,11 +181,6 @@
                     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()) {
@@ -199,6 +196,13 @@
             ds = (BasicDataSource)BasicDataSourceFactory
                 .createDataSource(dbcpProperties);
 
+            // This needs to be done manually as it is somehow ignored
+            // by the BasicDataSourceFactory if you set it as a dbcpProperty
+            String connectionInitSqls = props.getProperty("connectionInitSqls");
+            if (connectionInitSqls != null) {
+                StringTokenizer tokenizer = new StringTokenizer(connectionInitSqls, ";");
+                ds.setConnectionInitSqls(Collections.list(tokenizer));
+            }
             // The BasicDataSource has lazy initialization
             // borrowing a connection will start the DataSource
             // and make sure it is configured correctly.


More information about the Dive4elements-commits mailing list