Search in sources :

Example 6 with Classification

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

the class FunCustodial method throwUndefinedClassificationCodeException.

protected static void throwUndefinedClassificationCodeException(String tableDbName, String columnDbName, ClassificationMeta meta, Object code) {
    final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
    br.addNotice("Undefined classification code was set to the entity.");
    br.addItem("Advice");
    br.addElement("Confirm the value of the classification column on your database,");
    br.addElement("or setting value to your entity.");
    br.addElement("The code is NOT one of classification code defined on DBFlute.");
    br.addElement("");
    br.addElement("_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/");
    br.addElement(" Use formal code!");
    br.addElement("  Or add the code to classification definition.");
    br.addElement("_/_/_/_/_/_/_/_/_/_/");
    br.addElement("");
    br.addElement("Or if you (reluctantly) need to allow it, change the option like this:");
    br.addElement("but *Deprecated");
    br.addElement("(classificationDefinitionMap.dfprop)");
    br.addElement("    ; [classification-name] = list:{");
    br.addElement("        ; map:{");
    br.addElement("            ; topComment=...; codeType=...");
    br.addElement("            ; undefinedHandlingType=ALLOWED");
    br.addElement("        }");
    br.addElement("        map:{...}");
    br.addElement("    }");
    br.addElement("*for your information, the default of undefinedHandlingType is LOGGING");
    br.addItem("Table");
    br.addElement(tableDbName);
    br.addItem("Column");
    br.addElement(columnDbName);
    br.addItem("Classification");
    br.addElement(meta.classificationName());
    final List<Classification> listAll = meta.listAll();
    final StringBuilder sb = new StringBuilder();
    for (Classification cls : listAll) {
        if (sb.length() > 0) {
            sb.append(", ");
        }
        sb.append(cls.name()).append("(").append(cls.code()).append(")");
    }
    br.addElement(sb.toString());
    br.addItem("Undefined Code");
    br.addElement(code);
    final String msg = br.buildExceptionMessage();
    throw new UndefinedClassificationCodeException(msg);
}
Also used : ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) Classification(org.dbflute.jdbc.Classification) UndefinedClassificationCodeException(org.dbflute.exception.UndefinedClassificationCodeException)

Example 7 with Classification

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

the class ClassificationType method bindValue.

public void bindValue(Connection conn, PreparedStatement ps, int index, Object value) throws SQLException {
    if (value == null) {
        setNull(ps, index);
    } else {
        if (!(value instanceof Classification)) {
            String msg = "The value should be classification:";
            msg = msg + " value=" + value + " type=" + value.getClass();
            throw new IllegalStateException(msg);
        }
        final Classification cls = (Classification) value;
        if (ClassificationCodeType.String.equals(cls.meta().codeType())) {
            ps.setString(index, cls.code());
        } else if (ClassificationCodeType.Number.equals(cls.meta().codeType())) {
            ps.setInt(index, DfTypeUtil.toInteger(cls.code()));
        } else if (ClassificationCodeType.Boolean.equals(cls.meta().codeType())) {
            ps.setBoolean(index, DfTypeUtil.toBoolean(cls.code()));
        } else {
            ps.setObject(index, cls.code());
        }
    }
}
Also used : Classification(org.dbflute.jdbc.Classification)

Aggregations

Classification (org.dbflute.jdbc.Classification)7 Method (java.lang.reflect.Method)1 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 SpecifiedColumn (org.dbflute.cbean.dream.SpecifiedColumn)1 UndefinedClassificationCodeException (org.dbflute.exception.UndefinedClassificationCodeException)1 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)1 ClassificationCodeType (org.dbflute.jdbc.ClassificationCodeType)1 ClassificationMeta (org.dbflute.jdbc.ClassificationMeta)1 ClassificationUndefinedHandlingType (org.dbflute.jdbc.ClassificationUndefinedHandlingType)1 OptionalThing (org.dbflute.optional.OptionalThing)1 BeanDesc (org.lastaflute.di.helper.beans.BeanDesc)1 BeanMethodNotFoundException (org.lastaflute.di.helper.beans.exception.BeanMethodNotFoundException)1