Forums de discussion

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

thumbnail
Adam Victor Nazareth Brandizzi, modifié il y a 12 années.

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

Junior Member Publications: 67 Date d'inscription: 30/04/10 Publications récentes
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?
Hiran Chaudhuri, modifié il y a 12 années.

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

Regular Member Publications: 188 Date d'inscription: 01/09/10 Publications récentes
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.