Search in sources :

Example 1 with DfRunnerDispatchResult

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

the class DfCraftDiffAssertSqlFire method getSqlFileRunner4CraftDiff.

protected DfSqlFileRunner getSqlFileRunner4CraftDiff(final DfRunnerInformation runInfo, final DfCraftDiffAssertProvider provider) {
    final DfSqlFileRunnerExecute runnerExecute = new DfSqlFileRunnerExecute(runInfo, _dataSource) {

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

        @Override
        protected boolean isTargetFile(String sql) {
            return isTargetEnvTypeFile(sql);
        }
    };
    runnerExecute.setDispatcher(new DfSqlFileRunnerDispatcher() {

        public DfRunnerDispatchResult dispatch(File sqlFile, Statement st, String sql) throws SQLException {
            final DfCraftDiffAssertHandler handler = provider.provideCraftDiffAssertHandler(sqlFile, sql);
            if (handler == null) {
                throwCraftDiffNonAssertionSqlFoundException(sqlFile, sql);
            }
            handler.handle(sqlFile, st, sql);
            return DfRunnerDispatchResult.DISPATCHED;
        }
    });
    return runnerExecute;
}
Also used : 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 2 with DfRunnerDispatchResult

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

the class DfAlterCheckProcess method createSqlFileRunner.

protected DfSqlFileRunner createSqlFileRunner(final DfRunnerInformation runInfo) {
    final String loadType = getReplaceSchemaProperties().getRepsEnvType();
    final DfDataAssertProvider dataAssertProvider = new DfDataAssertProvider(loadType);
    final DfSqlFileRunnerExecute runnerExecute = new DfSqlFileRunnerExecute(runInfo, _dataSource);
    runnerExecute.setDispatcher(new DfSqlFileRunnerDispatcher() {

        public DfRunnerDispatchResult dispatch(File sqlFile, Statement st, String sql) throws SQLException {
            final DfDataAssertHandler dataAssertHandler = dataAssertProvider.provideDataAssertHandler(sql);
            if (dataAssertHandler == null) {
                return DfRunnerDispatchResult.NONE;
            }
            dataAssertHandler.handle(sqlFile, st, sql);
            return DfRunnerDispatchResult.DISPATCHED;
        }
    });
    return runnerExecute;
}
Also used : DfDataAssertHandler(org.dbflute.logic.replaceschema.dataassert.DfDataAssertHandler) DfDataAssertProvider(org.dbflute.logic.replaceschema.dataassert.DfDataAssertProvider) DfSqlFileRunnerDispatcher(org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerDispatcher) SQLException(java.sql.SQLException) DfAlterCheckAlterScriptSQLException(org.dbflute.exception.DfAlterCheckAlterScriptSQLException) DfSqlFileRunnerExecute(org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerExecute) Statement(java.sql.Statement) DfRunnerDispatchResult(org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerExecute.DfRunnerDispatchResult) File(java.io.File)

Example 3 with DfRunnerDispatchResult

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

the class DfCreateSchemaProcess method getSqlFileRunner.

protected DfSqlFileRunner getSqlFileRunner(final DfRunnerInformation runInfo) {
    final DfReplaceSchemaProperties prop = getReplaceSchemaProperties();
    final DfSqlFileRunnerExecute execute = new DfSqlFileRunnerExecuteCreateSchema(runInfo, getDataSource());
    execute.setDispatcher(new // for additional user dispatch
    DfSqlFileRunnerDispatcher() {

        protected final Set<String> _skippedFileSet = new HashSet<String>();

        public DfRunnerDispatchResult dispatch(File sqlFile, Statement st, String sql) throws SQLException {
            if (_currentUser == null || _currentUser.trim().length() == 0) {
                return DfRunnerDispatchResult.NONE;
            }
            checkSkippedUser();
            if (isSkippedUser()) {
                return DfRunnerDispatchResult.SKIPPED;
            }
            Connection conn = _changeUserConnectionMap.get(_currentUser);
            if (conn == null) {
                _log.info("...Creating a connection to " + _currentUser);
                conn = prop.createAdditionalUserConnection(_currentUser);
                if (conn != null) {
                    _changeUserConnectionMap.put(_currentUser, conn);
                } else {
                    final StringBuilder sb = new StringBuilder();
                    sb.append("...Saying good-bye to the user '").append(_currentUser).append("'");
                    sb.append(" because of no definition");
                    _log.info(sb.toString());
                    _goodByeUserSet.add(_currentUser);
                    return DfRunnerDispatchResult.SKIPPED;
                }
            }
            final Statement dispatchStmt = conn.createStatement();
            try {
                dispatchStmt.execute(sql);
                return DfRunnerDispatchResult.DISPATCHED;
            } catch (SQLException e) {
                final List<String> argList = analyzeCheckUser(sql);
                if (argList != null) {
                    // means the command was found
                    if (argList.contains("mainSchema")) {
                        _alreadyExistsMainSchema = true;
                    }
                    final StringBuilder sb = new StringBuilder();
                    sb.append("...Saying good-bye to the user '").append(_currentUser).append("'");
                    sb.append(" because of checked: ").append(argList);
                    _log.info(sb.toString());
                    final String exmsg = e.getMessage();
                    _log.info(" -> " + (exmsg != null ? exmsg.trim() : null));
                    _goodByeUserSet.add(_currentUser);
                    return DfRunnerDispatchResult.SKIPPED;
                }
                throw e;
            } finally {
                if (dispatchStmt != null) {
                    dispatchStmt.close();
                }
            }
        }

        protected void checkSkippedUser() {
            if (_skippedFileSet.contains(_currentUser)) {
                return;
            }
            if (prop.isAdditionalUserSkipIfNotFoundPasswordFileAndDefault(_currentUser)) {
                _log.info("...Skipping the user since no password file: " + _currentUser);
                _skippedFileSet.add(_currentUser);
            }
        }

        protected boolean isSkippedUser() {
            return _skippedFileSet.contains(_currentUser);
        }
    });
    return execute;
}
Also used : DfReplaceSchemaProperties(org.dbflute.properties.DfReplaceSchemaProperties) SQLException(java.sql.SQLException) DfSqlFileRunnerExecute(org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerExecute) Statement(java.sql.Statement) Connection(java.sql.Connection) DfRunnerDispatchResult(org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerExecute.DfRunnerDispatchResult) File(java.io.File) HashSet(java.util.HashSet)

Example 4 with DfRunnerDispatchResult

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

Aggregations

File (java.io.File)4 SQLException (java.sql.SQLException)4 Statement (java.sql.Statement)4 DfSqlFileRunnerExecute (org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerExecute)4 DfRunnerDispatchResult (org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerExecute.DfRunnerDispatchResult)4 DfSqlFileRunnerDispatcher (org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerDispatcher)3 DfDataAssertHandler (org.dbflute.logic.replaceschema.dataassert.DfDataAssertHandler)2 DfDataAssertProvider (org.dbflute.logic.replaceschema.dataassert.DfDataAssertProvider)2 DfReplaceSchemaProperties (org.dbflute.properties.DfReplaceSchemaProperties)2 Connection (java.sql.Connection)1 HashSet (java.util.HashSet)1 DfAlterCheckAlterScriptSQLException (org.dbflute.exception.DfAlterCheckAlterScriptSQLException)1 DfTakeFinallyAssertionFailureException (org.dbflute.exception.DfTakeFinallyAssertionFailureException)1