留言板

Service Builder not creating Finder Methods in *ServiceUtil Class

thumbnail
Gordon Augat,修改在14 年前。

Service Builder not creating Finder Methods in *ServiceUtil Class

Regular Member 帖子: 107 加入日期: 06-8-16 最近的帖子
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
thumbnail
Pravin Pawar,修改在14 年前。

RE: Service Builder not creating Finder Methods in *ServiceUtil Class

Junior Member 帖子: 62 加入日期: 09-11-17 最近的帖子
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

package com.liferay.sampleservicebuilder.service.impl;

import java.util.List;
import com.liferay.portal.SystemException;
import com.liferay.sampleservicebuilder.model.Foo;
import com.liferay.sampleservicebuilder.service.base.FooLocalServiceBaseImpl;
import com.liferay.sampleservicebuilder.service.persistence.FooUtil;

/**
 * <a href="FooLocalServiceImpl.java.html"><b><i>View Source</i></b></a>
 *
 * @author Brian Wing Shun Chan
 *
 */
public class FooLocalServiceImpl extends FooLocalServiceBaseImpl {
	public List<foo> getByField2(boolean field2)
	throws SystemException {

		return FooUtil.findByField2(field2);
	}
}</foo>


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
thumbnail
Pius Onobhayedo,修改在13 年前。

RE: Service Builder not creating Finder Methods in *ServiceUtil Class

Junior Member 帖子: 25 加入日期: 09-4-23 最近的帖子
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.
thumbnail
Shagul Khajamohideen,修改在13 年前。

RE: Service Builder not creating Finder Methods in *ServiceUtil Class

Liferay Master 帖子: 758 加入日期: 07-9-27 最近的帖子
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.
thumbnail
Pius Onobhayedo,修改在13 年前。

RE: Service Builder not creating Finder Methods in *ServiceUtil Class

Junior Member 帖子: 25 加入日期: 09-4-23 最近的帖子
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,修改在11 年前。

RE: Service Builder not creating Finder Methods in *ServiceUtil Class

Junior Member 帖子: 58 加入日期: 12-8-10 最近的帖子
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>
thumbnail
Chirag Patadia,修改在11 年前。

RE: Service Builder not creating Finder Methods in *ServiceUtil Class

Junior Member 帖子: 29 加入日期: 12-2-3 最近的帖子
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.


	public java.util.List<com.getransportation.cwc.webleads.model.favorites> findByallFilesForUGC(
			long USERID, long GROUPID, long COMPANYID)
			throws com.liferay.portal.kernel.exception.SystemException {
		return favoritesPersistence.findByallFilesForUGC(USERID, GROUPID, COMPANYID);
	}
</com.getransportation.cwc.webleads.model.favorites>


Best Regards,
Chirag Patadia.