<commit_before>package com.percero.datasource;

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

import javax.sql.DataSource;

import org.apache.log4j.Logger;
import org.springframework.util.StringUtils;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

public class BaseConnectionFactory implements IConnectionFactory {

    private static Logger logger = Logger.getLogger(BaseConnectionFactory.class);

    public static final String HIKARI_CONNECTION_POOL = "hikari";
    public static final String C3P0_CONNECTION_POOL = "c3p0";
    
    private String name;
    private String preferredConnectionPool = HIKARI_CONNECTION_POOL;
    private Integer acquireIncrement = 4;
    private Integer minPoolSize = 4;
    private Integer maxPoolSize = 52;
    private Integer maxIdleTime = 60 * 30; // 30 Minutes
    private String testQuery = "SELECT 1 FROM dual";
    private Integer fetchSize = 100;
    
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPreferredConnectionPool() {
		return preferredConnectionPool;
	}

	public void setPreferredConnectionPool(String preferredConnectionPool) {
		this.preferredConnectionPool = preferredConnectionPool;
	}

	public Integer getAcquireIncrement() {
		return acquireIncrement;
	}

	public void setAcquireIncrement(Integer acquireIncrement) {
		this.acquireIncrement = acquireIncrement;
	}

	public Integer getMinPoolSize() {
		return minPoolSize;
	}

	public void setMinPoolSize(Integer minPoolSize) {
		this.minPoolSize = minPoolSize;
	}

	public Integer getMaxPoolSize() {
		return maxPoolSize;
	}

	public void setMaxPoolSize(Integer maxPoolSize) {
		this.maxPoolSize = maxPoolSize;
	}

	public Integer getMaxIdleTime() {
		return maxIdleTime;
	}

	public void setMaxIdleTime(Integer maxIdleTime) {
		this.maxIdleTime = maxIdleTime;
	}

	public String getTestQuery() {
		return testQuery;
	}

	public void setTestQuery(String testQuery) {
		this.testQuery = testQuery;
	}

	public Integer getFetchSize() {
		// Default to 100;
		if (fetchSize == null || fetchSize <= 0) {
			return 100;
		}
		return fetchSize;
	}

	public void setFetchSize(Integer fetchSize) {
		this.fetchSize = fetchSize;
	}

    private String driverClassName;
    public void setDriverClassName(String val){
        this.driverClassName = val;
    }
    public String getDriverClassName(){
    	return driverClassName;
    }

    private String username;
    public void setUsername(String val){
        this.username = val;
    }
    public String getUsername(){
    	return username;
    }

    private String password;
    public void setPassword(String val){
        this.password = val;
    }
    public String getPassword(){
    	return password;
    }

    private String jdbcUrl;
    public void setJdbcUrl(String val){
        this.jdbcUrl = val;
    }
    public String getJdbcUrl(){
    	return jdbcUrl;
    }

    private DataSource ds;
    public DataSource getDataSource() {
    	return ds;
    }

