Example usage for org.springframework.transaction.annotation Propagation REQUIRES_NEW

List of usage examples for org.springframework.transaction.annotation Propagation REQUIRES_NEW

Introduction

In this page you can find the example usage for org.springframework.transaction.annotation Propagation REQUIRES_NEW.

Prototype

Propagation REQUIRES_NEW

To view the source code for org.springframework.transaction.annotation Propagation REQUIRES_NEW.

Click Source Link

Document

Create a new transaction, and suspend the current transaction if one exists.

Usage

From source file:es.emergya.bbdd.dao.StreetHome.java

@Transactional(readOnly = false, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW)
public Street save(Street s) {
    return (Street) getSession().merge(s);
}

From source file:es.emergya.bbdd.dao.RolHome.java

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
public Rol find(String nombreRol) {
    Session currentSession = getSession();
    currentSession.clear();//w ww  .  j  a v  a 2s  .  c o  m
    return (Rol) currentSession.createCriteria(Rol.class).add(Restrictions.ilike("nombre", nombreRol))
            .uniqueResult();
}

From source file:com.netsteadfast.greenstep.service.impl.SysCalendarNoteServiceImpl.java

/**
 *  CALENDAR_ID/*w ww . j  av a 2s  .  c o m*/
 * ?: +001 , 999 ,  20141915001
 * 
 * @param account
 * @param date
 * @return
 * @throws ServiceException
 * @throws Exception
 */
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true)
@Override
public String findForMaxCalendarId(String account, String date) throws ServiceException, Exception {
    if (StringUtils.isBlank(account) || StringUtils.isBlank(date)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    String calendarId = this.sysCalendarNoteDAO.findForMaxCalendarId(account, date);
    if (!StringUtils.isBlank(calendarId)) {
        int num = Integer.parseInt(calendarId.substring(8, 11)) + 1;
        if (num > 999) { // ?999note
            throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.DATA_ERRORS));
        }
        return date + StringUtils.leftPad(String.valueOf(num), 3, "0");
    }
    //  calendar_id      
    return date + "001";
}

From source file:architecture.ee.web.community.profile.DefaultProfileManager.java

@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public void addProfileImage(ProfileImage image, File file, User user) {
    List<Long> list = profileDao.getProfileImageIds(user.getUserId());
    for (Long id : list) {
        profileImageCache.remove(id);/*from  www  .  j a  v a  2s  . c  o m*/
    }

    profileDao.addProfileImage(image, file);
}

From source file:org.motechproject.mobile.omi.service.OMIServiceWorkerImpl.java

/**
 * Reschedules a <code>MessageRequest</code> for sending
 *
 * The schedule is only added if <code>maxRetries</code> on the <code>MessageRequest</code> has not been reached
 *
 * @param message <code>MessageRequest</code> to reschedule
 * @see org.motechproject.mobile.omi.service.OMIServiceWorker#processMessageRetry
 *//* w w  w .  j  a  v a 2  s  .co  m*/
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void processMessageRetry(MessageRequest message) {
    if (message != null) {
        MessageRequestDAO msgReqDao = getCoreManager().createMessageRequestDAO();
        GatewayRequestDetailsDAO gwReqDao = getCoreManager().createGatewayRequestDetailsDAO();
        MobileMessagingService msgSvc = getOmpManager().createMessagingService();

        if (message.getTryNumber() >= getMaxTries()) {
            message.setStatus(MStatus.FAILED);
        } else {

            message.setTryNumber(message.getTryNumber() + 1);

            if (message.getGatewayRequestDetails() == null) {
                return;
            }

            GatewayRequestDetails gwReqDet = (GatewayRequestDetails) gwReqDao
                    .getById(message.getGatewayRequestDetails().getId());

            GatewayRequest gwReq = (GatewayRequest) applicationContext.getBean("gatewayRequest",
                    GatewayRequest.class);
            gwReq.setDateFrom(message.getDateFrom());
            gwReq.setDateTo(message.getDateTo());
            gwReq.setMessageRequest(message);
            gwReq.setRecipientsNumber(getStoreManager().formatPhoneNumber(message.getRecipientNumber(),
                    message.getMessageType()));
            gwReq.setRequestId(message.getRequestId());
            gwReq.setTryNumber(message.getTryNumber());
            gwReq.setMessage(gwReqDet.getMessage());
            gwReq.setMessageStatus(MStatus.SCHEDULED);

            gwReqDet.getGatewayRequests().add(gwReq);
            msgSvc.scheduleMessage(gwReqDet);

            message.setStatus(MStatus.PENDING);
        }

        msgReqDao.merge(message);
    }
}

