@Override
    public DataSource getDataSource(JsonObject config) throws SQLException {
        String url = config.getString("url");
        if (url == null) {
            throw new NullPointerException("url cannot be null");
        }
        String driverClass = config.getString("driver_class");
        String user = config.getString("user");
        String password = config.getString("password");
        Integer maxPoolSize = config.getInteger("max_pool_size");
        Integer initialPoolSize = config.getInteger("initial_pool_size");
        Integer minPoolSize = config.getInteger("min_pool_size");
        Integer maxStatements = config.getInteger("max_statements");
        Integer maxStatementsPerConnection = config.getInteger("max_statements_per_connection");
        Integer maxIdleTime = config.getInteger("max_idle_time");
        Integer acquireRetryAttempts = config.getInteger("acquire_retry_attempts");
        Integer acquireRetryDelay = config.getInteger("acquire_retry_delay");
        Boolean breakAfterAcquireFailure = config.getBoolean("break_after_acquire_failure");

        //add c3p0 params
        String preferredTestQuery = config.getString("preferred_test_query");
        Integer idleConnectionTestPeriod = config.getInteger("idle_connection_test_period");
        Boolean testConnectionOnCheckin = config.getBoolean("test_connection_on_checkin");



        // If you want to configure any other C3P0 properties you can add a file c3p0.properties to the classpath
        ComboPooledDataSource cpds = new ComboPooledDataSource();
        cpds.setJdbcUrl(url);
        if (driverClass != null) {
            try {
                cpds.setDriverClass(driverClass);
            } catch (PropertyVetoException e) {
                throw new IllegalArgumentException(e);
            }
        }
        if (user != null) {
            cpds.setUser(user);
        }
        if (password != null) {
            cpds.setPassword(password);
        }
        if (maxPoolSize != null) {
            cpds.setMaxPoolSize(maxPoolSize);
        }
        if (minPoolSize != null) {
            cpds.setMinPoolSize(minPoolSize);
        }
        if (initialPoolSize != null) {
            cpds.setInitialPoolSize(initialPoolSize);
        }
        if (maxStatements != null) {
            cpds.setMaxStatements(maxStatements);
        }
        if (maxStatementsPerConnection != null) {
            cpds.setMaxStatementsPerConnection(maxStatementsPerConnection);
        }
        if (maxIdleTime != null) {
            cpds.setMaxIdleTime(maxIdleTime);
        }
        if(acquireRetryAttempts != null){
            cpds.setAcquireRetryAttempts(acquireRetryAttempts);
        }
        if(acquireRetryDelay != null){
            cpds.setAcquireRetryDelay(acquireRetryDelay);
        }
        if(breakAfterAcquireFailure != null){
            cpds.setBreakAfterAcquireFailure(breakAfterAcquireFailure);
        }

        if (preferredTestQuery != null) {
            cpds.setPreferredTestQuery(preferredTestQuery);
        }

        if (idleConnectionTestPeriod != null) {
            cpds.setIdleConnectionTestPeriod(idleConnectionTestPeriod);
        }

        if (testConnectionOnCheckin != null) {
            cpds.setTestConnectionOnCheckin(testConnectionOnCheckin);
        }

        return cpds;
    }
Date: 2019/9/17
Company: www.dtstack.com
@author maqi
rdb/rdb-side/src/main/java/com/dtstack/flink/sql/side/rdb/provider/DTC3P0DataSourceProvider.java