RE: findByXXX() with an ORDER BY parameter for Container-managed bean ?
>From: Markus Holmberg [mailto:[EMAIL PROTECTED]] > >You are relying on an implementation detail of your container. > >The reason it has worked for you so far is because your container has >used an instance of java.util.ArrayList/LinkedList, which indeed does >guarantee order. But CMP Entity EJB's finder methods do not return >java.util.List's! They return java.util.Collection. Your functionality >will break when the container changes it's implementation. I'll bet a case of beer that you can't find a J2EE server that uses an unordered implementation for the Collection :-) I would guess that Orion actually walks the RowSet from the Iterator rather than trying to shove everything into core first. Otherwise finders are going to choke on big queries. I think assuming this behavior is reasonably portable. My only worry is whether or not other app servers let you customize the finder sql so easily. Jeff
RE: findByXXX() with an ORDER BY parameter for Container-managed bean ?
The problem is that How can we just define one method such as Employee findAll And depend on $1 parameter (ASC or DESC) was transfered. we return the result with alphabetical order or vice versa. Is it possible? Any solutions? -Original Message- From: Robert Hargreaves [mailto:[EMAIL PROTECTED]] Sent: Friday, March 30, 2001 10:46 AM To: Orion-Interest Subject: RE: findByXXX() with an ORDER BY parameter for Container-managed bean ? I have to disagree. We've been using ORDER BY statements in finder method queries since day 1 and they work fine. As an example we have a findAll for an Employee entity bean configured as: Employee findAll and when we run the following we get a list of surnames in alphabetical order. EmployeeHome empHome = (EmployeeHome)initCtx.lookup("Employee"); ArrayList al = (ArrayList)empHome.findAll(); Iterator iter = al.iterator(); while(iter.hasNext()){ Employee emp = (Employee)iter.next(); System.out.println(emp.getSurname()); } If we take the "ORDER BY $surname ASC" statement out, the list ain't in alphabetical order. Hope this helps. Robert Hargreaves. > -Original Message- > From: Markus Holmberg [mailto:[EMAIL PROTECTED]] > Sent: 30 March 2001 16:47 > To: Orion-Interest > Cc: Magnus Rydin (E-mail) > Subject: Re: findByXXX() with an ORDER BY parameter for > Container-managed bean ? > > > Having ORDER BY in finder method queries is futile. Iterators of > java.util.Collection are not required to return objects in any kind of > order. >
Re: findByXXX() with an ORDER BY parameter for Container-managed bean ?
You are relying on an implementation detail of your container. Documentation for java.util.Collection#iterator: "Returns an iterator over the elements in this collection. There are no guarantees concerning the order in which the elements are returned (unless this collection is an instance of some class that provides a guarantee)." The reason it has worked for you so far is because your container has used an instance of java.util.ArrayList/LinkedList, which indeed does guarantee order. But CMP Entity EJB's finder methods do not return java.util.List's! They return java.util.Collection. Your functionality will break when the container changes it's implementation. Markus On Fri, Mar 30, 2001 at 05:46:10PM +0100, Robert Hargreaves wrote: > I have to disagree. We've been using ORDER BY statements in finder method > queries since day 1 and they work fine. > As an example we have a findAll for an Employee entity bean configured as: > > > > > Employee > findAll > > > > > > and when we run the following we get a list of surnames in alphabetical > order. > > EmployeeHome empHome = (EmployeeHome)initCtx.lookup("Employee"); > ArrayList al = (ArrayList)empHome.findAll(); > Iterator iter = al.iterator(); > > while(iter.hasNext()){ > Employee emp = (Employee)iter.next(); > System.out.println(emp.getSurname()); > } > > If we take the "ORDER BY $surname ASC" statement out, the list ain't in > alphabetical order. > > Hope this helps. > > Robert Hargreaves. > > > -Original Message- > > From: Markus Holmberg [mailto:[EMAIL PROTECTED]] > > Sent: 30 March 2001 16:47 > > To: Orion-Interest > > Cc: Magnus Rydin (E-mail) > > Subject: Re: findByXXX() with an ORDER BY parameter for > > Container-managed bean ? > > > > > > Having ORDER BY in finder method queries is futile. Iterators of > > java.util.Collection are not required to return objects in any kind of > > order. > > -- Markus Holmberg | Give me Unix or give me a typewriter. [EMAIL PROTECTED] | http://www.freebsd.org/
Re: findByXXX() with an ORDER BY parameter for Container-managed bean?
I'd guess, though I haven't tried it, that you could declare a finder with two arguments- your object and a String. Something like: findByGroupNameSorted(GroupName gn, String dir) where dir would be "asc" or "desc" (either constants or a special mini-bean{tm}) Then, in your orion-ejb-jar.xml, do this: Rian - Original Message - From: Meo Van Le <[EMAIL PROTECTED]> To: Orion-Interest <[EMAIL PROTECTED]> Cc: Magnus Rydin (E-mail) <[EMAIL PROTECTED]> Sent: Friday, March 30, 2001 6:35 AM Subject: findByXXX() with an ORDER BY parameter for Container-managed bean? > Dear all, > Could you tell me how to pass an ORDER BY parameter ( ASC or DESC ) > for a finder-method of Container-Managed bean? > > For example: > I have an Entity Bean was deployed as a Container-Managed > bean. The following lines were extracted from my orion-ejb-jar.xml: > > table="Rws_Group" data-source="jdbc/RWS_EJB_DS"> > > persistence-name="rws_group_id" /> > > persistence-name="rws_group_name" /> > > > > > psv.rws.ejbs.RwsGroup > > findByGroupNameAsc > > > java.lang.String > > > > > > > psv.rws.ejbs.RwsGroup > > findByGroupNameDesc > > > java.lang.String > > > > > > I have to write 2 finder methods for an normal finder method with > ascending order and descending order: findByGroupNameAsc and > findByGroupNameDesc. > > Are there any way to combine them become a finder method? > > Thanks in advance! > -- -- > -- > * Le Van Meo > * Senior Developer > * Tel: 8 251 250 > * Mobil: 091 64 26 36 > * [EMAIL PROTECTED] > -- -- > > >
RE: findByXXX() with an ORDER BY parameter for Container-managed bean ?
I have to disagree. We've been using ORDER BY statements in finder method queries since day 1 and they work fine. As an example we have a findAll for an Employee entity bean configured as: Employee findAll and when we run the following we get a list of surnames in alphabetical order. EmployeeHome empHome = (EmployeeHome)initCtx.lookup("Employee"); ArrayList al = (ArrayList)empHome.findAll(); Iterator iter = al.iterator(); while(iter.hasNext()){ Employee emp = (Employee)iter.next(); System.out.println(emp.getSurname()); } If we take the "ORDER BY $surname ASC" statement out, the list ain't in alphabetical order. Hope this helps. Robert Hargreaves. > -Original Message- > From: Markus Holmberg [mailto:[EMAIL PROTECTED]] > Sent: 30 March 2001 16:47 > To: Orion-Interest > Cc: Magnus Rydin (E-mail) > Subject: Re: findByXXX() with an ORDER BY parameter for > Container-managed bean ? > > > Having ORDER BY in finder method queries is futile. Iterators of > java.util.Collection are not required to return objects in any kind of > order. >
Re: findByXXX() with an ORDER BY parameter for Container-managed bean ?
Having ORDER BY in finder method queries is futile. Iterators of java.util.Collection are not required to return objects in any kind of order. Regards, Markus Holmberg. On Fri, Mar 30, 2001 at 09:35:20PM +0700, Meo Van Le wrote: > Dear all, > Could you tell me how to pass an ORDER BY parameter ( ASC or DESC ) > for a finder-method of Container-Managed bean? > > For example: > I have an Entity Bean was deployed as a Container-Managed > bean. The following lines were extracted from my orion-ejb-jar.xml: > >table="Rws_Group" data-source="jdbc/RWS_EJB_DS"> > >persistence-name="rws_group_id" /> > >persistence-name="rws_group_name" /> > > > > > psv.rws.ejbs.RwsGroup > > findByGroupNameAsc > > > java.lang.String > > > > > > > psv.rws.ejbs.RwsGroup > > findByGroupNameDesc > > > java.lang.String > > > > > > I have to write 2 finder methods for an normal finder method with > ascending order and descending order: findByGroupNameAsc and > findByGroupNameDesc. > > Are there any way to combine them become a finder method? > > Thanks in advance! > > -- > * Le Van Meo > * Senior Developer > * Tel: 8 251 250 > * Mobil: 091 64 26 36 > * [EMAIL PROTECTED] > > > -- Markus Holmberg | Give me Unix or give me a typewriter. [EMAIL PROTECTED] | http://www.freebsd.org/
findByXXX() with an ORDER BY parameter for Container-managed bean?
Dear all, Could you tell me how to pass an ORDER BY parameter ( ASC or DESC ) for a finder-method of Container-Managed bean? For example: I have an Entity Bean was deployed as a Container-Managed bean. The following lines were extracted from my orion-ejb-jar.xml: psv.rws.ejbs.RwsGroup findByGroupNameAsc java.lang.String psv.rws.ejbs.RwsGroup findByGroupNameDesc java.lang.String I have to write 2 finder methods for an normal finder method with ascending order and descending order: findByGroupNameAsc and findByGroupNameDesc. Are there any way to combine them become a finder method? Thanks in advance! -- * Le Van Meo * Senior Developer * Tel: 8 251 250 * Mobil: 091 64 26 36 * [EMAIL PROTECTED]