Ejemplo n.º 1
0
  private static void pullTomcatJdbcDataSourceProperties(String name, DataSource dataSource) {
    // si tomcat-jdbc, alors on récupère des infos
    final org.apache.tomcat.jdbc.pool.DataSource jdbcDataSource =
        (org.apache.tomcat.jdbc.pool.DataSource) dataSource;
    final BasicDataSourcesProperties properties = TOMCAT_JDBC_DATASOURCES_PROPERTIES;
    // basicDataSource.getNumActive() est en théorie égale à USED_CONNECTION_COUNT à un instant t,
    // numIdle + numActive est le nombre de connexions ouvertes dans la bdd pour ce serveur à un
    // instant t

    // les propriétés généralement importantes en premier (se méfier aussi de testOnBorrow)
    properties.put(name, MAX_ACTIVE_PROPERTY_NAME, jdbcDataSource.getMaxActive());

    properties.put(name, "defaultCatalog", jdbcDataSource.getDefaultCatalog());
    properties.put(name, "defaultAutoCommit", jdbcDataSource.getDefaultAutoCommit());
    properties.put(name, "defaultReadOnly", jdbcDataSource.getDefaultReadOnly());
    properties.put(
        name, "defaultTransactionIsolation", jdbcDataSource.getDefaultTransactionIsolation());
    properties.put(name, "driverClassName", jdbcDataSource.getDriverClassName());
    properties.put(name, "connectionProperties", jdbcDataSource.getConnectionProperties());
    properties.put(name, "initSQL", jdbcDataSource.getInitSQL());
    properties.put(name, "initialSize", jdbcDataSource.getInitialSize());
    properties.put(name, "maxIdle", jdbcDataSource.getMaxIdle());
    properties.put(name, "maxWait", jdbcDataSource.getMaxWait());
    properties.put(name, "maxAge", jdbcDataSource.getMaxAge());
    properties.put(name, "faireQueue", jdbcDataSource.isFairQueue());
    properties.put(name, "jmxEnabled", jdbcDataSource.isJmxEnabled());
    properties.put(
        name, "minEvictableIdleTimeMillis", jdbcDataSource.getMinEvictableIdleTimeMillis());
    properties.put(name, "minIdle", jdbcDataSource.getMinIdle());
    properties.put(name, "numTestsPerEvictionRun", jdbcDataSource.getNumTestsPerEvictionRun());
    properties.put(name, "testOnBorrow", jdbcDataSource.isTestOnBorrow());
    properties.put(name, "testOnConnect", jdbcDataSource.isTestOnConnect());
    properties.put(name, "testOnReturn", jdbcDataSource.isTestOnReturn());
    properties.put(name, "testWhileIdle", jdbcDataSource.isTestWhileIdle());
    properties.put(
        name, "timeBetweenEvictionRunsMillis", jdbcDataSource.getTimeBetweenEvictionRunsMillis());
    properties.put(name, "validationInterval", jdbcDataSource.getValidationInterval());
    properties.put(name, "validationQuery", jdbcDataSource.getValidationQuery());
    properties.put(name, "validatorClassName", jdbcDataSource.getValidatorClassName());
  }