示例#1
0
  public static DataSource pooledDataSource(
      DataSource unpooledDataSource, String configName, Map overrideProps) throws SQLException {
    try {
      WrapperConnectionPoolDataSource wcpds = new WrapperConnectionPoolDataSource(configName);
      wcpds.setNestedDataSource(unpooledDataSource);
      if (overrideProps != null)
        BeansUtils.overwriteAccessiblePropertiesFromMap(
            overrideProps, wcpds, false, null, true, MLevel.WARNING, MLevel.WARNING, false);

      PoolBackedDataSource nascent_pbds = new PoolBackedDataSource(configName);
      nascent_pbds.setConnectionPoolDataSource(wcpds);
      if (overrideProps != null)
        BeansUtils.overwriteAccessiblePropertiesFromMap(
            overrideProps, nascent_pbds, false, null, true, MLevel.WARNING, MLevel.WARNING, false);

      return nascent_pbds;
    }
    // 	catch ( PropertyVetoException e )
    // 	    {
    // 		e.printStackTrace();
    // 		PropertyChangeEvent evt = e.getPropertyChangeEvent();
    // 		throw new SQLException("Illegal value attempted for property " + evt.getPropertyName() + ":
    // " + evt.getNewValue());
    // 	    }
    catch (Exception e) {
      // e.printStackTrace();
      SQLException sqle =
          SqlUtils.toSQLException("Exception configuring pool-backed DataSource: " + e, e);
      if (Debug.DEBUG
          && Debug.TRACE >= Debug.TRACE_MED
          && logger.isLoggable(MLevel.FINE)
          && e != sqle) logger.log(MLevel.FINE, "Converted exception to throwable SQLException", e);
      throw sqle;
    }
  }
示例#2
0
  /**
   * Creates a pooled version of an unpooled DataSource using configuration information supplied
   * explicitly by a {@link com.mchange.v2.c3p0.PoolConfig}.
   *
   * @return a DataSource that can be cast to a {@link PooledDataSource} if you are interested in
   *     pool statistics
   * @deprecated if you want to set properties programmatically, please construct a
   *     ComboPooledDataSource and set its properties rather than using PoolConfig
   */
  public static DataSource pooledDataSource(DataSource unpooledDataSource, PoolConfig pcfg)
      throws SQLException {
    try {
      WrapperConnectionPoolDataSource wcpds = new WrapperConnectionPoolDataSource();
      wcpds.setNestedDataSource(unpooledDataSource);

      // set PoolConfig info -- WrapperConnectionPoolDataSource properties
      BeansUtils.overwriteSpecificAccessibleProperties(
          pcfg, wcpds, WRAPPER_CXN_POOL_DATA_SOURCE_OVERWRITE_PROPS);

      PoolBackedDataSource nascent_pbds = new PoolBackedDataSource();
      nascent_pbds.setConnectionPoolDataSource(wcpds);
      BeansUtils.overwriteSpecificAccessibleProperties(
          pcfg, nascent_pbds, POOL_BACKED_DATA_SOURCE_OVERWRITE_PROPS);

      return nascent_pbds;
    }
    // 	catch ( PropertyVetoException e )
    // 	    {
    // 		e.printStackTrace();
    // 		PropertyChangeEvent evt = e.getPropertyChangeEvent();
    // 		throw new SQLException("Illegal value attempted for property " + evt.getPropertyName() + ":
    // " + evt.getNewValue());
    // 	    }
    catch (Exception e) {
      // e.printStackTrace();
      SQLException sqle =
          SqlUtils.toSQLException("Exception configuring pool-backed DataSource: " + e, e);
      if (Debug.DEBUG
          && Debug.TRACE >= Debug.TRACE_MED
          && logger.isLoggable(MLevel.FINE)
          && e != sqle) logger.log(MLevel.FINE, "Converted exception to throwable SQLException", e);
      throw sqle;
    }
  }