You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by Ilkka Priha <ip...@surfeu.fi> on 2003/06/10 20:48:37 UTC

[patch] QueryFactory doesn't return queries by samples

Hi

Documentation of QueryFactory claims to return either an identity query
or a sample query when giving only one Object argument. However, the
implementation returns always an identity query, which is useless when
trying to query other object attributes than the primary key. Below is a
patch correcting the implementation (there is already a comment, which
perhaps suggests this kind of patch?).

-- Ilkka

+++ org.apache.ojb.broker.query.QueryFactory.java

      /**
       * Method declaration
       * @param example_or_identity
       * @return
       */
      public static Query newQuery(Object example_or_identity)
      {
          /**
           * should add criteria here.
           */
-        return new QueryByIdentity(example_or_identity);
+        return example_or_identity instanceof Identity ?
+            new QueryByIdentity(example_or_identity) :
+            new QueryByCriteria(example_or_identity);
      }






Re: [patch] QueryFactory doesn't return queries by samples

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi iikka,

i cannot apply your path because it causes some testcases to fail.  the 
reason is that the building of a QueryByExample based on an example 
object adds all non-nulls as criteria to the query (including ints !) 
and thus the query returns nothing.
but i added a new method to QueryFactory newQueryByExample that return a 
QueryByCriteria.

hth
jakob


Ilkka Priha wrote:

> Hi
>
> Documentation of QueryFactory claims to return either an identity query
> or a sample query when giving only one Object argument. However, the
> implementation returns always an identity query, which is useless when
> trying to query other object attributes than the primary key. Below is a
> patch correcting the implementation (there is already a comment, which
> perhaps suggests this kind of patch?).
>
> -- Ilkka
>
> +++ org.apache.ojb.broker.query.QueryFactory.java
>
>      /**
>       * Method declaration
>       * @param example_or_identity
>       * @return
>       */
>      public static Query newQuery(Object example_or_identity)
>      {
>          /**
>           * should add criteria here.
>           */
> -        return new QueryByIdentity(example_or_identity);
> +        return example_or_identity instanceof Identity ?
> +            new QueryByIdentity(example_or_identity) :
> +            new QueryByCriteria(example_or_identity);
>      }
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
>
>