You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Ivano Luberti <lu...@archicoop.it> on 2009/05/08 09:43:55 UTC

multiple criteria on the same field

Hello , I have searched the ml and googled for this.
I have found 2 old email asking for this but with no answer.

When I try to do this :

Criteria criteria = new Criteria();
Criterion dataIscrizioneInizio =
criteria.getNewCriterion(IscrizioniSocioPeer.TABLE_NAME, "starttime", 
(Date) (formUser.getDataIscrizioneInizio()), Criteria.GREATER_EQUAL);   
      

dataIscrizioneInizio.setIgnoreCase(true);   

criteria.add(dataIscrizioneInizio);

Criterion dataIscrizioneFine =
criteria.getNewCriterion(IscrizioniSocioPeer.TABLE_NAME, "starttime", 
(Date) (formUser.getDataIscrizioneFine()), Criteria.LESS_EQUAL);           

dataIscrizioneFine.setIgnoreCase(true);   

criteria.add(dataIscrizioneFine);

Only the last criterion is included in the where clause.

I have stepped into the add(Criterion) method of the Criteria class and
found this:

    public Criteria add(Criterion c)
    {
        StringBuffer sb = new StringBuffer(c.getTable().length()
                + c.getColumn().length() + 1);
        sb.append(c.getTable());
        sb.append('.');
        sb.append(c.getColumn());
        super.put(sb.toString(), c);
        return this;
    }

If I understand well , the map keys are based on the table and field
names then it is not possible to add two criteria on the same field to
produce sql like:

SELECT * FROM table WHERE table.field>x AND table.field<y

Can someone suggest the best practice to do this with Torque ?


-- 
==================================================
dott. Ivano Mario Luberti
Archimede Informatica societa' cooperativa a r. l.
Sede Operativa
Via Gereschi 36 - 56126- Pisa
tel.: +39-050- 580959
tel/fax: +39-050-9711344
web: www.archicoop.it
==================================================


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Re: multiple criteria on the same field

Posted by Ivano Luberti <lu...@archicoop.it>.
Thanks  Andreas and Greg .
I knew about this features, but I was misleaded by the fact that adding
to criteria in the other way wouldn't work even with an "or" operator.

I should have understood it anyway.



Greg Monroe ha scritto:
> For more information see the documentation at:
>
> http://db.apache.org/torque/releases/torque-3.3/runtime/reference/read-from-db.html#AND_and_OR_operators
>
>
>   
>> -----Original Message-----
>> From: Andras Balogh [mailto:andras@reea.net]
>> Sent: Friday, May 08, 2009 5:52 AM
>> To: Apache Torque Users List
>> Subject: Re: multiple criteria on the same field
>>
>> Hi,
>>
>> You need to do something like:
>>
>> criteria.add( dataIscrizioneInizio.and(dataIscrizioneFine)  ) ;
>>
>> to add both Criterions in the same time to the Criteria.
>>
>> Best regards,
>> Andras
>>
>>
>> Ivano Luberti wrote:
>>     
>>> Hello , I have searched the ml and googled for this.
>>> I have found 2 old email asking for this but with no answer.
>>>
>>> When I try to do this :
>>>
>>> Criteria criteria = new Criteria();
>>> Criterion dataIscrizioneInizio =
>>> criteria.getNewCriterion(IscrizioniSocioPeer.TABLE_NAME, "starttime",
>>> (Date) (formUser.getDataIscrizioneInizio()), Criteria.GREATER_EQUAL);
>>>
>>>
>>> dataIscrizioneInizio.setIgnoreCase(true);
>>>
>>> criteria.add(dataIscrizioneInizio);
>>>
>>> Criterion dataIscrizioneFine =
>>> criteria.getNewCriterion(IscrizioniSocioPeer.TABLE_NAME, "starttime",
>>> (Date) (formUser.getDataIscrizioneFine()), Criteria.LESS_EQUAL);
>>>
>>> dataIscrizioneFine.setIgnoreCase(true);
>>>
>>> criteria.add(dataIscrizioneFine);
>>>
>>> Only the last criterion is included in the where clause.
>>>
>>> I have stepped into the add(Criterion) method of the Criteria class and
>>> found this:
>>>
>>>     public Criteria add(Criterion c)
>>>     {
>>>         StringBuffer sb = new StringBuffer(c.getTable().length()
>>>                 + c.getColumn().length() + 1);
>>>         sb.append(c.getTable());
>>>         sb.append('.');
>>>         sb.append(c.getColumn());
>>>         super.put(sb.toString(), c);
>>>         return this;
>>>     }
>>>
>>> If I understand well , the map keys are based on the table and field
>>> names then it is not possible to add two criteria on the same field to
>>> produce sql like:
>>>
>>> SELECT * FROM table WHERE table.field>x AND table.field<y
>>>
>>> Can someone suggest the best practice to do this with Torque ?
>>>
>>>
>>>
>>>       
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: torque-user-help@db.apache.org
>>
>>     
>
> DukeCE Privacy Statement:
> Please be advised that this e-mail and any files transmitted with
> it are confidential communication or may otherwise be privileged or
> confidential and are intended solely for the individual or entity
> to whom they are addressed. If you are not the intended recipient
> you may not rely on the contents of this email or any attachments,
> and we ask that you please not read, copy or retransmit this
> communication, but reply to the sender and destroy the email, its
> contents, and all copies thereof immediately. Any unauthorized
> dissemination, distribution or copying of this communication is
> strictly prohibited.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>
>
>   

-- 
==================================================
dott. Ivano Mario Luberti
Archimede Informatica societa' cooperativa a r. l.
Sede Operativa
Via Gereschi 36 - 56126- Pisa
tel.: +39-050- 580959
tel/fax: +39-050-9711344
web: www.archicoop.it
==================================================



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


