Example usage for org.springframework.transaction.support DefaultTransactionDefinition setPropagationBehavior

List of usage examples for org.springframework.transaction.support DefaultTransactionDefinition setPropagationBehavior

Introduction

In this page you can find the example usage for org.springframework.transaction.support DefaultTransactionDefinition setPropagationBehavior.

Prototype

public final void setPropagationBehavior(int propagationBehavior) 

Source Link

Document

Set the propagation behavior.

Usage

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

@Transactional(propagation = Propagation.SUPPORTS)
public void testDeleteTransactionsByProviderId() {
    int txTransactionId = 1;
    String providerId = new String("provider");
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(Propagation.REQUIRES_NEW.value());
    TransactionStatus status = transactionManager.getTransaction(def);
    dbeTransactionDAO.deleteTransactionsByProviderId(providerId);
    transactionManager.commit(status);//from   w  w  w. j ava2  s. c om
    List<DbeTransaction> listDbeTr = dbeTransactionDAO.getTransactionsByProviderId(providerId);

    if (listDbeTr != null && listDbeTr.size() > 0) {
        DbeTransactionDaoImplTest.LOGGER.debug("looking result list data....");
        DbeTransactionDaoImplTest.LOGGER.error("Obtained:" + listDbeTr.get(0).getTxTransactionId());
        Assert.assertTrue("0 data obtained ", listDbeTr.get(0).getTxTransactionId() == txTransactionId);
    } else {
        DbeTransactionDaoImplTest.LOGGER.debug("Obtained 0 data is not possible with datatest values");
        Assert.assertTrue("0 data obtained ", true);
    }

}

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

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

    BmCurrency bmCurrency = new BmCurrency();
    bmCurrency.setNuCurrencyId(1);//from   w ww  . ja v  a2s. co m
    List<DbeExpendControl> l = expLimitDao.getExpendDataForUserAppProvCurrency("userId01", "agg123",
            "app123456", bmCurrency);

    Assert.assertTrue("Elements founds", 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();
        if (el.getId().getTxElType().equalsIgnoreCase("daily")) {
            el.setFtExpensedAmount(new BigDecimal("0"));
            Date dt = new Date(new Date().getTime() + 23 * 36000 * 1000);
            el.setDtNextPeriodStart(dt);
            el.setTxNotifications("");
        } else {
            el.setFtExpensedAmount(el.getFtExpensedAmount().add(new BigDecimal("22")));
            el.setTxNotifications(el.getTxNotifications() + ", 50");
        }
        expLimitDao.saveDbeExpendControl(el);
    }

    transactionManager.commit(status);

    l = expLimitDao.getExpendDataForUserAppProvCurrency("userId01", "agg123", "app123456", bmCurrency);

    it = l.iterator();
    while (it.hasNext()) {
        DbeExpendControl el = it.next();
        if (el.getId().getTxElType().equalsIgnoreCase("daily")) {
            Assert.assertTrue("Daily accumulate: ", el.getFtExpensedAmount().floatValue() == 0);
            Assert.assertTrue("Notifications: ",
                    el.getTxNotifications() == null || el.getTxNotifications().length() == 0);
        } else {
            Assert.assertTrue("Notifications: ", el.getTxNotifications().contains("50"));
        }
    }
}

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 ww . ja va2s  .  c  om

    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());
        }
    }
}

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

