Re: Sorting and Pagination in Many-to-Many relationship

From: Nishant Neeraj (nneeraj12..ahoo.com)
Date: Tue Sep 15 2009 - 16:22:31 EDT

  • Next message: Aristedes Maniatis: "Re: Sorting and Pagination in Many-to-Many relationship"

    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 <mgentr..asslight.net> wrote:

    From: Michael Gentry <mgentr..asslight.net>
    Subject: Re: Sorting and Pagination in Many-to-Many relationship
    To: use..ayenne.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 <nneeraj12..ahoo.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



    This archive was generated by hypermail 2.0.0 : Tue Sep 15 2009 - 16:23:13 EDT