<commit_before>package uk.co.byteindustries.bytecore.storage;

import com.sun.rowset.CachedRowSetImpl;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.bukkit.Bukkit;
import uk.co.byteindustries.bytecore.ByteCore;

import javax.sql.rowset.CachedRowSet;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.concurrent.*;

public abstract class Database {

    private HikariDataSource dataSource;

    /**
     * Initialize a Database connection.
     *
     * @param className Database type to connect to.
     * @param jdbcURL JDBC url to connect to.
     * @param username Username to log in with.
     * @param password <PASSWORD>.
     */
    protected Database(String className, String jdbcURL, String username, String password) {
        try {
            Class.forName(className);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            return;
        }

        HikariConfig config = new HikariConfig();

        config.setJdbcUrl(jdbcURL);

        config.setUsername(username);
        config.setPassword(password);

        config.setLeakDetectionThreshold(10000);
        config.setMaxLifetime(25000);
        config.setIdleTimeout(20000);
        config.setMaximumPoolSize(5);
        config.setConnectionTimeout(10000);
        config.setInitializationFailFast(false);

        try {
            dataSource = new HikariDataSource(config);
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (getConnection() == null) {
            ByteCore.PLUGIN.getLogger().severe("[ByteCore] " + ByteCore.PLUGIN.getName() + " was unable to connect to the database");
        }
    }

    /**
     * Close all current connections and disconnect from the database.
     */
    public void disconnect() {
        dataSource.close();
    }

    /**
     * Query the database.
     *
     * @param preparedStatement Query to submit.
     * @return A CachedRowSet with data from query, or null when an error has occurred.
     */
    public CachedRowSet query(final PreparedStatement preparedStatement) {

        try {
            ResultSet resultSet = preparedStatement.executeQuery();

            CachedRowSet cachedRowSet = new CachedRowSetImpl();
            cachedRowSet.populate(resultSet);
            resultSet.close();
            if(cachedRowSet.size() > 0) return cachedRowSet;
        } catch (SQLException e) {
            e.printStackTrace();
        }<commit_msg>Fixed another connection leak.<commit_after>package uk.co.byteindustries.bytecore.storage;

import com.sun.rowset.CachedRowSetImpl;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.bukkit.Bukkit;
import uk.co.byteindustries.bytecore.ByteCore;

import javax.sql.rowset.CachedRowSet;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.concurrent.*;

public abstract class Database {

    private HikariDataSource dataSource;

    /**
     * Initialize a Database connection.
     *
     * @param className Database type to connect to.
     * @param jdbcURL JDBC url to connect to.
     * @param username Username to log in with.
     * @param password <PASSWORD>.
     */
    protected Database(String className, String jdbcURL, String username, String password) {
        try {
            Class.forName(className);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            return;
        }

        HikariConfig config = new HikariConfig();

        config.setJdbcUrl(jdbcURL);

        config.setUsername(username);
        config.setPassword(password);

        config.setLeakDetectionThreshold(10000);
        config.setMaxLifetime(25000);
        config.setIdleTimeout(20000);
        config.setMaximumPoolSize(5);
        config.setConnectionTimeout(10000);
        config.setInitializationFailFast(false);

        try {
            dataSource = new HikariDataSource(config);
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (getConnection() == null) {
            ByteCore.PLUGIN.getLogger().severe("[ByteCore] " + ByteCore.PLUGIN.getName() + " was unable to connect to the database");
        }
    }

    /**
     * Close all current connections and disconnect from the database.
     */
    public void disconnect() {
        dataSource.close();
    }

    /**
     * Query the database.
     *
     * @param preparedStatement Query to submit.
     * @return A CachedRowSet with data from query, or null when an error has occurred.
     */
    public CachedRowSet query(final PreparedStatement preparedStatement) {

        try {
            ResultSet resultSet = preparedStatement.executeQuery();

            CachedRowSet cachedRowSet = new CachedRowSetImpl();
            cachedRowSet.populate(resultSet);
            resultSet.close();
            preparedStatement.getConnection().close();
            if(cachedRowSet.size() > 0) return cachedRowSet;
        } catch (SQLException e) {

            e.printStackTrace();
            try {
                preparedStatement.getConnection().close();
            } catch (SQLException e1) {
                e1.printStackTrace();
            }
        }
{'fraction_non_alphanumeric': 0.09524693650204233, 'fraction_numerical': 0.008540660972892685, 'mean_word_length': 2.475483870967742, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '3956191', 'n_tokens_mistral': 1516, 'n_tokens_neox': 1445, 'n_words': 342}