Re: collection loading and filtering
racle 8i === SPOOL projtest.log drop table T_A; create table T_A ( OID INTEGER NOT NULL, name VARCHAR2 ( 16 ) NULL, constraint PK_A PRIMARY KEY (OID) ); commit; drop table T_B; create table T_B ( OID INTEGER NOT NULL, filter VARCHAR2 ( 16 ) NULL, value VARCHAR2 ( 16 ) NULL, a_OID INTEGER NULL, constraint PK_B PRIMARY KEY (OID) ); commit; SPOOL OFF Exit 0 ; . / === repository.xml == jcd-alias="sim" default-connection="true" platform="Oracle" jdbc-level="2.0" driver="com.p6spy.engine.spy.P6SpyDriver" protocol="jdbc" subprotocol="oracle:thin" dbalias="@xx" username="xxx" password="xxx" eager-release="false" batch-mode="false" useAutoCommit="1" ignoreAutoCommitExceptions="false" > == END source == Gildas - Original Message - From: "Jakob Braeuchi" <[EMAIL PROTECTED]> To: "OJB Users List" <[EMAIL PROTECTED]> Sent: Wednesday, October 27, 2004 6:55 PM Subject: Re: collection loading and filtering hi gildas, could you please post the sql without and with projectionAttribute. i'd like to write a testcase and eventually document this feature. jakob - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: collection loading and filtering
Hi Jakob, I think you have not seen my last post :) JAVA code = package test.ojb; import java.util.Vector; public class A { private int oid; private String name = null; private Vector elements = null; public A() { super(); } public A(String name) { super(); this.name = name; } public void add(B b){ if(elements == null) elements = new Vector(); elements.addElement(b); } public boolean isEqual(A a){ return this.oid == a.getOid(); } public int getOid() { return oid; } } package test.ojb; public class B { private int oid; private String value = null; private String filter = null; public B(){ super(); } public B(String filter, String value) { super(); this.filter = filter; this.value = value; } public boolean isEqual(B b){ return this.oid == b.getOid(); } public int getOid() { return oid; } public String getFilter() { return filter; } public String getValue() { return value; } } package test.ojb; import java.util.Collection; import org.apache.log4j.Category; import org.apache.log4j.Logger; import org.apache.ojb.broker.PersistenceBroker; import org.apache.ojb.broker.PersistenceBrokerFactory; import org.apache.ojb.broker.query.Criteria; import org.apache.ojb.broker.query.Query; import org.apache.ojb.broker.query.QueryByCriteria; import org.apache.ojb.broker.query.QueryFactory; /** * Projection test with OJB 1.0.0 */ public class ProjectionTest { private static Category logger = null; private PersistenceBroker broker = null; public ProjectionTest(){ if(logger == null) logger = Logger.getInstance(ProjectionTest.class) ; this.broker = PersistenceBrokerFactory.defaultPersistenceBroker(); } public static void main(String[] args) { ProjectionTest projectionTest = new ProjectionTest(); // uncomment the following line to initialize the database //projectionTest.initDB(); // load the collection with a SQL statement B[] sqlResult = projectionTest.getFilteredArray1("xxx", "yyy"); // load the collection with OJB projection B[] ojbResult = projectionTest.getFilteredArray2("xxx", "yyy"); if(sqlResult != null && ojbResult != null){ if(sqlResult.length == ojbResult.length){ logger.info("result size SQL == result size OJB "); // log obj results for (int i=0;i"); } else logger.info("result size SQL != result size OJB - Test KO."); } } public void initDB(){ // objects with a relationship 1:N A a1 = new A("xxx"); A a2 = new A("fff"); // populate the "elements" relationship for(int i=0; i<3;i++){ // a1 contains two categories of filter a1.add(new B("yyy", "aby" + i)); a1.add(new B("zzz", "abz" + i)); // a2 contains two categories of filter a2.add(new B("yyy", "bby" + i)); a2.add(new B("zzz", "bbz" + i)); } broker.beginTransaction(); // store all into the DB (auto-update=true) broker.store(a1); broker.store(a2); broker.commitTransaction(); // make sure the relationship is loaded from the DB broker.serviceObjectCache().clear(); } // example realized with a SQL (SQL92) statement public B[] getFilteredArray1(String name, String filter){ B[] ret = null; StringBuffer sqlStatement = new StringBuffer(); sqlStatement.append("select b.* from T_A a, T_B b where b.a_oid=A.oid and a.name='"); sqlStatement.append(name); sqlStatement.append("' and b.filter='"); sqlStatement.append(filter); sqlStatement.append("'"); Query query = QueryFactory.newQuery(B.class, sqlStatement.toString()); Collection col = broker.getCollectionByQuery(query); broker.serviceObjectCache().clear(); if(col != null){ ret = new B[col.size()]; col.toArray(ret); } return ret; } // example realize with a SQL (SQL92) statement public B[] getFilteredArray2(String name, String filter){ B[] ret = null; Criteria criteria = new Criteria(); // criteria relative to A criteria.addEqualTo("name", name); criteria.addEqualTo("elements.filter", filter); QueryByCriteria query = QueryFactory.newQuery(A.class, criteria); query.setObjectProjectionAttribute("elements"); Collection col = broker.getCollectionByQuery(query); broker.serviceObjectCache().clear(); if(col != null){ ret = new B[col.size()]; col.toArray(ret); } return ret; } } == SQL for Oracle 8i === SPOOL projtest.log drop table T_A; create table T_A ( OID INTEGER NOT NULL, name VARCHAR2 ( 16 ) NULL, constraint PK_A PRIMARY KEY (OID) ); commit; drop table T_B; create table T_B ( OID INTEGER NOT NULL, filter VARCHAR2 ( 16 ) NULL, value VARCHAR2 ( 16 ) NULL, a_OID INTEGER NULL, constraint PK_B PRIMARY KEY (OID) ); commit; SPOOL OFF Exit 0 ; . / === repository.xml ==
Re: collection loading and filtering
hi gildas, the attachment did not make it to the list. please post the sql as normal text. jakob LE-QUERE Gildas - REN schrieb: Hi Jakob You will find in attachment my test case on Oracle 8i best regards Gildas - Original Message - From: "Jakob Braeuchi" <[EMAIL PROTECTED]> To: "OJB Users List" <[EMAIL PROTECTED]> Sent: Wednesday, October 27, 2004 6:55 PM Subject: Re: collection loading and filtering hi gildas, could you please post the sql without and with projectionAttribute. i'd like to write a testcase and eventually document this feature. jakob - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: collection loading and filtering
commit; drop table T_B; create table T_B ( OID INTEGER NOT NULL, filter VARCHAR2 ( 16 ) NULL, value VARCHAR2 ( 16 ) NULL, a_OID INTEGER NULL, constraint PK_B PRIMARY KEY (OID) ); commit; SPOOL OFF Exit 0 ; . / === repository.xml == ====== END source == Gildas - Original Message - From: "Jakob Braeuchi" <[EMAIL PROTECTED]> To: "OJB Users List" <[EMAIL PROTECTED]> Sent: Wednesday, October 27, 2004 6:55 PM Subject: Re: collection loading and filtering hi gildas, could you please post the sql without and with projectionAttribute. i'd like to write a testcase and eventually document this feature. jakob - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: collection loading and filtering
Hi Jakob You will find in attachment my test case on Oracle 8i best regards Gildas - Original Message - From: "Jakob Braeuchi" <[EMAIL PROTECTED]> To: "OJB Users List" <[EMAIL PROTECTED]> Sent: Wednesday, October 27, 2004 6:55 PM Subject: Re: collection loading and filtering hi gildas, could you please post the sql without and with projectionAttribute. i'd like to write a testcase and eventually document this feature. jakob - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: collection loading and filtering
Hi Jakob, I post that today. Gildas - Original Message - From: "Jakob Braeuchi" <[EMAIL PROTECTED]> To: "OJB Users List" <[EMAIL PROTECTED]> Sent: Wednesday, October 27, 2004 6:55 PM Subject: Re: collection loading and filtering hi gildas, could you please post the sql without and with projectionAttribute. i'd like to write a testcase and eventually document this feature. jakob LE-QUERE Gildas - REN schrieb: > Excellent! that's right. > > Thanks for your help > > Gildas > > - Original Message - > From: "Maksimenko Alexander" <[EMAIL PROTECTED]> > To: "OJB Users List" <[EMAIL PROTECTED]> > Sent: Wednesday, October 27, 2004 4:27 PM > Subject: Re: collection loading and filtering > > > query.setObjectProjectionAttribute("elements") > will solve your problem > > >>Hi Alexander, >> >>I tried your suggestion. With the "addPrefetchedRelationship()"method all >>elements of the relationship are loaded. The filter criteria, here, is a >>condition to retrieve the A object. In fact it's the right behaviour for >>this request. >> >>The problem is to realize a kind of left outer join in OOP to get the >>Collection of B which belong to A. >> >>In fact I use the A data to find some B elements. Now I think to load a >>filtered relationship is not very good idea. >> >>As a last resort I can use the sqlStatement but I loose the transparency of >>the persistence. >> >>Thanks >> >>Gildas >> >>- Original Message - >>From: "Maksimenko Alexander" <[EMAIL PROTECTED]> >>To: "OJB Users List" <[EMAIL PROTECTED]> >>Sent: Wednesday, October 27, 2004 2:25 PM >>Subject: Re: collection loading and filtering >> >> >>did you try query.addPrefetchedRelationship("elements") ? >> >> >> >> >>>Hi all, >>> >>>I have un object A referencing à collection with B elements. >>> >>>A has an attribute 'name' and a relation 'elements', B has an attribute >>>'filter'. >>> >>>I want to load elements where name='xxx' and filter='yyy'. >>> >>>I use the PersitenceBroker API, here is my request: >>> >>> criteria = new Criteria(); >>> >>> criteria.addEqualTo("name", 'xxx'); >>> criteria.addEqualTo("elements.filter", 'yyy'); >>> >>> query = QueryFactory.newQuery(A.class, criteria); >>> >>> A a = (A)broker.getObjectByQuery(query); >>> >>>With the relationship auto-retrieve=true all elements are loaded! >>> >>>If auto-retrieve=false the relationship is not loaded. >>> >>>Is there a solution ? >>> >>> >>>Thanks >>> >>>Gildas >>> >>>- >>>To unsubscribe, e-mail: [EMAIL PROTECTED] >>>For additional commands, e-mail: [EMAIL PROTECTED] >>> >>> >>> >>> >>> >>> >>> >> >> >>- >>To unsubscribe, e-mail: [EMAIL PROTECTED] >>For additional commands, e-mail: [EMAIL PROTECTED] >> >>- >>To unsubscribe, e-mail: [EMAIL PROTECTED] >>For additional commands, e-mail: [EMAIL PROTECTED] >> >> >> >> >> > > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: collection loading and filtering
hi charles, imo projectionAttributes and prefetcheRelationships are two completely different things. afaik (after trying to write a testcase) projectionAttribute change the search_class of a query. jakob Charles Anthony schrieb: That'd be cool - I've never even heard of it, and a search of the mailing list archives only turns up references in code for patches. Anyone got a handy description of what projectionAttribute does (and how it's different to, say, prefetchedRelationship) ? Cheers, Charles. -Original Message- From: Jakob Braeuchi [mailto:[EMAIL PROTECTED] Sent: 27 October 2004 17:55 To: OJB Users List Subject: Re: collection loading and filtering hi gildas, could you please post the sql without and with projectionAttribute. i'd like to write a testcase and eventually document this feature. jakob LE-QUERE Gildas - REN schrieb: Excellent! that's right. Thanks for your help Gildas - Original Message - From: "Maksimenko Alexander" <[EMAIL PROTECTED]> To: "OJB Users List" <[EMAIL PROTECTED]> Sent: Wednesday, October 27, 2004 4:27 PM Subject: Re: collection loading and filtering query.setObjectProjectionAttribute("elements") will solve your problem Hi Alexander, I tried your suggestion. With the "addPrefetchedRelationship()"method all elements of the relationship are loaded. The filter criteria, here, is a condition to retrieve the A object. In fact it's the right behaviour for this request. The problem is to realize a kind of left outer join in OOP to get the Collection of B which belong to A. In fact I use the A data to find some B elements. Now I think to load a filtered relationship is not very good idea. As a last resort I can use the sqlStatement but I loose the transparency of the persistence. Thanks Gildas - Original Message - From: "Maksimenko Alexander" <[EMAIL PROTECTED]> To: "OJB Users List" <[EMAIL PROTECTED]> Sent: Wednesday, October 27, 2004 2:25 PM Subject: Re: collection loading and filtering did you try query.addPrefetchedRelationship("elements") ? Hi all, I have un object A referencing à collection with B elements. A has an attribute 'name' and a relation 'elements', B has an attribute 'filter'. I want to load elements where name='xxx' and filter='yyy'. I use the PersitenceBroker API, here is my request: criteria = new Criteria(); criteria.addEqualTo("name", 'xxx'); criteria.addEqualTo("elements.filter", 'yyy'); query = QueryFactory.newQuery(A.class, criteria); A a = (A)broker.getObjectByQuery(query); With the relationship auto-retrieve=true all elements are loaded! If auto-retrieve=false the relationship is not loaded. Is there a solution ? Thanks Gildas --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] ___ HPD Software Ltd. - Helping Business Finance Business Email terms and conditions: www.hpdsoftware.com/disclaimer - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: collection loading and filtering
That'd be cool - I've never even heard of it, and a search of the mailing list archives only turns up references in code for patches. Anyone got a handy description of what projectionAttribute does (and how it's different to, say, prefetchedRelationship) ? Cheers, Charles. > -Original Message- > From: Jakob Braeuchi [mailto:[EMAIL PROTECTED] > Sent: 27 October 2004 17:55 > To: OJB Users List > Subject: Re: collection loading and filtering > > > hi gildas, > > could you please post the sql without and with projectionAttribute. > i'd like to write a testcase and eventually document this feature. > > jakob > > LE-QUERE Gildas - REN schrieb: > > Excellent! that's right. > > > > Thanks for your help > > > > Gildas > > > > - Original Message - > > From: "Maksimenko Alexander" <[EMAIL PROTECTED]> > > To: "OJB Users List" <[EMAIL PROTECTED]> > > Sent: Wednesday, October 27, 2004 4:27 PM > > Subject: Re: collection loading and filtering > > > > > > query.setObjectProjectionAttribute("elements") > > will solve your problem > > > > > >>Hi Alexander, > >> > >>I tried your suggestion. With the > "addPrefetchedRelationship()"method all > >>elements of the relationship are loaded. The filter > criteria, here, is a > >>condition to retrieve the A object. In fact it's the right > behaviour for > >>this request. > >> > >>The problem is to realize a kind of left outer join in OOP > to get the > >>Collection of B which belong to A. > >> > >>In fact I use the A data to find some B elements. Now I > think to load a > >>filtered relationship is not very good idea. > >> > >>As a last resort I can use the sqlStatement but I loose the > transparency of > >>the persistence. > >> > >>Thanks > >> > >>Gildas > >> > >>- Original Message - > >>From: "Maksimenko Alexander" <[EMAIL PROTECTED]> > >>To: "OJB Users List" <[EMAIL PROTECTED]> > >>Sent: Wednesday, October 27, 2004 2:25 PM > >>Subject: Re: collection loading and filtering > >> > >> > >>did you try query.addPrefetchedRelationship("elements") ? > >> > >> > >> > >> > >>>Hi all, > >>> > >>>I have un object A referencing à collection with B elements. > >>> > >>>A has an attribute 'name' and a relation 'elements', B has > an attribute > >>>'filter'. > >>> > >>>I want to load elements where name='xxx' and filter='yyy'. > >>> > >>>I use the PersitenceBroker API, here is my request: > >>> > >>> criteria = new Criteria(); > >>> > >>> criteria.addEqualTo("name", 'xxx'); > >>> criteria.addEqualTo("elements.filter", 'yyy'); > >>> > >>> query = QueryFactory.newQuery(A.class, criteria); > >>> > >>> A a = (A)broker.getObjectByQuery(query); > >>> > >>>With the relationship auto-retrieve=true all elements are loaded! > >>> > >>>If auto-retrieve=false the relationship is not loaded. > >>> > >>>Is there a solution ? > >>> > >>> > >>>Thanks > >>> > >>>Gildas > >>> > >>>--- > -- > >>>To unsubscribe, e-mail: [EMAIL PROTECTED] > >>>For additional commands, e-mail: [EMAIL PROTECTED] > >>> > >>> > >>> > >>> > >>> > >>> > >>> > >> > >> > >> > - > >>To unsubscribe, e-mail: [EMAIL PROTECTED] > >>For additional commands, e-mail: [EMAIL PROTECTED] > >> > >> > - > >>To unsubscribe, e-mail: [EMAIL PROTECTED] > >>For additional commands, e-mail: [EMAIL PROTECTED] > >> > >> > >> > >> > >> > > > > > > > > > - > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > - > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > ___ HPD Software Ltd. - Helping Business Finance Business Email terms and conditions: www.hpdsoftware.com/disclaimer - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: collection loading and filtering
hi gildas, could you please post the sql without and with projectionAttribute. i'd like to write a testcase and eventually document this feature. jakob LE-QUERE Gildas - REN schrieb: Excellent! that's right. Thanks for your help Gildas - Original Message - From: "Maksimenko Alexander" <[EMAIL PROTECTED]> To: "OJB Users List" <[EMAIL PROTECTED]> Sent: Wednesday, October 27, 2004 4:27 PM Subject: Re: collection loading and filtering query.setObjectProjectionAttribute("elements") will solve your problem Hi Alexander, I tried your suggestion. With the "addPrefetchedRelationship()"method all elements of the relationship are loaded. The filter criteria, here, is a condition to retrieve the A object. In fact it's the right behaviour for this request. The problem is to realize a kind of left outer join in OOP to get the Collection of B which belong to A. In fact I use the A data to find some B elements. Now I think to load a filtered relationship is not very good idea. As a last resort I can use the sqlStatement but I loose the transparency of the persistence. Thanks Gildas - Original Message - From: "Maksimenko Alexander" <[EMAIL PROTECTED]> To: "OJB Users List" <[EMAIL PROTECTED]> Sent: Wednesday, October 27, 2004 2:25 PM Subject: Re: collection loading and filtering did you try query.addPrefetchedRelationship("elements") ? Hi all, I have un object A referencing à collection with B elements. A has an attribute 'name' and a relation 'elements', B has an attribute 'filter'. I want to load elements where name='xxx' and filter='yyy'. I use the PersitenceBroker API, here is my request: criteria = new Criteria(); criteria.addEqualTo("name", 'xxx'); criteria.addEqualTo("elements.filter", 'yyy'); query = QueryFactory.newQuery(A.class, criteria); A a = (A)broker.getObjectByQuery(query); With the relationship auto-retrieve=true all elements are loaded! If auto-retrieve=false the relationship is not loaded. Is there a solution ? Thanks Gildas - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: collection loading and filtering
Excellent! that's right. Thanks for your help Gildas - Original Message - From: "Maksimenko Alexander" <[EMAIL PROTECTED]> To: "OJB Users List" <[EMAIL PROTECTED]> Sent: Wednesday, October 27, 2004 4:27 PM Subject: Re: collection loading and filtering query.setObjectProjectionAttribute("elements") will solve your problem >Hi Alexander, > >I tried your suggestion. With the "addPrefetchedRelationship()"method all >elements of the relationship are loaded. The filter criteria, here, is a >condition to retrieve the A object. In fact it's the right behaviour for >this request. > >The problem is to realize a kind of left outer join in OOP to get the >Collection of B which belong to A. > >In fact I use the A data to find some B elements. Now I think to load a >filtered relationship is not very good idea. > >As a last resort I can use the sqlStatement but I loose the transparency of >the persistence. > >Thanks > >Gildas > >- Original Message - >From: "Maksimenko Alexander" <[EMAIL PROTECTED]> >To: "OJB Users List" <[EMAIL PROTECTED]> >Sent: Wednesday, October 27, 2004 2:25 PM >Subject: Re: collection loading and filtering > > >did you try query.addPrefetchedRelationship("elements") ? > > > >>Hi all, >> >>I have un object A referencing à collection with B elements. >> >>A has an attribute 'name' and a relation 'elements', B has an attribute >>'filter'. >> >>I want to load elements where name='xxx' and filter='yyy'. >> >>I use the PersitenceBroker API, here is my request: >> >> criteria = new Criteria(); >> >> criteria.addEqualTo("name", 'xxx'); >> criteria.addEqualTo("elements.filter", 'yyy'); >> >> query = QueryFactory.newQuery(A.class, criteria); >> >> A a = (A)broker.getObjectByQuery(query); >> >>With the relationship auto-retrieve=true all elements are loaded! >> >>If auto-retrieve=false the relationship is not loaded. >> >>Is there a solution ? >> >> >>Thanks >> >>Gildas >> >>- >>To unsubscribe, e-mail: [EMAIL PROTECTED] >>For additional commands, e-mail: [EMAIL PROTECTED] >> >> >> >> >> >> >> > > >- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] > >- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] > > > > > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: collection loading and filtering
query.setObjectProjectionAttribute("elements") will solve your problem Hi Alexander, I tried your suggestion. With the "addPrefetchedRelationship()"method all elements of the relationship are loaded. The filter criteria, here, is a condition to retrieve the A object. In fact it's the right behaviour for this request. The problem is to realize a kind of left outer join in OOP to get the Collection of B which belong to A. In fact I use the A data to find some B elements. Now I think to load a filtered relationship is not very good idea. As a last resort I can use the sqlStatement but I loose the transparency of the persistence. Thanks Gildas - Original Message - From: "Maksimenko Alexander" <[EMAIL PROTECTED]> To: "OJB Users List" <[EMAIL PROTECTED]> Sent: Wednesday, October 27, 2004 2:25 PM Subject: Re: collection loading and filtering did you try query.addPrefetchedRelationship("elements") ? Hi all, I have un object A referencing à collection with B elements. A has an attribute 'name' and a relation 'elements', B has an attribute 'filter'. I want to load elements where name='xxx' and filter='yyy'. I use the PersitenceBroker API, here is my request: criteria = new Criteria(); criteria.addEqualTo("name", 'xxx'); criteria.addEqualTo("elements.filter", 'yyy'); query = QueryFactory.newQuery(A.class, criteria); A a = (A)broker.getObjectByQuery(query); With the relationship auto-retrieve=true all elements are loaded! If auto-retrieve=false the relationship is not loaded. Is there a solution ? Thanks Gildas - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: collection loading and filtering
Hi Alexander, I tried your suggestion. With the "addPrefetchedRelationship()"method all elements of the relationship are loaded. The filter criteria, here, is a condition to retrieve the A object. In fact it's the right behaviour for this request. The problem is to realize a kind of left outer join in OOP to get the Collection of B which belong to A. In fact I use the A data to find some B elements. Now I think to load a filtered relationship is not very good idea. As a last resort I can use the sqlStatement but I loose the transparency of the persistence. Thanks Gildas - Original Message - From: "Maksimenko Alexander" <[EMAIL PROTECTED]> To: "OJB Users List" <[EMAIL PROTECTED]> Sent: Wednesday, October 27, 2004 2:25 PM Subject: Re: collection loading and filtering did you try query.addPrefetchedRelationship("elements") ? >Hi all, > >I have un object A referencing à collection with B elements. > >A has an attribute 'name' and a relation 'elements', B has an attribute >'filter'. > >I want to load elements where name='xxx' and filter='yyy'. > >I use the PersitenceBroker API, here is my request: > > criteria = new Criteria(); > > criteria.addEqualTo("name", 'xxx'); > criteria.addEqualTo("elements.filter", 'yyy'); > > query = QueryFactory.newQuery(A.class, criteria); > > A a = (A)broker.getObjectByQuery(query); > >With the relationship auto-retrieve=true all elements are loaded! > >If auto-retrieve=false the relationship is not loaded. > >Is there a solution ? > > >Thanks > >Gildas > >- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] > > > > > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: collection loading and filtering
Hi David, With the following code criteria.addEqualTo("name", 'xxx'); criteria.addEqualTo("elements.filter", 'yyy'); I get A, but alos all elements of th relationship and not only the B elements where filter ='yyy'. Finaly it's right because the filter= 'yyy' is a criteria to retrieve A. I have a big volumetry on B, so I took your advice, to load the collection programmaticaly. If later I need all elements I have the proxy to navigate on the relationship. A solution would be like the following SQL statement: select B.* from A, B where A.name='xxx' and B.A_id =A.id and B.filter='yyy' (with A_id foreign key of A in B table) Thanks a lot for your help. Gildas - Original Message - From: <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, October 27, 2004 10:33 AM Subject: RE: collection loading and filtering Hi Gildas, According to me, the two approachs are not compatible. - If you are trying to get A and B in only one query: Then the following code criteria.addEqualTo("name", 'xxx'); criteria.addEqualTo("elements.filter", 'yyy'); is the way. And you will get A WITH the filtered collection of B. And I don't see why you don't want to load the relationship, because a join query is executed because you want the relationships. - If you try to avoid unnecessary relationships loading: Then the proxy is the solution. And in this case the filtering cannot be done automatically. You have to do it programmatically by adding a method like A.getB(int yyy) where you implement your filter. If you are taking of performance, first do it as simple as possible, then look if you face performance issues. Personally, I generally choose the second approach and I use the first one only in case of performance issues (but only monitoring can say what to do). Then I have two methods: A getById(); // criteria.addEqualTo("name", 'xxx') and use proxy A getByIdWithB(); // criteria.addEqualTo("name", 'xxx') criteria.addEqualTo("elements.filter", 'yyy') Be also aware that caching the objects increases performance. If B contains rather stable data, then cache them. A.getB() will then use the cache instead of generating a SQL. Hope it helps... David WIESZTAL. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: collection loading and filtering
did you try query.addPrefetchedRelationship("elements") ? Hi all, I have un object A referencing à collection with B elements. A has an attribute 'name' and a relation 'elements', B has an attribute 'filter'. I want to load elements where name='xxx' and filter='yyy'. I use the PersitenceBroker API, here is my request: criteria = new Criteria(); criteria.addEqualTo("name", 'xxx'); criteria.addEqualTo("elements.filter", 'yyy'); query = QueryFactory.newQuery(A.class, criteria); A a = (A)broker.getObjectByQuery(query); With the relationship auto-retrieve=true all elements are loaded! If auto-retrieve=false the relationship is not loaded. Is there a solution ? Thanks Gildas - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: collection loading and filtering
Hi Gildas, According to me, the two approachs are not compatible. - If you are trying to get A and B in only one query: Then the following code criteria.addEqualTo("name", 'xxx'); criteria.addEqualTo("elements.filter", 'yyy'); is the way. And you will get A WITH the filtered collection of B. And I don't see why you don't want to load the relationship, because a join query is executed because you want the relationships. - If you try to avoid unnecessary relationships loading: Then the proxy is the solution. And in this case the filtering cannot be done automatically. You have to do it programmatically by adding a method like A.getB(int yyy) where you implement your filter. If you are taking of performance, first do it as simple as possible, then look if you face performance issues. Personally, I generally choose the second approach and I use the first one only in case of performance issues (but only monitoring can say what to do). Then I have two methods: A getById(); // criteria.addEqualTo("name", 'xxx') and use proxy A getByIdWithB(); // criteria.addEqualTo("name", 'xxx') criteria.addEqualTo("elements.filter", 'yyy') Be also aware that caching the objects increases performance. If B contains rather stable data, then cache them. A.getB() will then use the cache instead of generating a SQL. Hope it helps... David WIESZTAL. -Original Message- From: LE-QUERE Gildas - REN [mailto:[EMAIL PROTECTED] Sent: Tuesday, October 26, 2004 6:10 PM To: OJB Users List Subject: Re: collection loading and filtering Hi David, Thanks for your solution with the proxy, I tried it. The relationship is loaded when I navigate however the elements are not filtered. When a proxy is used a proxy instance is set in the relationship attribute. The proxy instance contains the criteria to get the collection when the relationship is navigated, this criteria is not my criteria to filter the loading. The final goal is to get a collection of B where the filter='yyy' and and the name of the A owner is 'xxx' like the SQL statement : select b from A (alias) a, B (alias) b where a.name='xxx' and b.oid=a.oid and b.filter='yyy' regards Gildas ----- Original Message - From: <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, October 25, 2004 10:26 AM Subject: RE: collection loading and filtering Hi Gildas, You have to set proxy="true" in your collection descriptor. Like that the relationship is loaded only if you navigate. David WIESZTAL. -Original Message- From: LE-QUERE Gildas - REN [mailto:[EMAIL PROTECTED] Sent: Monday, October 25, 2004 10:06 AM To: OJB Users List Subject: collection loading and filtering Hi all, I have un object A referencing à collection with B elements. A has an attribute 'name' and a relation 'elements', B has an attribute 'filter'. I want to load elements where name='xxx' and filter='yyy'. I use the PersitenceBroker API, here is my request: criteria = new Criteria(); criteria.addEqualTo("name", 'xxx'); criteria.addEqualTo("elements.filter", 'yyy'); query = QueryFactory.newQuery(A.class, criteria); A a = (A)broker.getObjectByQuery(query); With the relationship auto-retrieve=true all elements are loaded! If auto-retrieve=false the relationship is not loaded. Is there a solution ? Thanks Gildas - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: collection loading and filtering
Hi, LE-QUERE Gildas - REN wrote: Hi David, Thanks for your solution with the proxy, I tried it. The relationship is loaded when I navigate however the elements are not filtered. When a proxy is used a proxy instance is set in the relationship attribute. The proxy instance contains the criteria to get the collection when the relationship is navigated, this criteria is not my criteria to filter the loading. Not sure, but maybe this could be useful http://db.apache.org/ojb/docu/guides/advanced-technique.html#Customizing+collection+queries regards, Armin The final goal is to get a collection of B where the filter='yyy' and and the name of the A owner is 'xxx' like the SQL statement : select b from A (alias) a, B (alias) b where a.name='xxx' and b.oid=a.oid and b.filter='yyy' regards Gildas - Original Message - From: <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, October 25, 2004 10:26 AM Subject: RE: collection loading and filtering Hi Gildas, You have to set proxy="true" in your collection descriptor. Like that the relationship is loaded only if you navigate. David WIESZTAL. -Original Message- From: LE-QUERE Gildas - REN [mailto:[EMAIL PROTECTED] Sent: Monday, October 25, 2004 10:06 AM To: OJB Users List Subject: collection loading and filtering Hi all, I have un object A referencing à collection with B elements. A has an attribute 'name' and a relation 'elements', B has an attribute 'filter'. I want to load elements where name='xxx' and filter='yyy'. I use the PersitenceBroker API, here is my request: criteria = new Criteria(); criteria.addEqualTo("name", 'xxx'); criteria.addEqualTo("elements.filter", 'yyy'); query = QueryFactory.newQuery(A.class, criteria); A a = (A)broker.getObjectByQuery(query); With the relationship auto-retrieve=true all elements are loaded! If auto-retrieve=false the relationship is not loaded. Is there a solution ? Thanks Gildas - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: collection loading and filtering
Hi David, Thanks for your solution with the proxy, I tried it. The relationship is loaded when I navigate however the elements are not filtered. When a proxy is used a proxy instance is set in the relationship attribute. The proxy instance contains the criteria to get the collection when the relationship is navigated, this criteria is not my criteria to filter the loading. The final goal is to get a collection of B where the filter='yyy' and and the name of the A owner is 'xxx' like the SQL statement : select b from A (alias) a, B (alias) b where a.name='xxx' and b.oid=a.oid and b.filter='yyy' regards Gildas - Original Message - From: <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, October 25, 2004 10:26 AM Subject: RE: collection loading and filtering Hi Gildas, You have to set proxy="true" in your collection descriptor. Like that the relationship is loaded only if you navigate. David WIESZTAL. -Original Message- From: LE-QUERE Gildas - REN [mailto:[EMAIL PROTECTED] Sent: Monday, October 25, 2004 10:06 AM To: OJB Users List Subject: collection loading and filtering Hi all, I have un object A referencing à collection with B elements. A has an attribute 'name' and a relation 'elements', B has an attribute 'filter'. I want to load elements where name='xxx' and filter='yyy'. I use the PersitenceBroker API, here is my request: criteria = new Criteria(); criteria.addEqualTo("name", 'xxx'); criteria.addEqualTo("elements.filter", 'yyy'); query = QueryFactory.newQuery(A.class, criteria); A a = (A)broker.getObjectByQuery(query); With the relationship auto-retrieve=true all elements are loaded! If auto-retrieve=false the relationship is not loaded. Is there a solution ? Thanks Gildas - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: collection loading and filtering
Hi Gildas, You have to set proxy="true" in your collection descriptor. Like that the relationship is loaded only if you navigate. David WIESZTAL. -Original Message- From: LE-QUERE Gildas - REN [mailto:[EMAIL PROTECTED] Sent: Monday, October 25, 2004 10:06 AM To: OJB Users List Subject: collection loading and filtering Hi all, I have un object A referencing à collection with B elements. A has an attribute 'name' and a relation 'elements', B has an attribute 'filter'. I want to load elements where name='xxx' and filter='yyy'. I use the PersitenceBroker API, here is my request: criteria = new Criteria(); criteria.addEqualTo("name", 'xxx'); criteria.addEqualTo("elements.filter", 'yyy'); query = QueryFactory.newQuery(A.class, criteria); A a = (A)broker.getObjectByQuery(query); With the relationship auto-retrieve=true all elements are loaded! If auto-retrieve=false the relationship is not loaded. Is there a solution ? Thanks Gildas - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
collection loading and filtering
Hi all, I have un object A referencing à collection with B elements. A has an attribute 'name' and a relation 'elements', B has an attribute 'filter'. I want to load elements where name='xxx' and filter='yyy'. I use the PersitenceBroker API, here is my request: criteria = new Criteria(); criteria.addEqualTo("name", 'xxx'); criteria.addEqualTo("elements.filter", 'yyy'); query = QueryFactory.newQuery(A.class, criteria); A a = (A)broker.getObjectByQuery(query); With the relationship auto-retrieve=true all elements are loaded! If auto-retrieve=false the relationship is not loaded. Is there a solution ? Thanks Gildas - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]