RE: multiple criteria on the same field

Posted by Greg Monroe <Gr...@dukece.com>.
For more information see the documentation at:

http://db.apache.org/torque/releases/torque-3.3/runtime/reference/read-from-db.html#AND_and_OR_operators


> -----Original Message-----
> From: Andras Balogh [mailto:andras@reea.net]
> Sent: Friday, May 08, 2009 5:52 AM
> To: Apache Torque Users List
> Subject: Re: multiple criteria on the same field
> 
> Hi,
> 
> You need to do something like:
> 
> criteria.add( dataIscrizioneInizio.and(dataIscrizioneFine)  ) ;
> 
> to add both Criterions in the same time to the Criteria.
> 
> Best regards,
> Andras
> 
> 
> Ivano Luberti wrote:
> > Hello , I have searched the ml and googled for this.
> > I have found 2 old email asking for this but with no answer.
> >
> > When I try to do this :
> >
> > Criteria criteria = new Criteria();
> > Criterion dataIscrizioneInizio =
> > criteria.getNewCriterion(IscrizioniSocioPeer.TABLE_NAME, "starttime",
> > (Date) (formUser.getDataIscrizioneInizio()), Criteria.GREATER_EQUAL);
> >
> >
> > dataIscrizioneInizio.setIgnoreCase(true);
> >
> > criteria.add(dataIscrizioneInizio);
> >
> > Criterion dataIscrizioneFine =
> > criteria.getNewCriterion(IscrizioniSocioPeer.TABLE_NAME, "starttime",
> > (Date) (formUser.getDataIscrizioneFine()), Criteria.LESS_EQUAL);
> >
> > dataIscrizioneFine.setIgnoreCase(true);
> >
> > criteria.add(dataIscrizioneFine);
> >
> > Only the last criterion is included in the where clause.
> >
> > I have stepped into the add(Criterion) method of the Criteria class and
> > found this:
> >
> >     public Criteria add(Criterion c)
> >     {
> >         StringBuffer sb = new StringBuffer(c.getTable().length()
> >                 + c.getColumn().length() + 1);
> >         sb.append(c.getTable());
> >         sb.append('.');
> >         sb.append(c.getColumn());
> >         super.put(sb.toString(), c);
> >         return this;
> >     }
> >
> > If I understand well , the map keys are based on the table and field
> > names then it is not possible to add two criteria on the same field to
> > produce sql like:
> >
> > SELECT * FROM table WHERE table.field>x AND table.field<y
> >
> > Can someone suggest the best practice to do this with Torque ?
> >
> >
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
> 

DukeCE Privacy Statement:
Please be advised that this e-mail and any files transmitted with
it are confidential communication or may otherwise be privileged or
confidential and are intended solely for the individual or entity
to whom they are addressed. If you are not the intended recipient
you may not rely on the contents of this email or any attachments,
and we ask that you please not read, copy or retransmit this
communication, but reply to the sender and destroy the email, its
contents, and all copies thereof immediately. Any unauthorized
dissemination, distribution or copying of this communication is
strictly prohibited.

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Re: multiple criteria on the same field

Posted by Andras Balogh <an...@reea.net>.
Hi,

You need to do something like:

criteria.add( dataIscrizioneInizio.and(dataIscrizioneFine)  ) ;

to add both Criterions in the same time to the Criteria.

Best regards,
Andras


Ivano Luberti wrote:
> Hello , I have searched the ml and googled for this.
> I have found 2 old email asking for this but with no answer.
>
> When I try to do this :
>
> Criteria criteria = new Criteria();
> Criterion dataIscrizioneInizio =
> criteria.getNewCriterion(IscrizioniSocioPeer.TABLE_NAME, "starttime", 
> (Date) (formUser.getDataIscrizioneInizio()), Criteria.GREATER_EQUAL);   
>       
>
> dataIscrizioneInizio.setIgnoreCase(true);   
>
> criteria.add(dataIscrizioneInizio);
>
> Criterion dataIscrizioneFine =
> criteria.getNewCriterion(IscrizioniSocioPeer.TABLE_NAME, "starttime", 
> (Date) (formUser.getDataIscrizioneFine()), Criteria.LESS_EQUAL);           
>
> dataIscrizioneFine.setIgnoreCase(true);   
>
> criteria.add(dataIscrizioneFine);
>
> Only the last criterion is included in the where clause.
>
> I have stepped into the add(Criterion) method of the Criteria class and
> found this:
>
>     public Criteria add(Criterion c)
>     {
>         StringBuffer sb = new StringBuffer(c.getTable().length()
>                 + c.getColumn().length() + 1);
>         sb.append(c.getTable());
>         sb.append('.');
>         sb.append(c.getColumn());
>         super.put(sb.toString(), c);
>         return this;
>     }
>
> If I understand well , the map keys are based on the table and field
> names then it is not possible to add two criteria on the same field to
> produce sql like:
>
> SELECT * FROM table WHERE table.field>x AND table.field<y
>
> Can someone suggest the best practice to do this with Torque ?
>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Re: multiple criteria on the same field

Posted by Thomas Vandahl <tv...@apache.org>.
Ivano Luberti wrote:
> Can someone suggest the best practice to do this with Torque ?

I suggest the following:

---8<---
Criteria criteria = new Criteria();

criteria.add(IscrizioniSocioPeer.STARTTIME,
(Date) (formUser.getDataIscrizioneInizio()), Criteria.GREATER_EQUAL);

criteria.and(IscrizioniSocioPeer.STARTTIME,
(Date) (formUser.getDataIscrizioneFine()), Criteria.LESS_EQUAL);
---8<---

What were you planning to achieve with
dataIscrizioneFine.setIgnoreCase(true)? The value is a Date object.

Bye, Thomas.

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org