@Override
    public String toDatabaseType(T constant) {
        if (constant == null) {
            return null;
        } else {
            final Class<?> enumClass = constant.getClass();

            final Method toDatabase;
            try {
                toDatabase = enumClass.getMethod(TO_DATABASE_METHOD);
            } catch (final NoSuchMethodException ex) {
                throw new IllegalArgumentException(
                    "Could not find generated '" + TO_DATABASE_METHOD + 
                    "'-method in enum class '" + 
                    constant.getClass().getName() + "'.", ex
                );
            }

            try {
                @SuppressWarnings("unchecked")
                final String result = (String) toDatabase.invoke(constant);
                return result;
            } catch (final IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
                throw new IllegalArgumentException("Error executing '" + TO_DATABASE_METHOD + "' in generated enum class '" + constant.getClass().getName() + "'.", ex);
            }
        }
    }
@param <T>  the enum type

@author  Emil Forslund
@author  Simon Jonasson
@since   3.0.0
plugin-parent/enum-generator/src/main/java/com/speedment/plugins/enums/StringToEnumTypeMapper.java