From source file:de.hska.ld.recommendation.client.SSSClient.java

@Transactional(propagation = Propagation.REQUIRES_NEW)
public void performInitialSSSTagLoad(Long documentId, String accessToken) throws IOException {
    String url = null;/*  www  . j  a  v  a2s  .co  m*/
    if (getSssAPIVersion() == 1) {
        url = env.getProperty("sss.server.endpoint") + "/recomm/recomm/update";
    } else {
        url = env.getProperty("sss.server.endpoint") + "/rest/recomm/update";
    }
    Document document = documentService.findById(documentId);
    List<String> tagStringList = new ArrayList<String>();
    document.getTagList().forEach(t -> {
        tagStringList.add(t.getName());
    });
    if (tagStringList.size() > 0) {
        /*String userPrefix = env.getProperty("sss.user.name.prefix");
        String documentPrefix = env.getProperty("sss.document.name.prefix");
                
        RecommUpdateDto recommUpdateDto = new RecommUpdateDto();
        recommUpdateDto.setRealm("dieter1");
        recommUpdateDto.setForUser(userPrefix + currentUser.getId());
        recommUpdateDto.setEntity(documentPrefix + document.getId());
        recommUpdateDto.setTags(tagStringList);
                
        HttpClient client = getHttpClientFor(url);
        HttpPut put = new HttpPut(url);
        addHeaderInformation(put, accessToken);
                
        String recommUpdateDtoString = mapper.writeValueAsString(recommUpdateDto);
        StringEntity stringEntity = new StringEntity(recommUpdateDtoString, ContentType.create("application/json", "UTF-8"));
        put.setEntity(stringEntity);
        BufferedReader rd = null;
                
        HttpResponse response = client.execute(put);
        System.out.println("Response Code : "
            + response.getStatusLine().getStatusCode());
                
        if (response.getStatusLine().getStatusCode() != 200) {
        if (response.getStatusLine().getStatusCode() == 403) {
            throw new UserNotAuthorizedException();
        }
        }
                
        try {
        rd = new BufferedReader(
                new InputStreamReader(response.getEntity().getContent()));
                
        StringBuilder result = new StringBuilder();
        String line = "";
        while ((line = rd.readLine()) != null) {
            result.append(line);
        }
        if (result.toString().contains("\"error_description\":\"Invalid access token:")) {
            throw new ValidationException("access token is invalid");
        }
        mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        RecommUpdateResponseDto recommUpdateResponseDto = mapper.readValue(result.toString(), RecommUpdateResponseDto.class);
        if (!recommUpdateResponseDto.isWorked()) {
            throw new Exception("Updating recommendations didn't work!");
        } else {
            documentRecommInfoService.addDocumentRecommInfo(documentId);
        }
        return;
        } catch (ValidationException ve) {
        throw ve;
        } catch (Exception e) {
        return;
        } finally {
        if (rd != null) {
            rd.close();
        }
        }*/
        addTagToDocumentUser(url, document, tagStringList, accessToken);
        addTagToDocumentDocument(url, document, tagStringList, accessToken);
        documentRecommInfoService.addDocumentRecommInfo(documentId);
    } else {
        documentRecommInfoService.addDocumentRecommInfo(documentId);
    }
}

From source file:be.peerassistedlearning.repository.ReviewRepositoryTest.java

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testRemove() {
    Review review = new Review(text, s1, l, 5, 5, 5, 5, false);

    reviewRepository.save(review);/*from  w  w w. ja v  a  2 s  .c o  m*/
    reviewRepository.delete(review);

    assertNull(reviewRepository.findOne(review.getId()));
}

