Advertisement
Guest User

Untitled

a guest
May 2nd, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 KB | None | 0 0
  1. @Configuration
  2. @EnableTransactionManagement
  3. @ComponentScan("com.atoutjeu")
  4. public class MvcConfig implements TransactionManagementConfigurer {
  5.  
  6.  
  7. @Bean(name = "viewResolver")
  8. public InternalResourceViewResolver getViewResolver() {
  9. InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
  10. viewResolver.setPrefix("/WEB-INF/jsp/");
  11. viewResolver.setSuffix(".jsp");
  12. return viewResolver;
  13. }
  14.  
  15. @Bean(name = "dataSource")
  16. public DataSource dataSource() {
  17. ResourceBundle dbBundle = ResourceBundle.getBundle("database");
  18. dbBundle.getString("db.ip");
  19. DriverManagerDataSource driverManagerDataSource = new TransactionalDataSource();
  20. driverManagerDataSource.setDriverClassName("org.postgresql.Driver");
  21. driverManagerDataSource.setUrl("jdbc:postgresql://"+dbBundle.getString("db.ip")+":5432/"+dbBundle.getString("db.dbname"));
  22. driverManagerDataSource.setUsername(dbBundle.getString("db.user"));
  23. driverManagerDataSource.setPassword(dbBundle.getString("db.password"));
  24. return driverManagerDataSource;
  25. }
  26.  
  27.  
  28. @Bean(name="txManager")
  29. public PlatformTransactionManager transactionManager() {
  30. return new DataSourceTransactionManager(dataSource());
  31. }
  32.  
  33. @Override
  34. public PlatformTransactionManager annotationDrivenTransactionManager() {
  35. return transactionManager();
  36. }
  37.  
  38. @Bean(name = "resourceBundleViewResolver")
  39. public ResourceBundleViewResolver getResourceBundleViewResolver(){
  40. ResourceBundleViewResolver rbvr = new ResourceBundleViewResolver();
  41. rbvr.setOrder(0);
  42. rbvr.setBasename("views");
  43. return rbvr;
  44. }
  45.  
  46. @Bean
  47. public PretServiceImpl pretServiceImpl() {
  48. // configure and return a class having @Transactional methods
  49. return new PretServiceImpl();
  50. }
  51.  
  52.  
  53. }
  54.  
  55. @Service
  56. @Transactional
  57. public class PretServiceImpl implements IPretService {
  58.  
  59. @Autowired
  60. private IAdherentDao adherentDao;
  61.  
  62. @Autowired
  63. private IJeuDao jeuDao;
  64.  
  65. @Autowired
  66. private IPretDao pretDao;
  67.  
  68. @Autowired
  69. private IOperationDao operationDao;
  70.  
  71. @Autowired
  72. private IParamLudoDao paramLudoDao;
  73.  
  74.  
  75. private Logger logger = Logger.getLogger(AdherentServiceImpl.class);
  76.  
  77. @Override
  78. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
  79. public int louerPaiementDirect(int idAdherent, int idJeu, String dateSortie, String dateRetourPrevue, String commentaireSortie) throws ExceptionMetier, ExceptionTechnique {
  80. Adherent adherent = null;
  81. try {
  82. adherent = adherentDao.getAdherent(idAdherent);
  83. } catch (ExceptionTechnique e) {
  84. // TODO: handle exception
  85. }
  86. Jeu jeu = jeuDao.getJeu(idJeu);
  87. Pret pret = new Pret();
  88. pret.setAdherent(adherent);
  89. pret.setJeu(jeu);
  90. pret.setDateSortie(DateUtils.getDateFromDatePicker(dateSortie));
  91. pret.setDateRetourPrevue(DateUtils.getDateFromDatePicker(dateRetourPrevue));
  92.  
  93. pret.setCommentaireSortie(commentaireSortie);
  94. int idPret = pretDao.creerPret(pret);
  95.  
  96. //throw new RuntimeException();
  97.  
  98. //TODO créer une opération
  99. Operation operation = new Operation();
  100. operation.setAdherent(adherent);
  101. operation.setDateOperation(DateUtils.getDateFromDatePicker(dateSortie));
  102. operation.setDateReglement(DateUtils.getDateFromDatePicker(dateSortie));
  103. operation.setModeReglement(paramLudoDao.getParamLudo(ModeReglement.class, "mode_reglement", ModeReglement.TIRELIRE));
  104. operation.setPrestation(jeu.getCategorie().getPrestation());
  105. operation.setMontant(operation.getPrestation().getCout());
  106. operation.setCredit(false);
  107. //operation.setTauxRemise(tauxRemise);
  108. operationDao.creerOperation(operation);
  109.  
  110. adherent.setTirelire(adherent.getTirelire() - jeu.getCategorie().getPrestation().getCout());
  111. return idPret;
  112. }
  113. //....
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement