<commit_before>package com.codacy.play.tomcatcp.pool;

import com.codacy.play.tomcatcp.metrics.MetricsTrackerFactory;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.health.HealthCheckRegistry;
import org.apache.tomcat.jdbc.pool.ConnectionPool;
import org.apache.tomcat.jdbc.pool.DataSource;
import org.apache.tomcat.jdbc.pool.PoolConfiguration;

import java.sql.SQLException;

public class TomcatCPDataSource extends DataSource {

    private MetricsTrackerFactory metricsTrackerFactory;
    private MetricRegistry metricRegistry;
    private HealthCheckRegistry healthCheckRegistry;
    private TomcatCPPool TCPool;


    public TomcatCPDataSource() {
        super();
    }


    public TomcatCPDataSource(PoolConfiguration poolProperties) {
        super(poolProperties);
    }

    @Override
    public ConnectionPool createPool() throws SQLException {
        if (pool != null) {
            return pool;
        } else {
            TCPool = new TomcatCPPool(poolProperties);
            pool = TCPool;
            return pool;
        }
    }


    public MetricRegistry getMetricRegistry() {
        return metricRegistry;
    }

    public void setMetricRegistry(MetricRegistry metricRegistry) {
        if (metricsTrackerFactory != null) {
            throw new IllegalStateException("cannot use setMetricRegistry() and setMetricsTrackerFactory() together");
        }

        boolean isAlreadySet = getMetricRegistry() != null;

        if (pool != null) {
            if (isAlreadySet) {
                throw new IllegalStateException("MetricRegistry can only be set one time");
            } else {
                TCPool.setMetricRegistry(metricRegistry);
            }
        }

        this.metricRegistry = metricRegistry;
    }

    public MetricsTrackerFactory getMetricsTrackerFactory() {
        return metricsTrackerFactory;
    }

    public void setMetricsTrackerFactory(MetricsTrackerFactory metricsTrackerFactory) {
        if (metricRegistry != null) {
            throw new IllegalStateException("cannot use setMetricsTrackerFactory() and setMetricRegistry() together");
        }

        boolean isAlreadySet = getMetricsTrackerFactory() != null;

        if (pool != null) {
            if (isAlreadySet) {
                throw new IllegalStateException("MetricsTrackerFactory can only be set one time");
            } else {
                TCPool.setMetricsTrackerFactory(metricsTrackerFactory);
            }
        }

        this.metricsTrackerFactory = metricsTrackerFactory;
    }

    public HealthCheckRegistry getHealthCheckRegistry() {
        return healthCheckRegistry;
    }

    public void setHealthCheckRegistry(HealthCheckRegistry healthCheckRegistry) {
        boolean isAlreadySet = getHealthCheckRegistry() != null;

        if (pool != null) {
            if (isAlreadySet) {
                throw new IllegalStateException("HealthCheckRegistry can only be set one time");
            } else {
                TCPool.setHealthCheckRegistry(healthCheckRegistry);
            }
        }

        this.healthCheckRegistry = healthCheckRegistry;
    }

}
<commit_msg>Add pool creation if not created yet<commit_after>package com.codacy.play.tomcatcp.pool;

import com.codacy.play.tomcatcp.metrics.MetricsTrackerFactory;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.health.HealthCheckRegistry;
import org.apache.tomcat.jdbc.pool.ConnectionPool;
import org.apache.tomcat.jdbc.pool.DataSource;
import org.apache.tomcat.jdbc.pool.PoolConfiguration;

import java.sql.SQLException;

public class TomcatCPDataSource extends DataSource {

    private MetricsTrackerFactory metricsTrackerFactory;
    private MetricRegistry metricRegistry;
    private HealthCheckRegistry healthCheckRegistry;
    private TomcatCPPool TCPool;


    public TomcatCPDataSource() {
        super();
    }


    public TomcatCPDataSource(PoolConfiguration poolProperties) {
        super(poolProperties);
    }

    @Override
    public ConnectionPool createPool() throws SQLException {
        if (pool != null) {
            return pool;
        } else {
            TCPool = new TomcatCPPool(poolProperties);
            pool = TCPool;
            return pool;
        }
    }


    public MetricRegistry getMetricRegistry() {
        return metricRegistry;
    }

    public void setMetricRegistry(MetricRegistry metricRegistry) {
        if (metricsTrackerFactory != null) {
            throw new IllegalStateException("cannot use setMetricRegistry() and setMetricsTrackerFactory() together");
        }

        boolean isAlreadySet = getMetricRegistry() != null;

        if (getPool() != null) {
            if (isAlreadySet) {
                throw new IllegalStateException("MetricRegistry can only be set one time");
            } else {
                TCPool.setMetricRegistry(metricRegistry);
            }
        }

        this.metricRegistry = metricRegistry;
    }

    public MetricsTrackerFactory getMetricsTrackerFactory() {
        return metricsTrackerFactory;
    }

    public void setMetricsTrackerFactory(MetricsTrackerFactory metricsTrackerFactory) {
        if (metricRegistry != null) {
            throw new IllegalStateException("cannot use setMetricsTrackerFactory() and setMetricRegistry() together");
        }

        boolean isAlreadySet = getMetricsTrackerFactory() != null;

        if (getPool() != null) {
            if (isAlreadySet) {
                throw new IllegalStateException("MetricsTrackerFactory can only be set one time");
            } else {
                TCPool.setMetricsTrackerFactory(metricsTrackerFactory);
            }
        }

        this.metricsTrackerFactory = metricsTrackerFactory;
    }

    public HealthCheckRegistry getHealthCheckRegistry() {
        return healthCheckRegistry;
    }

    public void setHealthCheckRegistry(HealthCheckRegistry healthCheckRegistry) {
        boolean isAlreadySet = getHealthCheckRegistry() != null;

        if (getPool() != null) {
            if (isAlreadySet) {
                throw new IllegalStateException("HealthCheckRegistry can only be set one time");
            } else {
                TCPool.setHealthCheckRegistry(healthCheckRegistry);
            }
        }

        this.healthCheckRegistry = healthCheckRegistry;
    }

}

{'fraction_non_alphanumeric': 0.07422615287428933, 'fraction_numerical': 0.0, 'mean_word_length': 2.662810873337189, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4333804', 'n_tokens_mistral': 1573, 'n_tokens_neox': 1496, 'n_words': 354}