Reputation: 981
So I have an abstract class that prepares my query up to after where clause. It looks something like this:
SelectConditionStep<Record2<Integer, String>> whereQuery = dslContext.select(FOO.DIGITS, FOO.WORD)
.from(FOO)
.where(/*some conditions*/);
It then returns whereQuery
and that instance is used by concrete implementations to add stuff onto it.
Is it possible to make this call return SelectConditionStep<MyClass>
so that I don't have to write all Record types in method signature (note that this is a simplified version, imagine having Record10). MyClass
would, in this example, have two fields, Integer
and String
fields.
Or if not that, is there any other way to do it.
I am using Postgres as a db
Upvotes: 1
Views: 383
Reputation: 220987
Assuming you have an immutable POJO MyClass
, e.g. a Java 16 record:
record MyClass(int digits, String word) {}
You could use a nested record to achieve something similar:
Select<Record1<MyClass>> whereQuery =
ctx.select(row(FOO.DIGITS, FOO.WORD).mapping(MyClass::new))
.from(FOO)
.where(...)
Upvotes: 1