Example #1
0
  private static void configureJdbcPool(
      Map<String, PoolingDataSource> dataSources, Set<ResourceBean> started, Configuration config)
      throws ConfigurationException {
    PoolingDataSource ds = new PoolingDataSource();
    final String uniqueName = confgureResourceBean(ds, config);

    for (Configuration child : config.getChildren()) {
      switch (child.getName()) {
        case "testQuery":
          ds.setTestQuery(child.getValue());
          break;
        case "enableJdbc4ConnectionTest":
          ds.setEnableJdbc4ConnectionTest(child.getValueAsBoolean());
          break;
        case "preparedStatementCacheSize":
          ds.setPreparedStatementCacheSize(child.getValueAsInteger());
          break;
        case "isolationLevel":
          ds.setIsolationLevel(child.getValue());
          break;
        case "cursorHoldability":
          ds.setCursorHoldability(child.getValue());
          break;
        case "localAutoCommit":
          ds.setLocalAutoCommit(child.getValue());
          break;
        case "driverProperties":
          configureDriverProperties(ds.getDriverProperties(), child);
          break;
        default:
          if (!RESOURCE_BEAN_PROPERTIES.contains(child.getName())) {
            throw new ConfigurationException(
                "unsupported element " + child.getName(), child.getPath(), child.getLocation());
          }
      }
    }

    if (config.getAttributeAsBoolean("eager", false)) {
      ds.init();
      started.add(ds);
    }
    dataSources.put(uniqueName, ds);
  }