<commit_before>package io.minimum.minecraft.superbvote.migration;

import io.minimum.minecraft.superbvote.SuperbVote;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

import java.io.File;
import java.sql.*;
import java.util.UUID;

public class GAListenerMigration implements Migration {
    @Override
    public void execute() {
        File galRoot = new File(SuperbVote.getPlugin().getDataFolder(), ".." + File.separator + "GAListener");
        File galConfig = new File(galRoot, "config.yml");

        if (!galConfig.exists() || !galConfig.isFile()) {
            throw new RuntimeException("GAListener configuration does not exist.");
        }

        FileConfiguration configuration = YamlConfiguration.loadConfiguration(galConfig);

        Connection connection;
        String prefix = configuration.getString("settings.dbPrefix");

        try {
            switch (configuration.getString("settings.dbMode")) {
                case "sqlite":
                    connection = DriverManager.getConnection("jdbc:sqlite:" +
                            new File(galRoot, configuration.getString("settings.dbFile")).getAbsolutePath());
                    break;
                case "mysql":
                    String host = configuration.getString("settings.dbHost");
                    int port = configuration.getInt("settings.dbPort");
                    String user = configuration.getString("settings.dbUser");
                    String pass = configuration.getString("settings.dbPass");
                    String name = configuration.getString("settings.dbName");
                    connection = DriverManager.getConnection(
                            "jdbc:mysql://" + host + ":" + port + "/" + name, user, pass
                    );
                    break;
                default:
                    throw new RuntimeException("'" + configuration.getString("settings.dbMode") + "' is not a supported database");
            }
        } catch (SQLException e) {
            throw new RuntimeException("Unable to open connection to GAListener DB", e);
        }

        try (PreparedStatement statement = connection.prepareStatement("SELECT UUID, votes FROM " + prefix + "GALTotals");
             ResultSet rs = statement.executeQuery()) {
            while (rs.next()) {
                UUID uuid = UUID.fromString(rs.getString(1));
                int votes = rs.getInt(2);

                SuperbVote.getPlugin().getVoteStorage().setVotes(uuid, votes);
            }
        } catch (SQLException e) {
            throw new RuntimeException("Unable to migrate database", e);
        }
    }
}
<commit_msg>Close connection<commit_after>package io.minimum.minecraft.superbvote.migration;

import io.minimum.minecraft.superbvote.SuperbVote;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

import java.io.File;
import java.sql.*;
import java.util.UUID;

public class GAListenerMigration implements Migration {
    @Override
    public void execute() {
        File galRoot = new File(SuperbVote.getPlugin().getDataFolder(), ".." + File.separator + "GAListener");
        File galConfig = new File(galRoot, "config.yml");

        if (!galConfig.exists() || !galConfig.isFile()) {
            throw new RuntimeException("GAListener configuration does not exist.");
        }

        FileConfiguration configuration = YamlConfiguration.loadConfiguration(galConfig);

        Connection connection;
        String prefix = configuration.getString("settings.dbPrefix");

        try {
            switch (configuration.getString("settings.dbMode")) {
                case "sqlite":
                    connection = DriverManager.getConnection("jdbc:sqlite:" +
                            new File(galRoot, configuration.getString("settings.dbFile")).getAbsolutePath());
                    break;
                case "mysql":
                    String host = configuration.getString("settings.dbHost");
                    int port = configuration.getInt("settings.dbPort");
                    String user = configuration.getString("settings.dbUser");
                    String pass = configuration.getString("settings.dbPass");
                    String name = configuration.getString("settings.dbName");
                    connection = DriverManager.getConnection(
                            "jdbc:mysql://" + host + ":" + port + "/" + name, user, pass
                    );
                    break;
                default:
                    throw new RuntimeException("'" + configuration.getString("settings.dbMode") + "' is not a supported database");
            }
        } catch (SQLException e) {
            throw new RuntimeException("Unable to open connection to GAListener DB", e);
        }

        try (PreparedStatement statement = connection.prepareStatement("SELECT UUID, votes FROM " + prefix + "GALTotals");
             ResultSet rs = statement.executeQuery()) {
            while (rs.next()) {
                UUID uuid = UUID.fromString(rs.getString(1));
                int votes = rs.getInt(2);

                SuperbVote.getPlugin().getVoteStorage().setVotes(uuid, votes);
            }
        } catch (SQLException e) {
            throw new RuntimeException("Unable to migrate database", e);
        } finally {
            try {
                connection.close();
            } catch (SQLException ignored) {
                // Ignore. How can we possibly clean this up?!?
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.10916874777024617, 'fraction_numerical': 0.0007135212272565109, 'mean_word_length': 2.0926640926640925, 'pattern_counts': {'":': 6, '<': 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': '3636934', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1312, 'n_words': 303}