Search in sources :

Example 1 with DfSqlFileRunner

use of org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunner in project dbflute-core by dbflute.

the class DfAlterCheckProcess method executeAlterSql.

// -----------------------------------------------------
// Alter Fire
// ----------
protected void executeAlterSql(DfAlterCheckFinalInfo finalInfo) {
    List<File> alterSqlFileList = findMigrationAlterSqlFileList();
    if (alterSqlFileList.isEmpty()) {
        _unreleasedAlterAgent.restoreUnreleasedAlterSql();
        alterSqlFileList = findMigrationAlterSqlFileList();
        if (alterSqlFileList.isEmpty()) {
            createEmptyAlterSqlFileIfNotExists();
            alterSqlFileList = findMigrationAlterSqlFileList();
            if (alterSqlFileList.isEmpty()) {
                // no way
                throwAlterCheckAlterSqlNotFoundException();
            }
        }
    }
    final DfRunnerInformation runInfo = createRunnerInformation();
    final DfSqlFileFireMan fireMan = createSqlFileFireMan();
    final DfSqlFileRunner runner = createSqlFileRunner(runInfo);
    finalInfo.addAlterSqlFileAll(alterSqlFileList);
    try {
        final DfSqlFileFireResult result = fireMan.fire(runner, alterSqlFileList);
        reflectAlterResultToFinalInfo(finalInfo, result);
    } catch (DfTakeFinallyAssertionFailureException e) {
        handleTakeFinallyAssertionFailureException(finalInfo, e);
    }
}
Also used : DfTakeFinallyAssertionFailureException(org.dbflute.exception.DfTakeFinallyAssertionFailureException) DfSqlFileFireMan(org.dbflute.helper.jdbc.sqlfile.DfSqlFileFireMan) DfSqlFileFireResult(org.dbflute.helper.jdbc.sqlfile.DfSqlFileFireResult) DfSqlFileRunner(org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunner) File(java.io.File) DfRunnerInformation(org.dbflute.helper.jdbc.DfRunnerInformation)

Example 2 with DfSqlFileRunner

use of org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunner in project dbflute-core by dbflute.

the class DfAlterCheckProcess method createSqlFileFireMan.

protected DfSqlFileFireMan createSqlFileFireMan() {
    final String[] scriptExtAry = SystemScript.getSupportedExtList().toArray(new String[] {});
    final SystemScript script = new SystemScript();
    return new DfSqlFileFireMan() {

        @Override
        protected DfSqlFileRunnerResult processSqlFile(DfSqlFileRunner runner, File sqlFile) {
            _executedAlterSqlFileList.add(sqlFile);
            final String path = resolvePath(sqlFile);
            if (!Srl.endsWith(path, scriptExtAry)) {
                // SQL file
                return super.processSqlFile(runner, sqlFile);
            }
            // script file
            final String baseDir = Srl.substringLastFront(path, "/");
            final String scriptName = Srl.substringLastRear(path, "/");
            _log.info("...Executing the script: " + path);
            final ProcessResult processResult;
            try {
                processResult = script.execute(new File(baseDir), scriptName);
            } catch (SystemScriptUnsupportedScriptException ignored) {
                _log.info("Skipped the script for system mismatch: " + scriptName);
                return null;
            }
            final String console = processResult.getConsole();
            if (Srl.is_NotNull_and_NotTrimmedEmpty(console)) {
                _log.info("Catched the console for " + scriptName + ":" + ln() + console);
            }
            final DfSqlFileRunnerResult runnerResult = new DfSqlFileRunnerResult(sqlFile);
            runnerResult.setTotalSqlCount(1);
            final int exitCode = processResult.getExitCode();
            if (exitCode != 0) {
                final String msg = "The script failed: " + scriptName + " exitCode=" + exitCode;
                final SQLException sqlEx = new DfAlterCheckAlterScriptSQLException(msg);
                final String sqlExp = "(commands on the script)";
                runnerResult.addErrorContinuedSql(sqlExp, sqlEx);
                return runnerResult;
            } else {
                runnerResult.setGoodSqlCount(1);
                return runnerResult;
            }
        }
    };
}
Also used : SystemScript(org.dbflute.helper.process.SystemScript) DfSqlFileFireMan(org.dbflute.helper.jdbc.sqlfile.DfSqlFileFireMan) SQLException(java.sql.SQLException) DfAlterCheckAlterScriptSQLException(org.dbflute.exception.DfAlterCheckAlterScriptSQLException) DfAlterCheckAlterScriptSQLException(org.dbflute.exception.DfAlterCheckAlterScriptSQLException) SystemScriptUnsupportedScriptException(org.dbflute.helper.process.exception.SystemScriptUnsupportedScriptException) ProcessResult(org.dbflute.helper.process.ProcessResult) DfSqlFileRunnerResult(org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerResult) DfSqlFileRunner(org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunner) File(java.io.File)

Example 3 with DfSqlFileRunner

use of org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunner in project dbflute-core by dbflute.

the class DfAlterCheckProcess method executeAlterSql.

