Search in sources :

Example 1 with DfSqlFileRunnerResult

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

the class DfOutsideSqlTestTask method handleSqlFileFailure.

// ===================================================================================
// Exception Handling
// ==================
protected void handleSqlFileFailure(DfSqlFileFireResult fireResult, List<File> sqlFileList) {
    final SQLFailureException topCause = fireResult.getBreakCause();
    if (topCause != null) {
        throw topCause;
    }
    final List<DfSqlFileRunnerResult> resultList = fireResult.getRunnerResultList();
    for (DfSqlFileRunnerResult runnerResult : resultList) {
        final SQLFailureException elementCause = runnerResult.getBreakCause();
        if (elementCause != null) {
            throw elementCause;
        }
        final List<ErrorContinuedSql> continuedSqlList = runnerResult.getErrorContinuedSqlList();
        if (!continuedSqlList.isEmpty()) {
            throwOutsideSqlTestFailureFoundException();
        }
    }
}
Also used : ErrorContinuedSql(org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerResult.ErrorContinuedSql) DfSqlFileRunnerResult(org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerResult) SQLFailureException(org.dbflute.exception.SQLFailureException)

Example 2 with DfSqlFileRunnerResult

use of org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerResult 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 DfSqlFileRunnerResult

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

the class DfOutsideSqlTestTask method buildFinalMessage.

protected String buildFinalMessage() {
    if (_fireResult == null) {
        return null;
    }
    final DfSqlFileFireResult fireResult = _fireResult;
    int countOK = 0;
    int countSkipped = 0;
    int countFailure = 0;
    final StringBuilder sb = new StringBuilder();
    sb.append(" {Checked SQL}");
    final List<DfSqlFileRunnerResult> runnerResultList = fireResult.getRunnerResultList();
    for (DfSqlFileRunnerResult runnerResult : runnerResultList) {
        final File sqlFile = runnerResult.getSqlFile();
        final List<ErrorContinuedSql> continuedSqlList = runnerResult.getErrorContinuedSqlList();
        sb.append(ln());
        if (continuedSqlList.isEmpty()) {
            if (_nonTargetSqlFileSet.contains(sqlFile)) {
                // accurately 'v' means the SQL file may have skipped SQLs
                // however SQL file for OutsideSqlTest has only one SQL normally
                sb.append("  v ");
                ++countSkipped;
            } else {
                sb.append("  o ");
                ++countOK;
            }
        } else {
            // you can say same as 'v'
            // (anyway, look at the log for detail)
            sb.append("  x ");
            ++countFailure;
        }
        sb.append(sqlFile.getName());
        for (ErrorContinuedSql errorContinuedSql : continuedSqlList) {
            final SQLException sqlEx = errorContinuedSql.getSqlEx();
            String sqlMsg = sqlEx.getMessage();
            if (sqlMsg != null) {
                sqlMsg = sqlMsg.trim();
                if (sqlMsg.contains(ln())) {
                    sqlMsg = Srl.substringFirstFront(sqlMsg, ln()).trim() + "...";
                }
            }
            sb.append(ln()).append("   -> ").append(sqlMsg);
        }
    }
    if (!runnerResultList.isEmpty()) {
        sb.append(ln());
        sb.append(ln()).append("   o: OK (").append(countOK).append(")");
        if (countSkipped > 0) {
            sb.append(ln()).append("   v: Skipped exists (").append(countSkipped).append(")");
        }
        if (countFailure > 0) {
            sb.append(ln()).append("   x: Failure exists (").append(countFailure).append(")");
        }
    }
    return sb.toString();
}
Also used : ErrorContinuedSql(org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerResult.ErrorContinuedSql) SQLException(java.sql.SQLException) DfSqlFileFireResult(org.dbflute.helper.jdbc.sqlfile.DfSqlFileFireResult) DfSqlFileRunnerResult(org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerResult) File(java.io.File) DfSpecifiedSqlFile(org.dbflute.task.bs.assistant.DfSpecifiedSqlFile)

Aggregations

DfSqlFileRunnerResult (org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerResult)3 File (java.io.File)2 SQLException (java.sql.SQLException)2 ErrorContinuedSql (org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerResult.ErrorContinuedSql)2 DfAlterCheckAlterScriptSQLException (org.dbflute.exception.DfAlterCheckAlterScriptSQLException)1 SQLFailureException (org.dbflute.exception.SQLFailureException)1 DfSqlFileFireMan (org.dbflute.helper.jdbc.sqlfile.DfSqlFileFireMan)1 DfSqlFileFireResult (org.dbflute.helper.jdbc.sqlfile.DfSqlFileFireResult)1 DfSqlFileRunner (org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunner)1 ProcessResult (org.dbflute.helper.process.ProcessResult)1 SystemScript (org.dbflute.helper.process.SystemScript)1 SystemScriptUnsupportedScriptException (org.dbflute.helper.process.exception.SystemScriptUnsupportedScriptException)1 DfSpecifiedSqlFile (org.dbflute.task.bs.assistant.DfSpecifiedSqlFile)1