Package com.mchange.v2.c3p0

Examples of com.mchange.v2.c3p0.ComboPooledDataSource


    {
  try
      {
        cpds.setIdentityToken("poop"); //simulate a never-before-seen data source, so it's a new registration on deserialization
    byte[] pickled = SerializableUtils.toByteArray(cpds);
    ComboPooledDataSource unpickled = (ComboPooledDataSource) SerializableUtils.fromByteArray( pickled );
    assertTrue( "Marshalled and unmarshalled DataSources should have the same properties!",
          BeansUtils.equalsByAccessibleProperties( cpds, unpickled, EXCLUDE_PROPS ) );
      }
  catch (Exception e)
      {
View Full Code Here


    {
  try
      {
        cpds.setIdentityToken("scoop"); //simulate a never-before-seen data source, so it's a new registration on deserialization
    Reference ref = cpds.getReference();
    ComboPooledDataSource unpickled = (ComboPooledDataSource) ReferenceableUtils.referenceToObject( ref, null, null, null );
    assertTrue( "Marshalled and unmarshalled DataSources should have the same properties!",
          BeansUtils.equalsByAccessibleProperties( cpds, unpickled, EXCLUDE_PROPS ) );
      }
  catch (Exception e)
      {
View Full Code Here

        // set the JMX domain for the C3P0
        C3P0CustomManagementCoordinator.setJmxDomainOnce(config.getJmxDomain());

        // create a new instance of the c3p0 datasource
        ComboPooledDataSource cpds = new ComboPooledDataSource(true);

        // set properties
        try {
            // set required properties
            cpds.setDriverClass(config.getDriver());
            cpds.setUser(config.getUsername());
            cpds.setPassword(config.getPassword());
            cpds.setJdbcUrl(config.getUrl());

            // set optional properties
            cpds.setDataSourceName(config.getName());
            cpds.setMinPoolSize(config.getMinPoolSize());
            cpds.setMaxPoolSize(config.getMaxPoolSize());
            // we'll set the initial pool size to the minimum size
            cpds.setInitialPoolSize(config.getMinPoolSize());

            // set the validation query
            cpds.setPreferredTestQuery(config.getValidationQuery());

            // amount of time (in ms) to wait for getConnection() to succeed
            cpds.setCheckoutTimeout((int)config.getCheckoutTimeout());

            // checkin validation
            cpds.setTestConnectionOnCheckin(config.getValidateOnCheckin());

            // checkout validation
            cpds.setTestConnectionOnCheckout(config.getValidateOnCheckout());

            // amount of time to wait to validate connections
            // NOTE: in seconds
            int seconds = (int)(config.getValidateIdleConnectionTimeout()/1000);
            cpds.setIdleConnectionTestPeriod(seconds);

            // set idleConnectionTimeout
            // NOTE: in seconds
            seconds = (int)(config.getIdleConnectionTimeout()/1000);
            cpds.setMaxIdleTimeExcessConnections(seconds);

            // set activeConnectionTimeout
            seconds = (int)(config.getActiveConnectionTimeout()/1000);
            cpds.setUnreturnedConnectionTimeout(seconds);

            if (config.getDebug()) {
                cpds.setDebugUnreturnedConnectionStackTraces(true);
            } else {
                cpds.setDebugUnreturnedConnectionStackTraces(false);
            }

            // properties I think aren't valid for c3p0
            // defines how many times c3p0 will try to acquire a new Connection from the database before giving up.
            cpds.setAcquireRetryAttempts(10);

        } catch (PropertyVetoException e) {
            throw new SQLConfigurationException("Property was vetoed during configuration", e);
        }
View Full Code Here

    private ThreadCategory log() {
        return ThreadCategory.getInstance(getClass());
    }

    private void initializePool(String jdbcUrl, String driverClass, String user, String password) throws PropertyVetoException, SQLException {
        m_pool = new ComboPooledDataSource();
        m_pool.setPassword(password);
        m_pool.setUser(user);
        m_pool.setJdbcUrl(jdbcUrl);
        m_pool.setDriverClass(driverClass);
View Full Code Here

   private ComboPooledDataSource pooledDataSource;

   @Override
   public void start(ConnectionFactoryConfig config) throws CacheLoaderException {
      logFileOverride();
      pooledDataSource = new ComboPooledDataSource();
      pooledDataSource.setProperties(new Properties());
      try {
         pooledDataSource.setDriverClass(config.getDriverClass()); //loads the jdbc driver
      } catch (PropertyVetoException e) {
         String message = "Error while instatianting JDBC driver: '" + config.getDriverClass();
View Full Code Here

      }
      else {
         throw new PersistenceException("ConnectionFactoryConfiguration passed in must be an instance of " +
               "PooledConnectionFactoryConfiguration");
      }
      pooledDataSource = new ComboPooledDataSource();
      pooledDataSource.setProperties(new Properties());
      try {
         /* Since c3p0 does not throw an exception when it fails to load a driver we attempt to do so here
          * Also, c3p0 does not allow specifying a custom classloader, so use c3p0's
          */
 
View Full Code Here

   private ComboPooledDataSource pooledDataSource;

   @Override
   public void start(ConnectionFactoryConfig config) throws CacheLoaderException {
      logFileOverride();
      pooledDataSource = new ComboPooledDataSource();
      pooledDataSource.setProperties(new Properties());
      try {
         pooledDataSource.setDriverClass(config.getDriverClass()); //loads the jdbc driver
      } catch (PropertyVetoException e) {
         String message = "Error while instatianting JDBC driver: '" + config.getDriverClass();
View Full Code Here

public class OracleMonitoringDbDialectTest extends MonitoringDbDialectTestBase{

  @Override
  void intit() {
 
    ComboPooledDataSource datasource_oracle = new ComboPooledDataSource();
    try {
      datasource_oracle.setDriverClass("oracle.jdbc.OracleDriver");
      datasource_oracle.setJdbcUrl("jdbc:oracle:thin:COPPER2/COPPER2@localhost:1521:HM");
      datasource_oracle.setMinPoolSize(1);
      datasource_oracle.setMaxPoolSize(8);
      datasource_oracle.setConnectionTesterClassName("de.scoopgmbh.copper.db.utility.oracle.c3p0.OracleConnectionTester");
      datasource_oracle.setConnectionCustomizerClassName("de.scoopgmbh.copper.db.utility.oracle.c3p0.OracleConnectionCustomizer");
      datasource_oracle.setIdleConnectionTestPeriod(15);
    } catch (PropertyVetoException e1) {
      throw new RuntimeException(e1);
    }
    this.datasource=datasource_oracle;
   
View Full Code Here

   */
  public SqlDao(final Properties properties) {
    super(properties);
   
    // Attempt to create the DataSource.
    ComboPooledDataSource comboPooledDataSource =
      new ComboPooledDataSource();
   
    // Set the properties from the properties file (the ones that begin
    // with "c3p0").
    comboPooledDataSource.setProperties(properties);

    // Attempt to load the driver to be used to connect to the database.
    if(properties.containsKey(KEY_PROPERTY_DATABASE_DRIVER)) {
      try {
        comboPooledDataSource
          .setDriverClass(
            properties.getProperty(KEY_PROPERTY_DATABASE_DRIVER));
      }
      catch(PropertyVetoException e) {
        LOGGER.log(Level.SEVERE, "The driver was rejected.", e);
        throw new IllegalStateException("The driver was rejected.", e);
      }
    }
    // Otherwise, we may error out.
    else {
      LOGGER
        .log(
          Level.SEVERE,
          "For SQL database connections, a driver must be " +
            "specified.");
    }
   
    // If the JDBC URL was given, use that.
    if(properties.containsKey(KEY_PROPERTY_DATABASE_JDBC_URL)) {
      comboPooledDataSource
        .setJdbcUrl(
          properties.getProperty(KEY_PROPERTY_DATABASE_JDBC_URL));
    }
    // Otherwise, ask the specific implementation for a default URL.
    else {
      comboPooledDataSource.setJdbcUrl(getJdbcUrl());
    }
   
    // Set the username and password.
    comboPooledDataSource.setUser(getDatabaseUsername());
    comboPooledDataSource.setPassword(getDatabasePassword());
   
    // Save the data source.
    dataSource = comboPooledDataSource;
   
    // Create the JDBC template from the data source.
View Full Code Here

        @Override
        protected ComboPooledDataSource setupDataSourcePool( DataSourceConfigurationValue config )
                throws Exception
        {
            ComboPooledDataSource pool = new ComboPooledDataSource();

            Class.forName( config.driver().get() );
            pool.setDriverClass( config.driver().get() );
            pool.setJdbcUrl( config.url().get() );

            if ( !config.username().get().equals( "" ) ) {
                pool.setUser( config.username().get() );
                pool.setPassword( config.password().get() );
            }

            if ( config.minPoolSize().get() != null ) {
                pool.setMinPoolSize( config.minPoolSize().get() );
            }
            if ( config.maxPoolSize().get() != null ) {
                pool.setMaxPoolSize( config.maxPoolSize().get() );
            }
            if ( config.loginTimeoutSeconds().get() != null ) {
                pool.setLoginTimeout( config.loginTimeoutSeconds().get() );
            }
            if ( config.maxConnectionAgeSeconds().get() != null ) {
                pool.setMaxIdleTime( config.maxConnectionAgeSeconds().get() );
            }
            if ( config.validationQuery().get() != null ) {
                pool.setPreferredTestQuery( config.validationQuery().get() );
            }

            String props = config.properties().get();
            String[] properties = props.split( "," );
            Properties poolProperties = new Properties();
            for ( String property : properties ) {
                if ( property.trim().length() > 0 ) {
                    String[] keyvalue = property.trim().split( "=" );
                    poolProperties.setProperty( keyvalue[0], keyvalue[1] );
                }
            }
            pool.setProperties( poolProperties );

            return pool;
        }
View Full Code Here

TOP

Related Classes of com.mchange.v2.c3p0.ComboPooledDataSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.