Mercurial > dive4elements > river
diff flys-backend/src/main/java/de/intevation/flys/utils/DBCPConnectionProvider.java @ 5200:42bb6ff78d1b 2.9.11
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
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Fri, 08 Mar 2013 11:48:33 +0100 |
parents | fb9dcc68b9c2 |
children |
line wrap: on
line diff
--- 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.