You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ofbiz.apache.org by "Robert G." <ga...@mercon24.de> on 2012/06/29 05:53:36 UTC
get random entries from entity field
Hey guys,
I want to get a list of reviews which are rated > 30. The list shall contain
a specific amount of reviews, which shall be randomly selected from all
reviews.
All that I wanna do in the groovy file. How can I do this?
--
View this message in context: http://ofbiz.135035.n4.nabble.com/get-random-entries-from-entity-field-tp4634190.html
Sent from the OFBiz - User mailing list archive at Nabble.com.
Re: get random entries from entity field
Posted by "Robert G." <ga...@mercon24.de>.
ok, I think this is my last question concerning this subject :)
I get a list with "delegator.findList(...)"
f.ex. for the Entity ProductReview I get:
/{[GenericEntity:ProductReview][productId,10000(java.lang.String)][productReview,this
is an example review no.
1(java.lang.String)][userLoginId,admin(java.lang.String)],
[GenericEntity:ProductReview][productId,10000(java.lang.String)][productReview,this
is an example review no.
2(java.lang.String)][userLoginId,admin(java.lang.String)]}
/
now I want to add a key value pair to both entries of this list. I could
only succeed when I change a value of an existing key, but adding a new K-V
combination I could not succeed. I also tried it with
"UtilMisc.addToSetInList", but couldnt get it work.
Do someone know the solution?
I want a result like (bold marked is new):
/{[GenericEntity:ProductReview][productId,10000(java.lang.String)][productReview,this
is an example review no.
1(java.lang.String)][userLoginId,admin(java.lang.String)]*[newValue,thisIsTheNewValue(java.lang.String)]*,
[GenericEntity:ProductReview][productId,10000(java.lang.String)][productReview,this
is an example review no.
2(java.lang.String)][userLoginId,admin(java.lang.String)]*[newValue,thisIsTheNewValue(java.lang.String)]*}
/
--
View this message in context: http://ofbiz.135035.n4.nabble.com/get-random-entries-from-entity-field-tp4634190p4634361.html
Sent from the OFBiz - User mailing list archive at Nabble.com.
Re: get random entries from entity field
Posted by "Robert G." <ga...@mercon24.de>.
great thanks!
--
View this message in context: http://ofbiz.135035.n4.nabble.com/get-random-entries-from-entity-field-tp4634190p4634338.html
Sent from the OFBiz - User mailing list archive at Nabble.com.
Re: get random entries from entity field
Posted by Deepak Dixit <de...@hotwaxmedia.com>.
You have to pass fieldToSelect as an Set, Use UtilMisc.toSet("field");
e.g
Set<String> fieldToSelect = UtilMisc.toSet("field");
Thanks & Regards
--
Deepak Dixit
HotWax Media Pvt. Ltd.
www.hotwaxmedia.com
Contact :- +91-98267-54548
Skype :- deepakdixit
On Jul 2, 2012, at 3:42 PM, Robert G. wrote:
> Hey, I tried to use this method:
>
> /public List<GenericValue> findList(String entityName, EntityCondition
> entityCondition, Set<String> fieldsToSelect, List<String> orderBy,
> EntityFindOptions findOptions, boolean useCache) throws
> GenericEntityException;/
>
> Now I understood, that I can choose the columns of the database table which
> I wanna get with:
> Set<String> fieldsToSelect
>
> is that right? but how do the Set does have to look? I checked the java API
> ref, but couldnt find an example. If I just give a string (name of the
> column) to the method, I get an error.
>
> please help me on that.
>
> Thank you.
>
> --
> View this message in context: http://ofbiz.135035.n4.nabble.com/get-random-entries-from-entity-field-tp4634190p4634321.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.
Re: get random entries from entity field
Posted by "Robert G." <ga...@mercon24.de>.
Hey, I tried to use this method:
/public List<GenericValue> findList(String entityName, EntityCondition
entityCondition, Set<String> fieldsToSelect, List<String> orderBy,
EntityFindOptions findOptions, boolean useCache) throws
GenericEntityException;/
Now I understood, that I can choose the columns of the database table which
I wanna get with:
Set<String> fieldsToSelect
is that right? but how do the Set does have to look? I checked the java API
ref, but couldnt find an example. If I just give a string (name of the
column) to the method, I get an error.
please help me on that.
Thank you.
--
View this message in context: http://ofbiz.135035.n4.nabble.com/get-random-entries-from-entity-field-tp4634190p4634321.html
Sent from the OFBiz - User mailing list archive at Nabble.com.
Re: get random entries from entity field
Posted by Rishi Solanki <ri...@gmail.com>.
By default it gives you latest records, for getting it in your way pass the
orderBy list. Also see the delegator.findListItereatorByCondition() method.
--
Rishi Solanki
Manager, Enterprise Software Development
HotWax Media Pvt. Ltd.
Direct: +91-9893287847
http://www.hotwaxmedia.com
On Mon, Jul 2, 2012 at 12:18 AM, Robert G. <ga...@mercon24.de> wrote:
> I should read better :)
>
> Ok when I say get "N" records, does it mean getting the latest N records?
> Or
> is it randomly from all?
>
> --
> View this message in context:
> http://ofbiz.135035.n4.nabble.com/get-random-entries-from-entity-field-tp4634190p4634309.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.
>
Re: get random entries from entity field
Posted by "Robert G." <ga...@mercon24.de>.
I should read better :)
Ok when I say get "N" records, does it mean getting the latest N records? Or
is it randomly from all?
--
View this message in context: http://ofbiz.135035.n4.nabble.com/get-random-entries-from-entity-field-tp4634190p4634309.html
Sent from the OFBiz - User mailing list archive at Nabble.com.
Re: get random entries from entity field
Posted by "Robert G." <ga...@mercon24.de>.
ok thanks, I can get the whole list..but Im scared, when you have in future
sth. like 150.000 Reviews, that this takes to much server resources...cause
I just neeed like 10 reviews to show, so calling 150.000 reviews instead is
kind of wasting data...what do you think?
--
View this message in context: http://ofbiz.135035.n4.nabble.com/get-random-entries-from-entity-field-tp4634190p4634308.html
Sent from the OFBiz - User mailing list archive at Nabble.com.
Re: get random entries from entity field
Posted by Rishi Solanki <ri...@gmail.com>.
Use delegator.find method, this will return you an object of
EntityListIterator. You can use its getPartialList() method to get N
records you want.
For random records you may need to add logic in groovy itself.
--
Rishi Solanki
Manager, Enterprise Software Development
HotWax Media Pvt. Ltd.
Direct: +91-9893287847
http://www.hotwaxmedia.com
On Fri, Jun 29, 2012 at 9:23 AM, Robert G. <ga...@mercon24.de> wrote:
> Hey guys,
>
> I want to get a list of reviews which are rated > 30. The list shall
> contain
> a specific amount of reviews, which shall be randomly selected from all
> reviews.
>
> All that I wanna do in the groovy file. How can I do this?
>
>
>
> --
> View this message in context:
> http://ofbiz.135035.n4.nabble.com/get-random-entries-from-entity-field-tp4634190.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.
>