Re: Prefetch in SelectQuery with a Qualifier

From: Jorge Sopena (jsopen..idsa.es)
Date: Thu Nov 13 2003 - 11:54:14 EST

  • Next message: Andrus Adamchik: "Re: Prefetch in SelectQuery with a Qualifier"

    Andrus,
    Here is the piece of code where I build the qualifier:

    Expression where = null;
       if (requestTypes !=null)
         where =
    ExpressionFactory.inExp("RequestType.groupRequest",requestTypes);

       if (statusTypes != null)
         if (where !=null)
           where =
    where.andExp(ExpressionFactory.inExp("statusType",statusTypes));
         else
           where = ExpressionFactory.inExp("statusType",statusTypes);

       if (companies !=null)
         if (where !=null)
           where =
    where.andExp(ExpressionFactory.inExp("customer.company",companies));
         else
           where = ExpressionFactory.inExp("customer.company",companies);

       if (firstDate!=null)
         if (where !=null)
           where =
    where.andExp(ExpressionFactory.greaterExp("startDate",firstDate));
         else
           where = ExpressionFactory.greaterExp("startDate",firstDate);

       if (secondDate!=null)
         if (where !=null)
           where =
    where.andExp(ExpressionFactory.lessExp("startDate",secondDate));
         else
           where = ExpressionFactory.lessExp("startDate",secondDate);

    It doesn't matter how the qualifier is at the end. I've checked several
    combinations and all of them threw the same exception.
    Here is an example of built query :

    INFO QueryLogger: SELECT t0.EndDate, t0.StartDate, t0.StatusType,
    t0.RequestType_idRequestType, t0.Customer_CustomerId,
     t0.MobileObject_MobileObjectId, t0.RequestId
    FROM request t0, customer t1
    WHERE t0.Customer_CustomerId = t1.CustomerId
    AND ((t1.Company_CompanyId IN (?)) AND (t0.StartDate > ?) AND
    (t0.StartDate < ?))
     [bind: '0', '2003-05-12 00:00:00.0', '2003-11-14 00:00:00.0']

    As you can guess what I want is to show in a web page a list of the
    requests and the customer who did it.
    So to avoid doing a query for each row, I'd want to do a prefetch.

    Is there any other way to do it?

    Thanks

    Jorge

    Andrus Adamchik wrote:

    > Hi Jorge,
    >
    > There is one known issue with prefetching that I suspect might cause
    > the problem in your case:
    >
    > http://objectstyle.org/jira/secure/ViewIssue.jspa?key=CAY-12
    >
    > Could you send the details on what qualifier you are using?
    >
    > Andrus
    >
    >
    >
    > On Nov 13, 2003, at 6:45 AM, Jorge Sopena wrote:
    >
    >> As in the examples of prefetching, I'm trying to prefetch some
    >> relationships in my SelectQuery.
    >> If I do a simple prefetch over a SelectQuery without any Qualifier,
    >> it goes right.
    >> SelectQuery query = new SelectQuery(Request.class);
    >> query.addPrefetch("customer");
    >> query.addPrefetch("customer.company");
    >>
    >> But if my SelectQuery has a Qualifier, an exception is thrown:
    >> SelectQuery query = new SelectQuery(Request.class,where);
    >> query.addPrefetch("customer");
    >> query.addPrefetch("customer.company");
    >>
    >> This is the message error:
    >> java.lang.NullPointerException
    >> at
    >> org.objectstyle.cayenne.access.util.QueryUtils$ExpressionTranslator.rev
    >> erseDbPath(QueryUtils.java:520)
    >> at
    >> org.objectstyle.cayenne.access.util.QueryUtils$ExpressionTranslator.<in
    >> it>(QueryUtils.java:430)
    >> at
    >> org.objectstyle.cayenne.access.util.QueryUtils.transformQualifier(Query
    >> Utils.java:353)
    >> at
    >> org.objectstyle.cayenne.access.util.QueryUtils.selectPrefetchPath(Query
    >> Utils.java:321)
    >> at
    >> org.objectstyle.cayenne.access.DataContext.performQueries(DataContext.j
    >> ava:794)
    >> at
    >> org.objectstyle.cayenne.access.DataContext.performQuery(DataContext.jav
    >> a:866)
    >> at
    >> org.objectstyle.cayenne.access.DataContext.performQuery(DataContext.jav
    >> a:744)
    >> at MapServer.Persistence.Request.search(Request.java:159)
    >>
    >> Am I doing sth wrong?
    >> Is there any restriction I should know?
    >>
    >> Thanks,
    >>
    >> Jorge Sopena
    >>
    >
    >



    This archive was generated by hypermail 2.0.0 : Thu Nov 13 2003 - 11:44:44 EST