use of org.dbflute.exception.SQLFailureException 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();
}
}
}
use of org.dbflute.exception.SQLFailureException in project dbflute-core by dbflute.
the class SQLExceptionHandler method throwSQLFailureException.
protected void throwSQLFailureException(SQLException e, SQLExceptionResource resource) {
final ExceptionMessageBuilder br = createExceptionMessageBuilder();
final List<String> noticeList = resource.getNoticeList();
if (!noticeList.isEmpty()) {
for (String notice : noticeList) {
br.addNotice(notice);
}
} else {
// as default
br.addNotice("The SQL failed to execute.");
}
br.addItem("Advice");
br.addElement("Read the SQLException message.");
final String advice = askAdvice(e, ResourceContext.currentDBDef());
if (advice != null && advice.trim().length() > 0) {
br.addElement("*" + advice);
}
setupCommonElement(br, e, resource);
final String msg = br.buildExceptionMessage();
throw new SQLFailureException(msg, e);
}
use of org.dbflute.exception.SQLFailureException in project dbflute-core by dbflute.
the class DfSqlFileFireMan method buildDetailMessage.
protected String buildDetailMessage(DfSqlFileFireResult fireResult) {
final StringBuilder sb = new StringBuilder();
final List<DfSqlFileRunnerResult> runnerResultList = fireResult.getRunnerResultList();
for (DfSqlFileRunnerResult runnerResult : runnerResultList) {
final List<ErrorContinuedSql> errorContinuedSqlList = runnerResult.getErrorContinuedSqlList();
final String fileName = runnerResult.getSqlFile().getName();
final SQLFailureException breakCause = runnerResult.getBreakCause();
if (sb.length() > 0) {
sb.append(ln());
}
if (breakCause != null) {
// break by error
sb.append("x ").append(fileName);
sb.append(ln()).append(" >> (failed: Look at the exception message)");
} else {
// normal or error-continued
if (errorContinuedSqlList.isEmpty()) {
// OK or skipped
sb.append(!runnerResult.isSkippedFile() ? "o " : "v ").append(fileName);
} else {
sb.append("x ").append(fileName);
doBuildErrorContinuedMessage(sb, errorContinuedSqlList);
}
}
}
return sb.toString();
}
use of org.dbflute.exception.SQLFailureException in project dbflute-core by dbflute.
the class DfSqlFileRunnerBase method runTransaction.
// ===================================================================================
// Run Transaction
// ===============
public DfSqlFileRunnerResult runTransaction() {
_goodSqlCount = 0;
_totalSqlCount = 0;
_skippedSqlCount = 0;
if (_sqlFile == null) {
String msg = "The attribute '_srcFile' should not be null.";
throw new IllegalStateException(msg);
}
boolean skippedFile = false;
String currentSql = null;
BufferedReader br = null;
try {
br = new BufferedReader(newInputStreamReader());
final List<String> sqlList = extractSqlList(br);
setupConnection();
setupStatement();
int sqlNumber = 0;
for (String sql : sqlList) {
++sqlNumber;
currentSql = sql;
if (sqlNumber == 1 && !isTargetFile(sql)) {
// first SQL only
skippedFile = true;
break;
}
if (!isTargetSql(sql)) {
continue;
}
++_totalSqlCount;
final String realSql = filterSql(sql);
if (!_runInfo.isSuppressLoggingSql()) {
traceSql(realSql);
}
execSQL(realSql);
}
rollbackOrCommit();
} catch (SQLFailureException breakCause) {
if (_runInfo.isBreakCauseThrow()) {
throw breakCause;
} else {
_runnerResult.setGoodSqlCount(_goodSqlCount);
_runnerResult.setTotalSqlCount(_totalSqlCount);
_runnerResult.setBreakCause(breakCause);
return _runnerResult;
}
} catch (SQLException e) {
// here is for the exception except executing SQL
// so it always does not continue
throwSQLFailureException(currentSql, e);
} finally {
try {
rollback();
} catch (SQLException ignored) {
}
closeStatement();
closeConnection();
closeReader(br);
}
// re-calculate total count with skipped count
_totalSqlCount = _totalSqlCount - _skippedSqlCount;
traceResult(_goodSqlCount, _totalSqlCount);
_runnerResult.setGoodSqlCount(_goodSqlCount);
_runnerResult.setTotalSqlCount(_totalSqlCount);
_runnerResult.setSkippedFile(skippedFile);
return _runnerResult;
}
use of org.dbflute.exception.SQLFailureException in project dbflute-core by dbflute.
the class DfSqlFileRunnerBase method throwSQLFailureException.
// ===================================================================================
// Exception Handling
// ==================
protected void throwSQLFailureException(String sql, SQLException e) {
final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
br.addNotice("Failed to execute the SQL!");
br.addItem("SQL File");
br.addElement(_sqlFile);
br.addItem("Executed SQL");
br.addElement(sql);
br.addItem("SQLState");
br.addElement(e.getSQLState());
br.addItem("ErrorCode");
br.addElement(e.getErrorCode());
br.addItem("SQLException");
br.addElement(e.getClass().getName());
br.addElement(extractMessage(e));
final SQLException nextEx = e.getNextException();
if (nextEx != null) {
br.addItem("NextException");
br.addElement(nextEx.getClass().getName());
br.addElement(extractMessage(nextEx));
final SQLException nextNextEx = nextEx.getNextException();
if (nextNextEx != null) {
br.addItem("NextNextException");
br.addElement(nextNextEx.getClass().getName());
br.addElement(extractMessage(nextNextEx));
}
}
final String msg = br.buildExceptionMessage();
throw new SQLFailureException(msg, e);
}
Aggregations