private void columnHandler(JavaClassTranslator<Table, Interface> translator, File file, Interface intrf, Column col) {
        final JavaLanguageNamer namer = translator.getSupport().namer();

        final String colEnumName     = enumNameOf(col, injector);
        final List<String> constants = enumConstantsOf(col);

        final Type enumType = new GeneratedEnumType(
            colEnumName,
            constants
        );

        final Type dbType;
        if (hasTypeMapper(col, StringToEnumTypeMapper.class)) {
            dbType = String.class;
        } else if (hasTypeMapper(col, IntegerToEnumTypeMapper.class)) {
            dbType = int.class;
        } else {
            throw new UnsupportedOperationException(format("Unknown enum type mapper '%s' in column '%s'.", col.getTypeMapper().orElse(null), col));
        }

        final Enum colEnum = Enum.of(shortName(colEnumName))
            .add(Field.of(DATABASE_NAME, String.class)
                .private_().final_()
            ).add(Field.of(DATABASE_ORDINAL, int.class)
                .private_().final_()
            );

        // Generate fromDatabase()-method
        final Method fromDatabase = Method.of(FROM_DATABASE_METHOD, enumType)
            .public_().static_()
            .add(Field.of(DATABASE_NAME, String.class))
            .add("if (" + DATABASE_NAME + " == null) return null;")
            .add("switch (" + DATABASE_NAME + ") {");

        final Method fromDatabaseOrdinal = Method.of(FROM_DATABASE_ORDINAL_METHOD, enumType)
            .public_().static_()
            .add(Field.of(DATABASE_ORDINAL, Integer.class))
            .add("if (" + DATABASE_ORDINAL + " == null) return null;")
            .add("switch (" + DATABASE_ORDINAL + ") {");

        // Generate enum constants
        final ListIterator<String> constantIt = constants.listIterator();
        while (constantIt.hasNext()) {
            final int ordinal     = constantIt.nextIndex();
            final String constant = constantIt.next();
            final String javaName = namer.javaStaticFieldName(constant);

            final EnumConstant enumConstant =
                EnumConstant.of(javaName)
                    .add(Value.ofText(constant))
                    .add(Value.ofNumber(ordinal));

            fromDatabase.add(Formatting.indent(
                "case \"" + constant + "\" : return " +
                    namer.javaStaticFieldName(constant) + ";"
            ));

            fromDatabaseOrdinal.add(Formatting.indent(
                "case " + ordinal + " : return " +
                    namer.javaStaticFieldName(constant) + ";"
            ));

            colEnum.add(enumConstant);
        }

        // Generate constructor
        colEnum.add(Constructor.of()
            .add(Field.of(DATABASE_NAME, String.class))
            .add(Field.of(DATABASE_ORDINAL, int.class))
            .add("this." + DATABASE_NAME + "    = " + DATABASE_NAME + ";")
            .add("this." + DATABASE_ORDINAL + " = " + DATABASE_ORDINAL + ";")
        );

        fromDatabase
            .add(Formatting.indent("default : throw new UnsupportedOperationException("))
            .add(Formatting.indent("\"Unknown enum constant '\" + " + DATABASE_NAME + " + \"'.\"", 2))
            .add(Formatting.indent(");"))
            .add("}");

        fromDatabaseOrdinal
            .add(Formatting.indent("default : throw new UnsupportedOperationException("))
            .add(Formatting.indent("\"Unknown enum ordinal '\" + " + DATABASE_ORDINAL + " + \"'.\"", 2))
            .add(Formatting.indent(");"))
            .add("}");

        colEnum.add(fromDatabase);
        colEnum.add(fromDatabaseOrdinal);

        // Generate toDatabase()-method
        colEnum.add(Method.of(TO_DATABASE_METHOD, String.class)
            .public_().add(RETURN + DATABASE_NAME + ";")
        );

        // Generate toDatabaseOrdinal()-method
        colEnum.add(Method.of(TO_DATABASE_ORDINAL_METHOD, int.class)
            .public_().add(RETURN + DATABASE_ORDINAL + ";")
        );

        // Add it to the interface.
        intrf.add(colEnum);

        // Rewrite the static field to use a inlined type mapper
        // instead.
        final String fieldName = namer.javaStaticFieldName(col.getJavaName());
        final Field field = intrf.getFields().stream()
            .filter(f -> f.getName().equals(fieldName))
            .findFirst().orElseThrow(() -> new SpeedmentGeneratorException(
                "Expected a static field with name '" +
                fieldName + "' to be generated."
            ));

        if (usesOptional(col)) {
            file.add(Import.of(OptionalUtil.class));
        }

        final String enumShortName = shortName(colEnumName);
        final String enumVarName = namer.javaVariableName(enumShortName);

        final List<Value<?>> params = new LinkedList<>();
        params.addAll(asList(
            ofReference("Identifier." + fieldName),
            ofReference(
                usesOptional(col)
                    ? "o -> " + OptionalUtil.class.getSimpleName() + ".unwrap(o.get" + translator.getSupport().typeName(col) + "())"
                    : translator.getSupport().entityName() + "::get" + translator.getSupport().typeName(col)
            ),
            ofReference(
                translator.getSupport().entityName() + "::set" +
                translator.getSupport().typeName(col)
            ),
            ofAnonymous(TypeMapper.class)
                .add(wrapIfPrimitive(dbType))
                .add(enumType)
                .add(Method.of("getLabel", String.class)
                    .public_().add(OVERRIDE)
                    .add("return \"" + shortName(dbType.getTypeName()) +
                        " to " + enumShortName + " Mapper\";")
                )
                .add(Method.of("getOrdering", TypeMapper.Ordering.class)
                    .public_().add(OVERRIDE)
                    .add(RETURN + TypeMapper.Ordering.class.getSimpleName() +
                        "." + TypeMapper.Ordering.RETAIN.name() + ";")
                )
                .add(Method.of("getJavaTypeCategory", TypeMapper.Category.class)
                    .public_().add(OVERRIDE)
                    .add(Field.of(COLUMN, Column.class))
                    .add(RETURN + TypeMapper.Category.class.getSimpleName() +
                        "." + TypeMapper.Category.ENUM.name() + ";")
                )
                .add(Method.of("getJavaType", Type.class)
                    .public_().add(OVERRIDE)
                    .add(Field.of(COLUMN, Column.class))
                    .add(RETURN + enumShortName + ".class;")
                )
                .add(Method.of("toJavaType", enumType)
                    .public_().add(OVERRIDE)
                    .add(Field.of(COLUMN, Column.class))
                    .add(Field.of("clazz", classOf(WILDCARD)))
                    .add(Field.of("value", wrapIfPrimitive(dbType)))
                    .add("return value == null ? null : " +
                        enumShortName + "." + ((dbType == String.class)
                            ? FROM_DATABASE_METHOD
                            : FROM_DATABASE_ORDINAL_METHOD
                        ) + "(value);"
                    )
                )
                .add(Method.of("toDatabaseType", wrapIfPrimitive(dbType))
                    .public_().add(OVERRIDE)
                    .add(Field.of(enumVarName, enumType))
                    .add(RETURN + enumVarName + " == null ? null : " +
                        enumVarName + "." + ((dbType == String.class)
                            ? TO_DATABASE_METHOD
                            : TO_DATABASE_ORDINAL_METHOD
                        ) + "();")
                )
        ));

        // Foreign key args
        final Optional<FkHolder> fk =
            ForeignKeyUtil.getForeignKey(
                translator.getSupport().tableOrThrow(), col
            ).map(fkc -> new FkHolder(injector, fkc.getParentOrThrow()));

        fk.ifPresent(holder ->
            params.add(ofReference(
                holder.getForeignEmt().getSupport().entityName() + "." +
                translator.getSupport().namer().javaStaticFieldName(
                    holder.getForeignColumn().getJavaName()
                ) + ","
            ))
        );

        params.add(Value.ofReference(enumShortName + "::" + TO_DATABASE_METHOD));
        params.add(Value.ofReference(enumShortName + "::" + FROM_DATABASE_METHOD));
        params.add(Value.ofReference(enumShortName + ".class"));

        final Optional<InvocationValue> existing =
            field.getValue()
                .filter(InvocationValue.class::isInstance)
                .map(InvocationValue.class::cast);

        field.set(ofInvocation(
            existing.map(InvocationValue::getType).orElseGet(
                () -> fk.isPresent()
                    ? EnumForeignKeyField.class
                    : EnumField.class
            ),
            existing.map(InvocationValue::getValue)
                .orElse("create"),
            params.toArray(new Value<?>[params.size()])
        ));
    }
@author  Emil Forslund
@author  Simon Jonasson
@since   3.0.0
plugin-parent/enum-generator/src/main/java/com/speedment/plugins/enums/internal/GeneratedEntityDecorator.java