cayenne-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <>
Subject Re: SQLExec query
Date Sat, 31 Jan 2015 12:38:58 GMT
"execute" will only be used when a query is known or expected to be "multi-part" (my own term),
i.e. returns more than one ResultSet, performs more than one update (or a combination of selects
or updates). There are more meaningful shortcuts for single-result queries. If you expect
a single ResultSet, you use, for a single insert/update, you use SQLExec.update(..).
This roughly mirrors the types of results a JDBC Statement can return:

ResultSet executeQuery(..)
int executeUpdate(..)
int[] executeBatch(..)
boolean execute(..) // this one is multi-part


> On Jan 27, 2015, at 8:13 PM, Aristedes Maniatis <> wrote:
> On 27/01/2015 10:45pm, Andrus Adamchik wrote:
>> List<Object> is a confusing data structure. When iterating through it you will
need to do instanceof/cast on every entry, and more importantly, you will need to know upfront
what are the valid entries in there. 
>> With List<QueryResult> you don't do instanceof/cast, and also if say tomorrow
we add/change something in the entry format/type, we simply alter QueryResult API, making
the change visible to the user. 
> OK, so let's examine your example:
> List<QueryResult> result = SQLExec
>     .query("INSERT INTO ARTIST (ARTIST_ID, ARTIST_NAME) VALUES (#bind($id), #bind($name))")
>     .paramsArray(55, "a3")
>     .execute(context);
> Let's say I want to get the number of rows added. I do this:
> count = result.get(0).getBatchUpdateResult()[0]; or
> count = result.get(0).getUpdateResult();
> except that I didn't run an "UPDATE", I ran an "INSERT". But perhaps that can be solved
with enough javadocs to explain the naming...
> Now, for a result set:
> List<QueryResult> result = SQLExec.query("CALL getContacts_proc()").execute(context);
> List<Contact> contact = (List<Contact>) result.get(0).getSelectResult();
> Am I missing the point here?
> Ari
> -- 
> -------------------------->
> Aristedes Maniatis
> GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A

View raw message