Foros de discusión
finder method to take array argument
Jigar N Gajjar, modificado hace 13 años.
finder method to take array argument
Junior Member Mensajes: 71 Fecha de incorporación: 25/12/09 Mensajes recientes
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
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, modificado hace 13 años.
RE: finder method to take array argument
Expert Mensajes: 255 Fecha de incorporación: 23/11/08 Mensajes recientes
This should solve your problem
http://www.liferay.com/community/wiki/-/wiki/Main/How+to+create+a+custom+query+in+ext+for+Liferay+models
http://www.liferay.com/community/wiki/-/wiki/Main/How+to+create+a+custom+query+in+ext+for+Liferay+models
Jigar N Gajjar, modificado hace 13 años.
RE: finder method to take array argument
Junior Member Mensajes: 71 Fecha de incorporación: 25/12/09 Mensajes recientes
i think we can do this by finder method but i dont how to do this, if someone can help
Masroor Khan, modificado hace 13 años.
RE: finder method to take array argument
Regular Member Mensajes: 124 Fecha de incorporación: 9/09/08 Mensajes recientes
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;
}
<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, modificado hace 11 años.
RE: finder method to take array argument
New Member Mensajes: 23 Fecha de incorporación: 27/06/12 Mensajes recientes
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?
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, modificado hace 11 años.
RE: finder method to take array argument
Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
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:
Second, you could always implement using a dynamic query in your xxxLocalServiceImpl class:
public List<organization> getOrganizations(final List<integer> organizationIds) throws SystemException {
DynamicQuery dq = DynamicQueryFactoryUtil.forClass(Organization.class, getClass().getClassLoader());
dq.add(PropertyFactoryUtil.forName("organizationId").in((Collection) organizationIds);
List<organization> orgs = organizationPersistence.findWithDynamicQuery(dq);
return orgs;
}</organization></integer></organization>
Ohad Raz, modificado hace 11 años.
RE: finder method to take array argument
New Member Mensajes: 23 Fecha de incorporación: 27/06/12 Mensajes recientes
I like the dynamic query answer better