Hi Deba,

How did you configure your code generator?

On Sat, Mar 20, 2021 at 5:21 PM Debapriya Patra <[email protected]>
wrote:

> Hi Lukas,
>
> I have gone through the documentation(
> https://www.jooq.org/doc/latest/manual/sql-execution/fetching/data-type-conversion/)
> of how to use custom enum converter in JOOQ but I somehow could not make it
> work.
>
> I have a table which has multiple columns and and one of the column is of
> type Integer. And while pulling the data from that table I wanted that
> Integer column value should convert to a ENUM value. Can you please help me
> understand how I can achieve that ?
>
> *Table: edu_document_type*
> -------------------------------------------
> *id Int (PrimaryKey)*
>
> *document_type VARCHAR*
> *document_display_name VARCHAR*
>
> *Table : edu_content*
> --------------------------------
> *title*
> *description*
> *edu_document_type_id (ForeignKey from **edu_document_type(id)**)*
>
>
> Java Entity: EduContent
> --------------------------------------
> String title;
> String description;
> String eduDocumentType;
>
> Java Enum: EduDocumentType
> --------------------------------------------------
> public enum EduDocumentType {
> SYLLABUS(1, "SYLLABUS"),
> QUIZ(2, "QUIZ"),
> EXAM_STUDY_GUIDE(3, "EXAM_STUDY_GUIDE"),
> LECTURE_NOTES(4, "LECTURE_NOTES"),
> EXAMS(5, "EXAMS"),
> OTHER(6, "OTHER");
>
> private Integer id;
> private String documentType;
>
> EduDocumentType(Integer id, String documentType) {
> this.id = id;
> this.documentType = documentType;
> }
>
> public String getDocumentType() {
> return this.documentType;
> }
>
> public Integer getId() {
> return this.id;
> }
>
> public static EduDocumentType findByDocumentType(final String
> documentType) {
> return Arrays.stream(values())
> .filter(value -> value.getDocumentType().equals(documentType))
> .findFirst()
> .orElse(null);
> }
>
> public static EduDocumentType findById(final Integer id) {
> return Arrays.stream(values())
> .filter(value -> value.getDocumentType().equals(id))
> .findFirst()
> .orElse(null);
> }
> }
>
> Enum Converter
> ---------------------------
> public class EduDocumentTypeConverter extends EnumConverter<Integer,
> EduDocumentType> {
> public EduDocumentTypeConverter(Class<Integer> fromType,
> Class<EduDocumentType> toType) {
> super(fromType, toType);
> }
> }
>
> I am not clear when I am writing the JOOQ query to fetch data from
> edu_content table how I can use the converter to convert from (id)
> *Integer* to *String(documentType). *
>
> Is my converter correct ? Or shall I use the normal converter (*Converter<U,
> T>*)?
>
> Please advise and need your help here.
>
> Thanks,
> Deba
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "jOOQ User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jooq-user/7d7da370-5d1b-496d-9c5d-dece088ce532n%40googlegroups.com
> <https://groups.google.com/d/msgid/jooq-user/7d7da370-5d1b-496d-9c5d-dece088ce532n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jooq-user/CAB4ELO6HAE_zwKyfxDWQoX6qZgL5K%3D7U4zOTp8o3PV7P%2BmG5aA%40mail.gmail.com.

Reply via email to