Hello,
2013/9/6 Eric Schwarzenbach <[email protected]>
> After writing all that, I think I've spotted the answer to both my
> questions. I hadn't realized that bind() returns another ResultQuery. In my
> proof-of-concept code I was attaching and binding my DSL-constructed query
> object and executing that directly. Now I see that I can get a new
> ResultQuery from the bind, and attach and execute that, leaving the
> original query object unattached (though not unbound it seems...which seems
> a little wonky to me). The new ResultQuery will go out of scope which I
> suppose is a way of "detaching" it. From running in a debugger it looks to
> me like this new ResultQuery is indeed a separate object from the original
> query object and so I assume I should have no thread-safety concerns if
> always create a new ResultQuery with bind and use that. Is that all correct?
>
> Is bind() essentially doing query object "cloning"?
>
No, that's not correct. Many jOOQ methods return a reference of the same
type in order to implement a fluent API. In other words, you can chain
method calls, such as
select(...)
.from(...)
.where(...)
.bind(...)
.bind(...)
.fetch();
As all other DSL methods in the query construction API, bind() returns the
*same* instance of the Query, not a new one. In other words, a Select<?>
object is mutable. This is hinted at in the manual, here:
http://www.jooq.org/doc/3.1/manual/sql-building/sql-statements/dsl-and-non-dsl/#N10947
Mutability / Immutability is another challenge to tackle in jOOQ 4.0, in
the context of a clean separation of a DSL and Model API:
https://github.com/jOOQ/jOOQ/issues/2198
In essence, the Model API will be mutable, whereas the DSL API will be
immutable. However, these things are not yet decided. It may well be that
jOOQ will gain influence from the Scala community, where immutability is a
key feature of most APIs. This would then render the Model API obsolete, in
favour of a (hopefully) very composable DSL API.
I still wonder if it wouldn't be nicer to have some API distinction between
> stateful statement building objects and immutable objects obtainable from
> them representing sql statements (or parts) that you have built. Perhaps
> this is overly idealistic to expect this in conjunction with a fluent DSL
> style API.
>
No it isn't overly idealistic. It's just that jOOQ is not there yet.
--
You received this message because you are subscribed to the Google Groups "jOOQ
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.