Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Can / Should i (still) use jOOλ for Tuples

26 views
Skip to first unread message

Bernd Huber

unread,
Nov 1, 2024, 11:11:19 AM11/1/24
to jOOQ User Group
when working with jOOQ, i embraced the use of Record1, Record2, ..., RecordN when i pulled data out of the database, and used the convertFrom of jooq where i convert those RecordN instances to my DTOs

All in all i found it great to work that way.

Java does not have Tuples (like RecordN) out of the box.

Sometimes i create DTOs outside of the database-context,
and it seems that RecordN can not be instantiiated manually so easily.

I found the Tuple1, Tuple2, ..., TupleN in the jOOλ library, and they seem to provide exactly what i need (using tuples that can be used everywhere in the project for different purposes).

Now, is there something in the jOOQ library already that i can use, or is it good to use the jOOλ library for this purpose?




Bernd Huber

unread,
Nov 2, 2024, 5:33:25 AM11/2/24
to jOOQ User Group
just to give a practical example, when such Tuple can be helpful in a typical SaaS that needs to work with JSON-columns.

---

When a new "Report" entry is created, the column "reportContentJson" must be filled with a nested json object consisting of specific! (not all) data from multiple other tables.

There is already an existing Repository that collects all relevant nested data from the multiple other tables as "Nested DTOs"

But for backwards-compatibility reasons the nested json must be "frozen" in regards to specific content (it should not contain all content)
So there are additional Nested DTOs needed, that only contain the data that is relevant to save into the json.

And now, when i want to create the NestedDTOs for the JSON-column from the NestedDTOs that contain all data,
the Tuple1, Tuple2, ..., TupleN can help me to create static constructors for creating the objects.

For example

class ReportContentJson {
   ...
   public static Nested1 create(Tuple2<SourceDTO, SubSourceDTO> rec) {
      return new Nested1()
         .setReportContentSourceJson(ReportContentSourceJson.from(rec.value1()))
         .setReportContentSubSourceJson(ReportContentSubSource.from(rec.value2()));
   }
}

class ReportContentSourceJson {
    ....
    public static ReportContentSourceJson from(SourceDTO dto) {
        return new ReportContentSourceJson()
            .setField1(dto.getField1())
            .setField2(dto.getField2());

Lukas Eder

unread,
Nov 4, 2024, 1:46:08 AM11/4/24
to jooq...@googlegroups.com
A jOOλ is a Java-style structural type, like Scala knows them. A jOOQ Record is a database record. It seems to me that they have well defined purposes and yet are generic enough to be used for whatever you think you want to do with them. Likewise, there's Map<K, V> in the JDK, but no one prevents you from using a List<Entry<K, V>> if your "map" focuses more on iteration use-cases than deduplication and random O(1) access use-cases.

As such, I don't really know what you're asking here. Are you asking if it's OK for you to use structural types as opposed to nominal ones (e.g. Java records)? You won't get an authoritative answer here or anywhere.

--
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 jooq-user+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/jooq-user/8fd8fd32-7872-4635-bb97-4ad79ab48bc1n%40googlegroups.com.

Bernd Huber

unread,
Nov 4, 2024, 12:28:14 PM11/4/24
to jOOQ User Group
Thanks Lukas,

i think my question is too specific to my concrete project,
and it was not the right place to ask.

All your named approaches are good!
And so i'm fine with this question.

Also: this is one of those very small problems that are not really a game-changer, 
but only something one battles with even though, everything is already good enough :D
Reply all
Reply to author
Forward
0 new messages