1 package org.myorg.jpatickets.webejb; 2 3 import javax.annotation.PostConstruct; 4 5 import javax.annotation.PreDestroy; 6 import javax.ejb.EJBException; 7 import javax.ejb.Stateless; 8 import javax.persistence.EntityManager; 9 import javax.persistence.PersistenceContext; 10 11 import org.myorg.jpatickets.bl.VenueMgmt; 12 import org.myorg.jpatickets.bl.VenueMgmtImpl; 13 import org.myorg.jpatickets.bo.Venue; 14 import org.myorg.jpatickets.dao.VenueDAOImpl; 15 import org.myorg.jpatickets.ejb.VenueMgmtRemote; 16 import org.slf4j.Logger; 17 import org.slf4j.LoggerFactory; 18 19 @Stateless 20 public class WebVenueMgmtEJB implements VenueMgmtRemote { 21 private static final Logger logger = LoggerFactory.getLogger(WebVenueMgmtEJB.class); 22 23 @PersistenceContext(unitName="jpaticketsweb-labex") 24 private EntityManager em; 25 26 private VenueMgmt venueMgmt; 27 28 @PostConstruct 29 public void init() { 30 logger.debug("*** WebVenueMgmtEJB:init({}) ***", super.hashCode()); 31 32 VenueDAOImpl vdao = new VenueDAOImpl(); 33 vdao.setEntityManager(em); 34 venueMgmt=new VenueMgmtImpl(); 35 ((VenueMgmtImpl)venueMgmt).setDao(vdao); 36 } 37 38 @PreDestroy 39 public void destroy() { 40 logger.debug("*** WebVenueMgmtEJB:destroy({}) ***", super.hashCode()); 41 } 42 43 @Override 44 public Venue createVenue(Venue venue, int sections, int positions, int rows) { 45 try { 46 return venueMgmt.createVenue(venue, sections, positions, rows); 47 } catch (Exception ex) { 48 logger.error("error creating venue", ex); 49 throw new EJBException("error creating venue:" + ex); 50 } 51 } 52 53 @Override 54 public Venue getVenue(String venueId) { 55 try { 56 return venueMgmt.getVenue(venueId); 57 } catch (Exception ex) { 58 logger.error("error getting venue", ex); 59 throw new EJBException("error getting venue:" + ex); 60 } 61 } 62 }