db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/xdocs query.xml
Date Mon, 08 Mar 2004 19:58:48 GMT
brj         2004/03/08 11:58:48

  Modified:    xdocs    query.xml
  Log:
  added howto use subqueries
  
  Revision  Changes    Path
  1.26      +48 -0     db-ojb/xdocs/query.xml
  
  Index: query.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/xdocs/query.xml,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- query.xml	14 Dec 2003 11:16:13 -0000	1.25
  +++ query.xml	8 Mar 2004 19:58:48 -0000	1.26
  @@ -238,6 +238,54 @@
   </p>
   </subsection>
   
  +<subsection name="subqueries">
  +<p>
  +Subqueries can be used instead of values in selection criteria.
  +The subquery should thus be a ReportQuery.
  +<br/>
  +The following example queries all articles having a price greator or equal than the
  +average price of articles named 'A%':
  +
  +<source><![CDATA[
  +ReportQueryByCriteria subQuery;
  +Criteria subCrit = new Criteria();
  +Criteria crit = new Criteria();
  +
  +subCrit.addLike("articleName", "A%");
  +subQuery = QueryFactory.newReportQuery(Article.class, subCrit);
  +subQuery.setColumns(new String[] { "avg(price)" });
  +
  +crit.addGreaterOrEqualThan("price", subQuery);
  +Query q = QueryFactory.newQuery(Article.class, crit);
  +
  +Collection results = broker.getCollectionByQuery(q);
  +]]></source>
  +</p>
  +<p>
  +It's also possible to build a subquery with attributes referencing the enclosing query.
  +These attributes have to use a special prefix <b>Criteria.PARENT_QUERY_PREFIX</b>.
  +<br/>
  +The following example queries all product groups having more than 10 articles:
  +
  +<source><![CDATA[
  +ReportQueryByCriteria subQuery;
  +Criteria subCrit = new Criteria();
  +Criteria crit = new Criteria();
  +
  +subCrit.addEqualToField("productGroupId", Criteria.PARENT_QUERY_PREFIX + "groupId");
  +subQuery = QueryFactory.newReportQuery(Article.class, subCrit);
  +subQuery.setColumns(new String[] { "count(productGroupId)" });
  +
  +crit.addGreaterThan(subQuery, "10"); // MORE than 10 articles
  +crit.addLessThan("groupId", new Integer(987654));
  +Query q = QueryFactory.newQuery(ProductGroup.class, crit);
  +
  +Collection results = broker.getCollectionByQuery(q);
  +]]></source>
  +
  +</p>
  +</subsection>
  +
   <subsection name="joins">
   <p>
   Joins resulting from <b>path expressions</b> ("relationship.attribute") in
criteria are automatically handled by OJB.
  
  
  

---------------------------------------------------------------------
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