Search in sources :

Example 21 with DfClassificationElement

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

the class ForeignKey method throwFixedConditionEmbeddedCommentClassificationElementNotFoundException.

protected void throwFixedConditionEmbeddedCommentClassificationElementNotFoundException(DfClassificationTop classificationTop, String elementName) {
    final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
    br.addNotice("Not found the classification element in fixed condition.");
    br.addItem("Foreign Key");
    br.addElement(_name);
    br.addItem("Classification Name");
    br.addElement(classificationTop.getClassificationName());
    br.addItem("NotFound Element");
    br.addElement(elementName);
    br.addItem("Defined Element");
    final List<DfClassificationElement> elementList = classificationTop.getClassificationElementList();
    for (DfClassificationElement element : elementList) {
        br.addElement(element);
    }
    final String msg = br.buildExceptionMessage();
    throw new DfFixedConditionInvalidClassificationEmbeddedCommentException(msg);
}
Also used : DfClassificationElement(org.dbflute.properties.assistant.classification.DfClassificationElement) ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) DfFixedConditionInvalidClassificationEmbeddedCommentException(org.dbflute.exception.DfFixedConditionInvalidClassificationEmbeddedCommentException)

Example 22 with DfClassificationElement

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

the class DfClassificationProperties method getClassificationDefinitionMap.

// -----------------------------------------------------
// Native Definition
// -----------------
/**
 * Get the map of classification definition.
 * @return The map of classification definition. (NotNull)
 */
protected Map<String, DfClassificationTop> getClassificationDefinitionMap() {
    if (_classificationTopMap != null) {
        return _classificationTopMap;
    }
    _classificationTopMap = newLinkedHashMap();
    final Map<String, Object> plainDefinitionMap;
    {
        final String mapName = KEY_classificationDefinitionMap;
        final String propKey = "torque." + mapName;
        plainDefinitionMap = resolveSplit(mapName, mapProp(propKey, DEFAULT_EMPTY_MAP));
    }
    final DfClsElementLiteralArranger literalArranger = new DfClsElementLiteralArranger();
    String allInOneSql = null;
    Connection conn = null;
    try {
        for (Entry<String, Object> entry : plainDefinitionMap.entrySet()) {
            final String classificationName = entry.getKey();
            final Object objValue = entry.getValue();
            // handle special elements
            if (classificationName.equalsIgnoreCase("$$SQL$$")) {
                allInOneSql = (String) objValue;
                continue;
            }
            // check duplicate classification
            if (_classificationTopMap.containsKey(classificationName)) {
                String msg = "Duplicate classification: " + classificationName;
                throw new DfIllegalPropertySettingException(msg);
            }
            final DfClassificationTop classificationTop = new DfClassificationTop(classificationName);
            _classificationTopMap.put(classificationName, classificationTop);
            // handle classification elements
            if (!(objValue instanceof List<?>)) {
                throwClassificationMapValueIllegalListTypeException(objValue);
            }
            final List<?> plainList = (List<?>) objValue;
            final List<DfClassificationElement> elementList = new ArrayList<DfClassificationElement>();
            boolean tableClassification = false;
            for (Object element : plainList) {
                if (!(element instanceof Map<?, ?>)) {
                    throwClassificationListElementIllegalMapTypeException(element);
                }
                @SuppressWarnings("unchecked") final Map<String, Object> elementMap = (Map<String, Object>) element;
                // from table
                final String table = (String) elementMap.get(DfClassificationElement.KEY_TABLE);
                if (Srl.is_NotNull_and_NotTrimmedEmpty(table)) {
                    tableClassification = true;
                    if (conn == null) {
                        // on demand
                        conn = createMainSchemaConnection();
                    }
                    arrangeTableClassification(classificationTop, elementMap, table, elementList, conn);
                    continue;
                }
                // from literal
                if (isElementMapClassificationTop(elementMap)) {
                    // top definition
                    arrangeClassificationTopFromLiteral(classificationTop, elementMap);
                } else {
                    literalArranger.arrange(classificationName, elementMap);
                    final DfClassificationElement classificationElement = new DfClassificationElement();
                    classificationElement.setClassificationName(classificationName);
                    classificationElement.acceptBasicItemMap(elementMap);
                    elementList.add(classificationElement);
                }
            }
            // adjust classification top
            classificationTop.addClassificationElementAll(elementList);
            classificationTop.setTableClassification(tableClassification);
            _classificationTopMap.put(classificationName, classificationTop);
        }
        if (allInOneSql != null) {
            if (conn == null) {
                // on demand
                conn = createMainSchemaConnection();
            }
            arrangeAllInOneTableClassification(conn, allInOneSql);
        }
        // *Classification Resource Point!
        reflectClassificationResourceToDefinition();
        filterUseDocumentOnly();
        verifyClassificationConstraintsIfNeeds();
        prepareSuppressedDBAccessClassTableSet();
    } finally {
        new DfClassificationJdbcCloser().closeConnection(conn);
    }
    return _classificationTopMap;
}
Also used : Connection(java.sql.Connection) ArrayList(java.util.ArrayList) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException) DfClassificationJdbcCloser(org.dbflute.properties.assistant.classification.coins.DfClassificationJdbcCloser) DfClsElementLiteralArranger(org.dbflute.properties.assistant.classification.element.proploading.DfClsElementLiteralArranger) DfClassificationElement(org.dbflute.properties.assistant.classification.DfClassificationElement) DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) StringKeyMap(org.dbflute.helper.StringKeyMap)

