Reputation: 29219
If my query results in a single column with primitive values, is there a way to fetch them with jooq, avoiding the primitive boxing?
Example, fetching the page count from each book in the table as an int[].
int[] pageCounts = dsl.select(BOOK.PAGE_COUNT)
.from(BOOK)
.fetch();
Upvotes: 1
Views: 329
Reputation: 220952
jOOQ makes heavy use of generics, meaning that at some point in jOOQ's internals, boxing is inevitable, even if it were possible for jOOQ to expose the results to you as an int[]
.
You're going to have to run the query with JDBC directly (you can still build it with jOOQ) to do what you want. E.g.
// Use some third party primitive int buffer
var buffer = new IntArrayList();
try (
Cursor<?> cursor = dsl.select(BOOK.PAGE_COUNT).from(BOOK).fetchLazy();
ResultSet rs = cursor.resultSet();
) {
while (rs.next())
buffer.add(rs.getInt(1));
}
Upvotes: 1