You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ofbiz.apache.org by Vikas Jadhav <vi...@finicity.com> on 2009/05/21 08:47:13 UTC

storeByCondition

Hi,

I am using GenericDelegator to to retrieve or store data from the tables.

But I am facing some problems to update some records using delegators.

e.g. I have a table as below.
EMP (empId primary key, name, age, salary, dept foreign key)

Here I want to update the salary of all the employees who belongs to
specific department.
e.g.
UPDATE EMP set salary=salary * 10 where dept='QA';

So, how to put this in ofbiz delegator.
How to set fields to update in query.

especially.. how to put salary=salary*10 in fieldsToUpdate map?

Thanks,
Vikas

Re: storeByCondition

Posted by Vikas Jadhav <vi...@finicity.com>.
Thanks for the reply.

I had done the same way.. But I was looking for best solution for that.
--
Vikas

On Thu, May 21, 2009 at 5:25 PM, Scott Gray <sc...@hotwaxmedia.com>wrote:

> I don't believe you can use that method to operate on the fields that you
> want to change, you can only use it to update to a predefined value i.e. a
> map containing [salary, 10000] for fieldsToSet
>
> If you wanted to multiply each salary by 10 (how generous of you :-) you
> would probably be best to retrieve the list of records you want to change,
> iterate of over them changing each record one by one and then use
> delegator.storeAll(luckyEmployees);
>
> Regards
> Scott
>
>
> On 21/05/2009, at 6:47 PM, Vikas Jadhav wrote:
>
>  Hi,
>>
>> I am using GenericDelegator to to retrieve or store data from the tables.
>>
>> But I am facing some problems to update some records using delegators.
>>
>> e.g. I have a table as below.
>> EMP (empId primary key, name, age, salary, dept foreign key)
>>
>> Here I want to update the salary of all the employees who belongs to
>> specific department.
>> e.g.
>> UPDATE EMP set salary=salary * 10 where dept='QA';
>>
>> So, how to put this in ofbiz delegator.
>> How to set fields to update in query.
>>
>> especially.. how to put salary=salary*10 in fieldsToUpdate map?
>>
>> Thanks,
>> Vikas
>>
>
>

Re: storeByCondition

Posted by Scott Gray <sc...@hotwaxmedia.com>.
I don't believe you can use that method to operate on the fields that  
you want to change, you can only use it to update to a predefined  
value i.e. a map containing [salary, 10000] for fieldsToSet

If you wanted to multiply each salary by 10 (how generous of you :-)  
you would probably be best to retrieve the list of records you want to  
change, iterate of over them changing each record one by one and then  
use delegator.storeAll(luckyEmployees);

Regards
Scott

On 21/05/2009, at 6:47 PM, Vikas Jadhav wrote:

> Hi,
>
> I am using GenericDelegator to to retrieve or store data from the  
> tables.
>
> But I am facing some problems to update some records using delegators.
>
> e.g. I have a table as below.
> EMP (empId primary key, name, age, salary, dept foreign key)
>
> Here I want to update the salary of all the employees who belongs to
> specific department.
> e.g.
> UPDATE EMP set salary=salary * 10 where dept='QA';
>
> So, how to put this in ofbiz delegator.
> How to set fields to update in query.
>
> especially.. how to put salary=salary*10 in fieldsToUpdate map?
>
> Thanks,
> Vikas