Foros de discusión

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

thumbnail
Adam Victor Nazareth Brandizzi, modificado hace 12 años.

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

Junior Member Mensajes: 67 Fecha de incorporación: 30/04/10 Mensajes recientes
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, modificado hace 12 años.

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

Regular Member Mensajes: 188 Fecha de incorporación: 1/09/10 Mensajes recientes
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.