Re: Behavior of Record.getValue(Field) when the Field is not present

38 views
Skip to first unread message

Lukas Eder

unread,
Jun 5, 2013, 4:25:59 AM6/5/13
to jooq...@googlegroups.com



2013/6/5 Adam Zell <zell...@gmail.com>
The Javadoc for Record.getValue(Field<T>) states:
  Throws: IllegalArgumentException - If the argument field is not contained in fieldsRow()

This is not quite true.  If the method is called with a Field that is not contained but has the same name as a field that is contained, the contained field's value will be returned instead of throwing an exception.

Example:

* record contains the Field FOO.ID only
* clients calls record.getValue(BAR.ID)
* record returns the value associated with FOO.ID

I would argue that this is unwanted behavior for TableFields, in that it hides a likely client bug.  I would prefer to see the client bug exposed through an exception versus continued behavior with a possibly bogus value.  Does anyone prefer the existing behavior?

Some background info (as also mentioned in #2501 [1]):
The idea behind the current implementation dates from very early jOOQ days, where Record.getValue() is supposed to return a "good enough" ID value, when accessing getValue(XXX.ID). An example:

SELECT f.ID
FROM FOO f

When selecting ID from records produced by the above query, you can now either choose the exact reference f.ID, or an "approximate" reference FOO.ID, or "ID" (String). The current implementation has a side-effect where BAR.ID is also considered an "approximate" reference.

So the discussion should evolve around:

1. Should "approximate" references be considered at all?
2. If yes, what qualifies as an "approximate" reference? e.g. FOO.as("f").ID is approximately the same as FOO.ID, but not as BAR.ID
3. If no, what qualifies as an "exact" reference? e.g. are these "exect" references: field("ID"), fieldByName("ID"), fieldByName("FOO", "ID") ?

User feedback is very welcome!

Cheers
Lukas

Reply all
Reply to author
Forward
0 new messages