<commit_before>/*
 * Copyright (c) 2008-2013 Haulmont. All rights reserved.
 * Use is subject to license terms, see http://www.cuba-platform.com/license for details.
 */

package com.haulmont.cuba.core.sys;

import com.haulmont.bali.db.DbUtils;
import com.haulmont.bali.db.QueryRunner;
import com.haulmont.bali.db.ResultSetHandler;
import com.haulmont.cuba.core.sys.persistence.DbmsSpecificFactory;
import groovy.lang.Binding;
import groovy.lang.Closure;
import groovy.util.GroovyScriptEngine;
import groovy.util.ResourceException;
import groovy.util.ScriptException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.text.StrMatcher;
import org.apache.commons.lang.text.StrTokenizer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.annotation.Nullable;
import javax.sql.DataSource;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.nio.file.Path;
import java.sql.*;
import java.util.*;

/**
 * @author artamonov
 * @version $Id$
 */
public class DbUpdaterEngine implements DbUpdater {

    private static final String SQL_EXTENSION = "sql";
    private static final String SQL_COMMENT_PREFIX = "--";
    private static final String SQL_DELIMITER = "^";

    private static final String GROOVY_EXTENSION = "groovy";

    private static final Log log = LogFactory.getLog(DbUpdaterEngine.class);

    protected DataSource dataSource;

    protected File dbDir;
    protected String dbmsType;
    protected String dbmsVersion;

    protected boolean changelogTableExists = false;

    protected final Map<String, String> requiredTables = new HashMap<>();
    {
        requiredTables.put("reports", "report_report");
        requiredTables.put("workflow", "wf_proc");
        requiredTables.put("ccpayments", "cc_credit_card");
        requiredTables.put("bpmn", "bpmn_group");
    }

    // register handlers for script files
    protected final Map<String, FileHandler> extensionHandlers = new HashMap<>();
    {
        extensionHandlers.put(SQL_EXTENSION, new FileHandler() {
            @Override
            public boolean run(File file) {
                return executeSqlScript(file);
            }
        });
        extensionHandlers.put(GROOVY_EXTENSION, new FileHandler() {
            @Override
            public boolean run(File file) {
                return executeGroovyScript(file);
            }
        });
    }
<commit_msg>BPM module tables are not automatically created when adding BPM module to existing project #PL-5816<commit_after>/*
 * Copyright (c) 2008-2013 Haulmont. All rights reserved.
 * Use is subject to license terms, see http://www.cuba-platform.com/license for details.
 */

package com.haulmont.cuba.core.sys;

import com.haulmont.bali.db.DbUtils;
import com.haulmont.bali.db.QueryRunner;
import com.haulmont.bali.db.ResultSetHandler;
import com.haulmont.cuba.core.sys.persistence.DbmsSpecificFactory;
import groovy.lang.Binding;
import groovy.lang.Closure;
import groovy.util.GroovyScriptEngine;
import groovy.util.ResourceException;
import groovy.util.ScriptException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.text.StrMatcher;
import org.apache.commons.lang.text.StrTokenizer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.annotation.Nullable;
import javax.sql.DataSource;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.nio.file.Path;
import java.sql.*;
import java.util.*;

/**
 * @author artamonov
 * @version $Id$
 */
public class DbUpdaterEngine implements DbUpdater {

    private static final String SQL_EXTENSION = "sql";
    private static final String SQL_COMMENT_PREFIX = "--";
    private static final String SQL_DELIMITER = "^";

    private static final String GROOVY_EXTENSION = "groovy";

    private static final Log log = LogFactory.getLog(DbUpdaterEngine.class);

    protected DataSource dataSource;

    protected File dbDir;
    protected String dbmsType;
    protected String dbmsVersion;

    protected boolean changelogTableExists = false;

    protected final Map<String, String> requiredTables = new HashMap<>();
    {
        requiredTables.put("reports", "report_report");
        requiredTables.put("workflow", "wf_proc");
        requiredTables.put("ccpayments", "cc_credit_card");
        requiredTables.put("bpm", "bpm_proc_definition");
    }

    // register handlers for script files
    protected final Map<String, FileHandler> extensionHandlers = new HashMap<>();
    {
        extensionHandlers.put(SQL_EXTENSION, new FileHandler() {
            @Override
            public boolean run(File file) {
                return executeSqlScript(file);
            }
        });
        extensionHandlers.put(GROOVY_EXTENSION, new FileHandler() {
            @Override
            public boolean run(File file) {
                return executeGroovyScript(file);
            }
        });
    }

{'fraction_non_alphanumeric': 0.10296953335904357, 'fraction_numerical': 0.0038565368299267257, 'mean_word_length': 3.5821554770318023, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5935733', 'n_tokens_mistral': 1555, 'n_tokens_neox': 1476, 'n_words': 350}