public Establishment createEstablishment(Establishment establishment) { establishment.setPassword(authenticationService.encryptPassword(establishment.getPassword())); final EntityManager em = entityManagerService.createEntityManager(); try { em.getTransaction().begin(); em.persist(establishment); em.getTransaction().commit(); return establishment; } finally { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } em.close(); } }
public void updateEstablishmentReviewsCountAndRatings(long establishmentId, int newRating) { final Establishment fromDb = getEstablishment(establishmentId); fromDb.setReviewsCount(fromDb.getReviewsCount() + 1); fromDb.setAllRatings(fromDb.getAllRatings() + newRating); updateEstablishment(fromDb); }