Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Gordon Augat
Service Builder not creating Finder Methods in *ServiceUtil Class
March 29, 2010 5:09 PM
Answer

Gordon Augat

Rank: Junior Member

Posts: 99

Join Date: August 16, 2006

Recent Posts

I am using the plugin sdk from the 5.2.x branch. When I run "ant build-service", it does not create any static finder methods in the *ServiceUtil classes for my service. I have verified this with the sample-service-builder-portlet as well. The service.xml files has this entry...

<finder name="Field2" return-type="Collection">
<finder-column name="field2" />
</finder>

Shouldn't the following files have static finder methods?

portlets\sample-service-builder-portlet\docroot\WEB-INF\service\com\liferay\sampleservicebuilder\service\FooLocalService.java

portlets\sample-service-builder-portlet\docroot\WEB-INF\service\com\liferay\sampleservicebuilder\service\FooLocalServiceUtil.java
Pravin Pawar
RE: Service Builder not creating Finder Methods in *ServiceUtil Class
February 14, 2013 7:57 PM
Answer

Pravin Pawar

Rank: Junior Member

Posts: 62

Join Date: November 17, 2009

Recent Posts

Hi Gordon,
I have just run the build-service command with sample-service-builder-portlet. The finder methods for Field2 are shown in \sample-service-builder-portlet\docroot\WEB-INF\service\com\liferay\sampleservicebuilder\service\persistence\FooUtil.java

When I run "ant build-service", it does not create any static finder methods in the *ServiceUtil classes for my service


For using this methods you need to add below code in FooLocalServiceImpl.java

 1package com.liferay.sampleservicebuilder.service.impl;
 2
 3import java.util.List;
 4import com.liferay.portal.SystemException;
 5import com.liferay.sampleservicebuilder.model.Foo;
 6import com.liferay.sampleservicebuilder.service.base.FooLocalServiceBaseImpl;
 7import com.liferay.sampleservicebuilder.service.persistence.FooUtil;
 8
 9/**
10 * <a href="FooLocalServiceImpl.java.html"><b><i>View Source</i></b></a>
11 *
12 * @author Brian Wing Shun Chan
13 *
14 */
15public class FooLocalServiceImpl extends FooLocalServiceBaseImpl {
16    public List<Foo> getByField2(boolean field2)
17    throws SystemException {
18
19        return FooUtil.findByField2(field2);
20    }
21}


Once this done, generate service layer again by executing build-service ant task.

Now you will get the finder methods for Field2 in files you have specified as

portlets\sample-service-builder-portlet\docroot\WEB-INF\service\com\liferay\sampleservicebuilder\service\FooLocalService.java

portlets\sample-service-builder-portlet\docroot\WEB-INF\service\com\liferay\sampleservicebuilder\service\FooLocalServiceUtil.java
Pius Onobhayedo
RE: Service Builder not creating Finder Methods in *ServiceUtil Class
July 29, 2010 3:46 AM
Answer

Pius Onobhayedo

Rank: Junior Member

Posts: 25

Join Date: April 23, 2009

Recent Posts

Hello,

Does this imply that the finders indicated in the service.xml are not automatically generated unless the corresponding methods are manually written in the service impl classes? Or is there an option for turning on the automatic generation of all the finders indicated in the service.xml?

Thank you.
Shagul Khajamohideen
RE: Service Builder not creating Finder Methods in *ServiceUtil Class
July 29, 2010 4:06 AM
Answer

Shagul Khajamohideen

Rank: Liferay Master

Posts: 759

Join Date: September 27, 2007

Recent Posts

I don't think there is an option to do have finder methods automatically wrapped in the LocalServieUtil. The methods are generated in the persistenceImpl and you need to make a single line call in localserviceImpl and rerun the service builder to update the utils and all interfaces. Looks like a great idea to have an option like that.

The best reference is liferay-service-builder_version.dtd in the Liferay source.
Pius Onobhayedo
RE: Service Builder not creating Finder Methods in *ServiceUtil Class
July 29, 2010 8:12 AM
Answer

Pius Onobhayedo

Rank: Junior Member

Posts: 25

Join Date: April 23, 2009

Recent Posts

Thanks Shagul for the feedback. I agree with you that it would be an interesting feature to have the option to autogenerate the finders already manually entered in the service.xml.
Raghu k
RE: Service Builder not creating Finder Methods in *ServiceUtil Class
February 6, 2013 6:46 AM
Answer

Raghu k

Rank: Junior Member

Posts: 58

Join Date: August 10, 2012

Recent Posts

Hi Pravin Pawar,
I created an entity for Favorites. I added finders in my service.xml. After build, I got finders in FavoritesUtil class which is in persistence package. In order to use them I added one finder method as you said in FavoritesLocalServiceImpl and did service-build. This dint generate my method in FavoritesLocalServiceUtil.
Below is the code snippet. Can you please help me here.

Service.xml
<entity name="Favorites" local-service="true" remote-service="false" table="FAVORITE_DOCUMENTS">
<!-- PK fields -->
<column name="GROUPID" type="long" primary="true"></column>
<column name="COMPANYID" type="long" primary="true"></column>
<column name="USERID" type="long" primary="true"></column>
<column name="FILEENTRYID" type="long" primary="true"></column>
<!-- UI fields -->

<column name="CREATEDATE" type="Date"></column>

<finder name="GroupId" return-type="Collection">
<finder-column name="GROUPID" />
</finder>
<finder name="CompanyId" return-type="Collection">
<finder-column name="COMPANYID" />
</finder>
<finder name="UserId" return-type="Collection">
<finder-column name="USERID" />
</finder>
<finder name="singleFileOfUser" return-type="Collection">
<finder-column name="USERID" />
<finder-column name="GROUPID" />
<finder-column name="COMPANYID" />
<finder-column name="FILEENTRYID" />
</finder>
<finder name="allFilesForUGC" return-type="Collection">
<finder-column name="USERID" />
<finder-column name="GROUPID" />
<finder-column name="COMPANYID" />
</finder>
Nee method which i added in FavoritesLocalServiceImpl:
public java.util.List<com.gettingtransport.cwc.webleads.model.Favorites> findByallFilesForUGC(
long USERID, long GROUPID, long COMPANYID)
throws com.liferay.portal.kernel.exception.SystemException {
return FavoritesUtil.findByallFilesForUGC(USERID, GROUPID, COMPANYID);
}

</entity>
Chirag Patadia
RE: Service Builder not creating Finder Methods in *ServiceUtil Class
February 6, 2013 2:03 AM
Answer

Chirag Patadia

Rank: Junior Member

Posts: 29

Join Date: February 2, 2012

Recent Posts

Hi Raghu,

If you check your FavoritesLocalServiceImpl class it extends FavoritesLocalServiceBaseImpl. If you check FavoritesLocalServiceBaseImpl file you can find favoritesPersistence object. So you need to call your finder method like as follows (i.e. using persistence object only) and by this way you can get data from the table as per finder method which has been generated by service-builder.

For your quick reference check below code snippet, which you should try.

1
2    public java.util.List<com.getransportation.cwc.webleads.model.Favorites> findByallFilesForUGC(
3            long USERID, long GROUPID, long COMPANYID)
4            throws com.liferay.portal.kernel.exception.SystemException {
5        return favoritesPersistence.findByallFilesForUGC(USERID, GROUPID, COMPANYID);
6    }


Best Regards,
Chirag Patadia.