Search in sources :

Example 16 with SQLFailureException

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

the class DfClassificationProperties method setupTableClassification.

protected void setupTableClassification(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 = newLinkedHashMap();
            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 DfClassificationSqlResourceCloser().closeStatement(st, rs);
    }
}
Also used : DfClassificationElement(org.dbflute.properties.assistant.classification.DfClassificationElement) DfClassificationSqlResourceCloser(org.dbflute.properties.assistant.classification.DfClassificationSqlResourceCloser) SQLException(java.sql.SQLException) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) LinkedHashMap(java.util.LinkedHashMap) SQLFailureException(org.dbflute.exception.SQLFailureException)

Example 17 with SQLFailureException

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

the class DfClassificationAllInOneSqlExecutor method executeAllInOneSql.

// ===================================================================================
// Execute
// =======
public List<Map<String, String>> executeAllInOneSql(Connection conn, String sql) {
    Statement st = null;
    ResultSet rs = null;
    final List<Map<String, String>> elementList = new ArrayList<Map<String, String>>();
    try {
        st = conn.createStatement();
        _log.debug("/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
        _log.debug("The classification sql: " + sql);
        rs = st.executeQuery(sql);
        while (rs.next()) {
            final String tmpClassificationNameValue = rs.getString("classificationName");
            final String tmpCodeValue = rs.getString(DfClassificationElement.KEY_CODE);
            assertCodeExists(sql, tmpCodeValue);
            String tmpNameValue = rs.getString(DfClassificationElement.KEY_NAME);
            if (tmpNameValue == null) {
                tmpNameValue = tmpCodeValue;
            }
            String tmpAliasValue = rs.getString(DfClassificationElement.KEY_ALIAS);
            if (tmpAliasValue == null) {
                tmpAliasValue = tmpNameValue;
            }
            final String tmpCommentValue = rs.getString(DfClassificationElement.KEY_COMMENT);
            final String tmpTopCommentValue = rs.getString(DfClassificationTop.KEY_TOP_COMMENT);
            final Map<String, String> selectedTmpMap = new LinkedHashMap<String, String>();
            selectedTmpMap.put("classificationName", tmpClassificationNameValue);
            selectedTmpMap.put(DfClassificationElement.KEY_CODE, tmpCodeValue);
            selectedTmpMap.put(DfClassificationElement.KEY_NAME, tmpNameValue);
            selectedTmpMap.put(DfClassificationElement.KEY_ALIAS, tmpAliasValue);
            if (tmpCommentValue != null) {
                selectedTmpMap.put(DfClassificationElement.KEY_COMMENT, tmpCommentValue);
            }
            if (tmpTopCommentValue != null) {
                selectedTmpMap.put(DfClassificationTop.KEY_TOP_COMMENT, tmpTopCommentValue);
            }
            elementList.add(selectedTmpMap);
        }
        _log.debug("- - - - - - - - /");
    } catch (SQLException e) {
        throw new SQLFailureException("Failed to execute the SQL:" + ln() + sql, e);
    } finally {
        new DfClassificationSqlResourceCloser().closeStatement(st, rs);
    }
    return elementList;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) SQLFailureException(org.dbflute.exception.SQLFailureException)

Example 18 with SQLFailureException

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

the class DfClassificationAllInOneSqlExecutor method executeAllInOneSql.

// ===================================================================================
// Execute
// =======
public List<Map<String, String>> executeAllInOneSql(Connection conn, String sql) {
    Statement st = null;
    ResultSet rs = null;
    final List<Map<String, String>> elementList = new ArrayList<Map<String, String>>();
    try {
        st = conn.createStatement();
        _log.debug("/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
        _log.debug("The classification sql: " + sql);
        rs = st.executeQuery(sql);
        while (rs.next()) {
            final String tmpClassificationNameValue = rs.getString("classificationName");
            final String tmpCodeValue = rs.getString(DfClassificationElement.KEY_CODE);
            assertCodeExists(sql, tmpCodeValue);
            String tmpNameValue = rs.getString(DfClassificationElement.KEY_NAME);
            if (tmpNameValue == null) {
                tmpNameValue = tmpCodeValue;
            }
            String tmpAliasValue = rs.getString(DfClassificationElement.KEY_ALIAS);
            if (tmpAliasValue == null) {
                tmpAliasValue = tmpNameValue;
            }
            final String tmpCommentValue = rs.getString(DfClassificationElement.KEY_COMMENT);
            final String tmpTopCommentValue = rs.getString(DfClassificationTop.KEY_TOP_COMMENT);
            final Map<String, String> selectedTmpMap = new LinkedHashMap<String, String>();
            selectedTmpMap.put("classificationName", tmpClassificationNameValue);
            selectedTmpMap.put(DfClassificationElement.KEY_CODE, tmpCodeValue);
            selectedTmpMap.put(DfClassificationElement.KEY_NAME, tmpNameValue);
            selectedTmpMap.put(DfClassificationElement.KEY_ALIAS, tmpAliasValue);
            if (tmpCommentValue != null) {
                selectedTmpMap.put(DfClassificationElement.KEY_COMMENT, tmpCommentValue);
            }
            if (tmpTopCommentValue != null) {
                selectedTmpMap.put(DfClassificationTop.KEY_TOP_COMMENT, tmpTopCommentValue);
            }
            elementList.add(selectedTmpMap);
        }
        _log.debug("- - - - - - - - /");
    } catch (SQLException e) {
        throw new SQLFailureException("Failed to execute the SQL:" + ln() + sql, e);
    } finally {
        new DfClassificationJdbcCloser().closeStatement(st, rs);
    }
    return elementList;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) SQLFailureException(org.dbflute.exception.SQLFailureException) DfClassificationJdbcCloser(org.dbflute.properties.assistant.classification.coins.DfClassificationJdbcCloser)

Example 19 with SQLFailureException

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

the class DfClsTableClassificationArranger 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);
}
Also used : ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) SQLFailureException(org.dbflute.exception.SQLFailureException)

