Digest for jooq-user@googlegroups.com - 1 update in 1 topic

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Digest for jooq-user@googlegroups.com - 1 update in 1 topic

http://groups.google.com/group/jooq-user/topics mailing list
"Thorsten Schöning" <[hidden email]>: Sep 20 09:12AM +0200

Guten Tag Lukas Eder,
am Donnerstag, 19. September 2019 um 09:52 schrieben Sie:
 
> Thank you very much for your message.
 
Thanks for your great answer, mentioned some very interesting
approaches I didn't had in mind.
 
> Result<?> result = ctx.select(...).fetch();
> for (Record record : ctx.select(...)) { ... }
 
That doesn't really make "SelectConditionStep" itself shorter, but
only hides it in combination with the "fetch". Some of my statements
need to be build using different methods and variables for individual
parts of the query, so sadly this is not always an option for me. But
will keeping using "Record" in the loop in mind.
 
Within that loop I could simply use "rec.get(Field)" as well as
"Record.into(...)" as mentioned in your docs?
 
> BookRecord book = record.into(BOOK);
> AuthorRecord author = record.into(AUTHOR);
 
What I don't understand from your example in the docs is the following
sentence:
 
> Sometimes, you may want to explicitly select only a subset of your
> columns, but still use strongly typed records.
 
While your select is the following:
 
> Record record = create.select()
> .from(BOOK)
> [...]
 
https://www.jooq.org/doc/latest/manual/sql-execution/fetching/record-vs-tablerecord/
 
How is that selecting a subset? From my understanding it isn't, but
retrieving all columns of all tables of the query. That's a problem
for me because I need to JOIN a lot of tables in many statements for
access permission reasons while only actually reading very few columns
of very few tables.
 
Or is there some magic in the background regarding "Record.into" and
which of the actual record getters are called in the end? Or is
"subset" speaking of cases like your first one above:
 
> Result<?> result = ctx.select(...).fetch();
> for (Record record : ctx.select(...)) { ... }
 
After using "Record.into(...)" in the loop I would be able to query
only the columns mentioned in "select(...)" I guess.
 
> The quickest way to get named records in jOOQ would be to write views and
> generate record types for them. In your case, you could write
 
Great idea I didn't had in mind yet. Creating a type in Java needed at
more than one place is of course a sign of redundancy I have in the
SQL-queries already. OTOH, that means changing two places where some
simple custom queries in Java only with some additional type would be
sufficient sometimes.
 
> Select<RecMeterLidWithReMbcdRecord> select =
> ctx.selectFrom(REC_METER_LID_WITH_RE_MBCD);
 
Which would be exactly what I want in the end.
 
> What is your expectation towards such a custom Record type? Why would you
> use it?
 
I would use it whenever I really need to only query some columns of
some table instead of all colums of all tables and beyond 2 columns
most likely. Because for 1 or 2 columns using generics is OK mostly,
but afterwards I feel it's getting to verbose.
 
Some custom type allows me proper documentation of that type, easy
renaming and especially reducing the length of variables holding some
SelectConditionStep like in my example. I have a lot of those
currently.
 
Using more views is definitely the correct thing for some statements,
but looking at my source it seems I have some very custom queries only
once or twice as well, for which changing the database model might not
be worth it. For those cases some way to simply give a custom name to
the fopllowing would be sufficient already:
 
> Record6<String, Integer, MeterProdCode, String, MeterType, Integer>
 
I most likely would not even need to add any additional API, really
only some custom name, pretty much like "typedef" in C++.
 
I've read about RecordMappers, but have the feeling those wouldn't
make "SelectConditionStep" itself shorter as well?
 
Mit freundlichen Grüßen,
 
Thorsten Schöning
 
--
Thorsten Schöning E-Mail: [hidden email]
AM-SoFT IT-Systeme http://www.AM-SoFT.de/
 
Telefon...........05151- 9468- 55
Fax...............05151- 9468- 88
Mobil..............0178-8 9468- 04
 
AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to [hidden email].