Example usage for org.springframework.transaction.support TransactionCallback TransactionCallback

List of usage examples for org.springframework.transaction.support TransactionCallback TransactionCallback

Introduction

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

Prototype

TransactionCallback

Source Link

Usage

From source file:de.hybris.platform.yb2bacceleratortest.orders.B2BAcceleratorTestOrderData.java

protected String placeOrderAndApproveByB2BApprover(final String userID, final String purchaseOrderNumber) {
    LOG.debug(String.format(//w ww  .ja va  2s .  co m
            "******************Starting Attempt to setup and create order for PONumber: %s for " + "%s ",
            purchaseOrderNumber, userID));

    final TransactionTemplate template = new TransactionTemplate(getTransactionManager());
    template.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRED);
    return template.execute(new TransactionCallback<String>() {
        @Override
        public String doInTransaction(final TransactionStatus status) {
            String orderCode = null;
            final Map<String, Long> products = new HashMap<String, Long>();
            products.put(PRODUCT_C, Long.valueOf(5));
            final OrderData orderData = placeOrder(userID, products, createUsAddressData(), purchaseOrderNumber,
                    YB2BAcceleratorTestConstants.STANDARD_COSTCENTER, null);

            orderCode = orderData == null ? null : orderData.getCode();

            if (orderCode != null) {
                b2bApproverApproveThisOrder(orderCode);
            }
            return orderCode;
        }
    });
}

From source file:com.mitre.test.orders.B2BAcceleratorTestOrderData.java

protected String placeOrderAndApproveByB2BApprover(final String userID, final String purchaseOrderNumber) {
    LOG.debug(String.format(/*from ww  w  . j a  va  2 s.  co  m*/
            "******************Starting Attempt to setup and create order for PONumber: %s for " + "%s ",
            purchaseOrderNumber, userID));

    final TransactionTemplate template = new TransactionTemplate(getTransactionManager());
    template.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRED);
    return template.execute(new TransactionCallback<String>() {
        @Override
        public String doInTransaction(final TransactionStatus status) {
            String orderCode = null;
            final Map<String, Long> products = new HashMap<String, Long>();
            products.put(PRODUCT_C, Long.valueOf(5));
            final OrderData orderData = placeOrder(userID, products, createUsAddressData(), purchaseOrderNumber,
                    MitreTestConstants.STANDARD_COSTCENTER, null);

            orderCode = orderData == null ? null : orderData.getCode();

            if (orderCode != null) {
                b2bApproverApproveThisOrder(orderCode);
            }
            return orderCode;
        }
    });
}

From source file:com.jnj.b2b.test.orders.B2BAcceleratorTestOrderData.java

protected String placeOrderAndApproveByB2BApprover(final String userID, final String purchaseOrderNumber) {
    LOG.debug(String.format(//from   w  w w .ja  v  a  2 s  .c  o  m
            "******************Starting Attempt to setup and create order for PONumber: %s for " + "%s ",
            purchaseOrderNumber, userID));

    final TransactionTemplate template = new TransactionTemplate(getTransactionManager());
    template.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRED);
    return template.execute(new TransactionCallback<String>() {
        @Override
        public String doInTransaction(final TransactionStatus status) {
            String orderCode = null;
            final Map<String, Long> products = new HashMap<String, Long>();
            products.put(PRODUCT_C, Long.valueOf(5));
            final OrderData orderData = placeOrder(userID, products, createUsAddressData(), purchaseOrderNumber,
                    Jnjb2bTestConstants.STANDARD_COSTCENTER, null);

            orderCode = orderData == null ? null : orderData.getCode();

            if (orderCode != null) {
                b2bApproverApproveThisOrder(orderCode);
            }
            return orderCode;
        }
    });
}

From source file:com.octanner.test.orders.B2BAcceleratorTestOrderData.java

