In the jooq snippet below, which I found from online material , there is a transition from "jooq ends here" to "start flow"
Does this mean that SQL queries are generated before fetch ()? And later after that, thread () starts, everything in memory inside the java process
Or java 8 streams, such as an active DSL record, and the entire code fragment is converted to SQL queries, including the stream () part?
This is because I saw examples where sortBy / groupingBy is executed inside threads in many online samples, when they can also be executed in SQL
DSL.using(c)
.select(
COLUMNS.TABLE_NAME,
COLUMNS.COLUMN_NAME,
COLUMNS.TYPE_NAME
)
.from(COLUMNS)
.orderBy(
COLUMNS.TABLE_CATALOG,
COLUMNS.TABLE_SCHEMA,
COLUMNS.TABLE_NAME,
COLUMNS.ORDINAL_POSITION
)
.fetch()
.stream()
.collect(groupingBy(
r -> r.getValue(COLUMNS.TABLE_NAME),
LinkedHashMap::new,
mapping(
r -> new Column(
r.getValue(COLUMNS.COLUMN_NAME),
r.getValue(COLUMNS.TYPE_NAME)
),
toList()
)
))
.forEach(
(table, columns) -> {
System.out.println(
"CREATE TABLE " + table + " (");
System.out.println(
columns.stream()
.map(col -> " " + col.name +
" " + col.type)
.collect(Collectors.joining(",\n"))
);
System.out.println(");");
}
);
source
share