<commit_before>package com.lenis0012.bukkit.loginsecurity.modules.storage;

import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.EbeanServerFactory;
import com.avaje.ebean.LogLevel;
import com.avaje.ebean.config.DataSourceConfig;
import com.avaje.ebean.config.ServerConfig;
import com.avaje.ebean.config.dbplatform.SQLitePlatform;
import com.avaje.ebeaninternal.api.SpiEbeanServer;
import com.avaje.ebeaninternal.server.ddl.DdlGenerator;
import com.avaje.ebeaninternal.server.lib.sql.TransactionIsolation;
import com.google.common.collect.Lists;
import com.lenis0012.bukkit.loginsecurity.LoginSecurity;
import com.lenis0012.bukkit.loginsecurity.storage.Migration;
import com.lenis0012.bukkit.loginsecurity.storage.PlayerProfile;
import com.lenis0012.bukkit.loginsecurity.util.ProfileUtil;
import com.lenis0012.bukkit.loginsecurity.util.UserIdMode;
import com.lenis0012.pluginutils.Module;
import com.lenis0012.pluginutils.modules.configuration.Configuration;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

import javax.persistence.PersistenceException;
import java.io.*;
import java.lang.reflect.Method;
import java.sql.Timestamp;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.regex.Pattern;

public class StorageModule extends Module<LoginSecurity> implements Comparator<String> {
    private EbeanServer database;
    private boolean mysql;
    private List<String> migrations;

    public StorageModule(LoginSecurity plugin) {
        super(plugin);
    }

