You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Tony Dahbura <da...@aopslab.com> on 2011/05/06 20:28:47 UTC
Example of an order by clause on a query
I am trying to find an example of using an order by on a cayenne query. I was hoping to have it sort the information using the database versus locally which cayenne seems to support either.
My example is I need to do a select * from event order by name ascending.
How do I build such a query:
SelectQuery query = new SelectQuery(Event.class);
//what goes in here to sort by some field in the object to order it
query.addOrdering();
List<Event> values = context.performQuery(query);
Thanks,
Tony
Re: Example of an order by clause on a query
Posted by Tony Dahbura <da...@aopslab.com>.
thanks!
----- Original Message -----
From: "Joe Baldwin" <jf...@earthlink.net>
To: user@cayenne.apache.org
Sent: Friday, May 6, 2011 2:46:33 PM
Subject: Re: Example of an order by clause on a query
Tony,
this is very simple. First create a SelectQuery based on the class then pass it an Ordering object. You have the option to order using the DBMS or once you have the result set. It is less resource intensive to let the DBMS do it.
SelectQuery query = new SelectQuery(Event.class); // Select Query
query.addOrdering(new Ordering(Event.NAME_PROPERTY, SortOrder.ASCENDING)); // order by name
Joe
On May 6, 2011, at 2:28 PM, Tony Dahbura wrote:
> I am trying to find an example of using an order by on a cayenne query. I was hoping to have it sort the information using the database versus locally which cayenne seems to support either.
>
> My example is I need to do a select * from event order by name ascending.
>
> How do I build such a query:
>
> SelectQuery query = new SelectQuery(Event.class);
> //what goes in here to sort by some field in the object to order it
> query.addOrdering();
> List<Event> values = context.performQuery(query);
>
>
> Thanks,
> Tony
>
Re: Example of an order by clause on a query
Posted by Joe Baldwin <jf...@earthlink.net>.
Tony,
this is very simple. First create a SelectQuery based on the class then pass it an Ordering object. You have the option to order using the DBMS or once you have the result set. It is less resource intensive to let the DBMS do it.
SelectQuery query = new SelectQuery(Event.class); // Select Query
query.addOrdering(new Ordering(Event.NAME_PROPERTY, SortOrder.ASCENDING)); // order by name
Joe
On May 6, 2011, at 2:28 PM, Tony Dahbura wrote:
> I am trying to find an example of using an order by on a cayenne query. I was hoping to have it sort the information using the database versus locally which cayenne seems to support either.
>
> My example is I need to do a select * from event order by name ascending.
>
> How do I build such a query:
>
> SelectQuery query = new SelectQuery(Event.class);
> //what goes in here to sort by some field in the object to order it
> query.addOrdering();
> List<Event> values = context.performQuery(query);
>
>
> Thanks,
> Tony
>
Re: Example of an order by clause on a query
Posted by Michael Gentry <mg...@masslight.net>.
Hi Tony,
SelectQuery query = new SelectQuery(Event.class);
query.addOrdering(new Ordering(Event.SOME_PROPERTY, SortOrder.ASCENDING));
List<Event> values = context.performQuery(query);
mrg
On Fri, May 6, 2011 at 2:28 PM, Tony Dahbura <da...@aopslab.com> wrote:
> I am trying to find an example of using an order by on a cayenne query. I was hoping to have it sort the information using the database versus locally which cayenne seems to support either.
>
> My example is I need to do a select * from event order by name ascending.
>
> How do I build such a query:
>
> SelectQuery query = new SelectQuery(Event.class);
> //what goes in here to sort by some field in the object to order it
> query.addOrdering();
> List<Event> values = context.performQuery(query);
>
>
> Thanks,
> Tony
>
>