Jooq and java 8 threads generating SQL

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()  // jOOQ ends here
   .stream() // Streams start here
   .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) -> {
            // Just emit a CREATE TABLE statement
            System.out.println(
                "CREATE TABLE " + table + " (");

            // Map each "Column" type into a String
            // containing the column specification,
            // and join them using comma and
            // newline. Done!
            System.out.println(
                columns.stream()
                       .map(col -> "  " + col.name +
                                    " " + col.type)
                       .collect(Collectors.joining(",\n"))
            );

           System.out.println(");");
       }
   );
+4
source share
1 answer

, SQL- fetch()? () , java-

java 8 , DSL, SQL-, stream()?

, , sortBy/groupingBy -, SQL

, JINQ library.

jOOQ API Java 8 Stream ( jOOQ, , List, List.stream() ), SQL. , JINQ, , , , API Stream , SQL, jOOQ SQL.

+4

Source: https://habr.com/ru/post/1670501/


All Articles