List of usage examples for javax.persistence EntityTransaction begin
public void begin();
From source file:org.apache.juddi.api.impl.JUDDIApiImpl.java
/** * Gets all client subscription information. This is used for server to server subscriptions * Administrative privilege required./*from www. j av a 2 s .c om*/ * @param body * @return ClientSubscriptionInfoDetail * @throws DispositionReportFaultMessage */ @SuppressWarnings("unchecked") public ClientSubscriptionInfoDetail getAllClientSubscriptionInfoDetail(GetAllClientSubscriptionInfoDetail body) throws DispositionReportFaultMessage { new ValidateClientSubscriptionInfo(null).validateGetAllClientSubscriptionDetail(body); EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); this.getEntityPublisher(em, body.getAuthInfo()); ClientSubscriptionInfoDetail result = new ClientSubscriptionInfoDetail(); Query query = em.createQuery("SELECT cs from ClientSubscriptionInfo as cs"); List<org.apache.juddi.model.ClientSubscriptionInfo> modelClientSubscriptionInfoList = query .getResultList(); for (ClientSubscriptionInfo modelClientSubscriptionInfo : modelClientSubscriptionInfoList) { org.apache.juddi.api_v3.ClientSubscriptionInfo apiClientSubscriptionInfo = new org.apache.juddi.api_v3.ClientSubscriptionInfo(); MappingModelToApi.mapClientSubscriptionInfo(modelClientSubscriptionInfo, apiClientSubscriptionInfo); result.getClientSubscriptionInfo().add(apiClientSubscriptionInfo); } tx.commit(); return result; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }
From source file:org.apache.juddi.api.impl.JUDDIApiImpl.java
/** * Saves publisher(s) to the persistence layer. This method is specific * to jUDDI. Administrative privilege required. * * @param body/*from w ww . jav a2 s. co m*/ * @return PublisherDetail * @throws DispositionReportFaultMessage */ public PublisherDetail savePublisher(SavePublisher body) throws DispositionReportFaultMessage { EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo()); new ValidatePublish(publisher).validateSavePublisher(em, body); PublisherDetail result = new PublisherDetail(); List<org.apache.juddi.api_v3.Publisher> apiPublisherList = body.getPublisher(); for (org.apache.juddi.api_v3.Publisher apiPublisher : apiPublisherList) { org.apache.juddi.model.Publisher modelPublisher = new org.apache.juddi.model.Publisher(); MappingApiToModel.mapPublisher(apiPublisher, modelPublisher); Object existingUddiEntity = em.find(modelPublisher.getClass(), modelPublisher.getAuthorizedName()); if (existingUddiEntity != null) { em.remove(existingUddiEntity); } em.persist(modelPublisher); result.getPublisher().add(apiPublisher); } tx.commit(); return result; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }
From source file:org.apache.juddi.api.impl.JUDDIApiImpl.java
/** * Saves clerk(s) to the persistence layer. This method is specific to * jUDDI. This is used for server to server subscriptions and for future use * with replication. Administrative privilege required. * @param body/*w w w. j a va 2 s. c om*/ * @return ClerkDetail * @throws DispositionReportFaultMessage */ public ClerkDetail saveClerk(SaveClerk body) throws DispositionReportFaultMessage { EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo()); new ValidateClerk(publisher).validateSaveClerk(em, body); ClerkDetail result = new ClerkDetail(); List<org.apache.juddi.api_v3.Clerk> apiClerkList = body.getClerk(); ; for (org.apache.juddi.api_v3.Clerk apiClerk : apiClerkList) { org.apache.juddi.model.Clerk modelClerk = new org.apache.juddi.model.Clerk(); MappingApiToModel.mapClerk(apiClerk, modelClerk); Object existingUddiEntity = em.find(modelClerk.getClass(), modelClerk.getClerkName()); if (existingUddiEntity != null) { em.merge(modelClerk); } else { em.persist(modelClerk); } result.getClerk().add(apiClerk); } tx.commit(); return result; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }
From source file:org.apache.juddi.api.impl.JUDDIApiImpl.java
/** * Saves nodes(s) to the persistence layer. This method is specific to * jUDDI. Administrative privilege required. This is used for server to server subscriptions and for future use * with replication. Administrative privilege required. * @param body// www . j a v a 2 s . co m * @return NodeDetail * @throws DispositionReportFaultMessage */ public NodeDetail saveNode(SaveNode body) throws DispositionReportFaultMessage { EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo()); new ValidateNode(publisher).validateSaveNode(em, body); NodeDetail result = new NodeDetail(); List<org.apache.juddi.api_v3.Node> apiNodeList = body.getNode(); ; for (org.apache.juddi.api_v3.Node apiNode : apiNodeList) { org.apache.juddi.model.Node modelNode = new org.apache.juddi.model.Node(); MappingApiToModel.mapNode(apiNode, modelNode); Object existingUddiEntity = em.find(modelNode.getClass(), modelNode.getName()); if (existingUddiEntity != null) { em.merge(modelNode); } else { em.persist(modelNode); } result.getNode().add(apiNode); } tx.commit(); return result; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }
From source file:info.dolezel.jarss.rest.v1.FeedsService.java
@DELETE @Path("{id}") public Response unsubscribeFeed(@Context SecurityContext context, @PathParam("id") int feedId) { EntityManager em;/*w w w . j a v a 2 s.co m*/ EntityTransaction tx; User user; Feed f; FeedData fd; em = HibernateUtil.getEntityManager(); tx = em.getTransaction(); user = (User) context.getUserPrincipal(); try { tx.begin(); try { f = (Feed) em.createQuery("from Feed where id = :id", Feed.class).setParameter("id", feedId) .getSingleResult(); } catch (NoResultException e) { return Response.status(Response.Status.NOT_FOUND) .entity(new ErrorDescription("Feed does not exist")).build(); } if (!f.getUser().equals(user)) { return Response.status(Response.Status.FORBIDDEN) .entity(new ErrorDescription("Feed not owned by user")).build(); } fd = f.getData(); em.remove(f); if (fd.getFeeds().isEmpty()) em.remove(fd); tx.commit(); return Response.noContent().build(); } finally { if (tx.isActive()) tx.rollback(); em.close(); } }
From source file:org.apache.juddi.api.impl.JUDDIApiImpl.java
/** * Adds client subscription information. This effectively links a server to * serverr subscription to clerk// w w w.ja v a2 s . c o m * Administrative privilege required. * @param body * @return ClientSubscriptionInfoDetail * @throws DispositionReportFaultMessage * @throws RemoteException */ public ClientSubscriptionInfoDetail saveClientSubscriptionInfo(SaveClientSubscriptionInfo body) throws DispositionReportFaultMessage, RemoteException { EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo()); new ValidateClientSubscriptionInfo(publisher).validateSaveClientSubscriptionInfo(em, body); ClientSubscriptionInfoDetail result = new ClientSubscriptionInfoDetail(); List<org.apache.juddi.api_v3.ClientSubscriptionInfo> apiClientSubscriptionInfoList = body .getClientSubscriptionInfo(); for (org.apache.juddi.api_v3.ClientSubscriptionInfo apiClientSubscriptionInfo : apiClientSubscriptionInfoList) { org.apache.juddi.model.ClientSubscriptionInfo modelClientSubscriptionInfo = new org.apache.juddi.model.ClientSubscriptionInfo(); MappingApiToModel.mapClientSubscriptionInfo(apiClientSubscriptionInfo, modelClientSubscriptionInfo); Object existingUddiEntity = em.find(modelClientSubscriptionInfo.getClass(), modelClientSubscriptionInfo.getSubscriptionKey()); if (existingUddiEntity != null) { em.remove(existingUddiEntity); } em.persist(modelClientSubscriptionInfo); result.getClientSubscriptionInfo().add(apiClientSubscriptionInfo); } tx.commit(); return result; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }
From source file:org.apache.juddi.api.impl.JUDDIApiImpl.java
/** * Retrieves publisher(s) from the persistence layer. This method is * specific to jUDDI. Administrative privilege required. * @param body/*from w w w . j a v a2 s . c o m*/ * @return PublisherDetail * @throws DispositionReportFaultMessage */ public PublisherDetail getPublisherDetail(GetPublisherDetail body) throws DispositionReportFaultMessage { new ValidatePublisher(null).validateGetPublisherDetail(body); EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); this.getEntityPublisher(em, body.getAuthInfo()); PublisherDetail result = new PublisherDetail(); List<String> publisherIdList = body.getPublisherId(); for (String publisherId : publisherIdList) { org.apache.juddi.model.Publisher modelPublisher = null; try { modelPublisher = em.find(org.apache.juddi.model.Publisher.class, publisherId); } catch (ClassCastException e) { } if (modelPublisher == null) { throw new InvalidKeyPassedException( new ErrorMessage("errors.invalidkey.PublisherNotFound", publisherId)); } org.apache.juddi.api_v3.Publisher apiPublisher = new org.apache.juddi.api_v3.Publisher(); MappingModelToApi.mapPublisher(modelPublisher, apiPublisher); result.getPublisher().add(apiPublisher); } tx.commit(); return result; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }
From source file:org.apache.juddi.api.impl.JUDDIApiImpl.java
/** * Retrieves clientSubscriptionKey(s) from the persistence layer. This * method is specific to jUDDI. Used for server to server subscriptions * Administrative privilege required.//from w w w .j a v a2 s .c o m * @param body * @return ClientSubscriptionInfoDetail * @throws DispositionReportFaultMessage */ public ClientSubscriptionInfoDetail getClientSubscriptionInfoDetail(GetClientSubscriptionInfoDetail body) throws DispositionReportFaultMessage { new ValidateClientSubscriptionInfo(null).validateGetClientSubscriptionInfoDetail(body); EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); this.getEntityPublisher(em, body.getAuthInfo()); ClientSubscriptionInfoDetail result = new ClientSubscriptionInfoDetail(); List<String> subscriptionKeyList = body.getClientSubscriptionKey(); for (String subscriptionKey : subscriptionKeyList) { org.apache.juddi.model.ClientSubscriptionInfo modelClientSubscriptionInfo = null; try { modelClientSubscriptionInfo = em.find(org.apache.juddi.model.ClientSubscriptionInfo.class, subscriptionKey); } catch (ClassCastException e) { } if (modelClientSubscriptionInfo == null) { throw new InvalidKeyPassedException( new ErrorMessage("errors.invalidkey.SubscripKeyNotFound", subscriptionKey)); } org.apache.juddi.api_v3.ClientSubscriptionInfo apiClientSubscriptionInfo = new org.apache.juddi.api_v3.ClientSubscriptionInfo(); MappingModelToApi.mapClientSubscriptionInfo(modelClientSubscriptionInfo, apiClientSubscriptionInfo); result.getClientSubscriptionInfo().add(apiClientSubscriptionInfo); } tx.commit(); return result; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }
From source file:org.opencastproject.usertracking.impl.UserTrackingServiceImpl.java
public UserAction addUserTrackingEvent(UserAction a) throws UserTrackingException { EntityManager em = null;/*from ww w .j a v a 2 s. c om*/ EntityTransaction tx = null; try { em = emf.createEntityManager(); tx = em.getTransaction(); tx.begin(); em.persist(a); tx.commit(); return a; } catch (Exception e) { if (tx.isActive()) { tx.rollback(); } throw new UserTrackingException(e); } finally { if (em != null && em.isOpen()) { em.close(); } } }
From source file:org.apache.juddi.api.impl.JUDDIApiImpl.java
/** * Deletes publisher(s) from the persistence layer. This method is * specific to jUDDI. Administrative privilege required. * * @param body/*from w w w. j a v a 2s. com*/ * @throws DispositionReportFaultMessage */ public void deletePublisher(DeletePublisher body) throws DispositionReportFaultMessage { EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo()); new ValidatePublish(publisher).validateDeletePublisher(em, body); List<String> entityKeyList = body.getPublisherId(); for (String entityKey : entityKeyList) { Publisher obj = em.find(org.apache.juddi.model.Publisher.class, entityKey); //get an authtoken for this publisher so that we can get its registeredInfo UDDISecurityImpl security = new UDDISecurityImpl(); AuthToken authToken = security.getAuthToken(entityKey); GetRegisteredInfo r = new GetRegisteredInfo(); r.setAuthInfo(authToken.getAuthInfo()); r.setInfoSelection(InfoSelection.ALL); log.info("removing all businesses owned by publisher " + entityKey + "."); UDDIPublicationImpl publish = new UDDIPublicationImpl(); RegisteredInfo registeredInfo = publish.getRegisteredInfo(r); BusinessInfos businessInfos = registeredInfo.getBusinessInfos(); if (businessInfos != null && businessInfos.getBusinessInfo() != null) { Iterator<BusinessInfo> iter = businessInfos.getBusinessInfo().iterator(); while (iter.hasNext()) { BusinessInfo businessInfo = iter.next(); Object business = em.find(org.apache.juddi.model.BusinessEntity.class, businessInfo.getBusinessKey()); em.remove(business); } } log.info("mark all tmodels for publisher " + entityKey + " as deleted."); TModelInfos tmodelInfos = registeredInfo.getTModelInfos(); if (tmodelInfos != null && tmodelInfos.getTModelInfo() != null) { Iterator<TModelInfo> iter = tmodelInfos.getTModelInfo().iterator(); while (iter.hasNext()) { TModelInfo tModelInfo = iter.next(); Tmodel tmodel = (Tmodel) em.find(org.apache.juddi.model.Tmodel.class, tModelInfo.getTModelKey()); tmodel.setDeleted(true); em.persist(tmodel); } } log.info("remove all persisted AuthTokens for publisher " + entityKey + "."); Query q1 = em .createQuery("DELETE FROM AuthToken auth WHERE auth.authorizedName = '" + entityKey + "'"); q1.executeUpdate(); log.info("removing publisher " + entityKey + "."); //delete the publisher em.remove(obj); } tx.commit(); } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }