List of usage examples for javax.persistence EntityTransaction isActive
public boolean isActive();
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 {// w w w . ja v a2 s .c o 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(); } }
From source file:org.eclipse.smila.connectivity.deltaindexing.jpa.impl.DeltaIndexingManagerImpl.java
/** * {@inheritDoc}/*from w w w. java 2s. c om*/ * * @see org.eclipse.smila.connectivity.deltaindexing.DeltaIndexingManager#init(java.lang.String) */ @Override public String init(final String dataSourceID) throws DeltaIndexingException { if (dataSourceID == null) { throw new DeltaIndexingException("parameter dataSourceID is null"); } _lock.readLock().lock(); try { final EntityManager em = createEntityManager(); final EntityTransaction transaction = em.getTransaction(); try { transaction.begin(); final DataSourceDao dao = findDataSourceDao(em, dataSourceID); if (dao != null && dao.getSessionId() != null) { throw new DeltaIndexingException( "data source " + dataSourceID + " is already locked by another session"); } final String sessionId = UUID.randomUUID().toString(); final DataSourceDao lockedDao = new DataSourceDao(dataSourceID, sessionId); // lock the data source if (dao == null) { em.persist(lockedDao); } else { em.merge(lockedDao); } // reset visited and modified flags resetFlags(em, dataSourceID); transaction.commit(); if (_log.isTraceEnabled()) { _log.trace("created session " + sessionId + " for data source: " + dataSourceID); } return sessionId; } catch (final DeltaIndexingException e) { if (transaction.isActive()) { transaction.rollback(); } throw e; } catch (final Exception e) { if (transaction.isActive()) { transaction.rollback(); } throw new DeltaIndexingException( "error initializing delta indexing for data source: " + dataSourceID, e); } finally { closeEntityManager(em); } } finally { _lock.readLock().unlock(); } }
From source file:org.apache.juddi.api.impl.UDDIPublicationImpl.java
public TModelDetail saveTModel(SaveTModel body) throws DispositionReportFaultMessage { long startTime = System.currentTimeMillis(); EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try {//from w w w . j a v a 2 s . co m tx.begin(); UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo()); new ValidatePublish(publisher).validateSaveTModel(em, body, null); TModelDetail result = new TModelDetail(); List<org.uddi.api_v3.TModel> apiTModelList = body.getTModel(); for (org.uddi.api_v3.TModel apiTModel : apiTModelList) { org.apache.juddi.model.Tmodel modelTModel = new org.apache.juddi.model.Tmodel(); MappingApiToModel.mapTModel(apiTModel, modelTModel); setOperationalInfo(em, modelTModel, publisher); em.persist(modelTModel); result.getTModel().add(apiTModel); } tx.commit(); long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(PublicationQuery.SAVE_TMODEL, QueryStatus.SUCCESS, procTime); return result; } catch (DispositionReportFaultMessage drfm) { long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(PublicationQuery.SAVE_TMODEL, QueryStatus.FAILED, procTime); throw drfm; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }
From source file:org.apache.juddi.api.impl.UDDICustodyTransferImpl.java
public void transferEntities(TransferEntities body) throws DispositionReportFaultMessage { long startTime = System.currentTimeMillis(); EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try {//from www . ja v a2 s . com tx.begin(); UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo()); new ValidateCustodyTransfer(publisher).validateTransferEntities(em, body); // Once validated, the ownership transfer is as simple as switching the publisher KeyBag keyBag = body.getKeyBag(); List<String> keyList = keyBag.getKey(); for (String key : keyList) { UddiEntity uddiEntity = em.find(UddiEntity.class, key); uddiEntity.setAuthorizedName(publisher.getAuthorizedName()); if (uddiEntity instanceof BusinessEntity) { BusinessEntity be = (BusinessEntity) uddiEntity; List<BusinessService> bsList = be.getBusinessServices(); for (BusinessService bs : bsList) { bs.setAuthorizedName(publisher.getAuthorizedName()); List<BindingTemplate> btList = bs.getBindingTemplates(); for (BindingTemplate bt : btList) bt.setAuthorizedName(publisher.getAuthorizedName()); } } } // After transfer is finished, the token can be removed org.uddi.custody_v3.TransferToken apiTransferToken = body.getTransferToken(); String transferTokenId = new String(apiTransferToken.getOpaqueToken()); org.apache.juddi.model.TransferToken modelTransferToken = em .find(org.apache.juddi.model.TransferToken.class, transferTokenId); em.remove(modelTransferToken); tx.commit(); long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(CustodyTransferQuery.TRANSFER_ENTITIES, QueryStatus.SUCCESS, procTime); } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }
From source file:org.opencastproject.search.impl.persistence.SearchServiceDatabaseImpl.java
/** * {@inheritDoc}/*from w w w . jav a2s . c o m*/ * * @see org.opencastproject.search.impl.persistence.SearchServiceDatabase#getMediaPackage(String) */ @Override public MediaPackage getMediaPackage(String mediaPackageId) throws NotFoundException, SearchServiceDatabaseException { EntityManager em = null; EntityTransaction tx = null; try { em = emf.createEntityManager(); tx = em.getTransaction(); tx.begin(); SearchEntity episodeEntity = getSearchEntity(mediaPackageId, em); if (episodeEntity == null) throw new NotFoundException("No episode with id=" + mediaPackageId + " exists"); // Ensure this user is allowed to read this episode String accessControlXml = episodeEntity.getAccessControl(); if (accessControlXml != null) { AccessControlList acl = AccessControlParser.parseAcl(accessControlXml); User currentUser = securityService.getUser(); Organization currentOrg = securityService.getOrganization(); // There are several reasons a user may need to load a episode: to read content, to edit it, or add content if (!AccessControlUtil.isAuthorized(acl, currentUser, currentOrg, READ.toString()) && !AccessControlUtil.isAuthorized(acl, currentUser, currentOrg, CONTRIBUTE.toString()) && !AccessControlUtil.isAuthorized(acl, currentUser, currentOrg, WRITE.toString())) { throw new UnauthorizedException( currentUser + " is not authorized to see episode " + mediaPackageId); } } return MediaPackageParser.getFromXml(episodeEntity.getMediaPackageXML()); } catch (NotFoundException e) { throw e; } catch (Exception e) { logger.error("Could not get episode {} from database: {} ", mediaPackageId, e.getMessage()); if (tx.isActive()) { tx.rollback(); } throw new SearchServiceDatabaseException(e); } finally { if (em != null) em.close(); } }
From source file:org.apache.juddi.api.impl.UDDIInquiryImpl.java
public ServiceList findService(FindService body) throws DispositionReportFaultMessage { long startTime = System.currentTimeMillis(); try {/* w ww. ja va 2 s. co m*/ new ValidateInquiry(null).validateFindService(body); } catch (DispositionReportFaultMessage drfm) { long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(InquiryQuery.FIND_SERVICE, QueryStatus.FAILED, procTime); throw drfm; } EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); if (isAuthenticated()) this.getEntityPublisher(em, body.getAuthInfo()); org.apache.juddi.query.util.FindQualifiers findQualifiers = new org.apache.juddi.query.util.FindQualifiers(); findQualifiers.mapApiFindQualifiers(body.getFindQualifiers()); List<?> keysFound = InquiryHelper.findService(body, findQualifiers, em); if (keysFound.size() == 0) { if (body.getBusinessKey() != null) { // Check that we were passed a valid businessKey per // 5.1.12.4 of the UDDI v3 spec String businessKey = body.getBusinessKey(); org.apache.juddi.model.BusinessEntity modelBusinessEntity = null; try { modelBusinessEntity = em.find(org.apache.juddi.model.BusinessEntity.class, businessKey); } catch (ClassCastException e) { } if (modelBusinessEntity == null) { throw new InvalidKeyPassedException( new ErrorMessage("errors.invalidkey.BusinessNotFound", businessKey)); } } } ServiceList result = InquiryHelper.getServiceListFromKeys(body, findQualifiers, em, keysFound); tx.rollback(); long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(InquiryQuery.FIND_SERVICE, QueryStatus.SUCCESS, procTime); return result; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }
From source file:org.apache.juddi.api.impl.UDDIInquiryImpl.java
public BindingDetail findBinding(FindBinding body) throws DispositionReportFaultMessage { long startTime = System.currentTimeMillis(); try {/* w ww . j a v a2 s . c o m*/ new ValidateInquiry(null).validateFindBinding(body); } catch (DispositionReportFaultMessage drfm) { long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(InquiryQuery.FIND_BINDING, QueryStatus.FAILED, procTime); throw drfm; } EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); if (isAuthenticated()) this.getEntityPublisher(em, body.getAuthInfo()); org.apache.juddi.query.util.FindQualifiers findQualifiers = new org.apache.juddi.query.util.FindQualifiers(); findQualifiers.mapApiFindQualifiers(body.getFindQualifiers()); List<?> keysFound = InquiryHelper.findBinding(body, findQualifiers, em); if (keysFound != null && keysFound.size() == 0) { if (body.getServiceKey() != null) { // Check that we were passed a valid serviceKey per // 5.1.12.4 of the UDDI v3 spec String serviceKey = body.getServiceKey(); org.apache.juddi.model.BusinessService modelBusinessService = null; try { modelBusinessService = em.find(org.apache.juddi.model.BusinessService.class, serviceKey); } catch (ClassCastException e) { logger.info("uh oh!", e); } if (modelBusinessService == null) throw new InvalidKeyPassedException( new ErrorMessage("errors.invalidkey.ServiceNotFound", serviceKey)); } } BindingDetail result = InquiryHelper.getBindingDetailFromKeys(body, findQualifiers, em, keysFound); tx.rollback(); long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(InquiryQuery.FIND_BINDING, QueryStatus.SUCCESS, procTime); return result; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }
From source file:com.eucalyptus.images.Images.java
public static void deregisterImage(String imageId) throws NoSuchImageException, InstanceNotTerminatedException { EntityTransaction tx = Entities.get(ImageInfo.class); try {// ww w .j a va2s .c o m ImageInfo img = Entities.uniqueResult(Images.exampleWithImageId(imageId)); if (ImageMetadata.State.deregistered.equals(img.getState()) || ImageMetadata.State.failed.equals(img.getState())) { Entities.delete(img); } else { if (img instanceof MachineImageInfo) { final String runManifestLocation = ((MachineImageInfo) img).getRunManifestLocation(); final String manifestLocation = ((MachineImageInfo) img).getManifestLocation(); // cleanup system generated buckets if exist if (!manifestLocation.equals(runManifestLocation)) img.setState(ImageMetadata.State.deregistered_cleanup); else img.setState(ImageMetadata.State.deregistered); } else img.setState(ImageMetadata.State.deregistered); } tx.commit(); if (img instanceof ImageMetadata.StaticDiskImage) { StaticDiskImages.flush((StaticDiskImage) img); } } catch (ConstraintViolationException cve) { tx.rollback(); throw new InstanceNotTerminatedException( "To deregister " + imageId + " all associated instances must be in the terminated state."); } catch (TransactionException ex) { tx.rollback(); throw new NoSuchImageException("Failed to lookup image: " + imageId, ex); } catch (NoSuchElementException ex) { tx.rollback(); throw new NoSuchImageException("Failed to lookup image: " + imageId, ex); } finally { if (tx.isActive()) tx.rollback(); } }
From source file:org.apache.juddi.api.impl.UDDIPublicationImpl.java
public void deleteBinding(DeleteBinding body) throws DispositionReportFaultMessage { long startTime = System.currentTimeMillis(); EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try {// w w w.j a va 2s . co m tx.begin(); UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo()); new ValidatePublish(publisher).validateDeleteBinding(em, body); List<String> entityKeyList = body.getBindingKey(); for (String entityKey : entityKeyList) { Object obj = em.find(org.apache.juddi.model.BindingTemplate.class, entityKey); ((org.apache.juddi.model.BindingTemplate) obj).getBusinessService() .setModifiedIncludingChildren(new Date()); // JUDDI-421: now the businessEntity parent will have it's modifiedIncludingChildren set ((org.apache.juddi.model.BindingTemplate) obj).getBusinessService().getBusinessEntity() .setModifiedIncludingChildren(new Date()); em.remove(obj); } tx.commit(); long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(PublicationQuery.DELETE_BINDING, QueryStatus.SUCCESS, procTime); } catch (DispositionReportFaultMessage drfm) { long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(PublicationQuery.DELETE_BINDING, QueryStatus.FAILED, procTime); throw drfm; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }
From source file:org.apache.juddi.api.impl.UDDISubscriptionImpl.java
@SuppressWarnings("unchecked") public List<Subscription> getSubscriptions(String authInfo) throws DispositionReportFaultMessage { long startTime = System.currentTimeMillis(); EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try {/*from w w w . j a v a2s .c o m*/ tx.begin(); UddiEntityPublisher publisher = this.getEntityPublisher(em, authInfo); List<Subscription> result = new ArrayList<Subscription>(0); List<org.apache.juddi.model.Subscription> modelSubscriptionList = (List<org.apache.juddi.model.Subscription>) FindSubscriptionByPublisherQuery .select(em, publisher.getAuthorizedName()); if (modelSubscriptionList != null && modelSubscriptionList.size() > 0) { for (org.apache.juddi.model.Subscription modelSubscription : modelSubscriptionList) { Subscription apiSubscription = new Subscription(); MappingModelToApi.mapSubscription(modelSubscription, apiSubscription); result.add(apiSubscription); } } tx.commit(); long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(SubscriptionQuery.GET_SUBSCRIPTIONS, QueryStatus.SUCCESS, procTime); return result; } catch (DispositionReportFaultMessage drfm) { long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(SubscriptionQuery.GET_SUBSCRIPTIONS, QueryStatus.FAILED, procTime); throw drfm; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }