use of org.dbflute.exception.SQLFailureException in project dbflute-core by dbflute.
the class DfJdbcFacade method createSQLFailureException.
// ===================================================================================
// Exception Handling
// ==================
protected SQLFailureException createSQLFailureException(String sql, SQLException e) {
final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
br.addNotice("Failed to execute the SQL");
br.addItem("Executed SQL");
// may be null when e.g. connection failure
br.addElement(sql);
br.addItem("SQLException");
br.addElement(e.getClass());
br.addElement(e.getMessage());
final String msg = br.buildExceptionMessage();
return new SQLFailureException(msg, e);
}
use of org.dbflute.exception.SQLFailureException in project dbflute-core by dbflute.
the class DfJdbcFacade method retryableExecuteQuery.
// -----------------------------------------------------
// Retry-able
// ----------
protected DfCurrentSqlResult retryableExecuteQuery(List<String> trySqlList, Statement st) throws SQLException {
ResultSet rs = null;
String currentSql = null;
SQLException latestEx = null;
for (String trySql : trySqlList) {
currentSql = trySql;
try {
rs = st.executeQuery(trySql);
if (latestEx != null) {
// retry now
if (_debugRetryable) {
_log.info("retry SQL success: {}", trySql);
}
}
latestEx = null;
break;
} catch (SQLException continued) {
latestEx = continued;
if (_debugRetryable) {
final SQLFailureException failureEx = createSQLFailureException(currentSql, continued);
_log.info("try SQL failure: {}", failureEx.getMessage());
}
}
}
if (rs == null) {
if (latestEx != null) {
// basically here
throw latestEx;
} else {
// basically no way (executeQuery() does not return null), just in case
throw new IllegalStateException("Cannot make result set by the SQL: currentSql=" + currentSql);
}
}
return new DfCurrentSqlResult(currentSql, rs);
}
use of org.dbflute.exception.SQLFailureException in project dbflute-core by dbflute.
the class DfSqlFileFireMan method executeScriptFile.
protected DfSqlFileRunnerResult executeScriptFile(DfSqlFileRunner runner, SystemScript script, File sqlFile) {
final String sqlPath = resolvePath(sqlFile);
final String baseDir = Srl.substringLastFront(sqlPath, "/");
final String scriptName = Srl.substringLastRear(sqlPath, "/");
_log.info("...Executing the script: " + sqlPath);
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("Caught 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;
// wrapping quickly because SQLFailureException needs SQLException
// (and nested exception message has debug information so simple message here)
final SQLException sqlEx = new DfFireSqlScriptSQLException(msg);
final SQLFailureException failureEx = new SQLFailureException("Break the process for script failure.", sqlEx);
// no error continue, script error is treated as programming error
// because you can freely skip SQL failure in your script
runnerResult.setBreakCause(failureEx);
return runnerResult;
} else {
runnerResult.setGoodSqlCount(1);
return runnerResult;
}
}
use of org.dbflute.exception.SQLFailureException in project dbflute-core by dbflute.
the class DfClsTableClassificationArranger method selectTableClassification.
// ===================================================================================
// Select Table Classification
// ===========================
protected void selectTableClassification(DfClassificationTop classificationTop, List<DfClassificationElement> elementList, DfClassificationElement metaElement, Set<String> exceptCodeSet, Connection conn, String sql) {
final String classificationName = classificationTop.getClassificationName();
final String[] sisters = metaElement.getSisters();
final Map<String, Object> subItemPropMap = metaElement.getSubItemMap();
Statement st = null;
ResultSet rs = null;
try {
st = conn.createStatement();
_log.info("...Selecting for " + classificationName + " classification" + ln() + sql);
rs = st.executeQuery(sql);
final Set<String> duplicateCheckSet = StringSet.createAsCaseInsensitive();
while (rs.next()) {
final String code = rs.getString("cls_code");
final String name = rs.getString("cls_name");
final String alias = rs.getString("cls_alias");
final String comment = rs.getString("cls_comment");
if (exceptCodeSet.contains(code)) {
_log.info(" exceptd: " + code);
continue;
}
if (duplicateCheckSet.contains(code)) {
_log.info(" duplicate: " + code);
continue;
} else {
duplicateCheckSet.add(code);
}
final Map<String, Object> selectedMap = new LinkedHashMap<>();
selectedMap.put(DfClassificationElement.KEY_CODE, code);
selectedMap.put(DfClassificationElement.KEY_NAME, filterTableClassificationName(classificationTop, name));
selectedMap.put(DfClassificationElement.KEY_ALIAS, filterTableClassificationLiteralOutput(alias));
if (Srl.is_NotNull_and_NotTrimmedEmpty(comment)) {
// because of not required
selectedMap.put(DfClassificationElement.KEY_COMMENT, comment);
}
if (sisters != null && sisters.length > 0) {
final String sisterValue = rs.getString("cls_sister");
selectedMap.put(DfClassificationElement.KEY_SISTER_CODE, sisterValue);
}
if (subItemPropMap != null && !subItemPropMap.isEmpty()) {
final Map<String, Object> subItemMap = new LinkedHashMap<String, Object>();
for (String subItemKey : subItemPropMap.keySet()) {
final String clsKey = "cls_" + subItemKey;
final String subItemValue = rs.getString(clsKey);
final String subItemVeloFriendlyValue;
if (subItemValue != null) {
subItemVeloFriendlyValue = filterTableClassificationLiteralOutput(subItemValue);
} else {
// for determination in templates
subItemVeloFriendlyValue = "null";
}
subItemMap.put(subItemKey, subItemVeloFriendlyValue);
}
selectedMap.put(DfClassificationElement.KEY_SUB_ITEM_MAP, subItemMap);
}
final DfClassificationElement element = new DfClassificationElement();
element.setClassificationName(classificationName);
element.acceptBasicItemMap(selectedMap);
elementList.add(element);
}
} catch (SQLException e) {
throwTableClassificationSelectSQLFailureException(classificationName, sql, e);
throw new SQLFailureException("Failed to execute the SQL:" + ln() + sql, e);
} finally {
new DfClassificationJdbcCloser().closeStatement(st, rs);
}
}
use of org.dbflute.exception.SQLFailureException in project dbflute-core by dbflute.
the class DfClassificationProperties method throwTableClassificationSelectSQLFailureException.
protected void throwTableClassificationSelectSQLFailureException(String classificationName, String sql, SQLException e) {
final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
br.addNotice("Failed to select the classification resource from the table.");
br.addItem("Advice");
br.addElement("Make sure your classificationDefinitionMap.dfprop.");
br.addElement("For example:");
br.addElement(" (x):");
br.addElement(" ; MemberStatus = list:{");
br.addElement(" ; map:{");
br.addElement(" ; table=NOEXISTING_STATUS // *NG");
br.addElement(" ; code=MEMBER_STATUS_CODE; name=MEMBER_STATUS_NAME");
br.addElement(" ; comment=DESCRIPTION; orderBy=DISPLAY_ORDER");
br.addElement(" }");
br.addElement(" }");
br.addElement(" (x):");
br.addElement(" ; MemberStatus = list:{");
br.addElement(" ; map:{");
br.addElement(" ; table=MEMBER_STATUS");
br.addElement(" ; code=MEMBER_STATUS_CODE; name=NOEXISTING_NAME // *NG");
br.addElement(" ; comment=DESCRIPTION; orderBy=DISPLAY_ORDER");
br.addElement(" }");
br.addElement(" }");
br.addElement(" (o):");
br.addElement(" ; MemberStatus = list:{");
br.addElement(" ; map:{");
br.addElement(" ; table=MEMBER_STATUS // OK");
br.addElement(" ; code=MEMBER_STATUS_CODE; name=MEMBER_STATUS_NAME");
br.addElement(" ; comment=DESCRIPTION; orderBy=DISPLAY_ORDER");
br.addElement(" }");
br.addElement(" }");
br.addElement("");
br.addElement("Or remove it if the table is deleted from your schema.");
br.addItem("Classification");
br.addElement(classificationName);
br.addItem("SQL");
br.addElement(sql);
final String msg = br.buildExceptionMessage();
throw new SQLFailureException(msg, e);
}
Aggregations