Search in sources :

Example 26 with DfClassificationTop

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

the class DfImplicitClassificationChecker method check.

public void check(File file, String tableDbName, String columnDbName, Connection conn) throws SQLException {
    final DfClassificationProperties prop = getClassificationProperties();
    final String classificationName = prop.getClassificationName(tableDbName, columnDbName);
    final DfClassificationTop classificationTop = prop.getClassificationTop(classificationName);
    if (classificationTop == null) {
        // no way (just in case)
        return;
    }
    if (classificationTop.isTableClassification()) {
        // basically checked by FK constraint
        return;
    }
    if (!classificationTop.isCheckClassificationCode() && !classificationTop.isCheckImplicitSet()) {
        // no option
        return;
    }
    final ClassificationUndefinedHandlingType undefinedHandlingType = classificationTop.getUndefinedHandlingType();
    if (undefinedHandlingType == null) {
        // no way (just in case)
        return;
    }
    if (!undefinedHandlingType.isChecked()) {
        // no handling option
        return;
    }
    final boolean quote = prop.isCodeTypeNeedsQuoted(classificationName);
    final List<String> codeList = prop.getClassificationElementCodeList(classificationName);
    final String sql = buildDistinctSql(tableDbName, columnDbName, quote, codeList);
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        _log.info(sql);
        ps = conn.prepareStatement(sql);
        rs = ps.executeQuery();
        final List<String> illegalCodeList = new ArrayList<String>();
        while (rs.next()) {
            illegalCodeList.add(rs.getString(1));
        }
        if (!illegalCodeList.isEmpty()) {
            handleLoadDataIllegalImplicitClassificationValueException(file, tableDbName, columnDbName, classificationName, codeList, illegalCodeList, undefinedHandlingType);
        }
    } finally {
        if (rs != null) {
            rs.close();
        }
        if (ps != null) {
            ps.close();
        }
    }
}
Also used : ClassificationUndefinedHandlingType(org.dbflute.jdbc.ClassificationUndefinedHandlingType) DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) DfClassificationProperties(org.dbflute.properties.DfClassificationProperties)

Example 27 with DfClassificationTop

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

the class DfRefClsLoadingHandler method registerRefClsReference.

// ===================================================================================
// Register Reference
// ==================
public void registerRefClsReference(String requestName, String clsTheme, List<DfClassificationTop> topList, Map<String, Object> optionMap) {
    if (!isOptionLastaFlute(optionMap)) {
        // only LastaFlute classifications can be referred (to be simple logic)
        return;
    }
    if (isOptionLastaDoc(optionMap)) {
        // LastaDoc uses real loader's registration (to avoid unexpected data use)
        return;
    }
    final Map<String, DfClassificationTop> clsTopMap = topList.stream().collect(Collectors.toMap(top -> top.getClassificationName(), top -> top));
    // not null here, already checked here
    final String cdefPackage = extractCDefPackage(optionMap);
    // me too
    final String cdefClassName = extractCDefClassName(optionMap);
    if (cdefPackage == null || cdefClassName == null) {
        // just in case
        throwRefClsReferenceCDefInfoNotFoundException(requestName, clsTheme, optionMap, cdefPackage, cdefClassName);
    }
    final DfRefClsReferredCDef referredCDef = new DfRefClsReferredCDef(cdefPackage, cdefClassName);
    DfRefClsReferenceRegistry.getInstance().registerReference(clsTheme, clsTopMap, referredCDef);
}
Also used : DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException) DfClassificationElement(org.dbflute.properties.assistant.classification.DfClassificationElement) DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop) DfRefClsReferredCDef(org.dbflute.properties.assistant.classification.refcls.DfRefClsReferredCDef) DfBuildProperties(org.dbflute.DfBuildProperties) DfBasicProperties(org.dbflute.properties.DfBasicProperties) Collectors(java.util.stream.Collectors) DfClassificationGroup(org.dbflute.properties.assistant.classification.DfClassificationGroup) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) List(java.util.List) Map(java.util.Map) Optional(java.util.Optional) DfRefClsElement(org.dbflute.properties.assistant.classification.refcls.DfRefClsElement) DfFreeGenResource(org.dbflute.logic.manage.freegen.DfFreeGenResource) Srl(org.dbflute.util.Srl) DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop) DfRefClsReferredCDef(org.dbflute.properties.assistant.classification.refcls.DfRefClsReferredCDef)

Example 28 with DfClassificationTop

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

the class DfRefClsLoadingHandler method prepareImportedReferredCDefFqcnList.

// ===================================================================================
// Referred CDef
// =============
public List<String> prepareImportedReferredCDefFqcnList(List<DfClassificationTop> topList, Map<String, Object> optionMap) {
    // null allowed, as best effort way
    final String currentCDefPackage = extractCDefPackage(optionMap);
    final Map<String, String> refThemeCDefFqcnMap = new LinkedHashMap<String, String>();
    for (DfClassificationTop top : topList) {
        final List<DfRefClsElement> refClsElementList = top.getRefClsElementList();
        for (DfRefClsElement refClsElement : refClsElementList) {
            final String refClsTheme = refClsElement.getRefClsTheme();
            final String existingImportExp = refThemeCDefFqcnMap.get(refClsTheme);
            if (existingImportExp != null) {
                break;
            }
            final String referredCDefPackage = refClsElement.getReferredCDefPackage();
            if (currentCDefPackage != null && currentCDefPackage.equals(referredCDefPackage)) {
                // same-package import statement is unneeded (to avoid Eclipse warning) e.g. namedcls to namedcls
                continue;
            }
            final String referredCDefClassName = refClsElement.getReferredCDefClassName();
            final String refThemeCDefFqcn = referredCDefPackage + "." + referredCDefClassName;
            refThemeCDefFqcnMap.put(refClsTheme, refThemeCDefFqcn);
        }
    }
    return new ArrayList<>(refThemeCDefFqcnMap.values());
}
Also used : DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop) ArrayList(java.util.ArrayList) DfRefClsElement(org.dbflute.properties.assistant.classification.refcls.DfRefClsElement) LinkedHashMap(java.util.LinkedHashMap)

