Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
lucas theisen
Does ServiceBuilder allow for non-transactional public methods?
March 1, 2013 12:28 PM
Answer

lucas theisen

Rank: New Member

Posts: 18

Join Date: March 1, 2011

Recent Posts

Unless I am missing something, every public method in a liferay ServiceBuilder built service is transactional and there appears to be no way around it.

I have a non-model service (no column's in the entity) which i want to use to work with multiple other services. I define it thuslly (in service.xml):

1    <entity name="Notification" local-service="false" remote-service="true" />


Then i add an public interface method:

 1
 2    @Override
 3    public void sendPending( Date now, String toEmail ) {
 4        ...
 5        updateAndSend( eventsToUpdate, messageToSend );
 6    }
 7
 8    @Override
 9    public void updateAndSend( List<Event> eventsToUpdate, Message messageToSend ) throws SystemException, PortalException {
10        try {
11            for ( Event event : eventsToUpdate ) {
12                eventLocalService.updateEvent( event );
13            }
14            Transport.send( messageToSend );
15        }
16        catch ( Exception e ) {
17            throw new PortalException( e );
18        }
19    }


The idea here is that sendPending should be a public interface method, and updateAndSend should be a private helper that executes atomically (if anything fails while sending the message the model updates get rolled back), but @Transactional AOP requires public methods. Anyway, when I run service builder, the generated NotificationService.java interface ALWAYS has this annotation at the interface level:

1
2@Transactional(isolation = Isolation.PORTAL, rollbackFor =  {
3    PortalException.class, SystemException.class}
4)
5public interface NotificationService {
6    ...
7}


And since the default propagation is REQUIRED, it seems that every generated method will be run in a transaction. There is a lot of work getting done in the sendPending method and I would like to avoid locking tables/columns/rows for the duration. Is there anyway around this?