@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;
  }
 @PostConstruct
 public void setupConfiguration() {
   List<AppConfig> appConfigs = appConfiguration.getAppConfigs();
   for (AppConfig appConfig : appConfigs) {
     ComboPooledDataSource cpds = new ComboPooledDataSource();
     cpds.setJdbcUrl(appConfig.getDbUrl());
     cpds.setUser(appConfig.getDbUser());
     cpds.setPassword(appConfig.getDbPassword());
     cpds.setAutoCommitOnClose(true);
     datasources.put(appConfig.getAppName(), cpds);
   }
 }
Esempio n. 3
0
 public void setAutoCommitOnClose(boolean autoCommitOnClose) throws NamingException {
   combods.setAutoCommitOnClose(autoCommitOnClose);
   rebind();
 }