RE: Patch for CAY-360

From: Gentry, Michael \(Contractor\) ("Gentry,)
Date: Wed Sep 14 2005 - 09:39:29 EDT

  • Next message: Kevin Menard: "Re: CayenneDataObject#setDataContext()"

    Good catch, I've updated my code base and will try to check it in
    tonight/tomorrow. You wouldn't actually get an NPE from it, either.
    The only time name is used is when constructing the new name and Java
    will just substitute "null" as the name ("foo" + null + "bar" =>
    "foonullbar"). Of course, if Andrus decides he wants to cache unnamed
    queries, too ... :-) Well, assuming you don't name your query "null"
    ...

    I don't know any downsides to the parameter map being arbitrarily long,
    outside of a slight additional processing time, but it's really not
    avoidable. That slight amount of overhead will be substantially faster
    than a trip to the DB, anyway, if the results are already cached.

    Thanks,

    /dev/mrg

    -----Original Message-----
    From: Cris Daniluk [mailto:cris.danilu..mail.com]
    Sent: Wednesday, September 14, 2005 8:59 AM
    To: cayenne-deve..bjectstyle.org
    Subject: Re: Patch for CAY-360

    I finally had a chance to look through this and it seems quite cool,
    actually. However, it seems to name and therefore register all
    queries, even if they aren't supposed to be:

    SelectQuery unnamedQuery = new SelectQuery(Order.class, "(isFilled =
    0) or (orderID = $orderID)");
    List result =
    dataContext.performQuery(unnamedQuery.queryWithParameters(tmap,
    false));

    Since I didn't name it, I don't think Cayenne should be caching this
    for me, should it? It will probably result in an NPE, anyway. Maybe
    there should be a check, like:

    if (name != null && !"".equals(name)) {
      query.setName(name + parametersHash.toHashCode());
    }

    Oh... is there any downsides to if the parameter map is arbitrarily
    long? Looks like it should be fine.

    On 9/6/05, Michael Gentry (Yes, I'm a Contractor)
    <michael_gentr..anniemae.com> wrote:
    > Could a few eyeballs look over this and give me feedback? It seems
    to work
    > with my test case.
    >
    > In org.objectstyle.cayenne.query.SelectQuery.java:354 (at least in my
    1.2
    > checkout):
    >
    >
    > public SelectQuery queryWithParameters(Map parameters, boolean
    > pruneMissing) {
    > // create a query replica
    > SelectQuery query = new SelectQuery();
    > query.setDistinct(distinct);
    >
    >
    this.selectProperties.copyToProperties(query.selectProperties);
    >
    > query.setLoggingLevel(logLevel);
    > query.setParentObjEntityName(parentObjEntityName);
    > query.setParentQualifier(parentQualifier);
    > query.setRoot(root);
    >
    > // TODO: implement algorithm for building the name based on
    the
    > original name and
    > // the hashcode of the map of parameters. This way query
    clone can
    > take advantage
    > // of caching.
    >
    > Iterator keyValuePairs =
    parameters.entrySet().iterator();
    > HashCodeBuilder parametersHash = new HashCodeBuilder();
    >
    > while (keyValuePairs.hasNext()) {
    > Map.Entry entry = (Map.Entry) keyValuePairs.next();
    >
    > parametersHash.append(entry.getKey());
    > parametersHash.append(entry.getValue());
    > }
    >
    > query.setName(name + parametersHash.toHashCode());
    >
    > if (prefetches != null) {
    > query.addPrefetches(prefetches);
    > }
    >
    > if (orderings != null) {
    > query.addOrderings(orderings);
    > }
    >
    > if (customDbAttributes != null) {
    > query.addCustomDbAttributes(customDbAttributes);
    > }
    >
    > // substitute qualifier parameters
    > if (qualifier != null) {
    >
    query.setQualifier(qualifier.expWithParameters(parameters,
    > pruneMissing));
    > }
    >
    > return query;
    > }
    >
    >
    > I bolded the portions of interest. Of course, the TODO can be
    removed if
    > everything thinks this is valid.
    >
    > Thanks,
    >
    > /dev/mrg
    > --
    > I'm Victor. I'm the cleaner.
    >
    >



    This archive was generated by hypermail 2.0.0 : Wed Sep 14 2005 - 09:39:33 EDT