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:be.peerassistedlearning.repository.StudentRepositoryTest.java

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testRemove() {
    Student s = new Student("David", "paswoord", "davidopdebeeck@hotmail.com", Curriculum.TI, "david",
            UserType.ADMIN);//from w  w  w  .  j  a  v  a2 s .  c o  m

    repository.save(s);
    repository.delete(s);

    s = repository.findOne(s.getId());

    assertNull(s);
}

From source file:org.motechproject.mobile.imp.serivce.MessageRegistryImpl.java

@SuppressWarnings("unchecked")
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = DuplicateMessageException.class)
public IncomingMessage registerMessage(String message) throws DuplicateMessageException {

    IncomingMessageDAO<IncomingMessage> msgDao = coreManager.createIncomingMessageDAO();

    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.MINUTE, 0 - duplicatePeriod);
    Date beforeDate = cal.getTime();
    IncomingMessage existingMsg = msgDao.getByContentNonDuplicatable(message);

    if (existingMsg != null) {

        if (existingMsg.getMessageStatus() == IncMessageStatus.PROCESSING)
            throw new DuplicateProcessingException("message is already processing");

        IncomingMessageForm existingMsgForm = existingMsg.getIncomingMessageForm();
        if (existingMsgForm != null
                && (existingMsgForm.getMessageFormStatus() == IncMessageFormStatus.SERVER_VALID)
                && (existingMsgForm.getIncomingMsgFormDefinition().getDuplicatable() == Duplicatable.DISALLOWED
                        || (existingMsgForm.getIncomingMsgFormDefinition()
                                .getDuplicatable() == Duplicatable.TIME_BOUND
                                && existingMsg.getDateCreated().after(beforeDate)))) {
            throw new DuplicateMessageException("message exists");
        }/*from   w  w  w  .j  ava  2s . co m*/
    }

    IncomingMessage newMsg = parser.parseRequest(message);

    return msgDao.save(newMsg);
}

From source file:architecture.common.i18n.impl.DefaultI18nTextManager.java

@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public void deleteTexts(List<I18nText> list) {
    i18nTextDao.deleteTexts(list);
}

From source file:architecture.ee.web.logo.DefaultLogoManager.java

@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public void addLogoImage(LogoImage logoImage, File file) {
    if (logoImage.getLogoId() < 1) {
        // clear cache
        List<Long> list = getLogoImageIdList(logoImage.getObjectType(), logoImage.getObjectId());
        for (Long logoImageId : list) {
            this.logoImageCache.remove(logoImageId);
        }//from  ww  w .j ava 2 s.c  om
        this.logoImageIdsCache
                .remove(getLogoImageIdListCacheKey(logoImage.getObjectType(), logoImage.getObjectId()));
        logoImageDao.addLogoImage(logoImage, file);
    }
}

From source file:org.fuin.auction.query.server.AuctionQueryServiceImpl.java

@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public final String findUserIdBySecurityToken(final String securityToken) {
    return userDao.findUserIdBySecurityToken(securityToken);
}

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

/**
 * Persists the specified PersistentEntity using the specified PersistenceProvider. Note that this method is transactional by default.
 * It is advisable to use {@link PersistenceManagerProvider#makePersistent(PersistentEntity)} instead of calling this method directly.
 * @param entity the PersistentEntity to persist
 * @param provider the PersistenceProvider to use in persistence
 * @return the PersistentEntity that was persisted
 * @throws PersistenceException in case of persistence errors
 *///from   www  . java 2s . c om
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.DEFAULT, rollbackForClassName = {
        "Exception" })
public PersistentEntity makePersistent(PersistentEntity entity, PersistenceProvider provider)
        throws PersistenceException {
    entity = provider.makePersistent(entity);
    return entity;
}

From source file:com.webapp.web.jpa.dao.PersonDaoImpl.java

/**
 * Saves address to person./*from   w w w.j  a  v a2  s  .  c  om*/
 */
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public Person saveAddress(Integer id, Address address) {
    Person person = findPersonById(id);

    if (person.getAddresses().contains(address)) {
        person.getAddresses().remove(address);
    }

    person.getAddresses().add(address);

    return save(person);
}

From source file:ch.algotrader.service.h2.H2TransactionPersistenceServiceImpl.java

/**
 * {@inheritDoc}//from   w w  w .  jav  a  2s.c om
 */
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void ensurePositionAndCashBalance(final Transaction transaction) {

    Validate.notNull(transaction, "Transaction is null");

    transaction.initializeSecurity(HibernateInitializer.INSTANCE);

    Strategy strategy = transaction.getStrategy();
    Security security = transaction.getSecurity();
    Set<Currency> currencySet = new HashSet<>();
    Collection<CurrencyAmountVO> attributions = transaction.getAttributions();
    for (CurrencyAmountVO attribution : attributions) {
        currencySet.add(attribution.getCurrency());
    }

    Session currentSession = this.sessionFactory.getCurrentSession();

    if (security != null) {

        Position position = this.positionDao.findBySecurityAndStrategy(security.getId(), strategy.getName());
        if (position == null) {
            position = Position.Factory.newInstance(0, new BigDecimal(0.0), new BigDecimal(0.0), false,
                    strategy, security);
            currentSession.save(position);
        }
    }

    if (!currencySet.isEmpty()) {

        for (Currency currency : currencySet) {

            CashBalance cashBalance = this.cashBalanceDao.findByStrategyAndCurrency(strategy, currency);
            if (cashBalance == null) {
                cashBalance = CashBalance.Factory.newInstance(currency, new BigDecimal(0.0), strategy);
                currentSession.save(cashBalance);
            }
        }
    }
}

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

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = Throwable.class)
public boolean saveOrUpdate(Inbox b) {
    Session currentSession = getSession();
    currentSession.flush();//from w  ww. j ava  2s  .  co  m
    currentSession.saveOrUpdate(currentSession.merge(b));
    return true;

}

From source file:org.arrow.service.DefaultRepositoryService.java

/**
 * {@inheritDoc}//  w  ww.jav a 2s  . c o m
 */
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void deploy(Definitions definitions) {

    if (CollectionUtils.isEmpty(definitions.getProcesses())) {
        logger.warn("no processes found, skip deployment");
        return;
    }

    // use a visitor to cache all BPMN event definitions
    CacheBpmnEventDefinitionEntityVisitor defVisitor = getDefVisitor();
    definitions.visit(defVisitor);

    for (Process process : definitions.getProcesses()) {
        Assert.notNull(process);
        prepareProcess(process, defVisitor.getCache());

        // add a relationship from a process to each element which demands one
        process.visit(new AddProcessRelationEntityVisitor(process, template));
    }

    // save the process meta data
    processMetaDataRepository.saveAll(prepareProcessMetaData(definitions));
    // save the definitions
    template.save(definitions);
}