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.ibm.asset.trails.service.impl.ReconServiceImpl.java

@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public BreakResult breakReconcileByAlertWithoutQueue(Long alertId, String remoteUser,
        Set<UsedLicenseHistory> usedLicHis) {

    BreakResult breakResult = null;/*from   w w w  .ja v a2  s.  c o  m*/

    AlertUnlicensedSw alert = findAlertById(alertId);
    Reconcile reconcile = findReconcile(alert);

    // Step 1: Break reconcile History
    ReconcileH reconcileH = findReconcileHistory(alert);
    breakReconcileHistory(reconcile, reconcileH, alert, remoteUser, usedLicHis);

    // Step 2: Open alert
    createAlertHistory(alert);
    alert = openAlert(alert);

    // Step 3: Break reconcile
    Account account = alert.getReconcile().getInstalledSoftware().getSoftwareLpar().getAccount();
    account.getId();// avoid no session issue
    breakResult = breakReconcileWithoutQueue(alert.getReconcile(), account, remoteUser);

    return breakResult;
}

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

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = Throwable.class)
public boolean saveOrUpdate(Incidencia p) {
    if (p == null)
        return false;

    Incidencia entity = null;/*from  ww w  .j  av a 2  s.c om*/
    try {
        Session currentSession = getSession();
        if (p.getId() != null && this.get(p.getId()) != null)
            entity = get(p.getId());

        if (entity == null)
            entity = p;
        else {
            if (p.getCategoria() != null)
                try {
                    entity.setCategoria((CategoriaIncidencia) super.getSession().get(CategoriaIncidencia.class,
                            p.getCategoria().getId()));
                } catch (Throwable t) {
                    log.error("Categoria desconocida", t);
                }
            else
                entity.setCategoria(null);
            if (p.getCreador() != null)
                entity.setCreador(UsuarioConsultas.find(p.getCreador().getNombreUsuario()));
            else
                entity.setCreador(null);
            entity.setDescripcion(p.getDescripcion());
            if (p.getEstado() != null)
                try {
                    entity.setEstado((EstadoIncidencia) super.getSession().get(EstadoIncidencia.class,
                            p.getEstado().getId()));
                } catch (Throwable t) {
                    log.error("Estado desconocido", t);
                }
            else
                entity.setEstado(null);
            entity.setFechaCierre(p.getFechaCierre());
            entity.setFechaCreacion(p.getFechaCreacion());
            entity.setGeometria(p.getGeometria());
            entity.setPrioridad(p.getPrioridad());
            entity.setTitulo(p.getTitulo());
        }
        currentSession.saveOrUpdate(entity);
    } catch (Throwable t) {
        log.error("Error al guardar una incidencia: " + p, t);
        return false;
    }
    return true;
}

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

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testGetById() {
    lessonRepository.save(l1);

    assertNotNull(l1.getId());
    assertNotNull(lessonRepository.findOne(l1.getId()));
}

From source file:architecture.user.DefaultCompanyManager.java

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

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

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

    repository.save(s1);

    Student s2 = repository.findByEmail("davidopdebeeck@hotmail.com");

    assertNotNull(s2);
    assertEquals(s1, s2);
}

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

@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);//from   w w w. j  a v a 2 s  .c  om
    transactionManager.commit(status);
    c = dbeSystemPropertiesDao.getById("name");
    Assert.assertTrue(
            dbeSystemPropertiesDao.getById("name").getTxParamDescription().equalsIgnoreCase("new description"));
}

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

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

    tutorRepository.save(t1);//from  w w  w .j ava2  s .c o  m
    tutorRepository.save(t2);

    Collection<Tutor> list = Utils.makeCollection(tutorRepository.findAll());

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

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

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testGetByName() {
    Course c1 = new Course("MBI80x", ".NET Programmeren", ".NET", Curriculum.TI, 3);

    repository.save(c1);/*w ww . j  a v  a  2  s.  c o m*/

    Course c2 = repository.findByName(c1.getName());

    assertNotNull(c2);
    assertEquals(c1, c2);
}

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

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

    reviewRepository.save(review);/*from www  .  j a  va  2  s.  c o m*/

    assertNotNull(review.getId());
}

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

/**
 * Devuelve la calle que tenga el codigo INE pasado como parmetro.
 * //from w  w w . j  av  a2  s.com
 * @param codigoine
 * @return
 */
@Transactional(readOnly = true, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW)
public Street getByCodigoIne(Integer codigoine) {
    Street res = null;
    Session currentSession = getSession();
    currentSession.flush();
    Criteria criteria = currentSession.createCriteria(Street.class)
            .add(Restrictions.eq("codigoine", codigoine));
    res = (Street) criteria.uniqueResult();
    return res;
}