// -----------------------------------------------------
// Alter Fire
// ----------
protected void executeAlterSql(DfAlterCheckFinalInfo finalInfo) {
    List<File> alterSqlFileList = getMigrationAlterSqlFileList();
    if (alterSqlFileList.isEmpty()) {
        restoreLatestCheckedAlterSql();
        alterSqlFileList = getMigrationAlterSqlFileList();
        if (alterSqlFileList.isEmpty()) {
            createEmptyAlterSqlFileIfNotExists();
            alterSqlFileList = getMigrationAlterSqlFileList();
            if (alterSqlFileList.isEmpty()) {
                // no way
                throwAlterCheckAlterSqlNotFoundException();
            }
        }
    }
    final DfRunnerInformation runInfo = createRunnerInformation();
    final DfSqlFileFireMan fireMan = createSqlFileFireMan();
    fireMan.setExecutorName("Alter Schema");
    final DfSqlFileRunner runner = createSqlFileRunner(runInfo);
    finalInfo.addAlterSqlFileAll(alterSqlFileList);
    try {
        final DfSqlFileFireResult result = fireMan.fire(runner, alterSqlFileList);
        reflectAlterResultToFinalInfo(finalInfo, result);
    } catch (DfTakeFinallyAssertionFailureException e) {
        handleTakeFinallyAssertionFailureException(finalInfo, e);
    }
}
Also used : DfTakeFinallyAssertionFailureException(org.dbflute.exception.DfTakeFinallyAssertionFailureException) DfSqlFileFireMan(org.dbflute.helper.jdbc.sqlfile.DfSqlFileFireMan) DfSqlFileFireResult(org.dbflute.helper.jdbc.sqlfile.DfSqlFileFireResult) DfSqlFileRunner(org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunner) File(java.io.File) DfRunnerInformation(org.dbflute.helper.jdbc.DfRunnerInformation)

Example 4 with DfSqlFileRunner

use of org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunner in project dbflute-core by dbflute.

the class DfTakeFinallyProcess method createSqlFileFireMan.

protected DfSqlFileFireMan createSqlFileFireMan() {
    // similar to alter check
    final String[] scriptExtAry = SystemScript.getSupportedExtList().toArray(new String[] {});
    final SystemScript script = new SystemScript();
    final DfSqlFileFireMan fireMan = new DfSqlFileFireMan() {

        @Override
        protected DfSqlFileRunnerResult processSqlFile(DfSqlFileRunner runner, File sqlFile) {
            _executedSqlFileList.add(sqlFile);
            if (isScriptFile(sqlFile, scriptExtAry)) {
                return processScriptFile(runner, script, sqlFile);
            } else {
                // mainly here
                return super.processSqlFile(runner, sqlFile);
            }
        }
    };
    fireMan.setExecutorName("Take Finally");
    return fireMan;
}
Also used : SystemScript(org.dbflute.helper.process.SystemScript) DfSqlFileFireMan(org.dbflute.helper.jdbc.sqlfile.DfSqlFileFireMan) DfSqlFileRunner(org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunner) File(java.io.File)

Example 5 with DfSqlFileRunner

use of org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunner in project dbflute-core by dbflute.

the class DfAlterCheckProcess method createSqlFileFireMan.

protected DfSqlFileFireMan createSqlFileFireMan() {
    final String[] scriptExtAry = SystemScript.getSupportedExtList().toArray(new String[] {});
    final SystemScript script = new SystemScript();
    final DfSqlFileFireMan fireMan = new DfSqlFileFireMan() {

        @Override
        protected DfSqlFileRunnerResult processSqlFile(DfSqlFileRunner runner, File sqlFile) {
            _executedAlterSqlFileList.add(sqlFile);
            if (isScriptFile(sqlFile, scriptExtAry)) {
                return processScriptFile(runner, script, sqlFile);
            } else {
                // mainly here
                return super.processSqlFile(runner, sqlFile);
            }
        }
    };
    fireMan.setExecutorName("Alter Schema");
    return fireMan;
}
Also used : SystemScript(org.dbflute.helper.process.SystemScript) DfSqlFileFireMan(org.dbflute.helper.jdbc.sqlfile.DfSqlFileFireMan) DfSqlFileRunner(org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunner) File(java.io.File)

Aggregations

DfSqlFileFireMan (org.dbflute.helper.jdbc.sqlfile.DfSqlFileFireMan)6 DfSqlFileRunner (org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunner)6 File (java.io.File)5 DfRunnerInformation (org.dbflute.helper.jdbc.DfRunnerInformation)3 SystemScript (org.dbflute.helper.process.SystemScript)3 DfTakeFinallyAssertionFailureException (org.dbflute.exception.DfTakeFinallyAssertionFailureException)2 DfSqlFileFireResult (org.dbflute.helper.jdbc.sqlfile.DfSqlFileFireResult)2 SQLException (java.sql.SQLException)1 DfAlterCheckAlterScriptSQLException (org.dbflute.exception.DfAlterCheckAlterScriptSQLException)1 DfSqlFileRunnerResult (org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerResult)1 ProcessResult (org.dbflute.helper.process.ProcessResult)1 SystemScriptUnsupportedScriptException (org.dbflute.helper.process.exception.SystemScriptUnsupportedScriptException)1 DfOutsideSqlPack (org.dbflute.logic.sql2entity.analyzer.DfOutsideSqlPack)1