Search in sources :

Example 11 with DfClassificationElement

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

the class DfAppClsTableLoader method doArrangeLiteral.

protected void doArrangeLiteral(String classificationName, DfClassificationTop classificationTop, Map<String, Object> elementMap) {
    final DfClassificationElement element = new DfClassificationElement();
    element.setClassificationName(classificationName);
    element.acceptBasicItemMap(elementMap);
    classificationTop.addClassificationElement(element);
}
Also used : DfClassificationElement(org.dbflute.properties.assistant.classification.DfClassificationElement)

Example 12 with DfClassificationElement

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

the class DfRefClsLoadingHandler method includeRefClsElement.

// ===================================================================================
// Include refCls
// ==============
public void includeRefClsElement(DfClassificationTop classificationTop, DfRefClsElement refClsElement) {
    final DfClassificationTop refClsTop = refClsElement.getReferredClsTop();
    if (refClsElement.isRefTypeIncluded()) {
        final String groupName = refClsElement.getGroupName();
        final List<DfClassificationElement> refElementList;
        if (groupName != null) {
            // e.g. map:{ refCls=maihamadb@MemberStatus.serviceAvailable ; refType=included }
            refElementList = findRefGroup(refClsElement, refClsTop, groupName).getElementList();
        } else {
            // e.g. map:{ refCls=maihamadb@MemberStatus ; refType=included }
            refElementList = refClsTop.getClassificationElementList();
        }
        classificationTop.addClassificationElementAll(copyIncludedElementList(classificationTop, refElementList));
    }
// later, literal elements are not evaluated yet here
// classificationTop.inheritRefClsGroup(dbClsTop);
}
Also used : DfClassificationElement(org.dbflute.properties.assistant.classification.DfClassificationElement) DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop)

Example 13 with DfClassificationElement

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

the class DfClsDeploymentInitializer method initializeClassificationDeployment.

// ===================================================================================
// Initialize
// ==========
public Map<String, Map<String, String>> initializeClassificationDeployment(Database database) {
    // this should be called immediately after creating schema data
    // it should be called after additional-foreign-key initialization
    // so no modification for now
    _log.info("...Initializing ClassificationDeployment: project={}", database.getProjectName());
    // only overridden if called with same database
    if (_allColumnClassificationMap != null) {
        final List<Table> tableList = database.getTableList();
        for (Table table : tableList) {
            final Map<String, String> columnClsMap = getColumnClsMap(_existingDeploymentMap, table.getTableDbName());
            for (Entry<String, String> entry : _allColumnClassificationMap.entrySet()) {
                columnClsMap.put(entry.getKey(), entry.getValue());
            }
        }
    }
    _classificationDefinitionInitializer.process();
    for (Entry<String, DfClassificationElement> entry : _tableClassificationMap.entrySet()) {
        final DfClassificationElement element = entry.getValue();
        if (element.getClassificationTop().isSuppressAutoDeploy()) {
            continue;
        }
        final Map<String, String> columnClsMap = getColumnClsMap(_existingDeploymentMap, element.getTable());
        final String classificationName = element.getClassificationName();
        registerColumnClsIfNeeds(columnClsMap, element.getCode(), classificationName);
        final Table table = database.getTable(element.getTable());
        if (table == null || table.hasCompoundPrimaryKey()) {
            continue;
        }
        final Column column = table.getColumn(element.getCode());
        if (column == null || !column.isPrimaryKey()) {
            continue;
        }
        final List<ForeignKey> referrers = column.getReferrers();
        for (ForeignKey referrer : referrers) {
            if (!referrer.isSimpleKeyFK()) {
                continue;
            }
            final Table referrerTable = referrer.getTable();
            final String referrerTableDbName = referrerTable.getTableDbName();
            final Map<String, String> referrerClsMap = getColumnClsMap(_existingDeploymentMap, referrerTableDbName);
            final Column localColumnAsOne = referrer.getLocalColumnAsOne();
            registerColumnClsIfNeeds(referrerClsMap, localColumnAsOne.getName(), classificationName);
        }
    }
    return _existingDeploymentMap;
}
Also used : DfClassificationElement(org.dbflute.properties.assistant.classification.DfClassificationElement) Table(org.apache.torque.engine.database.model.Table) Column(org.apache.torque.engine.database.model.Column) ForeignKey(org.apache.torque.engine.database.model.ForeignKey)

Example 14 with DfClassificationElement

use of org.dbflute.properties.assistant.classification.DfClassificationElement 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);
    }
}
Also used : DfClassificationElement(org.dbflute.properties.assistant.classification.DfClassificationElement) SQLException(java.sql.SQLException) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) LinkedHashMap(java.util.LinkedHashMap) SQLFailureException(org.dbflute.exception.SQLFailureException) DfClassificationJdbcCloser(org.dbflute.properties.assistant.classification.coins.DfClassificationJdbcCloser)

Example 15 with DfClassificationElement

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

the class DfRefClsRefTypeVerifier method doVerifyRefExists.

// -----------------------------------------------------
// Exists
// ------
protected void doVerifyRefExists(DfClassificationTop classificationTop) {
    final List<DfClassificationElement> appElementList = classificationTop.getClassificationElementList();
    final List<DfClassificationElement> referredElementList = _referredElementList;
    final List<DfClassificationElement> nonExistingList = appElementList.stream().filter(appElement -> {
        return notMatchesReferredElement(referredElementList, appElement);
    }).collect(Collectors.toList());
    if (!nonExistingList.isEmpty()) {
        final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
        br.addNotice("Not found the app classification code in the referred classification");
        br.addItem("Advice");
        br.addElement("The codes of the app classification should be included");
        br.addElement("in the referred classification because of refType='exists'.");
        br.addElement("For example:");
        br.addElement("  (x): app(A), referred(B, C)");
        br.addElement("  (x): app(A, B), referred(A, C)");
        br.addElement("  (x): app(A, B, C), referred(A, B)");
        br.addElement("  (o): app(A), referred(A, B)");
        br.addElement("  (o): app(A, B), referred(A, B, C)");
        br.addElement("  (o): app(A, B, C), referred(A, B, C)");
        br.addItem("dfprop File");
        br.addElement(_resourceFile);
        br.addItem("AppCls");
        br.addElement(classificationTop.getClassificationName() + ": " + buildClsCodesExp(appElementList));
        br.addItem("ReferredCls");
        br.addElement(buildReferredExp() + ": " + buildClsCodesExp(referredElementList));
        br.addItem("Ref Type");
        br.addElement(_refType);
        br.addItem("Non-Existing Code");
        br.addElement(nonExistingList.stream().map(element -> {
            return element.getCode();
        }).collect(Collectors.joining(", ")));
        final String msg = br.buildExceptionMessage();
        throw new DfIllegalPropertySettingException(msg);
    }
}
Also used : ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException) List(java.util.List) DfClassificationElement(org.dbflute.properties.assistant.classification.DfClassificationElement) DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop) Collectors(java.util.stream.Collectors) Srl(org.dbflute.util.Srl) DfClassificationGroup(org.dbflute.properties.assistant.classification.DfClassificationGroup) DfClassificationElement(org.dbflute.properties.assistant.classification.DfClassificationElement) ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException)

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