package pond.db.connpool;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import pond.common.f.Callback;
import pond.common.f.Function;

import java.beans.PropertyVetoException;
import java.sql.Connection;

/**
 * Created by ed on 12/18/15.
 */
class C3p0ConnectionPool extends AbstractConnectionPool {

  final ComboPooledDataSource cpds = new ComboPooledDataSource();
  C3p0ConnectionPool() {}

  @Override
  Function.F0ERR<Connection> build() {

//    cpds.setProperties(properties);

    try {
      cpds.setDriverClass(jdbc_driver); //loads the jdbc driver
    } catch (PropertyVetoException e) {
      throw new RuntimeException("jdbc init fail", e.getCause());
    }

    cpds.setJdbcUrl(conn_url);

    cpds.setUser(username);
    cpds.setPassword(password);

    cpds.setMaxPoolSize(max_size);
    cpds.setMaxStatements(20 * max_size);

//
//    //test every 60s
//    cpds.setIdleConnectionTestPeriod(60);
//
//    //wait 3000ms to get the connection or fail
//    cpds.setCheckoutTimeout(3000);
//
////    cpds.setAcquireIncrement(10);
//    cpds.setMaxIdleTime(300);
//
//    //pstmt cache

    return cpds::getConnection;
  }

  public ComboPooledDataSource rawC3p0(){
    return cpds;
  }
}

@@ -842,21 +842,17 @@
 size);%0A%0A
-//%0A//
+%0A
     //te
@@ -864,18 +864,16 @@
 ery 60s%0A
-//
     cpds
@@ -902,29 +902,25 @@
 Period(60);%0A
-//%0A//
+%0A
     //wait 3
@@ -955,18 +955,16 @@
 or fail%0A
-//
     cpds
@@ -990,21 +990,17 @@
 (3000);%0A
-//
 %0A
-//
 //    cp
@@ -1027,18 +1027,16 @@
 nt(10);%0A
-//
     cpds
@@ -1061,13 +1061,9 @@
 0);%0A
-//%0A//
+%0A
     

revert connectionpool config