From source file:es.emergya.bbdd.dao.FlotaHome.java

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = Throwable.class)
public boolean saveOrUpdate(Flota f) {
    boolean res = false;
    if (f == null)
        return res;
    try {/*from  w  w  w.  j  a  v a  2s  .c  o  m*/
        log.debug("Saving " + f);
        final Set<Rol> roles = f.getRoles();
        final Set<Recurso> recurso = f.getRecurso();
        removeRecursos(f);
        removeRoles(f);
        Session currentSession = getSession();
        currentSession.clear();

        Flota entity = null;

        if (f.getId() != null && this.get(f.getId()) != null)
            entity = (Flota) currentSession.merge(f);
        else
            entity = f;
        if (recurso != null)
            for (Recurso r : recurso) {
                r = (Recurso) currentSession.get(Recurso.class, r.getId());
                if (r != null) {
                    r.setFlotas(entity);
                    currentSession.saveOrUpdate(r);
                }
            }

        if (roles != null)
            for (Rol r : roles) {
                Rol rentity = (Rol) currentSession.get(Rol.class, r.getId());
                if (rentity != null) {
                    rentity.getFlotas().add(entity);
                    currentSession.saveOrUpdate(rentity);
                }
            }

        currentSession.saveOrUpdate(entity);
    } catch (Throwable t) {
        log.error(t, t);
        return false;
    }
    return true;
}

From source file:architecture.user.DefaultCompanyManager.java

@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public Company createCompany(String name, String displayName, String description)
        throws CompanyAlreadyExistsException {
    try {//ww  w .j  a  v a2s .co  m
        getCompany(name);
        throw new CompanyAlreadyExistsException();
    } catch (CompanyNotFoundException unfe) {
        Company company = new CompanyTemplate();
        company.setDescription(description);
        company.setDisplayName(displayName);
        company.setName(name);
        Date groupCreateDate = new Date();
        company.setCreationDate(groupCreateDate);
        company.setModifiedDate(groupCreateDate);
        companyDao.createCompany(company);
        return company;
    }
}

From source file:com.epam.catgenome.dao.ReferenceGenomeDaoTest.java

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testChromosomeManagement() {
    final List<Chromosome> chromosomes = reference.getChromosomes();
    // tests that batch of chromosomes are saved and IDs are assigned
    final int count = chromosomes.size();
    final int[] result = referenceGenomeDao.saveChromosomes(reference.getId(), chromosomes);
    assertEquals("Unexpected batch size.", count, result.length);
    for (int i = 0; i < count; i++) {
        assertEquals("Unexpected number of affected rows after chromosome has been saved successfully.", 1,
                result[i]);//from   www  .  j  a v  a2  s .c  o  m
        Chromosome entity = chromosomes.get(i);
        assertNotNull("Chromosome ID has been assigned.", entity.getId());
        assertNotNull("Reference ID has been assigned.", entity.getReferenceId());
    }

    final Chromosome chromosome = chromosomes.get(0);

    // tests that a chromosome can be retrieved by the given ID
    final Chromosome foundById = referenceGenomeDao.loadChromosome(chromosome.getId());
    assertNotNull("Chromosome isn't found by the given ID.", foundById);
    ReflectionAssert.assertReflectionEquals("Unexpected chromosome is loaded by ID.", chromosome, foundById);
    // tests that all chromosomes related to a reference genome with the given ID can be retrieved
    final List<Chromosome> allChromosomes = referenceGenomeDao
            .loadAllChromosomesByReferenceId(reference.getId());
    assertTrue("Collection of chromosomes is empty, but it should contain more than 1 value.",
            CollectionUtils.isNotEmpty(allChromosomes));
    assertEquals("Unexpected number of chromosomes for the given reference is detected.", count,
            allChromosomes.size());
    final Optional<Chromosome> foundInList = allChromosomes.stream()
            .filter(e -> chromosome.getId().equals(e.getId())).findFirst();
    assertTrue("Chromosome isn't found by ID in the retrieved list.", foundInList.isPresent());
    ReflectionAssert.assertReflectionEquals("Unexpected chromosome is found in the list.", chromosome,
            foundInList.get());
}