private EntityManager lookupEntityManager() { FacesContext facesContext = FacesContext.getCurrentInstance(); PersistenceService persistenceService = facesContext .getApplication() .evaluateExpressionGet(facesContext, "#{persistenceService}", PersistenceService.class); return persistenceService.getEntityManager(); }
/** * Post method for creating an instance of PrivacyPreferences using XML as the input format. * * @param data an PrivacyPreferencesConverter entity that is deserialized from an XML stream * @return an instance of PrivacyPreferencesConverter */ @POST @Consumes({"application/xml", "application/json"}) public Response post(PrivacyPreferencesConverter data) { PersistenceService persistenceSvc = PersistenceService.getInstance(); try { persistenceSvc.beginTx(); EntityManager em = persistenceSvc.getEntityManager(); PrivacyPreferences entity = data.resolveEntity(em); createEntity(data.resolveEntity(em)); persistenceSvc.commitTx(); return Response.created(uriInfo.getAbsolutePath().resolve(entity.getId() + "/")).build(); } finally { persistenceSvc.close(); } }
/** Constructor. */ public UserServiceImpl() { em = PersistenceService.getEntityManager(); }