You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Jakob Braeuchi <jb...@gmx.ch> on 2004/11/29 18:48:55 UTC

Re: Deep retrieve : a proposal

hi jean-baptiste,

ojb already offers auto-retrieve = true in the collection-descriptor to load 
related objects automatically. an additional feature are the prefetched 
relationships that allow you to load related object in a single query instead of 
executing one query for each parent object.

what is the additional benefit of DeepRetrieve ?

jakob

CLARAMONTE Jean-Baptiste schrieb:
> I've noticed that OJB doesn't offer a deep retrieve reference service, so I
> have developped an utility for retrieving from one reference all the deep
> references (and back references). 
> Example :
> we have the following model :
> [A]<(*)listeA-----(1)b>[B]<(1)b-----(*)listeC>[C]-----(1)d>[D]
>                         /\
>                     (*)listeB
>                         ||
>                     (*)listeE
>                         \/
>                        [E]
>                        
> Supposing we already have retrieved a reference on [A] and now we would like
> to retrieve all the references associated from this instance. Using the
> DeepRerieve utility the following code will do the job for you :
> 		
> Criteria crit = new Criteria();
> crit.addEqualTo("idA", new Long(0));
> 
> QueryByCriteria query = QueryFactory.newQuery(A.class, crit);
> 
> A result = (A)broker.getObjectByQuery(query);
> 
> DeepRetrieve deepRetrieve = new DeepRetrieve(broker);
> deepRetrieve.addRetrieveRef("b(listeA).listeC(b).d");
> deepRetrieve.addRetrieveRef("b.listeE(listeB)");
> deepRetrieve.retrieve(result);
> 		
> Without the DeepRetrieve utility the following code should have been used :
> 
> Criteria crit = new Criteria();
> crit.addEqualTo("idA", new Long(0));
> 
> QueryByCriteria query = QueryFactory.newQuery(A.class, crit);
> query.addPrefetchedRelationship("b");
> 
> A result = (A)broker.getObjectByQuery(query);
> 
> broker.retrieveReference(result.getB(), "listeA");
> broker.retrieveReference(result.getB(), "listeC");
> Iterator iter = result.getB().getListeC().iterator();
> while (iter.hasNext()) {
> 	C c = (C)iter.next();
> 	broker.retrieveReference(c, "d");
> 	broker.retrieveReference(c, "b");
> }
> 
> broker.retrieveReference(result.getB(), "listeE");
> iter = result.getB().getListeE().iterator();
> while (iter.hasNext()) {
> 	E e = (E)iter.next();
> 	broker.retrieveReference(e, "listeB");
> }	
> 
> 		
>>>From my first tests this DeepRetrive leads to the same amount of sql query.
> The code is easier to read. (well from my point of view...)
> 
> regards,
> 
> JB
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 

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