Search in sources :

Example 16 with DfClassificationElement

use of org.dbflute.properties.assistant.classification.DfClassificationElement in project dbflute-core by dbflute.

the class DfClsTableClassificationArranger method arrangeTableClassification.

// ===================================================================================
// Table Classification
// ====================
public void arrangeTableClassification(Map<String, DfClassificationElement> tableClassificationMap, DfClassificationTop classificationTop, Map<String, Object> elementMap, String table, List<DfClassificationElement> elementList, Connection conn) {
    final DfClassificationElement metaElement = createBasicElement(classificationTop, elementMap, table);
    if (isCompatibleElementMapSuppressAutoDeploy(elementMap)) {
        // for compatible
        classificationTop.setSuppressAutoDeploy(true);
    }
    final String where = (String) elementMap.get("where");
    final String orderBy = (String) elementMap.get("orderBy");
    final Set<String> exceptCodeSet = extractExceptCodeSet(classificationTop, elementMap);
    final String sql = buildTableClassificationSql(metaElement, table, where, orderBy);
    selectTableClassification(classificationTop, elementList, metaElement, exceptCodeSet, conn, sql);
    final String classificationName = classificationTop.getClassificationName();
    // e.g. for auto-deploy and determination
    tableClassificationMap.put(classificationName, metaElement);
    metaElement.setClassificationTop(classificationTop);
}
Also used : DfClassificationElement(org.dbflute.properties.assistant.classification.DfClassificationElement)

Example 17 with DfClassificationElement

use of org.dbflute.properties.assistant.classification.DfClassificationElement in project dbflute-core by dbflute.

the class DfClassificationProperties method processAllInOneTableClassification.

// -----------------------------------------------------
// All-in-One Table Classification
// -------------------------------
protected void processAllInOneTableClassification(Connection conn, String sql) {
    final DfClassificationAllInOneSqlExecutor executor = new DfClassificationAllInOneSqlExecutor();
    final List<Map<String, String>> resultList = executor.executeAllInOneSql(conn, sql);
    for (Map<String, String> map : resultList) {
        final String classificationName = map.get("classificationName");
        final DfClassificationTop classificationTop;
        {
            DfClassificationTop tmpTop = _classificationTopMap.get(classificationName);
            if (tmpTop == null) {
                tmpTop = createAllInOneTableClassificationTop(classificationName);
                _classificationTopMap.put(classificationName, tmpTop);
            }
            classificationTop = tmpTop;
        }
        // }
        if (!classificationTop.hasTopComment()) {
            final String topComment = map.get(DfClassificationTop.KEY_TOP_COMMENT);
            classificationTop.setTopComment(topComment);
        }
        if (!classificationTop.hasCodeType()) {
            final String codeType;
            {
                String tmpType = map.get(DfClassificationTop.KEY_CODE_TYPE);
                if (Srl.is_Null_or_TrimmedEmpty(tmpType)) {
                    // for compatibility
                    tmpType = map.get(DfClassificationTop.KEY_DATA_TYPE);
                }
                codeType = tmpType;
            }
            classificationTop.setCodeType(codeType);
        }
        final DfClassificationElement element = new DfClassificationElement();
        element.setClassificationName(classificationName);
        element.acceptBasicItemMap(map);
        classificationTop.addClassificationElement(element);
    }
}
Also used : DfClassificationElement(org.dbflute.properties.assistant.classification.DfClassificationElement) DfClassificationAllInOneSqlExecutor(org.dbflute.properties.assistant.classification.DfClassificationAllInOneSqlExecutor) DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) StringKeyMap(org.dbflute.helper.StringKeyMap)

Example 18 with DfClassificationElement

use of org.dbflute.properties.assistant.classification.DfClassificationElement 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 19 with DfClassificationElement

use of org.dbflute.properties.assistant.classification.DfClassificationElement in project dbflute-core by dbflute.

the class DfClassificationProperties method processTableClassification.

protected void processTableClassification(DfClassificationTop classificationTop, Map<?, ?> elementMap, String table, List<DfClassificationElement> elementList, Connection conn) {
    final DfClassificationElement metaElement = new DfClassificationElement();
    metaElement.setClassificationName(classificationTop.getClassificationName());
    metaElement.setTable(table);
    metaElement.acceptBasicItemMap(elementMap);
    if (isElementMapSuppressAutoDeploy(elementMap)) {
        // for compatible
        classificationTop.setSuppressAutoDeploy(true);
    }
    final String where = (String) elementMap.get("where");
    final String orderBy = (String) elementMap.get("orderBy");
    final Set<String> exceptCodeSet = extractExceptCodeSet(classificationTop, elementMap);
    final String sql = buildTableClassificationSql(metaElement, table, where, orderBy);
    setupTableClassification(classificationTop, elementList, metaElement, exceptCodeSet, conn, sql);
    final String classificationName = classificationTop.getClassificationName();
    // e.g. for auto-deploy and determination
    _tableClassificationMap.put(classificationName, metaElement);
    metaElement.setClassificationTop(classificationTop);
}
Also used : DfClassificationElement(org.dbflute.properties.assistant.classification.DfClassificationElement)

Example 20 with DfClassificationElement

use of org.dbflute.properties.assistant.classification.DfClassificationElement in project dbflute-core by dbflute.

the class ForeignKey method doExtractFixedConditionEmbeddedCommentClassificationNormalCode.

protected String doExtractFixedConditionEmbeddedCommentClassificationNormalCode(DfClassificationTop classificationTop, String elementName) {
    final List<DfClassificationElement> elementList = classificationTop.getClassificationElementList();
    String code = null;
    for (final DfClassificationElement element : elementList) {
        final String name = element.getName();
        if (elementName.equals(name)) {
            code = quoteClassifiationElementIfNeeds(classificationTop, element.getCode());
            break;
        }
    }
    return code;
}
Also used : DfClassificationElement(org.dbflute.properties.assistant.classification.DfClassificationElement)

Aggregations

DfClassificationElement (org.dbflute.properties.assistant.classification.DfClassificationElement)30 DfClassificationTop (org.dbflute.properties.assistant.classification.DfClassificationTop)10 DfIllegalPropertySettingException (org.dbflute.exception.DfIllegalPropertySettingException)8 ArrayList (java.util.ArrayList)6 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)6 LinkedHashMap (java.util.LinkedHashMap)5 List (java.util.List)5 DfClassificationGroup (org.dbflute.properties.assistant.classification.DfClassificationGroup)5 Map (java.util.Map)4 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Statement (java.sql.Statement)2 DfFixedConditionInvalidClassificationEmbeddedCommentException (org.dbflute.exception.DfFixedConditionInvalidClassificationEmbeddedCommentException)2 SQLFailureException (org.dbflute.exception.SQLFailureException)2 StringKeyMap (org.dbflute.helper.StringKeyMap)2 DfClassificationJdbcCloser (org.dbflute.properties.assistant.classification.coins.DfClassificationJdbcCloser)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1