List of usage examples for org.apache.commons.dbcp2 BasicDataSource setConnectionProperties
public void setConnectionProperties(String connectionProperties)
From source file:annis.administration.AdministrationDao.java
private BasicDataSource createDataSource(String host, String port, String database, String user, String password, boolean useSSL, String schema) { String url = "jdbc:postgresql://" + host + ":" + port + "/" + database; // DriverManagerDataSource is deprecated // return new DriverManagerDataSource("org.postgresql.Driver", url, user, password); BasicDataSource result = new BasicDataSource(); result.setUrl(url);/*from w w w . ja v a 2 s . c om*/ if (useSSL) { result.setConnectionProperties("ssl=true"); } result.setUsername(user); result.setPassword(password); result.setValidationQuery("SELECT 1;"); result.setAccessToUnderlyingConnectionAllowed(true); if (schema == null) { schema = "public"; } result.setConnectionInitSqls(Arrays.asList("SET search_path TO \"$user\"," + schema)); result.setDriverClassName("org.postgresql.Driver"); return result; }
From source file:org.ff4j.springboot.FF4jSpringConfig.java
@Bean public FF4j getFF4j() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(jdbcDriverClassName); dataSource.setUrl(jdbcUrl);/*from w w w.ja va2 s . co m*/ dataSource.setUsername(jdbcUser); dataSource.setPassword(jdbcPassword); dataSource.setConnectionProperties("useUnicode=yes;characterEncoding=UTF-8;"); FF4j ff4j = new FF4j(); ff4j.setFeatureStore(new FeatureStoreSpringJdbc(dataSource)); ff4j.setPropertiesStore(new PropertyStoreSpringJdbc(dataSource)); ff4j.audit(false); return ff4j; }
From source file:org.ofbiz.core.entity.transaction.DBCPConnectionFactory.java
public static Connection getConnection(String helperName, JdbcDatasourceInfo jdbcDatasource) throws SQLException, GenericEntityException { // the DataSource implementation BasicDataSource dataSource = dsCache.get(helperName); if (dataSource != null) { return trackConnection(helperName, dataSource); }/*from ww w. j a va 2 s .c o m*/ try { synchronized (DBCPConnectionFactory.class) { //try again inside the synch just in case someone when through while we were waiting dataSource = dsCache.get(helperName); if (dataSource != null) { return trackConnection(helperName, dataSource); } // Sets the connection properties. At least 'user' and 'password' should be set. final Properties info = jdbcDatasource.getConnectionProperties() != null ? copyOf(jdbcDatasource.getConnectionProperties()) : new Properties(); // Use the BasicDataSourceFactory so we can use all the DBCP properties as per http://commons.apache.org/dbcp/configuration.html dataSource = createDataSource(jdbcDatasource); dataSource.setConnectionProperties(toString(info)); // set connection pool attributes final ConnectionPoolInfo poolInfo = jdbcDatasource.getConnectionPoolInfo(); initConnectionPoolSettings(dataSource, poolInfo); dataSource.setLogWriter(Debug.getPrintWriter()); dsCache.put(helperName, dataSource); trackerCache.put(helperName, new ConnectionTracker(poolInfo)); return trackConnection(helperName, dataSource); } } catch (Exception e) { Debug.logError(e, "Error getting datasource via DBCP: " + jdbcDatasource); } catch (AbstractMethodError err) { if (checkIfProblemMayBeCausedByIsValidMethod(dataSource, err)) { unregisterDatasourceFromJmx(dataSource); log.warn( "*********************************************** IMPORTANT ***********************************************"); log.warn( " "); log.warn( " We found that you may experience problems with database connectivity because your database driver "); log.warn( " is not fully JDBC 4 compatible. As a workaround of this problem a validation query was added to your "); log.warn( " runtime configuration. Please add a line with validation query: \n"); log.warn( " <validation-query>select 1</validation-query> \n"); log.warn( " to your JIRA_HOME/dbconfig.xml or update your database driver to version which fully supports JDBC 4. "); log.warn( " More information about this problem can be found here: https://jira.atlassian.com/browse/JRA-59768 "); log.warn( " "); log.warn( "**********************************************************************************************************"); return getConnection(helperName, getUpdatedJdbcDatasource(jdbcDatasource)); } } return null; }