@Test
public void testUpdateExpendLimitDataForaUser() {

    BmService bmService = new BmService();
    bmService.setNuServiceId(1);//from  w w w . j  a  va  2 s  .c o  m
    BmCurrency bmCurrency = new BmCurrency();
    bmCurrency.setNuCurrencyId(1);
    BmObCountry bmObCountry = new BmObCountry();
    bmObCountry.setId(new BmObCountryId(1, 1));
    List<DbeExpendControl> l = expLimitDao.getExpendDataForUserAppProvCurrencyObCountry("userId01", bmService,
            "app123456", bmCurrency, bmObCountry);

    Assert.assertTrue("Elements founds", 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();
        if (el.getId().getTxElType().equalsIgnoreCase("daily")) {
            el.setFtExpensedAmount(new BigDecimal("0"));
            Date dt = new Date(new Date().getTime() + 23 * 36000 * 1000);
            el.setDtNextPeriodStart(dt);
            el.setTxNotifications("");
        } else {
            el.setFtExpensedAmount(el.getFtExpensedAmount().add(new BigDecimal("22")));
            el.setTxNotifications(el.getTxNotifications() + ", 50");
        }
        expLimitDao.saveDbeExpendControl(el);
    }
    transactionManager.commit(status);

    l = expLimitDao.getExpendDataForUserAppProvCurrencyObCountry("userId01", bmService, "app123456", bmCurrency,
            bmObCountry);

    it = l.iterator();
    while (it.hasNext()) {
        DbeExpendControl el = it.next();
        if (el.getId().getTxElType().equalsIgnoreCase("daily")) {
            Assert.assertTrue("Daily accumulate: ", el.getFtExpensedAmount().floatValue() == 0);
            Assert.assertTrue("Notifications: ",
                    el.getTxNotifications() == null || el.getTxNotifications().length() == 0);
        } else {
            Assert.assertTrue("Notifications: ", el.getTxNotifications().indexOf("50") > -1);
        }
    }
}

From source file:com.krawler.spring.common.CommonFnController.java

public ModelAndView changeUserPassword(HttpServletRequest request, HttpServletResponse response) {
    JSONObject jobj = new JSONObject();
    KwlReturnObject kmsg = null;/*from w ww.  j  av  a  2s .c om*/
    //Create transaction
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("CF_Tx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);

    TransactionStatus status = txnManager.getTransaction(def);
    try {
        String platformURL = this.getServletContext().getInitParameter("platformURL");

        HashMap<String, Object> requestParams = new HashMap<String, Object>();
        requestParams.put("currentpassword", StringUtil.checkForNull(request.getParameter("currentpassword")));
        requestParams.put("changepassword", StringUtil.checkForNull(request.getParameter("changepassword")));
        requestParams.put("userid", sessionHandlerImpl.getUserid(request));
        requestParams.put("companyid", sessionHandlerImpl.getCompanyid(request));
        requestParams.put("remoteapikey", ConfigReader.getinstance().get("remoteapikey"));

        kmsg = profileHandlerDAOObj.changeUserPassword(platformURL, requestParams);
        jobj = (JSONObject) kmsg.getEntityList().get(0);
        txnManager.commit(status);
        jobj.put("success", true);
    } catch (Exception e) {
        System.out.println(e.getMessage());
        txnManager.rollback(status);
    }
    return new ModelAndView("jsonView", "model", jobj.toString());
}

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

@Test
public void testNewExpendLimitDataForaUser() {

    BmService bmService = new BmService();
    bmService.setNuServiceId(1);//from  w w  w  .  j av a 2 s  .  com
    BmCurrency bmCurrency = new BmCurrency();
    bmCurrency.setNuCurrencyId(1);
    BmObCountry bmObCountry = new BmObCountry();
    bmObCountry.setId(new BmObCountryId(1, 1));
    List<DbeExpendControl> l = expLimitDao.getExpendDataForUserAppProvCurrencyObCountry("userId01", bmService,
            "app123456", bmCurrency, bmObCountry);

    Assert.assertTrue("Elements founds", 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().setNuCountryId(el.getId().getNuCountryId());
        neoEc.getId().setNuCurrencyId(el.getId().getNuCountryId());
        neoEc.getId().setNuObId(el.getId().getNuCountryId());
        neoEc.getId().setNuServiceId(el.getId().getNuCountryId());
        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);
    l = expLimitDao.getExpendDataForUserAppProvCurrencyObCountry("userId101", bmService, "123456", bmCurrency,
            bmObCountry);

    Assert.assertTrue("Elements founds", l != null && l.size() == 3);
    it = l.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());
        }
    }
}

