cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nishant Neeraj <nneeraj...@yahoo.com>
Subject Re: Sorting and Pagination in Many-to-Many relationship
Date Tue, 15 Sep 2009 20:22:31 GMT
Thanks mrg. This helps a bit my understanding. There are two things. 


1. Subscription type is dynamic. Actually, we should be able to add subscription type without
altering the code. 


2. The requirement is like this, I need to display paginated tabular list of magazines subscribed
by a user. Each row has indication of type of subscription that reader had chosen. 


I guess, I need (a) paginated list of subscriptions (b) sorted by any fields available in
Magazines or Subscription_Types table. I will inflate Magazines and SubscriptionTypes at display
time.


A question regarding caching. When we use SQLTemplate or Expression, does the objects gets
cached? I mean, these are very frequent used piece of code.... as soon as user logs in we
will show his list of Magazines... if the object is not cached, we may have sluggish performance
under load.


Help appreciated.



- Nishant
--- On Mon, 14/9/09, Michael Gentry <mgentry@masslight.net> wrote:

From: Michael Gentry <mgentry@masslight.net>
Subject: Re: Sorting and Pagination in Many-to-Many relationship
To: user@cayenne.apache.org
Date: Monday, 14 September, 2009, 8:23 PM

Hi Nishant,

First off, unless your Subscription Type is rather dynamic, you might
want to consider using an enum for it (especially if you are using
3.0):

http://cayenne.apache.org/doc/modeling-enumerations.html

Next, it sounds like what you are wanting is a list of magazines for a
given user.  Instead of starting at the user, you could start at the
magazines and put the sort order on it.  You essentially want to:
fetch magazines where subscriptions.readers.rname = your_reader order
by mname.

In Cayenne, it would be more like (and I'm guessing at your
relationship/attribute names):

Expression exp = Expression.fromString("subscriptions.readers.rname = $reader");
Map param = new HashMap(1);
param.put("reader", "reader's name");
SelectQuery query = new SelectQuery(Magazine.class,
exp.expWithParameters(param));
Ordering order = new Ordering(Magazine.MNAME_PROPERTY, true);
query.addOrdering(order);
List<Magazine> magazines = dataContext.performQuery(query);

mrg


On Sun, Sep 13, 2009 at 4:55 AM, Nishant Neeraj <nneeraj123@yahoo.com> wrote:
> I am having problem in sorting and paginating  many to many relationship objects.
> Here is the DB relationship model.  http://i30.tinypic.com/jaz4wm.jpgI want to do Readers.getMagzines()
that returns paginated resultset of page size, N.
>
> I write a Readers.getMagzine() Method that pulls out List of subscriptions. In the method,
I iterate through the list and inflating Magzines (subscriptions.getMagzines()) and injecting
SubscriptionType to magzine object. And then I return the list. This works fine.
> Now, I do not want to pull out the full list. Rather, I want do it page by page sort
by say, MagzineName with page Size N. Not sure how to do it. Can some one give a hint?
> ThanksNishant
>
>
>      Love Cricket? Check out live scores, photos, video highlights and more. Click
here http://cricket.yahoo.com



      Love Cricket? Check out live scores, photos, video highlights and more. Click here http://cricket.yahoo.com
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message