    public void init() throws PropertyVetoException{
        try {
            if (C3P0_CONNECTION_POOL.equalsIgnoreCase(preferredConnectionPool)) {
                ComboPooledDataSource cpds = new ComboPooledDataSource();
                cpds.setDriverClass(driverClassName); // loads the jdbc driver
                cpds.setJdbcUrl(jdbcUrl);
                cpds.setUser(username);
                cpds.setPassword(password);

                // the settings below are optional -- c3p0 can work with
                // defaults
                if (minPoolSize != null) {
                  cpds.setMinPoolSize(minPoolSize);
                }
                if (acquireIncrement != null) {
                  cpds.setAcquireIncrement(acquireIncrement);
                }
                if (maxPoolSize != null) {
                  cpds.setMaxPoolSize(maxPoolSize);
                }
                if (maxIdleTime != null) {
                  cpds.setMaxIdleTime(maxIdleTime);
                  cpds.setIdleConnectionTestPeriod(maxIdleTime);
                }
                cpds.setNumHelperThreads(30);
                cpds.setTestConnectionOnCheckout(true);
                if (StringUtils.hasText(testQuery)) {
                  cpds.setPreferredTestQuery(testQuery);
                }

                ds = cpds;
              } else {
                // Default to Hikari Connection Pool.
                HikariConfig config = new HikariConfig();
                config.setDriverClassName(driverClassName);<commit_msg>Updating to tell Hikari to register it's MBeans for monitoring.<commit_after>package com.percero.datasource;

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

import javax.sql.DataSource;

import org.apache.log4j.Logger;
import org.springframework.util.StringUtils;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

public class BaseConnectionFactory implements IConnectionFactory {

    private static Logger logger = Logger.getLogger(BaseConnectionFactory.class);

    public static final String HIKARI_CONNECTION_POOL = "hikari";
    public static final String C3P0_CONNECTION_POOL = "c3p0";
    
    private String name;
    private String preferredConnectionPool = HIKARI_CONNECTION_POOL;
    private Integer acquireIncrement = 4;
    private Integer minPoolSize = 4;
    private Integer maxPoolSize = 52;
    private Integer maxIdleTime = 60 * 30; // 30 Minutes
    private String testQuery = "SELECT 1 FROM dual";
    private Integer fetchSize = 100;
    
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPreferredConnectionPool() {
		return preferredConnectionPool;
	}

	public void setPreferredConnectionPool(String preferredConnectionPool) {
		this.preferredConnectionPool = preferredConnectionPool;
	}

	public Integer getAcquireIncrement() {
		return acquireIncrement;
	}

	public void setAcquireIncrement(Integer acquireIncrement) {
		this.acquireIncrement = acquireIncrement;
	}

	public Integer getMinPoolSize() {
		return minPoolSize;
	}

	public void setMinPoolSize(Integer minPoolSize) {
		this.minPoolSize = minPoolSize;
	}

	public Integer getMaxPoolSize() {
		return maxPoolSize;
	}

	public void setMaxPoolSize(Integer maxPoolSize) {
		this.maxPoolSize = maxPoolSize;
	}

	public Integer getMaxIdleTime() {
		return maxIdleTime;
	}

	public void setMaxIdleTime(Integer maxIdleTime) {
		this.maxIdleTime = maxIdleTime;
	}

	public String getTestQuery() {
		return testQuery;
	}

	public void setTestQuery(String testQuery) {
		this.testQuery = testQuery;
	}

	public Integer getFetchSize() {
		// Default to 100;
		if (fetchSize == null || fetchSize <= 0) {
			return 100;
		}
		return fetchSize;
	}

	public void setFetchSize(Integer fetchSize) {
		this.fetchSize = fetchSize;
	}

    private String driverClassName;
    public void setDriverClassName(String val){
        this.driverClassName = val;
    }
    public String getDriverClassName(){
    	return driverClassName;
    }

    private String username;
    public void setUsername(String val){
        this.username = val;
    }
    public String getUsername(){
    	return username;
    }

    private String password;
    public void setPassword(String val){
        this.password = val;
    }
    public String getPassword(){
    	return password;
    }

    private String jdbcUrl;
    public void setJdbcUrl(String val){
        this.jdbcUrl = val;
    }
    public String getJdbcUrl(){
    	return jdbcUrl;
    }

    private DataSource ds;
    public DataSource getDataSource() {
    	return ds;
    }

    public void init() throws PropertyVetoException{
        try {
            if (C3P0_CONNECTION_POOL.equalsIgnoreCase(preferredConnectionPool)) {
                ComboPooledDataSource cpds = new ComboPooledDataSource();
                cpds.setDriverClass(driverClassName); // loads the jdbc driver
                cpds.setJdbcUrl(jdbcUrl);
                cpds.setUser(username);
                cpds.setPassword(password);

                // the settings below are optional -- c3p0 can work with
                // defaults
                if (minPoolSize != null) {
                  cpds.setMinPoolSize(minPoolSize);
                }
                if (acquireIncrement != null) {
                  cpds.setAcquireIncrement(acquireIncrement);
                }
                if (maxPoolSize != null) {
                  cpds.setMaxPoolSize(maxPoolSize);
                }
                if (maxIdleTime != null) {
                  cpds.setMaxIdleTime(maxIdleTime);
                  cpds.setIdleConnectionTestPeriod(maxIdleTime);
                }
                cpds.setNumHelperThreads(30);
                cpds.setTestConnectionOnCheckout(true);
                if (StringUtils.hasText(testQuery)) {
                  cpds.setPreferredTestQuery(testQuery);
                }

                ds = cpds;
              } else {
                // Default to Hikari Connection Pool.
                HikariConfig config = new HikariConfig();
                config.setDriverClassName(driverClassName);
                config.setRegisterMbeans(true);
{'fraction_non_alphanumeric': 0.07656415694591728, 'fraction_numerical': 0.007423117709437964, 'mean_word_length': 2.603744745892243, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6888484', 'n_tokens_mistral': 2851, 'n_tokens_neox': 2644, 'n_words': 621}