storeByCondition

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

storeByCondition

Vikas Jadhav-2
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
Reply | Threaded
Open this post in threaded view
|

Re: storeByCondition

BJ Freeman
you can create the entity by using
https://localhost:8443/webtools/control/view/ModelInduceFromDb
once you clean them up you can use the entities created with java or
minilang to do CRUD services.
ofbiz will even create the CRUD services for you.
http://www.nabble.com/The-fancy-new-entity-auto-service-execution-engine-td18674040.html

you can use the mini lang to find records then update them.
http://docs.ofbiz.org/display/OFBIZ/OFBiz+Beginners+Development+Guide+Using+Practice+Application+%28Hello+World...%29
look at part 3.

the
applications\party\script\org\ofbiz\party\party\PartySimpleMethods.xml
can give you ideas.

you can also
https://localhost:8443/webtools/control/EntitySQLProcessor
look at the
framework\webtools\webapp\webtools\WEB-INF\actions\entity\EntitySQLProcessor.groovy


Vikas Jadhav sent the following on 5/20/2009 11:47 PM:

> 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
>

--
BJ Freeman
http://www.businessesnetwork.com/automation
http://bjfreeman.elance.com
http://www.linkedin.com/profile?viewProfile=&key=1237480&locale=en_US&trk=tab_pro
Systems Integrator.

Reply | Threaded
Open this post in threaded view
|

Re: storeByCondition

Scott Gray-2
In reply to this post by Vikas Jadhav-2
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


smime.p7s (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: storeByCondition

Vikas Jadhav-2
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 <[hidden email]>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
>>
>
>