Slide 61
Slide 61 text
@Transactional
public class TradeServiceImpl implements TradeService {
!
@Inject
public TradeServiceImpl(sessionProvider, businessContextProvider, daoFactory, notificationService) {
this.sessionProvider = sessionProvider;
this.businessContextProvider = businessContextProvider;
this.dao = daoFactory.create(meta);
this.notificationService = notificationService;
}
!
public Trade transit(Trade trade, TradeAction action) throws DataUpdateException {
TradeTransition transition = TradeTransition.getTransitionFor(trade, action);
checkOperationAllowed(transition);
if (transition.needsBackup()) {
dao.update(dao.clone(trade).invalidate());
}
Trade updated = dao.save(transition.transit(trade).validate());
notifyTransition(updated, backup);
return updated;
}
!
private void checkOperationAllowed(TradeTransition transition) throws OperationNotAllowedException {
businessContextProvider.getContext().map(new TradeTransitionChecker(getSession(), transition)).orThrow(…);
}
private void notifyTransition(Trade updated, Trade backup) {
notificationService.notify(I18N.translate("message.trade.transit", updated.getTradeNo()));
}
!
}
ドメインロジックを
使って遷移させる
宣言的トランザクションは
自前で実装
セッション情報は
Web とは関係ない