Search in sources :

Example 6 with DfTakeFinallyAssertionFailureException

use of org.dbflute.exception.DfTakeFinallyAssertionFailureException 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 7 with DfTakeFinallyAssertionFailureException

use of org.dbflute.exception.DfTakeFinallyAssertionFailureException in project dbflute-core by dbflute.

the class DfTakeFinallyProcess method getSqlFileRunner4TakeFinally.

protected DfSqlFileRunner getSqlFileRunner4TakeFinally(final DfRunnerInformation runInfo) {
    final DfReplaceSchemaProperties prop = getReplaceSchemaProperties();
    final DfSqlFileRunnerExecute runnerExecute = new DfSqlFileRunnerExecute(runInfo, _dataSource) {

        @Override
        protected String filterSql(String sql) {
            sql = super.filterSql(sql);
            sql = prop.resolveFilterVariablesIfNeeds(sql);
            return sql;
        }

        @Override
        protected boolean isHandlingCommentOnLineSeparator() {
            return true;
        }

        @Override
        protected boolean isDbCommentLine(String line) {
            final boolean commentLine = super.isDbCommentLine(line);
            if (commentLine) {
                return commentLine;
            }
            // for irregular pattern
            return isDbCommentLineForIrregularPattern(line);
        }

        @Override
        protected String getTerminator4Tool() {
            return resolveTerminator4Tool();
        }

        @Override
        protected boolean isTargetFile(String sql) {
            return getReplaceSchemaProperties().isTargetRepsFile(sql);
        }
    };
    final String loadType = getReplaceSchemaProperties().getRepsEnvType();
    final DfDataAssertProvider dataAssertProvider = new DfDataAssertProvider(loadType);
    runnerExecute.setDispatcher(new DfSqlFileRunnerDispatcher() {

        public DfRunnerDispatchResult dispatch(File sqlFile, Statement st, String sql) throws SQLException {
            final DfDataAssertHandler dataAssertHandler = dataAssertProvider.provideDataAssertHandler(sql);
            if (dataAssertHandler == null) {
                if (_skipIfNonAssetionSql) {
                    _log.info("*Skipped the statement because of not assertion SQL");
                    return DfRunnerDispatchResult.SKIPPED;
                } else if (_restrictIfNonAssetionSql) {
                    throwTakeFinallyNonAssertionSqlFoundException(sqlFile, sql);
                } else {
                    return DfRunnerDispatchResult.NONE;
                }
            }
            try {
                dataAssertHandler.handle(sqlFile, st, sql);
            } catch (DfTakeFinallyAssertionFailureException e) {
                handleAssertionFailureException(e);
            }
            return DfRunnerDispatchResult.DISPATCHED;
        }
    });
    return runnerExecute;
}
Also used : DfDataAssertHandler(org.dbflute.logic.replaceschema.dataassert.DfDataAssertHandler) DfTakeFinallyAssertionFailureException(org.dbflute.exception.DfTakeFinallyAssertionFailureException) DfReplaceSchemaProperties(org.dbflute.properties.DfReplaceSchemaProperties) DfDataAssertProvider(org.dbflute.logic.replaceschema.dataassert.DfDataAssertProvider) DfSqlFileRunnerDispatcher(org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerDispatcher) SQLException(java.sql.SQLException) DfSqlFileRunnerExecute(org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerExecute) Statement(java.sql.Statement) DfRunnerDispatchResult(org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerExecute.DfRunnerDispatchResult) File(java.io.File)

Example 8 with DfTakeFinallyAssertionFailureException

use of org.dbflute.exception.DfTakeFinallyAssertionFailureException in project dbflute-core by dbflute.

the class DfAlterCheckProcess method reflectTakeFinallyResultToFinalInfo.

protected void reflectTakeFinallyResultToFinalInfo(DfAlterCheckFinalInfo finalInfo, DfTakeFinallyFinalInfo takeFinally) {
    final List<String> detailMessageList = takeFinally.getDetailMessageList();
    for (String detailMessage : detailMessageList) {
        finalInfo.addDetailMessage(detailMessage);
    }
    final SQLFailureException breakCause = takeFinally.getBreakCause();
    if (breakCause != null) {
        finalInfo.setBreakCause(breakCause);
    }
    final DfTakeFinallyAssertionFailureException assertionEx = takeFinally.getAssertionEx();
    if (assertionEx != null) {
        finalInfo.setTakeFinallyAssertionEx(assertionEx);
    }
    if (takeFinally.isFailure()) {
        finalInfo.setFailure(true);
    }
}
Also used : DfTakeFinallyAssertionFailureException(org.dbflute.exception.DfTakeFinallyAssertionFailureException) SQLFailureException(org.dbflute.exception.SQLFailureException)

Example 9 with DfTakeFinallyAssertionFailureException

use of org.dbflute.exception.DfTakeFinallyAssertionFailureException in project dbflute-core by dbflute.

the class DfReplaceSchemaTask method takeFinally.

// -----------------------------------------------------
// Take Finally
// ------------
protected void takeFinally(String sqlRootDir, boolean previous) {
    final DfTakeFinallyProcess process = createTakeFinallyProcess(sqlRootDir, previous);
    _takeFinallyFinalInfo = process.execute();
    final SQLFailureException breakCause = _takeFinallyFinalInfo.getBreakCause();
    if (breakCause != null) {
        // high priority exception
        throw breakCause;
    }
    final DfTakeFinallyAssertionFailureException assertionEx = _takeFinallyFinalInfo.getAssertionEx();
    if (assertionEx != null) {
        // high priority exception
        throw assertionEx;
    }
}
Also used : DfTakeFinallyAssertionFailureException(org.dbflute.exception.DfTakeFinallyAssertionFailureException) DfTakeFinallyProcess(org.dbflute.logic.replaceschema.process.DfTakeFinallyProcess) SQLFailureException(org.dbflute.exception.SQLFailureException)

Aggregations

DfTakeFinallyAssertionFailureException (org.dbflute.exception.DfTakeFinallyAssertionFailureException)9 File (java.io.File)4 SQLFailureException (org.dbflute.exception.SQLFailureException)3 DfRunnerInformation (org.dbflute.helper.jdbc.DfRunnerInformation)3 DfSqlFileFireResult (org.dbflute.helper.jdbc.sqlfile.DfSqlFileFireResult)3 DfSqlFileFireMan (org.dbflute.helper.jdbc.sqlfile.DfSqlFileFireMan)2 DfSqlFileRunner (org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunner)2 DfTakeFinallyFinalInfo (org.dbflute.logic.replaceschema.finalinfo.DfTakeFinallyFinalInfo)2 BufferedWriter (java.io.BufferedWriter)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 DfSqlFileRunnerDispatcher (org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerDispatcher)1 DfSqlFileRunnerExecute (org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerExecute)1 DfRunnerDispatchResult (org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerExecute.DfRunnerDispatchResult)1 DfDataAssertHandler (org.dbflute.logic.replaceschema.dataassert.DfDataAssertHandler)1 DfDataAssertProvider (org.dbflute.logic.replaceschema.dataassert.DfDataAssertProvider)1 DfTakeFinallyProcess (org.dbflute.logic.replaceschema.process.DfTakeFinallyProcess)1