Search in sources :

Example 6 with ClassificationUndefinedHandlingType

use of org.dbflute.jdbc.ClassificationUndefinedHandlingType 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 7 with ClassificationUndefinedHandlingType

use of org.dbflute.jdbc.ClassificationUndefinedHandlingType in project dbflute-core by dbflute.

the class DfClassificationProperties method getElementMapUndefinedHandlingType.

@SuppressWarnings("unchecked")
protected ClassificationUndefinedHandlingType getElementMapUndefinedHandlingType(Map<?, ?> elementMap) {
    if (isElementMapCheckImplicitSet(elementMap)) {
        return ClassificationUndefinedHandlingType.EXCEPTION;
    }
    final String key = DfClassificationTop.KEY_UNDEFINED_HANDLING_TYPE;
    final DfLittleAdjustmentProperties prop = getLittleAdjustmentProperties();
    final ClassificationUndefinedHandlingType defaultType = prop.getClassificationUndefinedHandlingType();
    final String defaultValue = defaultType.code();
    final String code = getProperty(key, defaultValue, (Map<String, ? extends Object>) elementMap);
    final ClassificationUndefinedHandlingType handlingType = ClassificationUndefinedHandlingType.codeOf(code);
    if (handlingType == null) {
        throwUnknownClassificationUndefinedCodeHandlingTypeException(code);
    }
    return handlingType;
}
Also used : ClassificationUndefinedHandlingType(org.dbflute.jdbc.ClassificationUndefinedHandlingType)

Example 8 with ClassificationUndefinedHandlingType

use of org.dbflute.jdbc.ClassificationUndefinedHandlingType 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 9 with ClassificationUndefinedHandlingType

use of org.dbflute.jdbc.ClassificationUndefinedHandlingType in project dbflute-core by dbflute.

the class DfLittleAdjustmentProperties method throwUnknownClassificationUndefinedHandlingTypeException.

protected void throwUnknownClassificationUndefinedHandlingTypeException(String code, String dfpropFile) {
    final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
    br.addNotice("Unknown handling type of classification undefined code.");
    br.addItem("Advice");
    br.addElement("You can specify following types:");
    for (ClassificationUndefinedHandlingType handlingType : ClassificationUndefinedHandlingType.values()) {
        br.addElement(" " + handlingType.code());
    }
    final String exampleCode = ClassificationUndefinedHandlingType.EXCEPTION.code();
    br.addElement("");
    br.addElement("For example: (littleAdjustmentMap.dfprop)");
    br.addElement("map:{");
    br.addElement("    ...");
    br.addElement("    ");
    br.addElement("    ; classificationUndefinedCodeHandlingType = " + exampleCode);
    br.addElement("    ...");
    br.addElement("}");
    br.addItem("Specified Unknown Type");
    br.addElement(code);
    br.addItem("dfprop File");
    br.addElement(dfpropFile);
    final String msg = br.buildExceptionMessage();
    throw new DfIllegalPropertySettingException(msg);
}
Also used : ClassificationUndefinedHandlingType(org.dbflute.jdbc.ClassificationUndefinedHandlingType) ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException)

Example 10 with ClassificationUndefinedHandlingType

use of org.dbflute.jdbc.ClassificationUndefinedHandlingType in project dbflute-core by dbflute.

the class DfClsTopLiteralArranger method getElementMapUndefinedHandlingType.

@SuppressWarnings("unchecked")
protected ClassificationUndefinedHandlingType getElementMapUndefinedHandlingType(Map<?, ?> elementMap) {
    if (isElementMapCheckImplicitSet(elementMap)) {
        return ClassificationUndefinedHandlingType.EXCEPTION;
    }
    final String key = DfClassificationTop.KEY_UNDEFINED_HANDLING_TYPE;
    final DfLittleAdjustmentProperties prop = getLittleAdjustmentProperties();
    final ClassificationUndefinedHandlingType defaultType = prop.getClassificationUndefinedHandlingType();
    final String defaultValue = defaultType.code();
    final String code = getProperty(key, defaultValue, (Map<String, ? extends Object>) elementMap);
    final ClassificationUndefinedHandlingType handlingType = ClassificationUndefinedHandlingType.codeOf(code);
    if (handlingType == null) {
        throwUnknownClassificationUndefinedCodeHandlingTypeException(code);
    }
    return handlingType;
}
Also used : ClassificationUndefinedHandlingType(org.dbflute.jdbc.ClassificationUndefinedHandlingType) DfLittleAdjustmentProperties(org.dbflute.properties.DfLittleAdjustmentProperties)

Aggregations

ClassificationUndefinedHandlingType (org.dbflute.jdbc.ClassificationUndefinedHandlingType)11 DfIllegalPropertySettingException (org.dbflute.exception.DfIllegalPropertySettingException)3 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)3 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 DfClassificationProperties (org.dbflute.properties.DfClassificationProperties)2 DfClassificationTop (org.dbflute.properties.assistant.classification.DfClassificationTop)2 Classification (org.dbflute.jdbc.Classification)1 ClassificationMeta (org.dbflute.jdbc.ClassificationMeta)1 DfLittleAdjustmentProperties (org.dbflute.properties.DfLittleAdjustmentProperties)1