Example usage for org.springframework.transaction.annotation Propagation SUPPORTS

List of usage examples for org.springframework.transaction.annotation Propagation SUPPORTS

Introduction

In this page you can find the example usage for org.springframework.transaction.annotation Propagation SUPPORTS.

Prototype

Propagation SUPPORTS

To view the source code for org.springframework.transaction.annotation Propagation SUPPORTS.

Click Source Link

Document

Support a current transaction, execute non-transactionally if none exists.

Usage

From source file:org.jrecruiter.service.impl.JobServiceImpl.java

/** {@inheritDoc} */
@Override/*from   www .java 2 s.c o m*/
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public List<Job> getUsersJobsForStatistics(final String username) {

    final User user = userDao.getUser(username);

    if (user == null) {
        throw new IllegalArgumentException("No user found for username " + username);
    }

    if (AcegiUtil.hasRole(Roles.ADMIN.name())) {
        return jobDao.getAll();
    }

    return jobDao.getAllUserJobsForStatistics(user.getId());
}

From source file:it.geosdi.era.server.dao.hibernate.DAOUtenteHibernate.java

@Transactional(propagation = Propagation.SUPPORTS)
public int countAllUtentiProgetto(long id) {
    Session session = getSession();//from w  w  w.  j a v  a2 s.c o  m
    Query query = session
            .createQuery("select count(*) from UtenteProgetto utenteProgetto where utenteProgetto.utente = ? ");
    query.setLong(0, id);
    return ((Long) query.uniqueResult()).intValue();
}

From source file:es.upm.fiware.rss.expenditureLimit.manager.test.BalanceAccumulateManagerTest.java

/**
 * /* www  .j  a v  a  2  s .  co m*/
 */
@Transactional(propagation = Propagation.SUPPORTS)
public void deleteUserAccumulated() throws RSSException {
    BalanceAccumulateManagerTest.logger.debug("Into getUserAccumulated method.");
    ExpendControl control = generateExpendControl();
    balanceAccumulateManager.deleteUserAccumulated(endUserId, control);
    BalanceAccumulateManagerTest.logger.debug("Get objects after deleting.");

    AccumsExpend result = balanceAccumulateManager.getUserAccumulated(endUserId, control.getService(),
            control.getAggregator(), control.getAppProvider(), control.getCurrency(), control.getType());

    Assert.assertTrue(result.getAccums().size() > 0);
    boolean changed = false;
    for (AccumExpend accum : result.getAccums()) {
        if (accum.getType().equalsIgnoreCase(control.getType())
                && accum.getExpensedAmount().compareTo(BigDecimal.valueOf(0)) == 0) {
            changed = true;
        }
    }
    Assert.assertTrue(changed);
}

From source file:es.upm.fiware.rss.expenditureLimit.server.test.ExpenditureLimitServerTest.java

/**
 * @throws Exception//from w  w w  . j a v  a2  s .  co m
 */
//@Test
@Transactional(propagation = Propagation.SUPPORTS)
public void storeGeneralUserExpLimits() throws Exception {
    ExpenditureLimitServerTest.logger.debug("Into storeGeneralUserExpLimits method");
    LimitGroupBean expLimits = ExpenditureLimitBeanConstructor.generateLimitGroupBean();
    Response response = server.createModifUserExpLimit(aggregator, appProvider, userId, expLimits);
    Assert.assertEquals(201, response.getStatus());
}

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

@Transactional(propagation = Propagation.SUPPORTS)
public void testgDeleteById() {
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(Propagation.REQUIRES_NEW.value());
    TransactionStatus status = transactionManager.getTransaction(def);
    dbeSystemPropertiesDao.deleteById("name2");
    transactionManager.commit(status);//w ww  . ja  v  a  2  s . com
    Assert.assertTrue(dbeSystemPropertiesDao.getById("name2") == null);
}

From source file:es.upm.fiware.rss.expenditureLimit.manager.test.ExpenditureLimitManagerTest.java

/**
 * /*from   w w w  . j  a  v  a 2  s.  com*/
 * @throws RSSException
 */
@Transactional(propagation = Propagation.SUPPORTS)
public void storeGeneralProviderExpLimitsNoService() throws RSSException {
    ExpenditureLimitManagerTest.logger.debug("Into storeGeneralProviderExpLimits method");
    thrown.expect(RSSException.class);
    thrown.expectMessage("Service Identifier");
    LimitGroupBean expLimits = ExpenditureLimitBeanConstructor.generateLimitGroupBean();
    expLimits.setService(null);
    elManager.storeGeneralProviderExpLimit(aggregator, appProvider, expLimits);
    ExpenditureLimitManagerTest.logger.debug("Exception expected");
}

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

