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.HistoricoGPSHome.java

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = Throwable.class)
public void delete(String identificador, Calendar ini, Calendar fin) {
    Session currentSession = getSession();
    currentSession//from  w w w  .  jav a 2 s .  co  m
            .createSQLQuery("DELETE FROM historico_gps "
                    + "WHERE recurso like :ID AND marca_temporal > :INI AND marca_temporal < :FIN")
            .setDate("FIN", fin.getTime()).setDate("INI", ini.getTime()).setString("ID", identificador)
            .executeUpdate();
}

From source file:architecture.ee.web.site.DefaultWebSiteManager.java

@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public void updateWebSite(WebSite webSite) throws WebSiteAlreadyExistsExcaption, WebSiteNotFoundException {
    WebSite old = getWebSiteById(webSite.getWebSiteId());
    if (!StringUtils.equals(old.getUrl(), webSite.getUrl())) {
        if (webSiteDao.findWebSitesByUrl(webSite.getUrl()).size() > 0) {
            throw new WebSiteAlreadyExistsExcaption();
        } else {//  www.j  a v a  2  s .  c  o m
            webSiteUrlCache.remove(old.getUrl());
        }
    }
    if (!StringUtils.equals(old.getName(), webSite.getName())) {
        if (webSiteDao.findWebSitesByName(webSite.getName()).size() > 0) {
            throw new WebSiteAlreadyExistsExcaption();
        } else {
            webSiteIdCache.remove(old.getName());
        }
    }
    webSiteDao.updateWebSite(webSite);
}

From source file:se.inera.intyg.intygstjanst.persistence.model.dao.impl.CertificateDaoImpl.java

/**
 * {@inheritDoc}/*from w w  w.j a  v  a  2  s .  com*/
 * <p>
 * Implementation note: This method is executed in a new nested transaction. This ensures that any errors that might
 * occur while removing intygs doesn't affect the other changes that are done in the parent transaction.
 */
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void removeCertificatesDeletedByCareGiver(Personnummer civicRegistrationNumber) {
    List<Certificate> certificatesOfCitizen = findCertificate(civicRegistrationNumber, null, null, null, null);
    for (Certificate certificate : certificatesOfCitizen) {
        if (certificate.isDeletedByCareGiver()) {
            entityManager.remove(certificate);
            LOG.info("Removing intyg {} from database since it's flaged as deletedByCareGiver",
                    certificate.getId());
        }
    }
}

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

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = Throwable.class)
private void removeRecursos(Flota p) {
    try {//  ww w  .  j  a va2s.c o m
        if (p != null && p.getId() != null) {
            Session currentSession = getSession();
            currentSession.clear();
            p = this.get(p.getId());
            if (p != null && p.getRecurso() != null) {
                for (Recurso r : p.getRecurso()) {
                    r = (Recurso) currentSession.get(Recurso.class, r.getId());
                    if (r != null) {
                        r.setFlotas(null);
                        currentSession.saveOrUpdate(r);
                    }
                }
            }
        }
    } catch (Throwable t) {
        log.error(t, t);
    }
}

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

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = Throwable.class)
public boolean saveOrUpdate(Patrulla p) {
    boolean res = false;
    if (p == null)
        return res;
    log.debug("Saving " + p);
    try {/*from   www.  jav  a 2  s.c  o  m*/
        Session currentSession = getSession();
        currentSession.clear();

        Patrulla entity = null;

        if (p.getId() != null && this.get(p.getId()) != null)
            entity = (Patrulla) currentSession.merge(p);
        else
            entity = p;

        if (p.getRecursos() != null)
            for (Recurso r : p.getRecursos()) {
                if (r.getId() != null) {
                    r = (Recurso) currentSession.get(Recurso.class, r.getId());
                    r.setPatrullas(entity);
                    currentSession.saveOrUpdate(r);
                }
            }

        currentSession.saveOrUpdate(entity);

        log.debug(p + " saved");
        return true;

    } catch (Throwable t) {
        log.error(t, t);
        return false;
    }
}

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

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = Throwable.class)
public boolean saveOrUpdate(final Rol rol) {

    Session currentSession = getSession();
    currentSession.clear();/*  w  ww.  j ava 2  s . c  o m*/
    Rol entity = null;

    final Set<Flota> flotas = rol.getFlotas();
    if (rol.getId() != null && this.get(rol.getId()) != null)
        entity = this.get(rol.getId());

    if (entity == null)
        entity = rol;

    if (entity == null)
        return false;

    entity.setInfoAdicional(rol.getInfoAdicional());
    currentSession.saveOrUpdate(entity);

    if (entity != null && flotas != null) {
        for (Flota f : flotas) {
            try {
                Flota flota = (Flota) currentSession.get(Flota.class, f.getId());
                flota.getRoles().add(entity);
                entity.getFlotas().add(flota);
                currentSession.saveOrUpdate(flota);
            } catch (Throwable t) {
                log.error(t);
            }
        }
    }
    return true;
}

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

