@Bean(name = "mainDataSource") public DataSource dataSource() { ComboPooledDataSource dataSource = new ComboPooledDataSource(); try { dataSource.setDriverClass(env.getProperty("jdbc.driverClassName")); } catch (PropertyVetoException e) { // TODO Auto-generated catch block logger.info("PropertyVetoException : {}", e.getMessage()); } dataSource.setJdbcUrl(env.getProperty("jdbc.url")); dataSource.setUser(env.getProperty("jdbc.username")); dataSource.setPassword(env.getProperty("jdbc.password")); dataSource.setAcquireIncrement(20); dataSource.setAcquireRetryAttempts(30); dataSource.setAcquireRetryDelay(1000); dataSource.setAutoCommitOnClose(false); dataSource.setDebugUnreturnedConnectionStackTraces(true); dataSource.setIdleConnectionTestPeriod(100); dataSource.setInitialPoolSize(10); dataSource.setMaxConnectionAge(1000); dataSource.setMaxIdleTime(200); dataSource.setMaxIdleTimeExcessConnections(3600); dataSource.setMaxPoolSize(10); dataSource.setMinPoolSize(2); dataSource.setPreferredTestQuery("select 1"); dataSource.setTestConnectionOnCheckin(false); dataSource.setUnreturnedConnectionTimeout(1000); return dataSource; }
/** * Create DataSource * * @param connection connection * @return data dource */ @Override public DataSource getDataSource(CConnection connection) { if (m_ds != null) return m_ds; try { System.setProperty("com.mchange.v2.log.MLog", "com.mchange.v2.log.FallbackMLog"); // System.setProperty("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "ALL"); ComboPooledDataSource cpds = new ComboPooledDataSource(); cpds.setDataSourceName("AdempiereDS"); cpds.setDriverClass(DRIVER); // loads the jdbc driver cpds.setJdbcUrl(getConnectionURL(connection)); cpds.setUser(connection.getDbUid()); cpds.setPassword(connection.getDbPwd()); cpds.setPreferredTestQuery(DEFAULT_CONN_TEST_SQL); cpds.setIdleConnectionTestPeriod(1200); cpds.setAcquireRetryAttempts(2); // cpds.setTestConnectionOnCheckin(true); // cpds.setTestConnectionOnCheckout(true); // cpds.setCheckoutTimeout(60); if (Ini.isClient()) { cpds.setInitialPoolSize(1); cpds.setMinPoolSize(1); cpds.setMaxPoolSize(15); cpds.setMaxIdleTimeExcessConnections(1200); cpds.setMaxIdleTime(900); m_maxbusyconnections = 10; } else { cpds.setInitialPoolSize(10); cpds.setMinPoolSize(5); cpds.setMaxPoolSize(150); cpds.setMaxIdleTimeExcessConnections(1200); cpds.setMaxIdleTime(1200); m_maxbusyconnections = 120; } // the following sometimes kill active connection! // cpds.setUnreturnedConnectionTimeout(1200); // cpds.setDebugUnreturnedConnectionStackTraces(true); m_ds = cpds; } catch (Exception ex) { m_ds = null; // log might cause infinite loop since it will try to acquire database connection again // log.log(Level.SEVERE, "Could not initialise C3P0 Datasource", ex); System.err.println("Could not initialise C3P0 Datasource: " + ex.getLocalizedMessage()); } return m_ds; } // getDataSource
@Override public DataSource createDataSource( final String url, final String username, final String password) { try { final ComboPooledDataSource cpds = new ComboPooledDataSource(); cpds.setDriverClass(driverClass); cpds.setJdbcUrl(url); cpds.setUser(username); cpds.setPassword(password); cpds.setMinPoolSize(0); cpds.setMaxPoolSize(20); cpds.setMaxIdleTime(7200); cpds.setPreferredTestQuery("SELECT 1"); cpds.setIdleConnectionTestPeriod(15); return cpds; } catch (PropertyVetoException e) { throw new IllegalArgumentException(e); } }
public void setPreferredTestQuery(String preferredTestQuery) throws NamingException { combods.setPreferredTestQuery(preferredTestQuery); rebind(); }