Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Aldo De Vleeschauwer
UserServiceImpl accesses userPersistence directly
November 20, 2012 5:16 AM
Answer

Aldo De Vleeschauwer

Rank: New Member

Posts: 23

Join Date: March 9, 2011

Recent Posts

ENV = Liferay 6.1GA2

I was implementing a hook containing a UserLocalServiceWrapper, intercepting calls to the method getUserById, and found that in some cases Liferay was not calling my wrapped method.

Turns out that UserServiceImpl implements getUserById by going directly to the userPersistence layer, so bypassing the UserLocalServiceImpl layer.

1User user = userPersistence.findByPrimaryKey(userId);


To me this feels wrong and was quite unexpected.

Anyone care to comment ?

- Aldo -
David H Nebinger
RE: UserServiceImpl accesses userPersistence directly
November 20, 2012 5:38 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 8555

Join Date: September 1, 2006

Recent Posts

Well, it's easy to see where you may have gone wrong...

For most cases, methods in XxxServiceImpl match those of XxxLocalServiceImpl, and the XxxServiceImpl will typically just have the added permission checker stuff layered over XxxLocalServiceImple methods.

But in reality they do represent different API entry points.

XxxLocalServiceImpl classes provide access points for local services only, and XxxServiceImpl provides the API for any remote access points. In many cases you probably do have an overlap, so deferring to XxxLocalServiceImpl for the implementation will typically be just what you need.

But there can be cases where you need to expose an API which is remote only. In these cases, it is only appropriate to put logic into XxxServiceImpl and not pass through to XxxLocalServiceImpl, especially if you have good reason to not expose the method as a local service method at all.
Aldo De Vleeschauwer
RE: UserServiceImpl accesses userPersistence directly
November 20, 2012 6:40 AM
Answer

Aldo De Vleeschauwer

Rank: New Member

Posts: 23

Join Date: March 9, 2011

Recent Posts

In this case, it is quite unexpected because getUserById exists in both services and has the exact same (simple) implementation.

I understand that they represent different API entry points but they are more than that, they are also one layer on top of another. In this architecture, XxxServiceImpl should try to reuse as much of XxxLocalServiceImpl as possible, while adding functionality.

Skipping a layer does not feel right.