Beispiel #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;
    }
  }
Beispiel #2
0
  public static void main(String[] argv) {
    if (argv.length > 0) {
      System.err.println(
          TestRefSerStuff.class.getName()
              + " now requires no args. Please set everything in standard c3p0 config files.");
      return;
    }

    /*
    String jdbcUrl = null;
    String username = null;
    String password = null;
    if (argv.length == 3)
        {
    	jdbcUrl = argv[0];
    	username = argv[1];
    	password = argv[2];
        }
    else if (argv.length == 1)
        {
    	jdbcUrl = argv[0];
    	username = null;
    	password = null;
        }
    else
        usage();

    if (! jdbcUrl.startsWith("jdbc:") )
        usage();
    */

    try {
      DriverManagerDataSource dmds = new DriverManagerDataSource();
      // dmds.setJdbcUrl( jdbcUrl );
      // dmds.setUser( username );
      // dmds.setPassword( password );
      try {
        drop(dmds);
      } catch (Exception e) {
        /* Ignore */
      }
      create(dmds);

      System.err.println("DriverManagerDataSource:");
      doTest(dmds);

      WrapperConnectionPoolDataSource wcpds = new WrapperConnectionPoolDataSource();
      wcpds.setNestedDataSource(dmds);
      PoolBackedDataSource pbds = new PoolBackedDataSource();
      pbds.setConnectionPoolDataSource(wcpds);

      System.err.println("PoolBackedDataSource:");
      doTest(pbds);

      ComboPooledDataSource cpds = new ComboPooledDataSource();
      doTest(cpds);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Beispiel #3
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;
    }
  }