Example usage for org.springframework.transaction TransactionDefinition PROPAGATION_REQUIRED

List of usage examples for org.springframework.transaction TransactionDefinition PROPAGATION_REQUIRED

Introduction

In this page you can find the example usage for org.springframework.transaction TransactionDefinition PROPAGATION_REQUIRED.

Prototype

int PROPAGATION_REQUIRED

To view the source code for org.springframework.transaction TransactionDefinition PROPAGATION_REQUIRED.

Click Source Link

Document

Support a current transaction; create a new one if none exists.

Usage

From source file:org.ednovo.gooru.domain.service.storage.S3ResourceHandler.java

protected TransactionStatus initTransaction(String name, boolean isReadOnly) {

    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName(AUTHENTICATE_USER);//from w w  w.  j av  a 2  s . com
    if (isReadOnly) {
        def.setReadOnly(isReadOnly);
    } else {
        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    }

    return getTransactionManager().getTransaction(def);

}

From source file:org.fcrepo.camel.FcrepoEndpoint.java

/**
 * Create a template for use in transactions
 *
 * @return a transaction template/*from  ww w  .j  a  v a 2s. c o  m*/
 */
public TransactionTemplate createTransactionTemplate() {
    final TransactionTemplate transactionTemplate;

    if (getTransactionManager() != null) {
        transactionTemplate = new TransactionTemplate(getTransactionManager());
    } else {
        final FcrepoTransactionManager txMgr = new FcrepoTransactionManager();
        txMgr.setBaseUrl(getBaseUrlWithScheme());
        txMgr.setAuthUsername(getAuthUsername());
        txMgr.setAuthPassword(getAuthPassword());
        txMgr.setAuthHost(getAuthHost());
        transactionTemplate = new TransactionTemplate(txMgr);
    }
    transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    transactionTemplate.afterPropertiesSet();
    return transactionTemplate;
}

From source file:org.opoo.oqs.spring.transaction.SpringJdbcTransaction.java

public void begin() throws TransactionException {
    log.debug("begin");

    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);

    status = transactionManager.getTransaction(def);
    begun = true;// w ww .  jav  a  2s. c om
}

From source file:org.sakaiproject.coursemanagement.impl.SampleDataLoader.java

public void init() {
    log.info("Initializing " + getClass().getName());
    if (cmAdmin == null) {
        return;/*from w w  w  . j  a  v a  2  s.  c  o  m*/
    }
    if (loadSampleData) {
        loginToSakai();
        PlatformTransactionManager tm = (PlatformTransactionManager) beanFactory
                .getBean("org.sakaiproject.springframework.orm.hibernate.GlobalTransactionManager");
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus status = tm.getTransaction(def);
        try {
            load();
        } catch (Exception e) {
            log.error("Unable to load CM data: " + e);
            tm.rollback(status);
        } finally {
            if (!status.isCompleted()) {
                tm.commit(status);
            }
        }
        logoutFromSakai();
    } else {
        if (log.isInfoEnabled())
            log.info("Skipped CM data load");
    }
}

From source file:org.sakaiproject.coursemanagement.test.performance.IndexPerformance.java

public void loadLotsOfData() {
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus status = tm.getTransaction(def);

    try {/*from   w  ww .j  a  va2 s  .  c o m*/
        String asId = "IndexPerf AS";
        cmAdmin.createAcademicSession(asId, asId, asId, null, null);

        String csId = "IndexPerf CS";
        cmAdmin.createCourseSet(csId, csId, csId, "DEPT", null);

        String ccId = "IndexPerf CC";
        cmAdmin.createCanonicalCourse(ccId, ccId, ccId);

        String coId = "IndecPerf CO";
        cmAdmin.createCourseOffering(coId, csId, csId, "open", asId, ccId, null, null);

        for (int i = 1; i <= secCount; i++) {
            String esId = esPrefix + i;
            Set<String> instructors = new HashSet<String>();
            instructors.add("instructor_A_" + i);
            instructors.add("instructor_B_" + i);
            instructors.add("instructor_C_" + i);
            cmAdmin.createEnrollmentSet(esId, esId, esId, "lecture", "3", coId, instructors);
        }

        for (int i = 1; i <= secCount; i++) {
            String secId = secPrefix + i;
            cmAdmin.createSection(secId, secId, secId, "lecture", null, coId, (esPrefix + i));
        }

        for (int i = 1; i <= secCount; i++) {
            for (int j = 1; j <= enrollmentsPerEnrollmentSet; j++) {
                cmAdmin.addOrUpdateEnrollment("student" + j, esPrefix + i, "enrolled", "3", "letter grade");
            }
        }

        for (int i = 1; i <= secCount; i++) {
            for (int j = 1; j <= membersPerSection; j++) {
                cmAdmin.addOrUpdateSectionMembership("student" + j, "some role", secPrefix + i, "some status");
            }
        }
    } catch (Exception e) {
        tm.rollback(status);
    } finally {
        if (!status.isCompleted()) {
            tm.commit(status);
        }
    }
}

