db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jakob Braeuchi <jbraeu...@gmx.ch>
Subject Re: [vote] reference to a parent attribute in subquery
Date Sun, 17 Aug 2003 08:57:06 GMT
hi all,

i just commited a solution which uses the prefix _'parentQuery'_ to 
refererence attributes of the enclosing query:

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

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

        crit.addLessThan("10", subQuery);    // MORE than 10 articles
        Query q = QueryFactory.newQuery(ProductGroup.class, crit);

        Collection results = broker.getCollectionByQuery(q);

i switched from 'super' to 'parentQuery' because 'super' may be used for 
attributes of the super class with multiple joined tables.  i'm not sure 
wether using a path expression is appropriate in this situation, may be 
a simple prefix character like #, &, + will be sufficient.

i will NOT document this feature as long as the prefix is not defined !

jakob

Jakob Braeuchi wrote:

> hi again,
>
> 'super' may probably collide with anonymous fields.
>
> jakob
>
> Jakob Braeuchi wrote:
>
>> hi all,
>>
>> i'm working on subquery attributes referencing an attribute in parent 
>> query.
>> the problem is how prefix those attributes in a way not causing 
>> problems with relationship names ?
>>
>> super.attributeOfParentQuery  ?
>> parent.attributeOfParentQuery  ?
>> enclosing.attributeOfParentQuery  ?
>> or any other prefix
>>
>>
>>
>> sample:
>>
>>        ReportQueryByCriteria subQuery;
>>        Criteria subCrit = new Criteria();
>>        Criteria crit = new Criteria();
>>
>>        subCrit.addEqualToField("productGroupId","super.groupId");   
>> << refer to attribute of enclosing query
>>        subQuery = QueryFactory.newReportQuery(Article.class, subCrit);
>>        subQuery.setColumns(new String[]{"count(productGroupId)"});
>>
>>        crit.addLessThan("10", subQuery);     // MORE than 10 articles
>>        Query q = QueryFactory.newQuery(ProductGroup.class, crit);
>>
>> this results in the following sql:
>>
>> SELECT A0.KategorieName,A0.Kategorie_Nr,A0.Beschreibung FROM 
>> Kategorien A0 WHERE 10 <  (SELECT count(B0.Kategorie_Nr) FROM Artikel 
>> B0 WHERE B0.Kategorie_Nr = A0.Kategorie_Nr)
>>
>>
>> jakob
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-dev-help@db.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
>
>


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


Mime
View raw message