protected String placeOrderAndApproveByB2BApprover(final String userID, final String purchaseOrderNumber) {
    LOG.debug(String.format(/*from w w  w  . j av a2 s  . c  om*/
            "******************Starting Attempt to setup and create order for PONumber: %s for " + "%s ",
            purchaseOrderNumber, userID));

    final TransactionTemplate template = new TransactionTemplate(getTransactionManager());
    template.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRED);
    return template.execute(new TransactionCallback<String>() {
        @Override
        public String doInTransaction(final TransactionStatus status) {
            String orderCode = null;
            final Map<String, Long> products = new HashMap<String, Long>();
            products.put(PRODUCT_C, Long.valueOf(5));
            final OrderData orderData = placeOrder(userID, products, createUsAddressData(), purchaseOrderNumber,
                    OctannerTestConstants.STANDARD_COSTCENTER, null);

            orderCode = orderData == null ? null : orderData.getCode();

            if (orderCode != null) {
                b2bApproverApproveThisOrder(orderCode);
            }
            return orderCode;
        }
    });
}

From source file:gov.nih.nci.ncicb.tcga.dcc.dam.dao.DAMQueriesLevel2.java

/**
 * Return a {@link List} of {@link DataFile} associated with the given {@link DataSet}s.
 *
 * Note: it is assumed that those {@link DataSet}s are all for 1 single disease type.
 *
 * @param selectedDataSets the {@link DataSet}s
 * @param consolidateFiles whether data for selected data sets should be consolidated into as few files as possible
 * or put in one file per sample//www . j  av a  2 s .c om
 * @return a {@link List} of {@link DataFile} associated with the given {@link DataSet}s
 * @throws DAMQueriesException
 */
private List<DataFile> getFileInfoForSelectedDataSetsUniqueDisease(final List<DataSet> selectedDataSets,
        final boolean consolidateFiles) throws DAMQueriesException {

    final List<DataFile> dataFiles = new ArrayList<DataFile>();

    final Map<String, DataSetLevelTwoThree> barcodeDataSetMap = getBarcodesForDataSets(selectedDataSets);

    final Set<String> platformIds = new HashSet<String>();
    for (DataSet dataSet : selectedDataSets) {
        if (dataSet.getPlatformId() != null && !StringUtils.isEmpty(dataSet.getPlatformId())) {
            platformIds.add(dataSet.getPlatformId());
        }
    }

    if (barcodeDataSetMap.size() > 0) {
        final List<String> barcodes = new ArrayList(barcodeDataSetMap.keySet());

        transactionTemplate.execute(new TransactionCallback() {
            public Object doInTransaction(final TransactionStatus transactionStatus) {
                // insert barcodes into temp table
                insertBarcodesInToTmpTable(barcodes);
                final ParameterizedRowMapper<DataFile> mapper = new ParameterizedRowMapper<DataFile>() {
                    public DataFile mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        final DataSet dataSet = barcodeDataSetMap.get(rs.getString(5));
                        final DataFile dataFile = new DataFileLevelTwo();
                        dataFile.setFileId(rs.getString(1));
                        dataFile.setFileName(rs.getString(2));
                        dataFile.setSize(rs.getLong(3));
                        dataFile.setPath(rs.getString(4));
                        dataFile.setPlatformTypeId(dataSet.getPlatformTypeId());
                        dataFile.setCenterId(dataSet.getCenterId());
                        dataFile.setPlatformId(dataSet.getPlatformId());
                        dataFile.setDisplaySample(dataSet.getSample());
                        dataFile.setProtected(dataSet.isProtected());
                        dataFile.setBarcodes(dataSet.getBarcodes());
                        dataFile.setPermanentFile(true);
                        dataFile.setDiseaseType(dataSet.getDiseaseType());
                        return dataFile;
                    }
                };
                // get data files
                final MapSqlParameterSource parameter = new MapSqlParameterSource();
                parameter.addValue("platformids", platformIds);
                final SimpleJdbcTemplate jdbc = new SimpleJdbcTemplate(getDataSource());
                dataFiles.addAll(jdbc.query(FILE_INFO_QUERY, mapper, parameter));
                return null;
            }
        });

        if (consolidateFiles) {

            return buildConsolidatedFiles(dataFiles, barcodeDataSetMap.get(barcodes.get(0)));
        }
    }
    return dataFiles;
}

