You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by "Henning P. Schmiedehausen" <ma...@hometree.net> on 2001/05/03 19:02:55 UTC

append() method in Criteria

Hi,

to facilitate the adding of multiple criterions to a single column,
I propose the following addition:

--- cut ---
/**
 * This method checks whether a criterion for this column already exists
 * and if yes, appends the given criterion with an "AND" to the already 
 * existing criterion
 *
 * @param c a Criterion object
 *
 * @return A Criterion.
 */

  public Criteria append(Criterion c)
  {
    Criterion old = getCriterion(c.getTable()+"."+c.getColumn());
    
    if(old == null)
      add(c);
    else
      old.and(c);
    
    return this;
  }
--- cut ---

Which is similar to add(Criterion c).

If this is welcome, I would prepare a (huge) patch to
o.a.t.u.d.Criteria.java which contains append() methods similar to
the add() methods in this class.

	Regards
		Henning


-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen       -- Geschaeftsfuehrer
INTERMETA - Gesellschaft fuer Mehrwertdienste mbH     hps@intermeta.de

Am Schwabachgrund 22  Fon.: 09131 / 50654-0   info@intermeta.de
D-91054 Buckenhof     Fax.: 09131 / 50654-20   

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: append() method in Criteria

Posted by Daniel Rall <dl...@finemaltcoding.com>.
Eric Dobbs <er...@dobbse.net> writes:

[snip]
> Ideally, it would remove the need for dealing with Criterion directly.
> It would double the number of methods you would be adding, but I think
> it would make for more readable code around Criteria objects.
> 
> Criteria criteria = new Criteria("TABLE.COLUMN",0,Criteria.GREATER_THAN);
> criteria.or ("TABLE.COLUMN",10,Criteria.LESS_THAN);

Eric, I like that API, though I'm a tad unsure about the Criteria
constructor.  I think that the interface presented via the
parameter-less constructor and and()/or() instance methods is more
clear because it removes the interface overlap.  Other than that, +1.

Dan

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: append() method in Criteria

Posted by Eric Dobbs <er...@dobbse.net>.
Henning,

It seems we have been thinking along similar lines.

As to your append() method, I would rather see a collection of
and() and or() convenience methods that would do the same thing
you suggest with append():  create a new criterion based on the
supplied arguments and append it to the appropriate existing
criterion.

public Criteria and(Criterion c)
{
     Criterion old = getCriterion(c.getTable()+"."+c.getColumn());

     if(old == null)
         add(c);
     else
         old.and(c);

     return this;
}

public Criteria or(Criterion c)
{
     Criterion old = getCriterion(c.getTable()+"."+c.getColumn());

     if(old == null)
         add(c);
     else
         old.or(c);

     return this;
}


Ideally, it would remove the need for dealing with Criterion directly.
It would double the number of methods you would be adding, but I think
it would make for more readable code around Criteria objects.

Criteria criteria = new Criteria("TABLE.COLUMN",0,Criteria.GREATER_THAN);
criteria.or ("TABLE.COLUMN",10,Criteria.LESS_THAN);

Instead of
Criteria criteria = new Criteria("TABLE.COLUMN",0,Criteria.GREATER_THAN);
Criteria.Criterion criterion = criteria.getCriterion("TABLE.COLUMN");
criterion.or("TABLE.COLUMN",10,Criteria.LESS_THAN);

-Eric


On Thursday, May 3, 2001, at 11:02  AM, Henning P. Schmiedehausen wrote:

> Hi,
>
> to facilitate the adding of multiple criterions to a single column,
> I propose the following addition:
>
> --- cut ---
> /**
>  * This method checks whether a criterion for this column already exists
>  * and if yes, appends the given criterion with an "AND" to the already
>  * existing criterion
>  *
>  * @param c a Criterion object
>  *
>  * @return A Criterion.
>  */
>
>   public Criteria append(Criterion c)
>   {
>     Criterion old = getCriterion(c.getTable()+"."+c.getColumn());
>
>     if(old == null)
>       add(c);
>     else
>       old.and(c);
>
>     return this;
>   }
> --- cut ---
>
> Which is similar to add(Criterion c).
>
> If this is welcome, I would prepare a (huge) patch to
> o.a.t.u.d.Criteria.java which contains append() methods similar to
> the add() methods in this class.
>
> 	Regards
> 		Henning
>
>
> --
> Dipl.-Inf. (Univ.) Henning P. Schmiedehausen       -- Geschaeftsfuehrer
> INTERMETA - Gesellschaft fuer Mehrwertdienste mbH     hps@intermeta.de
>
> Am Schwabachgrund 22  Fon.: 09131 / 50654-0   info@intermeta.de
> D-91054 Buckenhof     Fax.: 09131 / 50654-20
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-dev-help@jakarta.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org