Esempio n. 1
0
  /**
   * 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
Esempio n. 2
0
 public void setDataSourceName(String name) throws NamingException {
   combods.setDataSourceName(name);
   rebind();
 }