comparison 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
comparison
equal deleted inserted replaced
5199:29d79741c2fe 5200:42bb6ff78d1b
19 import java.sql.SQLException; 19 import java.sql.SQLException;
20 20
21 import java.util.Iterator; 21 import java.util.Iterator;
22 import java.util.Properties; 22 import java.util.Properties;
23 import java.util.Map; 23 import java.util.Map;
24 import java.util.Collections;
25 import java.util.StringTokenizer;
24 26
25 import org.apache.commons.dbcp.BasicDataSource; 27 import org.apache.commons.dbcp.BasicDataSource;
26 import org.apache.commons.dbcp.BasicDataSourceFactory; 28 import org.apache.commons.dbcp.BasicDataSourceFactory;
27 29
28 import org.apache.log4j.Logger; 30 import org.apache.log4j.Logger;
177 dbcpProperties.put( 179 dbcpProperties.put(
178 "maxOpenPreparedStatements", 180 "maxOpenPreparedStatements",
179 props.getProperty(DBCP_PS_MAXACTIVE)); 181 props.getProperty(DBCP_PS_MAXACTIVE));
180 } 182 }
181 183
182 String connectionInitSqls = props.getProperty("connectionInitSqls");
183 if (connectionInitSqls != null) {
184 dbcpProperties.put("connectionInitSqls", connectionInitSqls);
185 }
186
187 // Some debug info 184 // Some debug info
188 /* // commented out, because it leaks the password 185 /* // commented out, because it leaks the password
189 if (log.isDebugEnabled()) { 186 if (log.isDebugEnabled()) {
190 log.debug("Creating a DBCP BasicDataSource" + 187 log.debug("Creating a DBCP BasicDataSource" +
191 " with the following DBCP factory properties:"); 188 " with the following DBCP factory properties:");
197 194
198 // Let the factory create the pool 195 // Let the factory create the pool
199 ds = (BasicDataSource)BasicDataSourceFactory 196 ds = (BasicDataSource)BasicDataSourceFactory
200 .createDataSource(dbcpProperties); 197 .createDataSource(dbcpProperties);
201 198
199 // This needs to be done manually as it is somehow ignored
200 // by the BasicDataSourceFactory if you set it as a dbcpProperty
201 String connectionInitSqls = props.getProperty("connectionInitSqls");
202 if (connectionInitSqls != null) {
203 StringTokenizer tokenizer = new StringTokenizer(connectionInitSqls, ";");
204 ds.setConnectionInitSqls(Collections.list(tokenizer));
205 }
202 // The BasicDataSource has lazy initialization 206 // The BasicDataSource has lazy initialization
203 // borrowing a connection will start the DataSource 207 // borrowing a connection will start the DataSource
204 // and make sure it is configured correctly. 208 // and make sure it is configured correctly.
205 209
206 // Connection conn = ds.getConnection(); 210 // Connection conn = ds.getConnection();

http://dive4elements.wald.intevation.org