Example 20 with SQLFailureException

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

the class DfSqlFileFireMan method fire.

// ===================================================================================
// Execute
// =======
/**
 * Load the SQL files and then fire them.
 * @return The result about firing SQL. (NotNull)
 */
public DfSqlFileFireResult fire(DfSqlFileRunner runner, List<File> sqlFileList) {
    final DfSqlFileFireResult fireResult = new DfSqlFileFireResult();
    SQLFailureException breakCause = null;
    int goodSqlCount = 0;
    int totalSqlCount = 0;
    for (final File sqlFile : sqlFileList) {
        if (!sqlFile.exists()) {
            String msg = "The file was not found: " + sqlFile;
            throw new IllegalStateException(msg);
        }
        if (_log.isInfoEnabled()) {
            _log.info("...Firing: " + sqlFile.getName());
        }
        final DfSqlFileRunnerResult runnerResult = processSqlFile(runner, sqlFile);
        if (runnerResult != null) {
            fireResult.addRunnerResult(runnerResult);
            goodSqlCount = goodSqlCount + runnerResult.getGoodSqlCount();
            breakCause = runnerResult.getBreakCause();
            if (breakCause != null) {
                break;
            } else {
                totalSqlCount = totalSqlCount + runnerResult.getTotalSqlCount();
            }
        }
    }
    final String title = _executorName != null ? _executorName : "Fired SQL";
    // Break Cause
    fireResult.setBreakCause(breakCause);
    // Exists Error
    fireResult.setExistsError((breakCause != null) || (totalSqlCount > goodSqlCount));
    // Result Message
    buildResultMessage(sqlFileList, fireResult, goodSqlCount, totalSqlCount, title);
    _log.info(fireResult.getResultMessage());
    // Detail Message
    fireResult.setDetailMessage(buildDetailMessage(fireResult));
    return fireResult;
}
Also used : File(java.io.File) SQLFailureException(org.dbflute.exception.SQLFailureException)

Aggregations

SQLFailureException (org.dbflute.exception.SQLFailureException)31 SQLException (java.sql.SQLException)19 Statement (java.sql.Statement)9 ResultSet (java.sql.ResultSet)7 LinkedHashMap (java.util.LinkedHashMap)5 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)5 ArrayList (java.util.ArrayList)4 Connection (java.sql.Connection)3 DatabaseMetaData (java.sql.DatabaseMetaData)3 DfTakeFinallyAssertionFailureException (org.dbflute.exception.DfTakeFinallyAssertionFailureException)3 DfProcedureMeta (org.dbflute.logic.jdbc.metadata.info.DfProcedureMeta)3 DfTableMeta (org.dbflute.logic.jdbc.metadata.info.DfTableMeta)3 File (java.io.File)2 Map (java.util.Map)2 ErrorContinuedSql (org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerResult.ErrorContinuedSql)2 DfProcedureExtractor (org.dbflute.logic.jdbc.metadata.basic.DfProcedureExtractor)2 DfTableExtractor (org.dbflute.logic.jdbc.metadata.basic.DfTableExtractor)2 DfTakeFinallyProcess (org.dbflute.logic.replaceschema.process.DfTakeFinallyProcess)2 DfClassificationElement (org.dbflute.properties.assistant.classification.DfClassificationElement)2 DfClassificationJdbcCloser (org.dbflute.properties.assistant.classification.coins.DfClassificationJdbcCloser)2