Example 23 with DfClassificationElement

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

the class DfClsTableAllInOneArranger method arrangeAllInOneTableClassification.

public void arrangeAllInOneTableClassification(Map<String, DfClassificationTop> classificationTopMap, 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.allinone.DfClassificationAllInOneSqlExecutor) DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop) Map(java.util.Map)

Example 24 with DfClassificationElement

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

the class DfRefClsRefTypeVerifier method doVerifyRefMatches.

// -----------------------------------------------------
// Matches
// -------
protected void doVerifyRefMatches(DfClassificationTop classificationTop) {
    final List<DfClassificationElement> appElementList = classificationTop.getClassificationElementList();
    final List<DfClassificationElement> referredElementList = _referredElementList;
    final boolean hasNonExisting = appElementList.stream().anyMatch(appElement -> {
        return notMatchesReferredElement(referredElementList, appElement);
    });
    if (appElementList.size() != referredElementList.size() || hasNonExisting) {
        final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
        br.addNotice("Unmatched the web classification code with the referred classification");
        br.addItem("Advice");
        br.addElement("The codes of the web classification should match");
        br.addElement("with referred classification because of refType='matches'.");
        br.addElement("For example:");
        br.addElement("  (x): web(A), referred(A, C)");
        br.addElement("  (x): web(A, B), referred(A, C)");
        br.addElement("  (o): web(A, B), referred(A, B)");
        br.addElement("  (o): web(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("Code Count");
        br.addElement("app=" + appElementList.size() + " / referred=" + referredElementList.size());
        final String msg = br.buildExceptionMessage();
        throw new DfIllegalPropertySettingException(msg);
    }
}
Also used : DfClassificationElement(org.dbflute.properties.assistant.classification.DfClassificationElement) ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException)

Example 25 with DfClassificationElement

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

the class DfClassificationResourceFileAnalyzer method extractClassificationElement.

protected DfClassificationElement extractClassificationElement(String line) {
    if (!isElementLine(line)) {
        String msg = "The line should be element line: line=" + line;
        throw new IllegalArgumentException(msg);
    }
    line = line.trim();
    line = removeRearXmlEndIfNeeds(line);
    line = line.substring(line.indexOf("- ") + "- ".length());
    final String code = line.substring(0, line.indexOf(",")).trim();
    line = line.substring(line.indexOf(",") + ",".length());
    final String name;
    String alias = null;
    String comment = null;
    if (line.contains(",")) {
        name = line.substring(0, line.indexOf(",")).trim();
        line = line.substring(line.indexOf(",") + ",".length());
        if (line.contains(",")) {
            alias = line.substring(0, line.indexOf(",")).trim();
            line = line.substring(line.indexOf(",") + ",".length());
            comment = line.substring(0).trim();
        } else {
            alias = line.substring(0).trim();
        }
    } else {
        name = line.substring(0).trim();
    }
    final DfClassificationElement classificationElement = new DfClassificationElement();
    classificationElement.setCode(code);
    classificationElement.setName(name);
    classificationElement.setAlias(alias);
    classificationElement.setComment(comment);
    // unsupported here
    classificationElement.setSisters(new String[] {});
    return classificationElement;
}
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