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;
}
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;
}
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;
}
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;
}
Aggregations