Example 29 with DfClassificationTop

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

the class DfRefClsLoadingHandler method findReferredClsTop.

// ===================================================================================
// Find Reference
// ==============
// -----------------------------------------------------
// Referred ClsTop
// ---------------
protected DfClassificationTop findReferredClsTop(String classificationName, String refAttr, String refClsTheme, String refClsName, DfFreeGenResource resource) {
    final DfRefClsReference reference = findReference(classificationName, refAttr, refClsTheme, refClsName, resource);
    final Map<String, DfClassificationTop> clsTopMap = reference.getReferredClsTopMap();
    final DfClassificationTop referredClsTop = clsTopMap.get(refClsName);
    if (referredClsTop == null) {
        throwAppClsReferredClsNotFoundException(classificationName, refAttr, refClsTheme, refClsName, clsTopMap, resource);
    }
    return referredClsTop;
}
Also used : DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop)

Example 30 with DfClassificationTop

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

the class DfRefClsLoadingHandler method createRefClsElement.

public DfRefClsElement createRefClsElement(String classificationName, Map<String, Object> elementMap, DfFreeGenResource resource) {
    // e.g. map:{ refCls=maihamadb@MemberStatus ; refType=included }
    final String refAttr = (String) elementMap.get(DfRefClsElement.KEY_REFCLS);
    // of e.g. DB or "appcls" or namedcls's name
    final String refClsTheme;
    // classification name
    final String refClsName;
    final String refGroupName;
    if (refAttr.contains("@")) {
        // #hope other schema's reference
        refClsTheme = Srl.substringFirstFront(refAttr, "@");
        final String rearName = Srl.substringFirstRear(refAttr, "@");
        if (rearName.contains(".")) {
            refClsName = Srl.substringFirstFront(rearName, ".");
            refGroupName = Srl.substringFirstRear(rearName, ".");
        } else {
            refClsName = rearName;
            refGroupName = null;
        }
    } else {
        // current DB as default
        refClsTheme = getBasicProperties().getProjectName();
        if (refAttr.contains(".")) {
            refClsName = Srl.substringFirstFront(refAttr, ".");
            refGroupName = Srl.substringFirstRear(refAttr, ".");
        } else {
            refClsName = refAttr;
            refGroupName = null;
        }
    }
    final String refType = extractRefType(classificationName, elementMap);
    final DfClassificationTop referredClsTop = findReferredClsTop(classificationName, refAttr, refClsTheme, refClsName, resource);
    final DfRefClsReferredCDef referredCDef = findReferredCDef(classificationName, refAttr, refClsTheme, refClsName, resource);
    final DfClassificationGroup referredGroup = findReferredGroup(classificationName, refAttr, refClsTheme, refClsName, refGroupName, referredClsTop, resource);
    final String resourceFile = resource.getResourceFile();
    return new DfRefClsElement(refClsTheme, refClsName, refGroupName, refType, referredClsTop, referredCDef, referredGroup, resourceFile);
}
Also used : DfClassificationGroup(org.dbflute.properties.assistant.classification.DfClassificationGroup) DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop) DfRefClsReferredCDef(org.dbflute.properties.assistant.classification.refcls.DfRefClsReferredCDef) DfRefClsElement(org.dbflute.properties.assistant.classification.refcls.DfRefClsElement)

Aggregations

DfClassificationTop (org.dbflute.properties.assistant.classification.DfClassificationTop)38 DfClassificationElement (org.dbflute.properties.assistant.classification.DfClassificationElement)11 ArrayList (java.util.ArrayList)10 DfIllegalPropertySettingException (org.dbflute.exception.DfIllegalPropertySettingException)10 List (java.util.List)6 Map (java.util.Map)6 DfClassificationProperties (org.dbflute.properties.DfClassificationProperties)5 DfClassificationGroup (org.dbflute.properties.assistant.classification.DfClassificationGroup)5 LinkedHashMap (java.util.LinkedHashMap)4 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)4 DfRefClsElement (org.dbflute.properties.assistant.classification.refcls.DfRefClsElement)4 DfRefClsElement (org.dbflute.properties.assistant.classification.DfRefClsElement)3 DfRefClsReferredCDef (org.dbflute.properties.assistant.classification.refcls.DfRefClsReferredCDef)3 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 Collectors (java.util.stream.Collectors)2 DfFixedConditionInvalidClassificationEmbeddedCommentException (org.dbflute.exception.DfFixedConditionInvalidClassificationEmbeddedCommentException)2 StringKeyMap (org.dbflute.helper.StringKeyMap)2 ClassificationUndefinedHandlingType (org.dbflute.jdbc.ClassificationUndefinedHandlingType)2 DfClsElementLiteralArranger (org.dbflute.properties.assistant.classification.element.proploading.DfClsElementLiteralArranger)2