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.ciphertool.sentencebuilder.dao.WordDao.java

/**
 * Inserts a List of Words in batch./*from w w  w.  j  av  a  2  s .co  m*/
 * 
 * @param wordBatch
 *            the batch of Words to insert
 * @return whether the insert was successful
 */
@Transactional(propagation = Propagation.REQUIRES_NEW)
public boolean insertBatch(List<Word> wordBatch) {
    if (wordBatch == null || wordBatch.isEmpty()) {
        log.warn(
                "Attempted to insert Words in batch which was found to be null or empty.  Unable to continue, thus returning false.");

        return false;
    }

    Session session = sessionFactory.getCurrentSession();
    for (Word word : wordBatch) {
        session.save(word);
    }
    return true;
}

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

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testRemove() {
    lessonRepository.save(l1);
    lessonRepository.delete(l1);
    assertNull(lessonRepository.findOne(l1.getId()));
}

From source file:org.openwms.wms.shipping.ShippingOrderStarter.java

/**
 * @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
 *///from  ww w.  j  a v a 2s.co  m
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void onApplicationEvent(RootApplicationEvent event) {
    if (ShippingOrderCreatedNotification.class.equals(event.getClass())) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Got Notification to allocate open ShippingOrders");
        }
        allocateOrders();
    }
}

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

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testGetById() {
    Tutor t1 = new Tutor(s1, courses);

    tutorRepository.save(t1);//  w  w  w .  ja  va  2  s  .  c o m

    Tutor t2 = tutorRepository.findOne(t1.getId());

    assertNotNull(t1);
    assertEquals(t1, t2);
}

From source file:architecture.ee.web.community.poll.DefaultPollManager.java

@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public void updatePoll(Poll poll) throws NotFoundException {
    pollDao.updatePoll(poll);/*w w w . java 2 s .c  o  m*/
    pollCache.remove(poll.getPollId());
}

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

@SuppressWarnings("unchecked")
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
public List<Rol> getAll(String order, boolean asc) {
    List<Rol> res = new ArrayList<Rol>(0);
    Session currentSession = getSession();
    currentSession.clear();/* www .  jav a2  s. co m*/
    if (asc)
        res = currentSession.createCriteria(Rol.class).addOrder(Order.asc(order))
                .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();
    else
        res = currentSession.createCriteria(Rol.class).addOrder(Order.desc(order))
                .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();

    return res;
}

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

@Transactional(readOnly = true, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW)
public Recurso get2(Long id) {
    try {//from ww  w. j a va  2  s  . c o  m
        Recurso uniqueResult = this.get(id);
        if (uniqueResult != null) {
            this.getSession().refresh(uniqueResult);
            if (uniqueResult.getPatrullas() != null) {
                uniqueResult.getPatrullas().getId();
            }
            if (uniqueResult.getFlotas() != null) {
                uniqueResult.getFlotas().getId();
            }
            if (uniqueResult.getEstadoEurocop() != null) {
                uniqueResult.getEstadoEurocop().getId();
            }
            if (uniqueResult.getIncidencias() != null) {
                uniqueResult.getIncidencias().getId();
            }
        }
        return uniqueResult;
    } catch (Throwable t) {
        log.error("Estamos buscando un objeto que no existe", t);
        return null;
    }
}

From source file:es.tid.fiware.rss.dao.impl.test.DbeSystemPropertiesDaoImplTest.java

@Test
@Transactional(propagation = Propagation.SUPPORTS)
public void testeUpdate() {
    DbeSystemProperties c = dbeSystemPropertiesDao.getById("name");
    c.setTxParamDescription("new description");
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(Propagation.REQUIRES_NEW.value());
    TransactionStatus status = transactionManager.getTransaction(def);
    dbeSystemPropertiesDao.update(c);// w ww  .  j  ava2  s .  c om
    transactionManager.commit(status);
    c = dbeSystemPropertiesDao.getById("name");
    Assert.assertTrue(
            dbeSystemPropertiesDao.getById("name").getTxParamDescription().equalsIgnoreCase("new description"));
}

From source file:architecture.ee.web.community.announce.impl.DefaultAnnounceManager.java

@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public void updateAnnounce(Announce announce) {
    Date now = new Date();
    announce.setModifiedDate(now);//from  w ww  .  j ava2s  . c  o m

    announceDao.update(announce);
    updateCache(announce);
}

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

@Test
@Override/*  w  w w.  ja v  a  2  s  .  com*/
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testGetAll() {
    Request request = new Request("some title", "some description", c1, s1);
    Request otherRequest = new Request("some other title", "some different description", c1, s1);
    requestRepository.save(request);
    requestRepository.save(otherRequest);
    assertNotNull(request.getId());
    assertNotNull(otherRequest.getId());

    Collection<Request> list = Utils.makeCollection(requestRepository.findAll());

    assertNotNull(list);
    assertEquals(2, list.size());
}