Search in sources :

Example 1 with SystemScriptUnsupportedScriptException

use of org.dbflute.helper.process.exception.SystemScriptUnsupportedScriptException in project dbflute-core by dbflute.

the class DfSqlFileFireMan method executeScriptFile.

protected DfSqlFileRunnerResult executeScriptFile(DfSqlFileRunner runner, SystemScript script, File sqlFile) {
    final String sqlPath = resolvePath(sqlFile);
    final String baseDir = Srl.substringLastFront(sqlPath, "/");
    final String scriptName = Srl.substringLastRear(sqlPath, "/");
    _log.info("...Executing the script: " + sqlPath);
    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("Caught 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;
        // wrapping quickly because SQLFailureException needs SQLException
        // (and nested exception message has debug information so simple message here)
        final SQLException sqlEx = new DfFireSqlScriptSQLException(msg);
        final SQLFailureException failureEx = new SQLFailureException("Break the process for script failure.", sqlEx);
        // no error continue, script error is treated as programming error
        // because you can freely skip SQL failure in your script
        runnerResult.setBreakCause(failureEx);
        return runnerResult;
    } else {
        runnerResult.setGoodSqlCount(1);
        return runnerResult;
    }
}
Also used : SQLException(java.sql.SQLException) DfFireSqlScriptSQLException(org.dbflute.exception.DfFireSqlScriptSQLException) SystemScriptUnsupportedScriptException(org.dbflute.helper.process.exception.SystemScriptUnsupportedScriptException) DfFireSqlScriptSQLException(org.dbflute.exception.DfFireSqlScriptSQLException) ProcessResult(org.dbflute.helper.process.ProcessResult) File(java.io.File) SQLFailureException(org.dbflute.exception.SQLFailureException)

Example 2 with SystemScriptUnsupportedScriptException

use of org.dbflute.helper.process.exception.SystemScriptUnsupportedScriptException 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 SystemScriptUnsupportedScriptException

use of org.dbflute.helper.process.exception.SystemScriptUnsupportedScriptException in project dbflute-core by dbflute.

the class DfArrangeBeforeRepsProcess method arrangeScript.

// ===================================================================================
// Script
// ======
protected void arrangeScript(String path) {
    final SystemScript script = new SystemScript();
    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;
    }
    final String console = processResult.getConsole();
    if (Srl.is_NotNull_and_NotTrimmedEmpty(console)) {
        _log.info("Catched the console for " + scriptName + ":" + ln() + console);
    }
    final int exitCode = processResult.getExitCode();
    if (exitCode != 0) {
        throwRepsArrangeScriptFailureException(path, exitCode);
    }
}
Also used : SystemScript(org.dbflute.helper.process.SystemScript) SystemScriptUnsupportedScriptException(org.dbflute.helper.process.exception.SystemScriptUnsupportedScriptException) ProcessResult(org.dbflute.helper.process.ProcessResult) File(java.io.File)

Example 4 with SystemScriptUnsupportedScriptException

use of org.dbflute.helper.process.exception.SystemScriptUnsupportedScriptException in project dbflute-core by dbflute.

the class DfArrangeBeforeRepsProcess method arrangeScript.

// ===================================================================================
// Script
// ======
protected void arrangeScript(String path) {
    final SystemScript script = new SystemScript();
    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;
    }
    final String console = processResult.getConsole();
    if (Srl.is_NotNull_and_NotTrimmedEmpty(console)) {
        _log.info("Catched the console for " + scriptName + ":" + ln() + console);
    }
    final int exitCode = processResult.getExitCode();
    if (exitCode != 0) {
        throwRepsArrangeScriptFailureException(path, exitCode);
    }
}
Also used : SystemScript(org.dbflute.helper.process.SystemScript) SystemScriptUnsupportedScriptException(org.dbflute.helper.process.exception.SystemScriptUnsupportedScriptException) ProcessResult(org.dbflute.helper.process.ProcessResult) File(java.io.File)

Aggregations

File (java.io.File)4 ProcessResult (org.dbflute.helper.process.ProcessResult)4 SystemScriptUnsupportedScriptException (org.dbflute.helper.process.exception.SystemScriptUnsupportedScriptException)4 SystemScript (org.dbflute.helper.process.SystemScript)3 SQLException (java.sql.SQLException)2 DfAlterCheckAlterScriptSQLException (org.dbflute.exception.DfAlterCheckAlterScriptSQLException)1 DfFireSqlScriptSQLException (org.dbflute.exception.DfFireSqlScriptSQLException)1 SQLFailureException (org.dbflute.exception.SQLFailureException)1 DfSqlFileFireMan (org.dbflute.helper.jdbc.sqlfile.DfSqlFileFireMan)1 DfSqlFileRunner (org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunner)1 DfSqlFileRunnerResult (org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerResult)1