Search in sources :

Example 1 with DBEnumValue

use of core.framework.db.DBEnumValue in project core-ng-project by neowu.

the class DatabaseClassValidator method validateEnumClass.

private void validateEnumClass(Class<?> enumClass, Field field) {
    Enum<?>[] constants = (Enum<?>[]) enumClass.getEnumConstants();
    Set<String> enumValues = Sets.newHashSet();
    for (Enum<?> constant : constants) {
        DBEnumValue enumValue = Enums.constantAnnotation(constant, DBEnumValue.class);
        if (enumValue == null) {
            throw Exceptions.error("db enum must have @DBEnumValue, field={}, enum={}", Fields.path(field), Enums.path(constant));
        }
        boolean added = enumValues.add(enumValue.value());
        if (!added) {
            throw Exceptions.error("db enum value must be unique, enum={}, value={}", Enums.path(constant), enumValue.value());
        }
        Property property = Enums.constantAnnotation(constant, Property.class);
        if (property != null) {
            throw Exceptions.error("db enum must not have json annotation, please separate view and entity, field={}, enum={}", Fields.path(field), Enums.path(constant));
        }
    }
}
Also used : DBEnumValue(core.framework.db.DBEnumValue) Property(core.framework.api.json.Property)

Aggregations

Property (core.framework.api.json.Property)1 DBEnumValue (core.framework.db.DBEnumValue)1