Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Configuration
- @EnableTransactionManagement
- @ComponentScan("com.atoutjeu")
- public class MvcConfig implements TransactionManagementConfigurer {
- @Bean(name = "viewResolver")
- public InternalResourceViewResolver getViewResolver() {
- InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
- viewResolver.setPrefix("/WEB-INF/jsp/");
- viewResolver.setSuffix(".jsp");
- return viewResolver;
- }
- @Bean(name = "dataSource")
- public DataSource dataSource() {
- ResourceBundle dbBundle = ResourceBundle.getBundle("database");
- dbBundle.getString("db.ip");
- DriverManagerDataSource driverManagerDataSource = new TransactionalDataSource();
- driverManagerDataSource.setDriverClassName("org.postgresql.Driver");
- driverManagerDataSource.setUrl("jdbc:postgresql://"+dbBundle.getString("db.ip")+":5432/"+dbBundle.getString("db.dbname"));
- driverManagerDataSource.setUsername(dbBundle.getString("db.user"));
- driverManagerDataSource.setPassword(dbBundle.getString("db.password"));
- return driverManagerDataSource;
- }
- @Bean(name="txManager")
- public PlatformTransactionManager transactionManager() {
- return new DataSourceTransactionManager(dataSource());
- }
- @Override
- public PlatformTransactionManager annotationDrivenTransactionManager() {
- return transactionManager();
- }
- @Bean(name = "resourceBundleViewResolver")
- public ResourceBundleViewResolver getResourceBundleViewResolver(){
- ResourceBundleViewResolver rbvr = new ResourceBundleViewResolver();
- rbvr.setOrder(0);
- rbvr.setBasename("views");
- return rbvr;
- }
- @Bean
- public PretServiceImpl pretServiceImpl() {
- // configure and return a class having @Transactional methods
- return new PretServiceImpl();
- }
- }
- @Service
- @Transactional
- public class PretServiceImpl implements IPretService {
- @Autowired
- private IAdherentDao adherentDao;
- @Autowired
- private IJeuDao jeuDao;
- @Autowired
- private IPretDao pretDao;
- @Autowired
- private IOperationDao operationDao;
- @Autowired
- private IParamLudoDao paramLudoDao;
- private Logger logger = Logger.getLogger(AdherentServiceImpl.class);
- @Override
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
- public int louerPaiementDirect(int idAdherent, int idJeu, String dateSortie, String dateRetourPrevue, String commentaireSortie) throws ExceptionMetier, ExceptionTechnique {
- Adherent adherent = null;
- try {
- adherent = adherentDao.getAdherent(idAdherent);
- } catch (ExceptionTechnique e) {
- // TODO: handle exception
- }
- Jeu jeu = jeuDao.getJeu(idJeu);
- Pret pret = new Pret();
- pret.setAdherent(adherent);
- pret.setJeu(jeu);
- pret.setDateSortie(DateUtils.getDateFromDatePicker(dateSortie));
- pret.setDateRetourPrevue(DateUtils.getDateFromDatePicker(dateRetourPrevue));
- pret.setCommentaireSortie(commentaireSortie);
- int idPret = pretDao.creerPret(pret);
- //throw new RuntimeException();
- //TODO créer une opération
- Operation operation = new Operation();
- operation.setAdherent(adherent);
- operation.setDateOperation(DateUtils.getDateFromDatePicker(dateSortie));
- operation.setDateReglement(DateUtils.getDateFromDatePicker(dateSortie));
- operation.setModeReglement(paramLudoDao.getParamLudo(ModeReglement.class, "mode_reglement", ModeReglement.TIRELIRE));
- operation.setPrestation(jeu.getCategorie().getPrestation());
- operation.setMontant(operation.getPrestation().getCout());
- operation.setCredit(false);
- //operation.setTauxRemise(tauxRemise);
- operationDao.creerOperation(operation);
- adherent.setTirelire(adherent.getTirelire() - jeu.getCategorie().getPrestation().getCout());
- return idPret;
- }
- //....
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement