List of usage examples for javax.persistence EntityTransaction commit
public void commit();
From source file:org.apache.juddi.api.impl.UDDISubscriptionImpl.java
public void deleteSubscription(DeleteSubscription body) throws DispositionReportFaultMessage { long startTime = System.currentTimeMillis(); EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try {// www .j a v a2 s . c o m tx.begin(); UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo()); new ValidateSubscription(publisher).validateDeleteSubscription(em, body); List<String> subscriptionKeyList = body.getSubscriptionKey(); for (String subscriptionKey : subscriptionKeyList) { Object obj = em.find(org.apache.juddi.model.Subscription.class, subscriptionKey); em.remove(obj); } tx.commit(); long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(SubscriptionQuery.DELETE_SUBSCRIPTION, QueryStatus.SUCCESS, procTime); } catch (DispositionReportFaultMessage drfm) { long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(SubscriptionQuery.DELETE_SUBSCRIPTION, QueryStatus.FAILED, procTime); throw drfm; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }
From source file:fr.natoine.dao.annotation.DAOAnnotation.java
/** * Retrieves an annotationStatus/*from w ww. jav a 2 s . com*/ * @param id * @return */ public AnnotationStatus retrieveAnnotationStatus(long id) { // EntityManagerFactory emf = this.setEMF(); EntityManager em = emf.createEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); AnnotationStatus _synchro = em.find(AnnotationStatus.class, id); tx.commit(); if (_synchro != null) return _synchro; System.out.println( "[RetrieveAnnotationStatus.retrieveAnnotationStatus] unable to retrieve AnnotationStatus" + " id : " + id); return new AnnotationStatus(); } catch (Exception e) { tx.rollback(); //em.close(); System.out.println( "[RetrieveAnnotationStatus.retrieveAnnotationStatus] unable to retrieve AnnotationStatus" + " id : " + id + " cause : " + e.getMessage()); return new AnnotationStatus(); } }
From source file:org.apache.juddi.api.impl.UDDIInquiryImpl.java
public TModelDetail getTModelDetail(GetTModelDetail body) throws DispositionReportFaultMessage { long startTime = System.currentTimeMillis(); try {/*from w w w.ja va 2 s .co m*/ new ValidateInquiry(null).validateGetTModelDetail(body); } catch (DispositionReportFaultMessage drfm) { long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(InquiryQuery.GET_TMODELDETAIL, QueryStatus.FAILED, procTime); throw drfm; } EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); if (isAuthenticated()) this.getEntityPublisher(em, body.getAuthInfo()); TModelDetail result = new TModelDetail(); List<String> tmodelKeyList = body.getTModelKey(); for (String tmodelKey : tmodelKeyList) { org.apache.juddi.model.Tmodel modelTModel = null; try { modelTModel = em.find(org.apache.juddi.model.Tmodel.class, tmodelKey); } catch (ClassCastException e) { } if (modelTModel == null) throw new InvalidKeyPassedException( new ErrorMessage("errors.invalidkey.TModelNotFound", tmodelKey)); org.uddi.api_v3.TModel apiTModel = new org.uddi.api_v3.TModel(); MappingModelToApi.mapTModel(modelTModel, apiTModel); result.getTModel().add(apiTModel); } tx.commit(); long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(InquiryQuery.GET_TMODELDETAIL, QueryStatus.SUCCESS, procTime); return result; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }
From source file:uk.ac.ebi.bioinvindex.utils.datasourceload.DataSourceLoader.java
private void persistLocations(ReferenceSource isaTabSource, Collection<AssayTypeDataLocation> locations) { EntityTransaction transaction = getEntityManager().getTransaction(); Timestamp ts = new Timestamp(System.currentTimeMillis()); DaoFactory daoFactory = DaoFactory.getInstance(getEntityManager()); DataLocationPersister locPersister = new DataLocationPersister(daoFactory, ts); ReferenceSourcePersister srcPersister = new ReferenceSourcePersister(daoFactory, ts); IdentifiableDAO<AssayTypeDataLocation> dao = daoFactory.getIdentifiableDAO(AssayTypeDataLocation.class); List<AssayTypeDataLocation> dataLocations = dao.getAll(); boolean needsCommit = false; for (AssayTypeDataLocation dataLocation : dataLocations) { // TODO: Playing this way with serialize transactions is dangerous and we should fix this // PLEASE LEAVE THIS transaction commands here until we find a workaround, THEY ARE NEEDED in the ISATAB loader if (!transaction.isActive()) transaction.begin();//from w w w. ja v a 2 s .co m UnloadManager unloadManager = new UnloadManager(daoFactory, dataLocation.getSubmissionTs()); unloadManager.queue(dataLocation); unloadManager.delete(); needsCommit = true; } if (needsCommit) transaction.commit(); if (!transaction.isActive()) transaction.begin(); needsCommit = false; for (AssayTypeDataLocation location : locations) { locPersister.persist(location); needsCommit = true; } if (needsCommit) transaction.commit(); if (!transaction.isActive()) transaction.begin(); // Gets the old isaTabSource and replace with the new one in case it's already there // AccessibleDAO<ReferenceSource> daoRef = DaoFactory.getInstance(entityManager) .getAccessibleDAO(ReferenceSource.class); ReferenceSource oldIsaTabSrc = daoRef.getByAcc(ReferenceSource.ISATAB_METADATA); if (oldIsaTabSrc != null) { UnloadManager unloadManager = new UnloadManager(DaoFactory.getInstance(entityManager), oldIsaTabSrc.getSubmissionTs()); unloadManager.queue(oldIsaTabSrc); unloadManager.delete(); transaction.commit(); // At the end we have another initiated transaction transaction.begin(); } srcPersister.persist(isaTabSource); transaction.commit(); // Leave an opened transaction, so that it's possible to rejoin the one opened by an invoker // TODO: Playing this way to serialize transactions is dangerous and we should fix this // transaction.begin(); }
From source file:fr.natoine.dao.annotation.DAOAnnotation.java
/** * Retrieves all the existing AnnotationStatus * @return/*from w ww . j a v a2s . c o m*/ */ public List<AnnotationStatus> retrieveAnnotationStatus() { // EntityManagerFactory emf = this.setEMF(); EntityManager em = emf.createEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); List<AnnotationStatus> annotationstatus = em.createQuery("from AnnotationStatus").getResultList(); tx.commit(); return annotationstatus; } catch (Exception e) { tx.rollback(); //em.close(); System.out.println( "[RetrieveAnnotationStatus.retrieveAnnotationStatus] unable to retrieve AnnotationStatus" + " cause : " + e.getMessage()); return new ArrayList<AnnotationStatus>(); } }
From source file:org.opencastproject.usertracking.impl.UserTrackingServiceImpl.java
@SuppressWarnings("unchecked") public UserAction addUserFootprint(UserAction a) throws UserTrackingException { a.setType("FOOTPRINT"); EntityManager em = null;/*from w w w . ja v a 2 s . c om*/ EntityTransaction tx = null; try { em = emf.createEntityManager(); tx = em.getTransaction(); tx.begin(); Query q = em.createNamedQuery("findLastUserFootprintOfSession"); q.setMaxResults(1); q.setParameter("sessionId", a.getSessionId()); Collection<UserAction> userActions = q.getResultList(); if (userActions.size() >= 1) { UserAction last = userActions.iterator().next(); if (last.getMediapackageId().equals(a.getMediapackageId()) && last.getType().equals(a.getType()) && last.getOutpoint() == a.getInpoint()) { last.setOutpoint(a.getOutpoint()); a = last; a.setId(last.getId()); } else { em.persist(a); } } else { em.persist(a); } tx.commit(); return a; } catch (Exception e) { if (tx != null && tx.isActive()) { tx.rollback(); } throw new UserTrackingException(e); } finally { if (em != null && em.isOpen()) { em.close(); } } }
From source file:fr.natoine.dao.annotation.DAOAnnotation.java
/** * Retrieves the Resource in the database with the specified id. * @param id/*from ww w .j av a 2s. c o m*/ * @return a Resource that may be empty */ public Resource retrieveResource(long id) { //TODO move this method elsewhere, it's here because extension of Resource Class are not queried if it were in controler-resource package //EntityManagerFactory emf = this.setEMF(); EntityManager em = emf.createEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); Resource resource = (Resource) em.createQuery("from Resource where id = ?").setParameter(1, id) .getSingleResult(); tx.commit(); ////em.close(); return resource; } catch (Exception e) { tx.rollback(); //em.close(); System.out.println("[RetrieveResource.retrieveResource] unable to retrieve Resource" + " id : " + id + " cause : " + e.getMessage()); return new Resource(); } }
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./* w w w. j ava2s . c o m*/ * @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 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//from www . j av a 2s . c o 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:org.apache.juddi.api.impl.UDDIPublicationImpl.java
public void deletePublisherAssertions(DeletePublisherAssertions body) throws DispositionReportFaultMessage { long startTime = System.currentTimeMillis(); EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try {/* ww w .j av a 2 s .co m*/ tx.begin(); UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo()); new ValidatePublish(publisher).validateDeletePublisherAssertions(em, body); List<org.uddi.api_v3.PublisherAssertion> entityList = body.getPublisherAssertion(); for (org.uddi.api_v3.PublisherAssertion entity : entityList) { org.apache.juddi.model.PublisherAssertionId pubAssertionId = new org.apache.juddi.model.PublisherAssertionId( entity.getFromKey(), entity.getToKey()); Object obj = em.find(org.apache.juddi.model.PublisherAssertion.class, pubAssertionId); em.remove(obj); } tx.commit(); long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(PublicationQuery.DELETE_PUBLISHERASSERTIONS, QueryStatus.SUCCESS, procTime); } catch (DispositionReportFaultMessage drfm) { long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(PublicationQuery.DELETE_PUBLISHERASSERTIONS, QueryStatus.FAILED, procTime); throw drfm; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }