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:com.epam.catgenome.manager.GffManagerTest.java

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testRegisterGtf() throws Exception {
    Assert.assertTrue(testRegister(GENES_SORTED_GTF_PATH));
}

From source file:org.trpr.platform.core.impl.persistence.PersistenceDelegate.java

/**
 * Updates the underlying data store with information available in the specified Criteria instances using the specified PersistenceProvider
 * instances, with matching indexes. Note that this method is transactional by default.
 * It is advisable to use {@link PersistenceManagerProvider#update(Criteria...)} instead of calling this method directly.    
 * @param providers the PersistenceProvider instances to be used in persistence of the Criteria information, matched by indices
 * @param criteria the Criteria instances whose information must be persisted
 * @return int array containing the outcome status of update operation
 * @throws PersistenceException in case of peristence errors
 *///from   w  w w . ja v a 2 s .  c om
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.DEFAULT, rollbackForClassName = {
        "Exception" })
public int[] update(PersistenceProvider[] providers, Criteria... criteria) throws PersistenceException {
    int[] returnValue = new int[criteria.length];
    for (int i = 0; i < criteria.length; i++) {
        returnValue[i] = providers[i].update(criteria[i]);
    }
    return returnValue;
}

From source file:architecture.user.DefaultCompanyManager.java

@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public void updateCompany(Company company) throws CompanyNotFoundException, CompanyAlreadyExistsException {

    Company original = companyDao.getCompanyById(company.getCompanyId());
    if (original == null)
        throw CodeableException.newException(CompanyAlreadyExistsException.class, 5141, company.getCompanyId()); // new
    // GroupNotFoundException();

    String oldCompanyName = null;
    String newCompanyName = null;

    if (!nameEquals(original, company)) {
        try {/*from w w w. java 2  s  . c om*/
            Company checked = getCompany(caseCompanyName(company.getName()));
            if (checked.getCompanyId() == company.getCompanyId()) {
                throw CodeableException.newException(CompanyAlreadyExistsException.class, 5143); // new
                // GroupAlreadyExistsException("Group
                // with
                // this
                // name
                // already
                // exists.");
            }
        } catch (CompanyNotFoundException e) {
            oldCompanyName = original.getName();
            newCompanyName = company.getName();
        }
    }
    company.setModifiedDate(new Date());
    companyDao.updateCompany(company);
    if (oldCompanyName != null && newCompanyName != null) {
        companyNameUpdated(oldCompanyName);
    }
    clearCompanyFromCache(company);
}

From source file:es.upm.fiware.rss.dao.impl.test.DbeTransactionDaoImplTest.java

@Transactional(propagation = Propagation.SUPPORTS)
public void testDeleteTransactionsByProviderId() {
    int txTransactionId = 1;
    String providerId = new String("provider");
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(Propagation.REQUIRES_NEW.value());
    TransactionStatus status = transactionManager.getTransaction(def);
    dbeTransactionDAO.deleteTransactionsByProviderId(providerId);
    transactionManager.commit(status);//from   ww w.  ja v  a2s.c om
    List<DbeTransaction> listDbeTr = dbeTransactionDAO.getTransactionsByProviderId(providerId);

    if (listDbeTr != null && listDbeTr.size() > 0) {
        DbeTransactionDaoImplTest.LOGGER.debug("looking result list data....");
        DbeTransactionDaoImplTest.LOGGER.error("Obtained:" + listDbeTr.get(0).getTxTransactionId());
        Assert.assertTrue("0 data obtained ", listDbeTr.get(0).getTxTransactionId() == txTransactionId);
    } else {
        DbeTransactionDaoImplTest.LOGGER.debug("Obtained 0 data is not possible with datatest values");
        Assert.assertTrue("0 data obtained ", true);
    }

}

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

@Transactional(readOnly = true, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW)
public Usuario find(String nombreUsuario) {
    try {/*from  w  ww .  j a  va 2  s.  co  m*/
        org.hibernate.Session currentSession = getSession();
        if (currentSession == null)
            throw new RuntimeException("No tenemos session");
        currentSession.clear();
        Usuario u = (Usuario) currentSession.createCriteria(Usuario.class)
                .add(Restrictions.eq("nombreUsuario", nombreUsuario)).uniqueResult();
        u.getCapasInformacion();
        return u;
    } catch (Throwable t) {
        log.error("Error al buscar el usuario", t);
    }
    return null;
}

From source file:com.jaspersoft.jasperserver.api.logging.access.service.impl.AccessServiceImpl.java

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false)
public void purgeAccessEvents() {
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -maxAccessEventAge);
    Date last = cal.getTime();// w ww  .j a v  a 2s  .co m

    getHibernateTemplate().bulkUpdate("delete RepoAccessEvent e where e.eventDate < ?", last);
}

From source file:org.openmrs.module.idgen.service.BaseIdentifierSourceService.java

/**
 * This method exists because we want a transaction to be opened and closed inside the synchronized block in generateIdentifiers
 * @param source//from ww w  . j  a  v a  2  s  . c o m
 * @param batchSize
 * @param comment
 * @param processor
 * @return
 */
@Transactional(propagation = Propagation.REQUIRES_NEW)
public List<String> generateIdentifiersInternal(Integer sourceId, Integer batchSize, String comment) {

    IdentifierSource source = getIdentifierSource(sourceId);
    IdentifierSourceProcessor processor = getProcessor(source);

    if (processor == null) {
        throw new APIException("No registered processor found for source: " + source);
    }

    List<String> identifiers = processor.getIdentifiers(source, batchSize);

    Date now = new Date();
    User currentUser = Context.getAuthenticatedUser();

    for (String s : identifiers) {
        LogEntry logEntry = new LogEntry(source, s, now, currentUser, comment);
        dao.saveLogEntry(logEntry);
    }

    return identifiers;
}

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

/**
 * Merges a <code>MessageRequest</code> to the persistent store.This is needed if a dirty version of the objects exists
 * within the same persistet context.//from w w  w . j  a  va2s  .c om
 *
 * @param mr <code>MessageReques<./code> to merge
 * @see org.motechproject.mobile.omi.service.OMIServiceWorker#mergeMessageNow
 */
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void mergeMessageNow(MessageRequest mr) {
    if (mr != null) {
        MessageRequestDAO msgreqDao = getCoreManager().createMessageRequestDAO();

        msgreqDao.merge(mr);
    }
}

From source file:io.cloudslang.engine.node.services.WorkerNodeServiceImpl.java

@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void updateStatusInSeparateTransaction(String uuid, WorkerStatus status) {
    WorkerNode worker = workerNodeRepository.findByUuid(uuid);
    if (worker == null) {
        throw new IllegalStateException("no worker was found by the specified UUID:" + uuid);
    }//from w w  w . j a v a 2  s  .c om
    worker.setStatus(status);
}