cayenne-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject SQLExec query
Date Sun, 25 Jan 2015 11:25:42 GMT
Starting to experiment with fluent API for non-selecting queries. Since I'd like to avoid delaying
4.0.M2 release any further, I created a pull request instead of committing it to master:

https://github.com/apache/cayenne/pull/64

So now executing SQL will look like this:

int inserted = SQLExec
     .query("INSERT INTO ARTIST (ARTIST_ID, ARTIST_NAME) VALUES (#bind($id), #bind($name))")
     .paramsArray(55, "a3")
     .update(context);

or like this:

List<QueryResult> = SQLExec
     .query("INSERT INTO ARTIST (ARTIST_ID, ARTIST_NAME) VALUES (#bind($id), #bind($name))")
     .paramsArray(55, "a3")
     .execute(context);

The second form ("execute") is more generic. It is not very useful for this simple example.
Still need some actual tests that would execute multiple statements via a single SQLExec.
I know you can do it when calling a stored procedure (which would be a separate query), but
IIRC most drivers will blow if you put multiple SQL statements in a single JDBC PreparedStatement.

Still, I am showing it here with an eye on eventually refactoring ObjectContext.performGenericQuery(..)
to also return result in a form of List<QueryResult> (instead of current ugly QueryResponse).

Comments are welcome.

Andrus



Mime
View raw message