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.sshdemo.common.security.web.authentication.rememberme.JPAPersistentTokenRepository.java

@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public void removeUserTokens(String username) {
    this.rememberMeTokenDAO.removeUserTokens(username);
}

From source file:org.ops4j.orient.spring.tx.object.TransactionalObjectService.java

@Transactional(propagation = Propagation.REQUIRES_NEW)
public void commitInNewTransaction() {
    assertThat(dbf.db().getTransaction().isActive(), is(true));

    Person person = dbf.db().newInstance(Person.class);
    person.setFirstName("Donald");
    person.setLastName("Duck");
    person = dbf.db().save(person);//w  w  w  . j av  a  2s. c o m
}

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

@Transactional(readOnly = true, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW)
public Integer getTotal() {
    Integer res = new Integer(-1);
    org.hibernate.Session currentSession = getSession();
    currentSession.clear();//from w ww.j  a  v  a2  s  . c o  m
    Criteria criteria = currentSession.createCriteria(Usuario.class).setProjection(Projections.rowCount());
    Integer count = (Integer) criteria.uniqueResult();
    res = count.intValue();
    return res;
}

From source file:com.ciphertool.sentencebuilder.dao.WordDao.java

/**
 * Finds all occurrences of a particular Word by its String value.
 * /*w ww  . jav a  2s.c  o m*/
 * @param word
 *            the String value of the word to find
 * @return the List of matching Words
 */
@Transactional(readOnly = true, propagation = Propagation.REQUIRES_NEW)
public List<Word> findByWordString(String word) {
    if (word == null) {
        log.warn("Attempted to find Word by null String.  Unable to continue, thus returning null.");

        return null;
    }

    Session session = sessionFactory.getCurrentSession();
    @SuppressWarnings("unchecked")
    List<Word> words = (List<Word>) session.createQuery("from Word where word = " + separator + wordParameter)
            .setParameter(wordParameter, word).list();

    return words;
}

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

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
public String getStringValue(String key) {
    String res = getConfiguration(key);
    try {//from w  w  w  .j av  a 2s  .co  m
        Configuracion c = this.get(key);
        if (c != null) {
            res = c.getValor();
            if (!c.getUpdatable())
                setConfiguration(key, res);
        }
    } catch (Throwable t) {
        log.error("Configuracion no encontrada", t);
    }

    return res;
}

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

@Test
@Override//from  w  ww .j  a  v  a  2  s  .co  m
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testAdd() {
    Request request = new Request("some title", "some description", c1, s1);
    requestRepository.save(request);
    assertNotNull(request.getId());
    requestRepository.findAllWithoutLesson();
}

From source file:ch.algotrader.service.mysql.MySqlTransactionPersistenceServiceImpl.java

/**
 * {@inheritDoc}//from  w  ww  .  ja  v  a2s  .c  o  m
 */
@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) {

        Serializable id = HibernateUtil.getNextId(this.sessionFactory, PositionImpl.class);

        SQLQuery sqlQuery = currentSession.createSQLQuery("INSERT IGNORE INTO position "
                + "  (id, quantity, cost, realized_p_l, persistent, security_fk, strategy_fk, version) "
                + "  VALUES (:position_id, 0, 0, 0, 0, :security_id, :strategy_id, 1)");

        sqlQuery.setParameter("position_id", id);
        sqlQuery.setParameter("security_id", security.getId());
        sqlQuery.setParameter("strategy_id", strategy.getId());
        sqlQuery.executeUpdate();
    }

    if (!currencySet.isEmpty()) {

        SQLQuery sqlQuery = currentSession.createSQLQuery("INSERT IGNORE INTO cash_balance "
                + "(currency, amount, strategy_fk, version) VALUES (:currency, 0, :strategy_id, 1)");
        for (Currency currency : currencySet) {

            sqlQuery.setParameter("currency", currency.name());
            sqlQuery.setParameter("strategy_id", strategy.getId());
            sqlQuery.executeUpdate();
        }
    }
}

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

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testRemove() {
    Room r = new Room("2.25", Campus.PROXIMUS, RoomType.COMPUTER);

    repository.save(r);/*from   w  ww.j a  v  a2 s  .  c o m*/
    repository.delete(r);

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

    assertNull(r);
}

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

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
public Integer getTotal() {
    try {//w w w. j  av  a2  s  .  c  om
        Session currentSession = getSession();
        currentSession.clear();
        Criteria criteria = currentSession.createCriteria(Flota.class).add(Restrictions.eq("habilitada", true))
                .setProjection(Projections.rowCount());
        Integer count = (Integer) criteria.uniqueResult();
        return count.intValue();
    } catch (Throwable t) {
        log.error(t, t);
        return -1;
    }
}

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

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
public EstadoIncidencia getByIdentificador(String identificador) {

    Session currentSession = getSession();
    if (currentSession == null) {
        throw new NullPointerException("La sesion de Hibernate es nula");
    }/*from   w w w  . j  a  v a2s.com*/
    Criteria crit = currentSession.createCriteria(EstadoIncidencia.class)
            .add(Restrictions.eq("identificador", identificador));
    return (EstadoIncidencia) crit.setMaxResults(1).uniqueResult();
}