From source file:org.skife.jdbi.spring.TestSpringIntegration.java

public void testDBIUtilsSameHandleInTx() throws Exception {
    final DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    final PlatformTransactionManager ptm = (PlatformTransactionManager) ctx.getBean("transactionManager");
    final TransactionStatus status = ptm.getTransaction(def);

    final IDBI dbi = (IDBI) ctx.getBean("dbi");

    Handle one = DBIUtils.getHandle(dbi);
    Handle two = DBIUtils.getHandle(dbi);

    assertSame(one, two);/*from  w  ww  . j a  v  a 2  s  .co  m*/

    ptm.commit(status);
}

From source file:org.skife.jdbi.spring.TestSpringIntegration.java

public void testSuspendAndResumeTx() throws Exception {
    final DefaultTransactionDefinition prop_req = new DefaultTransactionDefinition();
    prop_req.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    final PlatformTransactionManager ptm = (PlatformTransactionManager) ctx.getBean("transactionManager");
    final TransactionStatus prop_req_status = ptm.getTransaction(prop_req);

    final IDBI dbi = (IDBI) ctx.getBean("dbi");

    final Handle one = DBIUtils.getHandle(dbi);

    final DefaultTransactionDefinition req_new = new DefaultTransactionDefinition();
    req_new.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);

    // REQUIRES_NEW inside PROPAGATION_REQUIRED
    final TransactionStatus req_new_status = ptm.getTransaction(req_new);

    final Handle two = DBIUtils.getHandle(dbi);
    assertNotSame(one, two);//from   ww w.j  a v a2 s .c  om

    ptm.commit(req_new_status);
    ptm.commit(prop_req_status);
}

From source file:org.skife.jdbi.spring.TestSpringIntegration.java

public void testCloseIfNecessaryNotNecesarry() throws Exception {
    final DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    final PlatformTransactionManager ptm = (PlatformTransactionManager) ctx.getBean("transactionManager");
    final TransactionStatus status = ptm.getTransaction(def);

    final IDBI dbi = (IDBI) ctx.getBean("dbi");

    Handle one = DBIUtils.getHandle(dbi);

    DBIUtils.closeHandleIfNecessary(one, dbi);
    assertTrue(one.isOpen());/*w  ww .  j a  va2s .c om*/

    ptm.commit(status);
    assertFalse(one.isOpen());
}

From source file:org.skife.jdbi.spring.TestSpringIntegration.java

public void testHandleCallbackUsesTxHandle() throws Exception {
    final DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    final PlatformTransactionManager ptm = (PlatformTransactionManager) ctx.getBean("transactionManager");
    final TransactionStatus status = ptm.getTransaction(def);

    final IDBI dbi = (IDBI) ctx.getBean("dbi");

    final Handle outer = DBIUtils.getHandle(dbi);

    dbi.open(new HandleCallback() {
        public void withHandle(Handle handle) throws Exception {
            assertSame(outer, handle);/*  w ww.  j av a2s  .c om*/
        }
    });

    ptm.commit(status);
}

From source file:org.skife.jdbi.spring.TestSpringIntegration.java

public void testExceptionInHandleCallbackRollsbackTx() throws Exception {
    final DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    final PlatformTransactionManager ptm = (PlatformTransactionManager) ctx.getBean("transactionManager");
    final TransactionStatus status = ptm.getTransaction(def);

    final IDBI dbi = (IDBI) ctx.getBean("dbi");

    try {//  ww w . j av  a 2s .  c  om
        dbi.open(new HandleCallback() {
            public void withHandle(Handle handle) throws Exception {
                throw new UnsupportedOperationException("Not yet implemented!");
            }
        });
        fail("Should have thrown exception");
    } catch (DBIException e) {
        assertTrue(true);
    }

    ptm.rollback(status);
}