From source file:org.seasar.dbflute.unit.spring.SpringTestCase.java

/**
 * {@inheritDoc}/*w ww.  ja va 2s . co m*/
 */
@Override
protected TransactionResource beginNewTransaction() { // user method
    final String managerKey = "transactionManager";
    if (!hasComponent(managerKey)) {
        return null;
    }
    final PlatformTransactionManager manager = getComponent(managerKey);
    final DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
    final TransactionStatus status = manager.getTransaction(def);
    final SpringTransactionResource resource = new SpringTransactionResource();
    resource.setTransactionManager(manager);
    resource.setTransactionStatus(status);
    return resource; // for thread-fire's transaction or manual transaction
}

From source file:com.krawler.spring.common.CommonFnController.java

public ModelAndView saveUsers(HttpServletRequest request, HttpServletResponse response) {
    HashMap hm = null;//from w ww .j a  va 2 s . c o  m
    String msg = "";
    Boolean success = false;
    JSONObject jobj = new JSONObject();
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("CF_Tx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);

    TransactionStatus status = txnManager.getTransaction(def);
    try {
        hm = new FileUploadHandler().getItems(request);
        HashMap<String, Object> requestMap = generateMap(hm);
        KwlReturnObject rtObj = profileHandlerDAOObj.saveUser(requestMap);
        User usr = (User) rtObj.getEntityList().get(0);
        String imageName = ((FileItem) (hm.get("userimage"))).getName();
        if (StringUtil.isNullOrEmpty(imageName) == false) {
            String fileName = usr.getUserID() + FileUploadHandler.getImageExt();
            usr.setImage(ProfileImageServlet.ImgBasePath + fileName);
            new FileUploadHandler().uploadImage((FileItem) hm.get("userimage"), fileName,
                    StorageHandler.GetProfileImgStorePath(), 100, 100, false, false);
        }
        success = true;
        msg = messageSource.getMessage("acc.rem.189", null, RequestContextUtils.getLocale(request));
        txnManager.commit(status);
    } catch (ServiceException ex) {
        success = false;
        msg = ex.getMessage();
        txnManager.rollback(status);
        Logger.getLogger(CommonFnController.class.getName()).log(Level.SEVERE, "saveUsers", ex);
    } catch (Exception ex) {
        msg = "" + ex.getMessage();
        success = false;
        txnManager.rollback(status);
        Logger.getLogger(CommonFnController.class.getName()).log(Level.SEVERE, "saveUsers", ex);
    } finally {
        try {
            jobj.put("success", success);
            jobj.put("msg", msg);
        } catch (com.krawler.utils.json.base.JSONException ex) {
            Logger.getLogger(CommonFnController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    // }
    return new ModelAndView("jsonView_ex", "model", jobj.toString());
}

From source file:nz.co.senanque.functions.CustomerDAOImpl.java

@SuppressWarnings({ "unused", "unchecked" })
public void transactionTester() {
    final DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    // explicitly setting the transaction name is something that can only be done programmatically
    def.setName("SomeTxName");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    def.setReadOnly(true);/*from   ww  w  .j av a  2  s .c  o  m*/

    final TransactionStatus status = m_txManager.getTransaction(def);
    Session session = getSessionFactory().getCurrentSession();
    final Transaction transaction = session.getTransaction();
    Query query = session.createQuery("select p from nz.co.senanque.madura.sandbox.Customer p");
    List<Customer> customers = query.list();
    for (Customer customer : customers) {
        final Session session1 = getSessionFactory().openSession();
        final Session currentSession = getSessionFactory().getCurrentSession();
        final Transaction transaction1 = currentSession.getTransaction();
        getSubTransaction().process(customer);
    }

}