掲示板

How to implement transaction on MVCPortlet

thumbnail
7年前 に Yoshikazu Kobayashi によって更新されました。

How to implement transaction on MVCPortlet

New Member 投稿: 20 参加年月日: 13/08/26 最新の投稿
When updating multiple models , I realized transaction processing as follows.

① Create updating process for each model with service builder
Model1LocalServiceImpl#update (model1) {
 ...
 }
Model2LocalServiceImpl#update (model2) {
 ...
}


② Create update method for multiple models in service builder
Model1LocalServiceImpl#updateAll (model1, model2) {
  Model1LocalService.update (model1);
  Model2LocalService.update (model2);
}


② Call the above method from the class inheriting Base MVCActionCommand.
MyBaseMVCActionCommand#processAction {
  Model1LocalService.updateAll(model1, model2);
}


■On the other hand, I found BaseTransactionalMVCActionCommand in the source code of Liferay DXP SP1.
Transaction processing seems to be possible if transaction processing is implemented as follows.

MyBaseTransactionalMVCActionCommand # doTransactionalCommand {
  Model1LocalService.update (model1);
  Model2LocalService.update (model2);
}


As you can see, there are two ways to inherit BaseTransactionalMVCActionCommand and create update method for multiple service builder models, which one should be used?
thumbnail
7年前 に David H Nebinger によって更新されました。

RE: How to implement transaction on MVCPortlet (回答)

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
The first one, transactions should apply around the database access, not the MVC action layer.

The reason is that you cannot guarantee that future developers will use the BaseTransactionalMVCActionCommand to provide a transactional wrapper around the calls. They might use it in, say, a scheduler or in a serve resource action or a normal MVC action command or ...

As soon as they do something like that, the txn logic is lost.

If you wrap the calls in your normal SB tier, the transaction handling will be automagic and won't matter where they call it from.

Remember that transactions are a database detail, not an MVC detail.