<commit_before>package ru.naumen.core.game.impl.magicselect;

import java.beans.PropertyVetoException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.commons.lang.math.RandomUtils;
import org.apache.log4j.Logger;

/**
 *
 * @author achernin
 * @since 30.10.13
 */
public class TemporarySchemaProvider
{

    private static final Logger log = Logger.getLogger(TemporarySchemaProvider.class.getName());

    private static final String POSTGRES_ADMIN = "postgres";
    private static final String POSTGRES_ADMIN_PWSD = "manager";

    private static final String POSTGRES_USER = "swaldman";
    private static final String POSTGRES_PWSD = "<PASSWORD>";

    private static final String DB_URL = "jdbc:postgresql://localhost:5432/";

    private synchronized static String getBaseName()
    {
        return "klingon" + RandomUtils.nextLong();
    }

    public static String execute(String sqlCode) throws PropertyVetoException, SQLException, IOException
    {
        return execute(sqlCode, true);
    }


    public static String execute(String sqlCode, boolean withDrop) throws PropertyVetoException, SQLException, IOException
    {
        String baseName = getBaseName();
        String res = "";
        String url = DB_URL + "klingon_template";
        Connection connection = null;

        try
        {
            connection = DriverManager.getConnection(url, POSTGRES_ADMIN, POSTGRES_ADMIN_PWSD);
            createDB(connection, baseName);
            res = runSQL(baseName, sqlCode);
        }
        finally
        {
            if (withDrop && connection != null)
                dropDB(connection, baseName);
            if (connection != null)
                connection.close();
        }

        return res;
    }

    private static String runSQL(String baseName, String sqlCode) throws SQLException
    {
        String url = DB_URL + baseName;

        Integer start_year = 0;

        String default_sql = "select start_year from klingon_leader where leader = '" + sqlCode + "'";
        try (Connection conn = DriverManager.getConnection(url, POSTGRES_USER, POSTGRES_PWSD))
        {
            conn.setAutoCommit(false);
            createTable(conn);
            String[] sqls = default_sql.split(";");

            for (int i=0; i < sqls.length - 2; i++)
            {
                String sql = sqls[i];
                conn.createStatement().execute(sql);
                conn.commit();<commit_msg>sql execution fixed<commit_after>package ru.naumen.core.game.impl.magicselect;

import java.beans.PropertyVetoException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.commons.lang.math.RandomUtils;
import org.apache.log4j.Logger;

/**
 *
 * @author achernin
 * @since 30.10.13
 */
public class TemporarySchemaProvider
{

    private static final Logger log = Logger.getLogger(TemporarySchemaProvider.class.getName());

    private static final String POSTGRES_ADMIN = "postgres";
    private static final String POSTGRES_ADMIN_PWSD = "manager";

    private static final String POSTGRES_USER = "swaldman";
    private static final String POSTGRES_PWSD = "<PASSWORD>";

    private static final String DB_URL = "jdbc:postgresql://localhost:5432/";

    private synchronized static String getBaseName()
    {
        return "klingon" + RandomUtils.nextLong();
    }

    public static String execute(String sqlCode) throws PropertyVetoException, SQLException, IOException
    {
        return execute(sqlCode, true);
    }


    public static String execute(String sqlCode, boolean withDrop) throws PropertyVetoException, SQLException, IOException
    {
        String baseName = getBaseName();
        String res = "";
        String url = DB_URL + "klingon_template";
        Connection connection = null;

        try
        {
            connection = DriverManager.getConnection(url, POSTGRES_ADMIN, POSTGRES_ADMIN_PWSD);
            createDB(connection, baseName);
            res = runSQL(baseName, sqlCode);
        }
        finally
        {
            if (withDrop && connection != null)
                dropDB(connection, baseName);
            if (connection != null)
                connection.close();
        }

        return res;
    }

    private static String runSQL(String baseName, String sqlCode) throws SQLException
    {
        String url = DB_URL + baseName;

        Integer start_year = 0;

        String default_sql = "select start_year from klingon_leader where leader = '" + sqlCode + "'";
        try (Connection conn = DriverManager.getConnection(url, POSTGRES_USER, POSTGRES_PWSD))
        {
            conn.setAutoCommit(false);
            createTable(conn);
            String[] sqls = default_sql.split(";");

            for (int i=0; i < sqls.length - 1; i++)
            {
                String sql = sqls[i];
                conn.createStatement().execute(sql);
                conn.commit();
{'fraction_non_alphanumeric': 0.09443573667711598, 'fraction_numerical': 0.0054858934169279, 'mean_word_length': 2.6180014174344435, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '6725349', 'n_tokens_mistral': 1459, 'n_tokens_neox': 1376, 'n_words': 351}