@Test
@Transactional(propagation = Propagation.SUPPORTS)
public void testgDeleteById() {
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(Propagation.REQUIRES_NEW.value());
    TransactionStatus status = transactionManager.getTransaction(def);
    dbeSystemPropertiesDao.deleteById("name2");
    transactionManager.commit(status);//w w w.j ava 2 s . co m
    Assert.assertTrue(dbeSystemPropertiesDao.getById("name2") == null);
}

From source file:es.upm.fiware.rss.expenditureLimit.manager.test.ExpenditureLimitDataCheckerTest.java

/**
 * //from w  w  w . j  av a2  s.c  om
 */
@Transactional(propagation = Propagation.SUPPORTS)
public void checkServiceTest() throws RSSException {
    ExpenditureLimitDataCheckerTest.logger.debug("Into checkServiceTest mehtod");
    thrown.expect(RSSException.class);
    thrown.expectMessage("Service Not found.");
    //checker.checkService("ServiceTest1");
    ExpenditureLimitDataCheckerTest.logger.debug("No exception expected");
    //checker.checkService("bluevia");
}

From source file:com.brienwheeler.svc.usergroups.impl.UserGroupService.java

@Override
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
@MonitoredWork/*from w  w  w.j  a  v a 2  s.  c  o  m*/
@GracefulShutdown
public List<UserGroup> getGroupsForUserAndType(User user, String groupType) {
    DbValidationUtils.assertPersisted(user);
    ValidationUtils.assertNotEmpty(groupType, "groupType cannot be empty");

    List<UserGroupMember> groupMemberList = userGroupMemberDao.findForUserAndType(user, groupType);
    ArrayList<UserGroup> groupList = new ArrayList<UserGroup>(groupMemberList.size());
    for (UserGroupMember groupMember : groupMemberList)
        groupList.add(groupMember.getUserGroup());
    return groupList;
}

From source file:info.jtrac.repository.HibernateJtracDao.java

@Override
@Transactional(propagation = Propagation.SUPPORTS)
public List<Item> findItems(ItemSearch itemSearch) {
    int pageSize = itemSearch.getPageSize();
    // TODO: if we are ordering by a custom column, we must load the whole
    // list to do an in-memory sort. we need to find a better way
    Field.Name sortFieldName = Field.isValidName(itemSearch.getSortFieldName())
            ? Field.convertToName(itemSearch.getSortFieldName())
            : null;/* w  w  w.ja v a2 s .  c  o m*/
    // only trigger the in-memory sort for drop-down fields and when querying within a space
    // UI currently does not allow you to sort by custom field when querying across spaces, but check again
    boolean doInMemorySort = sortFieldName != null && sortFieldName.isDropDownType()
            && itemSearch.getSpace() != null;
    DetachedCriteria criteria = getCriteria(itemSearch);
    if (pageSize == -1 || doInMemorySort) {
        @SuppressWarnings("unchecked")
        List<Item> list = criteria.getExecutableCriteria(getSession()).list();
        if (!list.isEmpty() && doInMemorySort) {
            doInMemorySort(list, itemSearch);
        }
        itemSearch.setResultCount(list.size());
        if (pageSize != -1) {
            // order-by was requested on custom field, so we loaded all results, but only need one page
            int start = pageSize * itemSearch.getCurrentPage();
            int end = Math.min(start + itemSearch.getPageSize(), list.size());
            return list.subList(start, end);
        }
        return list;
    } else {
        // pagination
        if (itemSearch.isBatchMode()) {
            entityManager.clear();
        }
        int firstResult = pageSize * itemSearch.getCurrentPage();
        @SuppressWarnings("unchecked")
        List<Item> list = criteria.getExecutableCriteria(getSession()).setFirstResult(firstResult)
                .setMaxResults(pageSize).list();
        if (!itemSearch.isBatchMode()) {
            criteria = getCriteriaForCount(itemSearch).criteria;
            criteria.setProjection(Projections.rowCount());
            Long count = (Long) criteria.getExecutableCriteria(getSession()).list().get(0);
            itemSearch.setResultCount(count);
        }
        return list;
    }
}