Tribune

Home » Liferay Portal » English » 3. Development

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
Gordon Augat
Service Builder not creating Finder Methods in *ServiceUtil Class
29 marzo 2010 17.09
Risposta

Gordon Augat

Punteggio: Junior Member

Messaggi: 99

Data di Iscrizione: 16 agosto 2006

Messaggi recenti

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
14 febbraio 2013 19.57
Risposta

Pravin Pawar

Punteggio: Junior Member

Messaggi: 62

Data di Iscrizione: 17 novembre 2009

Messaggi recenti

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
29 luglio 2010 3.46
Risposta

Pius Onobhayedo

Punteggio: Junior Member

Messaggi: 25

Data di Iscrizione: 23 aprile 2009

Messaggi recenti

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
29 luglio 2010 4.06
Risposta

Shagul Khajamohideen

Punteggio: Liferay Master

Messaggi: 759

Data di Iscrizione: 27 settembre 2007

Messaggi recenti

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
29 luglio 2010 8.12
Risposta

Pius Onobhayedo

Punteggio: Junior Member

Messaggi: 25

Data di Iscrizione: 23 aprile 2009

Messaggi recenti

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
6 febbraio 2013 6.46
Risposta

Raghu k

Punteggio: Junior Member

Messaggi: 58

Data di Iscrizione: 10 agosto 2012

Messaggi recenti

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
6 febbraio 2013 2.03
Risposta

Chirag Patadia

Punteggio: Junior Member

Messaggi: 29

Data di Iscrizione: 2 febbraio 2012

Messaggi recenti

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.