掲示板

Which is better to use: injected Persistence instances or persistence utils

thumbnail
12年前 に Adam Victor Nazareth Brandizzi によって更新されました。

Which is better to use: injected Persistence instances or persistence utils

Junior Member 投稿: 67 参加年月日: 10/04/30 最新の投稿
Hi, all!

When I create new methods in the local service classes generated by Service Builder, I used to use the persistence util class. For example, in this way:

public class StuffLocalServiceImpl extends StuffLocalServiceBaseImpl {
    // ...
    public List<stuff> getStuffsBySomeParameter(String parameter) {
        List<stuff> stuffs = StuffUtil.getStuffs();
        // Process results
        return  stuffs;
    }
}</stuff></stuff>


But the local service classes has an instance of the persistence class injected, and it is commonly used in some services, more or less this way

public class StuffLocalServiceImpl extends StuffLocalServiceBaseImpl {
    // ...
    public List<stuff> getStuffsBySomeParameter(String parameter) {
        List<stuff> stuffs = stuffPersistence.getStuffs();
        // Process results
        return  stuffs;
    }
}</stuff></stuff>


What is the better way of executing persistence operations?

BTW, what is the purpose of the util classes which encapsulates the persistence classes? I cannot use them e.g. inside a portlet. Where can I use them? For what purpose?
12年前 に Hiran Chaudhuri によって更新されました。

RE: Which is better to use: injected Persistence instances or persistence u

Regular Member 投稿: 188 参加年月日: 10/09/01 最新の投稿
Adam Victor Nazareth Brandizzi:
BTW, what is the purpose of the util classes which encapsulates the persistence classes? I cannot use them e.g. inside a portlet. Where can I use them? For what purpose?

Sorry, I do not know the answer to your main question.
However my guess is that this encapsulation is the architecture in Liferay that hides the implementation of services from dependent components. This way you get some freedom to change and keep compatibility.