From source file:org.openvpms.component.business.service.archetype.ArchetypeServiceActTestCase.java

/**
 * Verifies that related acts can be saved individually, but in the one
 * transaction.//from  w  w w  .j a  va 2 s .  c o  m
 */
@Test
public void testSaveRelatedActsInTxn() {
    // Create 2 acts with the following relationship:
    // act1 -- (parent/child) --> act2
    final Act act1 = createSimpleAct("act1", "IN_PROGRESS");
    final Act act2 = createSimpleAct("act2", "IN_PROGRESS");
    addRelationship(act1, act2, "act1->act2", true);

    // now try to save each act within a transaction.
    template.execute(new TransactionCallback<Object>() {
        public Object doInTransaction(TransactionStatus status) {
            save(act1);
            // act has been saved, but the identifier cannot be assigned
            // until the related act is also saved
            assertEquals(-1, act1.getId());

            save(act2);

            // identifiers should have updated
            assertFalse(act1.getId() == -1);
            assertFalse(act2.getId() == -1);
            return null;
        }
    });
}

From source file:com.github.rholder.spring.transaction.TransactionBindingSupportTest.java

@Test
public void testResourceHelperList() throws Exception {

    // run this in a transaction        
    transactionTemplate.execute(new TransactionCallback() {

        public Object doInTransaction(TransactionStatus status) {
            List<String> list = TransactionalResourceHelper.getList("abc");
            Assert.assertNotNull("List not created", list);
            list.add("ONE");

            List<String> listCheck = TransactionalResourceHelper.getList("abc");
            Assert.assertTrue("Same list not retrieved", list == listCheck);
            return null;
        }//from  www.ja  va2s  .c o  m
    });
}

From source file:com.devnexus.ting.core.service.impl.BusinessServiceImpl.java

/**
 * {@inheritDoc}//w w  w  .j  a v  a 2 s .co  m
 */
@Override
public List<Speaker> getSpeakersForCurrentEvent() {

    final List<Speaker> speakers = transactionTemplate.execute(new TransactionCallback<List<Speaker>>() {
        public List<Speaker> doInTransaction(TransactionStatus status) {
            return speakerDao.getSpeakersForCurrentEvent();
        }
    });

    return speakers;

}

From source file:org.tibetjungle.demo.service.DataSourcePopulator.java

private void updateAclInTransaction(final MutableAcl acl) {
    tt.execute(new TransactionCallback<Object>() {
        public Object doInTransaction(TransactionStatus arg0) {
            mutableAclService.updateAcl(acl);

            return null;
        }//from   w ww .j  a  va 2  s . c  om
    });
}

From source file:org.jspresso.hrsample.backend.JspressoUnitOfWorkTest.java

/**
 * Tests sanity check on linked components. See bug #846.
 *//*  ww w.  j a  va  2 s .  co m*/
@Test(expected = BackendException.class)
public void testSanityChecksOnComponents() {
    final HibernateBackendController hbc = (HibernateBackendController) getBackendController();
    final TransactionTemplate tt = hbc.getTransactionTemplate();

    Employee emp = tt.execute(new TransactionCallback<Employee>() {

        /**
         * {@inheritDoc}
         */
        @Override
        public Employee doInTransaction(TransactionStatus status) {
            DetachedCriteria empCrit = DetachedCriteria.forClass(Employee.class);
            return (Employee) empCrit.getExecutableCriteria(hbc.getHibernateSession()).list().iterator().next();
        }
    });
    // From here, any modification on employee should result in an exception
    // since this instance of employee is not merged in session.
    // The exception should also occur on component (contact) properties
    // modification.
    emp.getContact().setAddress("test");
}