Re: SQLTemplate with SQL MAX function

From: Borut Bolčina (borut.bolcin..mail.com)
Date: Mon Oct 05 2009 - 04:40:12 EDT

  • Next message: Andrus Adamchik: "Re: Prefetching and iterated queries"

    Hi Evgeny,

    thanks for your answers and tips. The last solution you proposed aims at
    creating SQLTemplates for tables with no attributes other than FKs (that is
    join tables or cross tables). In my case it makes no difference, as my cross
    table (user_bookmark) also have one meaningful attibute (ordering), so I
    need to have it mapped. It is only one FK in that table that needs to be
    part of SQLTemplate (userid).

    Using alias makes the code more readable, thanks for that.

    Cheers,
    Borut

    2009/10/2 Evgeny Ryabitskiy <evgeny.ryabitski..mail.com>

    > If you still interested.. I found a solution of how to perform simple
    > SQLTemplate query without mapping.
    > In you example it will be like:
    >
    > DataMap someDataMap = ..... // get it from somewhere... e.g. from
    > DataContext
    >
    > SQLTemplate template = new SQLTemplate(someDataMap, "SELECT
    > max(ordering) as MAX_ORDERING FROM user_bookmark WHERE userid=$uid");
    > template.setParameters(Collections.singletonMap("uid", user.getId()));
    > template.setFetchingDataRows(true);
    > List<DataRow> res = context.performQuery(template);
    >
    > Integer maxOrdering = null;
    > if (res != null) {
    > DataRow row =res.get(0);
    > if (row != null) {
    > maxOrdering = (Integer) row.get("MAX_ORDERING");
    > }
    > }
    > if (maxOrdering == null) {
    > maxOrdering = 0;
    > }
    >
    > Hope it can help you...
    >
    > Best regards,
    > Evgeny Ryabitskiy.
    >
    >
    >
    > 2009/10/2 Evgeny Ryabitskiy <evgeny.ryabitski..mail.com>:
    > >> Unfortunately there is an empty page at
    > >> http://cayenne.apache.org/doc/modeling-queries.html
    > >
    > >> I would also report a broken link on the front page for the Wiki (
    > >> http://cayenne.apache.org/CAY/index.html)
    > >
    > >> I would also recomend a FAQ section on the main page which would answer
    > >> common questions, like "How do I do SELECT count(*) FROM artist WHERE
    > >> first_name LIKE '%abl%'
    > >
    > > Best way to get any Cayenne Improvement (Documentation or
    > > Functionality) is to report an issue in JIRA.
    > > https://issues.apache.org/jira/secure/BrowseProject.jspa
    > > It's not hard.
    > >
    > > Once issue is reported you got every notify about every it's change in
    > > progress. And the main advantage that since issue reported, it's not
    > > going to be lost as in this mail list....
    > > One problem is that JIRA not working properly last few days... hope it
    > > will be fixed....
    > >
    > >
    > >
    > >> And that holds true for EJBQLQuery as well does it not? Maybe there
    > should
    > >> be an advice somewhere in the docs that one must use DataRows as soon as
    > >> there is just one non-mapped attribute in the query.
    > >
    > > I'v created an JIRA issue for this
    > > https://issues.apache.org/jira/browse/CAY-1287
    > > The progress of fix should be faster, if you someday registry in JIRA
    > > and vote for it... ;)
    > >
    > >
    > > Best regards,
    > > Evgeny Ryabitskiy.
    > >
    >



    This archive was generated by hypermail 2.0.0 : Mon Oct 05 2009 - 04:42:38 EDT