    @Override
    public void enable() {
        // Load config
        File file = new File(plugin.getDataFolder(), "database.yml");
        if(!file.exists()) {
            copyFile(plugin.getResource("database.yml"), file);
        }
        Configuration config = new Configuration(file);
        config.reload(true);

        // Check config for mysql settings
        FileConfiguration conf = plugin.getConfig();
        if(conf.contains("MySQL")) {
            // Rewrite mysql settings
            config.set("mysql.enabled", conf.getBoolean("MySQL.use"));
            String host = conf.getString("MySQL.host", "localhost") + ":" + conf.getInt("MySQL.port", 3306);
            config.set("mysql.host", host);
            config.set("mysql.username", conf.getString("MySQL.username"));
            config.set("mysql.password", config.getString("MySQL.password"));
            config.set("mysql.database", config.getString("MySQL.database"));
            config.save();

            // Cleanup old config
            conf.set("MySQL", null);
            conf.set("settings", null);
            plugin.saveConfig();
        }

        // Server settings
        ServerConfig server = new ServerConfig();
        server.setDefaultServer(false);
        server.setRegister(false);
        server.setClasses(plugin.getDatabaseClasses());
        server.setName("LoginSecurityDB");
        server.setLoggingLevel(LogLevel.NONE);

        // Datasource settings
        DataSourceConfig source = new DataSourceConfig();
        final int isolation = TransactionIsolation.getLevel(config.getString("isolation"));
        this.mysql = config.getBoolean("mysql.enabled");
        source.setDriver(mysql ? "com.mysql.jdbc.Driver" : "org.sqlite.JDBC");
        source.setIsolationLevel(isolation);
        source.setHeartbeatSql("select 1");
        if(mysql) {
            source.setUrl(String.format("jdbc:mysql://%s/%s", config.getString("mysql.host"), config.getString("mysql.database")));
            source.setUsername(config.getString("mysql.username"));
            source.setPassword(config.getString("mysql.password"));
            System.out.println("MYSQL");
        } else {
            server.setDatabasePlatform(new SQLitePlatform());
            server.getDatabasePlatform().getDbDdlSyntax().setIdentity("");
            String path = plugin.getDataFolder().getPath().replaceAll("\\\\", "/");
            source.setUrl("jdbc:sqlite:" + path + "/LoginSecurity.db");
            source.setUsername("trump");
            source.setPassword("<PASSWORD>");
        }
        server.setDataSourceConfig(source);

        // Create server
        plugin.getLogger().log(Level.INFO, "Connection to database....");
        ClassLoader previous = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(getClassLoader());
        this.database = EbeanServerFactory.create(server);
        Thread.currentThread().setContextClassLoader(previous);

        // List migrations
        this.migrations = Lists.newArrayList();
        try {
            JarFile jarFile = new JarFile(getPluginFile());
            Enumeration<JarEntry> entries = jarFile.entries();
            while(entries.hasMoreElements()) {
                JarEntry entry = entries.nextElement();
                if(entry.getName().startsWith("sql/sqlite/") && entry.getName().contains("__")) {
                    migrations.add(entry.getName().substring("sql/sqlite/".length()));
                }
            }<commit_msg>try to disable ebean logging<commit_after>package com.lenis0012.bukkit.loginsecurity.modules.storage;

import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.EbeanServerFactory;
import com.avaje.ebean.LogLevel;
import com.avaje.ebean.config.DataSourceConfig;
import com.avaje.ebean.config.ServerConfig;
import com.avaje.ebean.config.dbplatform.SQLitePlatform;
import com.avaje.ebeaninternal.api.SpiEbeanServer;
import com.avaje.ebeaninternal.server.ddl.DdlGenerator;
import com.avaje.ebeaninternal.server.lib.sql.TransactionIsolation;
import com.google.common.collect.Lists;
import com.lenis0012.bukkit.loginsecurity.LoginSecurity;
import com.lenis0012.bukkit.loginsecurity.storage.Migration;
import com.lenis0012.bukkit.loginsecurity.storage.PlayerProfile;
import com.lenis0012.bukkit.loginsecurity.util.ProfileUtil;
import com.lenis0012.bukkit.loginsecurity.util.UserIdMode;
import com.lenis0012.pluginutils.Module;
import com.lenis0012.pluginutils.modules.configuration.Configuration;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

import javax.persistence.PersistenceException;
import java.io.*;
import java.lang.reflect.Method;
import java.sql.Timestamp;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.regex.Pattern;

public class StorageModule extends Module<LoginSecurity> implements Comparator<String> {
    private EbeanServer database;
    private boolean mysql;
    private List<String> migrations;

    public StorageModule(LoginSecurity plugin) {
        super(plugin);
    }

    @Override
    public void enable() {
        // Load config
        File file = new File(plugin.getDataFolder(), "database.yml");
        if(!file.exists()) {
            copyFile(plugin.getResource("database.yml"), file);
        }
        Configuration config = new Configuration(file);
        config.reload(true);

        // Check config for mysql settings
        FileConfiguration conf = plugin.getConfig();
        if(conf.contains("MySQL")) {
            // Rewrite mysql settings
            config.set("mysql.enabled", conf.getBoolean("MySQL.use"));
            String host = conf.getString("MySQL.host", "localhost") + ":" + conf.getInt("MySQL.port", 3306);
            config.set("mysql.host", host);
            config.set("mysql.username", conf.getString("MySQL.username"));
            config.set("mysql.password", config.getString("MySQL.password"));
            config.set("mysql.database", config.getString("MySQL.database"));
            config.save();

            // Cleanup old config
            conf.set("MySQL", null);
            conf.set("settings", null);
            plugin.saveConfig();
        }

        // Server settings
        ServerConfig server = new ServerConfig();
        server.setDefaultServer(false);
        server.setRegister(false);
        server.setClasses(plugin.getDatabaseClasses());
        server.setName("LoginSecurityDB");
        server.setLoggingLevel(LogLevel.NONE);
        server.setEnhanceLogLevel(0);

        // Datasource settings
        DataSourceConfig source = new DataSourceConfig();
        final int isolation = TransactionIsolation.getLevel(config.getString("isolation"));
        this.mysql = config.getBoolean("mysql.enabled");
        source.setDriver(mysql ? "com.mysql.jdbc.Driver" : "org.sqlite.JDBC");
        source.setIsolationLevel(isolation);
        source.setHeartbeatSql("select 1");
        if(mysql) {
            source.setUrl(String.format("jdbc:mysql://%s/%s", config.getString("mysql.host"), config.getString("mysql.database")));
            source.setUsername(config.getString("mysql.username"));
            source.setPassword(config.getString("mysql.password"));
            System.out.println("MYSQL");
        } else {
            server.setDatabasePlatform(new SQLitePlatform());
            server.getDatabasePlatform().getDbDdlSyntax().setIdentity("");
            String path = plugin.getDataFolder().getPath().replaceAll("\\\\", "/");
            source.setUrl("jdbc:sqlite:" + path + "/LoginSecurity.db");
            source.setUsername("trump");
            source.setPassword("<PASSWORD>");
        }
        server.setDataSourceConfig(source);

        // Create server
        plugin.getLogger().log(Level.INFO, "Connection to database....");
        ClassLoader previous = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(getClassLoader());
        this.database = EbeanServerFactory.create(server);
        database.getAdminLogging().setLogLevel(LogLevel.NONE);
        Thread.currentThread().setContextClassLoader(previous);

        // List migrations
        this.migrations = Lists.newArrayList();
        try {
            JarFile jarFile = new JarFile(getPluginFile());
            Enumeration<JarEntry> entries = jarFile.entries();
            while(entries.hasMoreElements()) {
                JarEntry entry = entries.nextElement();
                if(entry.getName().startsWith("sql/sqlite/") && entry.getName().contains("__")) {
                    migrations.add(entry.getName().substring("sql/sqlite/".length()));
                }
            }
{'fraction_non_alphanumeric': 0.12934947049924356, 'fraction_numerical': 0.0070915279878971255, 'mean_word_length': 3.165813312327688, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 13, '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': '6991236', 'n_tokens_mistral': 2915, 'n_tokens_neox': 2833, 'n_words': 448}