Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Jigar N Gajjar
finder method to take array argument
June 29, 2010 11:18 PM
Answer

Jigar N Gajjar

Rank: Junior Member

Posts: 56

Join Date: December 24, 2009

Recent Posts

Hi,
i want to generate a finder method in service builder that takes array of longs and return list
for e.g

OrganizationLocalServiceUtil.getOrganizations(organizationIds)

same way i want to create for my ext service

please guide me

Thanks
Jigar Gajjar
Rishi Dev Gupta
RE: finder method to take array argument
June 30, 2010 5:50 AM
Answer

Rishi Dev Gupta

Rank: Expert

Posts: 255

Join Date: November 23, 2008

Recent Posts

This should solve your problem

http://www.liferay.com/community/wiki/-/wiki/Main/How+to+create+a+custom+query+in+ext+for+Liferay+models
Jigar N Gajjar
RE: finder method to take array argument
June 30, 2010 6:11 AM
Answer

Jigar N Gajjar

Rank: Junior Member

Posts: 56

Join Date: December 24, 2009

Recent Posts

i think we can do this by finder method but i dont how to do this, if someone can help
Masroor Khan
RE: finder method to take array argument
June 30, 2010 7:22 AM
Answer

Masroor Khan

Rank: Regular Member

Posts: 119

Join Date: September 9, 2008

Recent Posts

In service.xml you can entry like

<finder name="Name" return-type="Collection">
<finder-column name="columnName" />
</finder>

then ant build-service

Then generated LocalServiceimpl you need to write method like

public List<Organization> getOrganizations(long[] organizationIds)
throws PortalException, SystemException {

List<Organization> organizations = new ArrayList<Organization>(
organizationIds.length);

for (long organizationId : organizationIds) {
Organization organization = getOrganization(organizationId);

organizations.add(organization);
}

return organizations;
}
Ohad Raz
RE: finder method to take array argument
November 29, 2012 6:01 AM
Answer

Ohad Raz

Rank: New Member

Posts: 23

Join Date: June 27, 2012

Recent Posts

Yeah. this should work, but what will be the cost?...
The suggestion means establish a connection in each iteration and closing it.
That's too expensive, and cannot be consider a decent answer.
Is there some other way to accomplish this without having to pay this penalty?
David H Nebinger
RE: finder method to take array argument
November 29, 2012 6:14 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11047

Join Date: September 1, 2006

Recent Posts

First, you would be using a connection pool so it is not that expensive.

Second, you could always implement using a dynamic query in your xxxLocalServiceImpl class:

 1public List<Organization> getOrganizations(final List<Integer> organizationIds) throws SystemException {
 2    DynamicQuery dq = DynamicQueryFactoryUtil.forClass(Organization.class, getClass().getClassLoader());
 3
 4    dq.add(PropertyFactoryUtil.forName("organizationId").in((Collection) organizationIds);
 5
 6    List<Organization> orgs = organizationPersistence.findWithDynamicQuery(dq);
 7
 8    return orgs;
 9}
Ohad Raz
RE: finder method to take array argument
January 9, 2013 4:51 AM
Answer

Ohad Raz

Rank: New Member

Posts: 23

Join Date: June 27, 2012

Recent Posts

I like the dynamic query answer better emoticon