Package org.springframework.transaction.support

Examples of org.springframework.transaction.support.TransactionTemplate


        return (counter > 1 ? pb2 : pb1);
      }
    };

    assertTrue("Hasn't thread broker", !TransactionSynchronizationManager.hasResource(tm.getPbKey()));
    final TransactionTemplate tt = new TransactionTemplate(tm);
    tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
    tt.execute(new TransactionCallbackWithoutResult() {
      protected void doInTransactionWithoutResult(TransactionStatus status) {
        assertTrue("Has thread broker", TransactionSynchronizationManager.hasResource(tm.getPbKey()));
        assertEquals(pb1, OjbFactoryUtils.getPersistenceBroker(tm.getPbKey(), false));
        tt.execute(new TransactionCallbackWithoutResult() {
          protected void doInTransactionWithoutResult(TransactionStatus status) {
            assertTrue("Has thread broker", TransactionSynchronizationManager.hasResource(tm.getPbKey()));
            assertEquals(pb2, OjbFactoryUtils.getPersistenceBroker(tm.getPbKey(), false));
          }
        });
View Full Code Here


        return pb;
      }
    };
    tm.setDataSource(ds);

    TransactionTemplate tt = new TransactionTemplate(tm);
    assertTrue("Hasn't thread broker", !TransactionSynchronizationManager.hasResource(tm.getPbKey()));
    assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
    tt.execute(new TransactionCallbackWithoutResult() {
      protected void doInTransactionWithoutResult(TransactionStatus status) {
        assertTrue("Has thread broker", TransactionSynchronizationManager.hasResource(tm.getPbKey()));
        assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(ds));
        PersistenceBrokerTemplate pbt = new PersistenceBrokerTemplate();
        pbt.delete(entity);
View Full Code Here

  public void testGetSessionInsideTransaction() {
    log.info("getSessionInsideTransaction");
    final Map sessionMap = new HashMap();

    TransactionTemplate transactionTemplate = new TransactionTemplate(this.transactionManager);
    transactionTemplate.execute(new TransactionCallback() {
      public Object doInTransaction(TransactionStatus status) {
        JbpmSession firstSession = JbpmSessionFactoryUtils.getSession(jbpmSessionFactory);
        JbpmSession secondSession = JbpmSessionFactoryUtils.getSession(jbpmSessionFactory);
        sessionMap.put("first", firstSession);
        sessionMap.put("second", secondSession);
View Full Code Here

   * http://opensource2.atlassian.com/projects/spring/browse/MOD-78
   *
   */
  public void testJbpmSessionSynchronization(){
    log.info("jbpmSessionSynchronization");
    TransactionTemplate transactionTemplate = new TransactionTemplate(this.transactionManager);
    transactionTemplate.execute(new TransactionCallback() {
      public Object doInTransaction(TransactionStatus status) {
        JbpmTemplate jbpmTemplate = new JbpmTemplate(jbpmSessionFactory, processDefinition);

        jbpmTemplate.execute(new JbpmCallback() {
          public Object doInJbpm(JbpmSession session) {
View Full Code Here

    protected EntityManager createEntityManager() {
        return getEntityManagerFactory().createEntityManager();
    }

    protected TransactionTemplate createTransactionTemplate() {
        TransactionTemplate transactionTemplate = new TransactionTemplate(getTransactionManager());
        transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        transactionTemplate.afterPropertiesSet();
        return transactionTemplate;
    }
View Full Code Here

    public SpringTransactionPolicy(TransactionTemplate template) {
        this.template = template;
    }

    public Processor wrap(Processor processor) {
        final TransactionTemplate transactionTemplate = getTemplate();
        if (transactionTemplate == null) {
            LOG.warn("No TransactionTemplate available so transactions will not be enabled!");
            return processor;
        }
View Full Code Here

    public static JpaMessageIdRepository jpaMessageIdRepository(JpaTemplate jpaTemplate, String processorName) {
        return new JpaMessageIdRepository(jpaTemplate, processorName);
    }

    private static TransactionTemplate createTransactionTemplate(JpaTemplate jpaTemplate) {
        TransactionTemplate transactionTemplate = new TransactionTemplate();
        transactionTemplate.setTransactionManager(new JpaTransactionManager(jpaTemplate.getEntityManagerFactory()));
        transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        return transactionTemplate;
    }
View Full Code Here

        overdueEndpoint.setDefaulResultWaitMillis(8000);
    }

    protected RouteBuilder createRouteBuilder() throws Exception {
        JpaTemplate jpaTemplate = getMandatoryBean(JpaTemplate.class, "jpaTemplate");
        TransactionTemplate transactionTemplate = getMandatoryBean(TransactionTemplate.class, "transactionTemplate");

        // START SNIPPET: example
        return new ProcessBuilder(jpaTemplate, transactionTemplate) {
            public void configure() throws Exception {
View Full Code Here

    }
   
    protected void cleanupRepository() {
        jpaTemplate = (JpaTemplate)applicationContext.getBean("jpaTemplate", JpaTemplate.class);

        TransactionTemplate transactionTemplate = new TransactionTemplate();
        transactionTemplate.setTransactionManager(new JpaTransactionManager(jpaTemplate.getEntityManagerFactory()));
        transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);

        transactionTemplate.execute(new TransactionCallback() {
            public Object doInTransaction(TransactionStatus arg0) {
                List list = jpaTemplate.find(SELECT_ALL_STRING, PROCESSOR_NAME);
                for (Object item: list) {
                  jpaTemplate.remove(item);
                }
View Full Code Here

    public static JpaTemplateTransactionStrategy newInstance(EntityManagerFactory emf, JpaTemplate template) {
        JpaTransactionManager transactionManager = new JpaTransactionManager(emf);
        transactionManager.afterPropertiesSet();

        TransactionTemplate tranasctionTemplate = new TransactionTemplate(transactionManager);
        tranasctionTemplate.afterPropertiesSet();

        return new JpaTemplateTransactionStrategy(template, tranasctionTemplate);
    }
View Full Code Here

TOP

Related Classes of org.springframework.transaction.support.TransactionTemplate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.