I would like to perform a join between a database table and a table of
user-given custom values. What is a good way to do this in JOOQ?
I have figured out how to do it, but the code does not maintain all the
type safety that I would prefer.
DSLContext context = createDSLContext();
// add the user data to a List (in reality this is done in a loop)
List<Row3<String, Integer, Integer>> rowList = new ArrayList<>();
rowList.add(DSL.row("A", 35, 120));
rowList.add(DSL.row("B", 52, 375));
rowList.add(DSL.row("C", 19, 85));
// convert that data to a table
Row3[] rows = rowList.toArray(new Row3[rowList.size()]);
Table userInput = createDSLContext().select().from(values(rows))
.asTable("userInput", "name", "a", "b");
// join user input with data in table MY_TABLE
Result result = context.select(
userInput.field("name"),
userInput.field("a"),
userInput.field("b"),
MY_TABLE.SOME_FIELD
).from(MY_TABLE).crossJoin(userInput).where(
MY_TABLE.ID_FIELD.equal(userInput.field("name"))
).fetch();
This code works, but it bothers me that if I try to grab a field of my
temporary table, it does not know anything about the data types. It does
not know, for example, that userInput.field("name") is a String data field.
Is there a more recommended way of adding-in user input values?
--
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].
For more options, visit https://groups.google.com/d/optout.