@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public void setPollOptions(Poll poll, List<PollOption> options) {
    try {/*ww  w .  j a v  a2 s .com*/
        pollDao.updatePollOptions(poll, options);
        updatePoll(poll);
    } catch (NotFoundException e) {
        e.printStackTrace();
    }

}

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

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
public Calendar lastUpdated() {
    Calendar res = Calendar.getInstance();
    try {//from   w w  w .  j a  v  a2s  .com
        Session currentSession = getSession();
        currentSession.clear();
        Criteria criteria = currentSession.createCriteria(Incidencia.class)
                .setProjection(Projections.max("updatedAt"));
        res.setTime((Date) criteria.uniqueResult());
    } catch (NullPointerException t) {
        log.error("No hay datos en la tabla.");
        return null;
    } catch (Throwable t) {
        log.error(t, t);
        return null;
    }
    return res;
}

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

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = Throwable.class)
public boolean delete(CapaInformacion r) {
    if (r == null || r.getId() == null) {
        return false;
    }/*w w  w.  j a  v  a 2 s  . c  o m*/
    try {
        this.remove(r.getId());

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

From source file:es.upm.fiware.rss.expenditureLimit.dao.impl.tests.DbeExpendControlDaoTest.java

@Transactional(propagation = Propagation.SUPPORTS)
public void testNewExpendLimitDataForaUser() {

    BmCurrency bmCurrency = new BmCurrency();
    bmCurrency.setNuCurrencyId(1);/*from  w w  w . j a  v  a 2 s . c  o m*/

    List<DbeExpendControl> l = expLimitDao.getExpendDataForUserAppProvCurrency("userId01", "agg123",
            "app123456", bmCurrency);

    Assert.assertTrue("Elements found before " + l.toString(), l != null && l.size() == 3);
    Iterator<DbeExpendControl> it = l.iterator();

    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(Propagation.REQUIRES_NEW.value());
    TransactionStatus status = transactionManager.getTransaction(def);

    while (it.hasNext()) {
        DbeExpendControl el = it.next();
        DbeExpendControl neoEc = new DbeExpendControl();
        neoEc.setId(new DbeExpendLimitPK());
        neoEc.getId().setTxAppProviderId("123456");
        neoEc.getId().setTxElType(el.getId().getTxElType());
        neoEc.getId().setTxEndUserId("userId101");
        neoEc.setDtNextPeriodStart(el.getDtNextPeriodStart());
        neoEc.setTxNotifications(el.getTxNotifications());
        neoEc.setFtExpensedAmount(el.getFtExpensedAmount());
        expLimitDao.saveDbeExpendControl(neoEc);
    }

    transactionManager.commit(status);

    List<DbeExpendControl> l1 = expLimitDao.getExpendDataForUserAppProvCurrency("userId101", "agg123", "123456",
            bmCurrency);

    Assert.assertTrue("Elements found after " + l.toString() + " " + l1.toString(), l != null && l.size() == 3);
    it = l1.iterator();
    while (it.hasNext()) {
        DbeExpendControl el = it.next();
        if (!el.getId().getTxAppProviderId().equalsIgnoreCase("123456")) {
            Assert.fail("Application provider invalid: " + el.getId().getTxAppProviderId());
        }
        if (!el.getId().getTxEndUserId().equalsIgnoreCase("userId101")) {
            Assert.fail("User invalid: " + el.getId().getTxEndUserId());
        }
    }
}