db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jakob Braeuchi <jbraeu...@gmx.ch>
Subject better support for subqueries
Date Fri, 12 Sep 2003 21:57:01 GMT
hi all,

i'm currently working on a better support for subqueries.
these queries can now be used in place of attributes and subquery criteria
can refer to attributes of the enclosing query (using the parentQuery. 
prefix )

this query looks for all productgroups with more than 10 articles:

        ReportQueryByCriteria subQuery;
        Criteria subCrit = new Criteria();
        Criteria crit = new Criteria();

subCrit.addEqualToField("productGroupId","parentQuery.groupId");   // 
refer to enclosing query
        subQuery = QueryFactory.newReportQuery(Article.class, subCrit);
        subQuery.setColumns(new String[]{"count(productGroupId)"});

        crit.addGreaterThan(subQuery,"10");    // subquery as attribute
        crit.addLessThan("groupId",new Integer(987654));
        Query q = QueryFactory.newQuery(ProductGroup.class, crit);

        Collection results = broker.getCollectionByQuery(q);

the resulting sql is as follows:

SELECT A0.KategorieName,A0.Kategorie_Nr,A0.Beschreibung FROM Kategorien A0
WHERE ((SELECT count(B0.Kategorie_Nr) FROM Artikel B0 WHERE 
B0.Kategorie_Nr = A0.Kategorie_Nr) >  '10' )
AND A0.Kategorie_Nr <  '987654'

i know we are feature complete for 1.0. so i ask _you_ whether i should 
check it in or not ????


To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org

View raw message