Re: How to do these two tasks properly in cayenne?

From: Gili (cowwo..bs.darktech.org)
Date: Tue Sep 20 2005 - 11:25:08 EDT

  • Next message: Gentry, Michael \(Contractor\): "RE: How to do these two tasks properly in cayenne?"

            I think this is what I was thinking of:
    http://www.objectstyle.org/cayenne/userguide/introduction/whats-new.html
    "Lazy Relationship Creation". Looks like it doesn't explicitly mention
    the list size.

            Looking at the implementation of ToManyList.size(), it is currently
    defined as "return resolvedObjectList().size()" but we could easily
    redefine it as "If the list is not yet resolved, issue a count(*) query,
    otherwise use the original implementation."

            It's also a matter of optimization. If the user almost always uses a
    list after retrieving its size, then the current implementation is
    preferable. If otherwise, the new implementation is preferable. I'm
    guessing we have no statistics on this?

    Gili

    Gentry, Michael (Contractor) wrote:
    > I use an SQLTemplate to retrieve sizes. I'm 99% certain Cayenne would
    > have to fetch all rows to give you the size using a regular SelectQuery.
    >
    > For Sybase (you'll have to tailor it for MySQL, probably), I used
    > something like:
    >
    > final String queryString = "SELECT count(*) 'rowCount' from Foo where
    > bar = $bar";
    > final SQLTemplate queryTemplate = new SQLTemplate(Foo.class,
    > queryString, true);
    >
    > queryTemplate.setFetchingDataRows(true);
    >
    > Map queryParameters = new HashMap(1);
    > queryParameters.put("bar", "xyzzy");
    > SQLTemplate query = queryTemplate.queryWithParameters(queryParameters);
    > List results = dataContext.performQuery(query);
    >
    > if (results.size() == 1)
    > return results.get(0).get("rowCount").intValue();
    > else
    > return 0;
    >
    >
    > -----Original Message-----
    > From: Gili [mailto:cowwo..bs.darktech.org]
    > Sent: Tuesday, September 20, 2005 10:49 AM
    > To: cayenne-use..bjectstyle.org
    > Subject: Re: How to do these two tasks properly in cayenne?
    >
    >
    >
    > For #1, I believe it is possible to create a SelectQuery for the
    > table
    > in question, and invoke size() on the resulting size(). My guess is that
    >
    > Cayenne will be smart enough to invoke "select count(*)" without
    > actually retrieving the actual rows.
    >
    > Gili
    >
    > Tore Halset wrote:
    >
    >>On Sep 20, 2005, at 9:26, Tomas Jucius wrote:
    >>
    >>
    >>>I wanted to know how properly to do these:
    >>>
    >>>1) count rows in the table
    >>>2) execute "password" function and get result..
    >>>
    >>>DataBase: MySql..
    >>>
    >>>Is it possible with cayenne to execute simple query and get result
    >
    > map?
    >
    >>
    >>Yes, using SQLTemplate
    >>
    >>http://www.objectstyle.org/cayenne/userguide/fetch/sqltemplate.html
    >>
    >> - Tore.
    >>
    >
    >

    -- 
    http://www.desktopbeautifier.com/
    



    This archive was generated by hypermail 2.0.0 : Tue Sep 20 2005 - 11:25:08 EDT