cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Gentry" <blackn...@gmail.com>
Subject Re: delete from ... where ... in (...)
Date Fri, 30 May 2008 13:42:50 GMT
Wow, you just gave me a Star Wars flashback.  If we make it to C3PO,
we'll be *golden*!  :-)

If you want to execute that exact SQL, you could do it with
SQLTemplate.  For example, in one of my demo/test projects, I have:

    sqlQuery = new SQLTemplate(Order.class, "DELETE FROM Orders");
    dataContext.performNonSelectingQuery(sqlQuery);

If you need it more dynamic, look at inExp() on this page:

http://cayenne.apache.org/doc/expression-factory-utilities.html

You'd then make an Expression and perform query them/fetch them, then
delete them.  There might be an easier way to do this, but I know this
approach would keep your Cayenne object graph in sync (the SQLTemplate
can get things out of sync).  Something like:

    Expression exp = ExpressionFactory.inExp("oid", values);
    SelectQuery select = new SelectQuery(Artist.class, exp);
    List list = dataContext.performQuery(select);
    // loop over list and:
    dataContext.deleteObject(item);
    // then save
    dataContext.commitChanges();

/dev/mrg

PS. The "oid" field needs to be mapped in the above example ...


On Fri, May 30, 2008 at 9:27 AM, Borut BolĨina <borut.bolcina@gmail.com> wrote:
> Hi,
>
> what is the C3M4 prefered way of doing this SQL equivalent: DELETE FROM
> Artist WHERE Oid IN (1,4,8,9);
>
> Thanks,
> Borut
>
Mime
View raw message