Examples of TransactionTemplate


Examples of org.springframework.transaction.support.TransactionTemplate

   * 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

Examples of org.springframework.transaction.support.TransactionTemplate

    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

Examples of org.springframework.transaction.support.TransactionTemplate

    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

Examples of org.springframework.transaction.support.TransactionTemplate

    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

Examples of org.springframework.transaction.support.TransactionTemplate

        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

Examples of org.springframework.transaction.support.TransactionTemplate

    }
   
    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

Examples of org.springframework.transaction.support.TransactionTemplate

    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

Examples of org.springframework.transaction.support.TransactionTemplate

    protected void cleanupRepository() {
        // must type cast with Spring 2.x
        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<Boolean>() {
            public Boolean doInTransaction(TransactionStatus arg0) {
                @SuppressWarnings("rawtypes")
                List list = jpaTemplate.find(SELECT_ALL_STRING);
                for (Object item : list) {
                    jpaTemplate.remove(item);
View Full Code Here

Examples of org.springframework.transaction.support.TransactionTemplate

    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

Examples of org.springframework.transaction.support.TransactionTemplate

                                                                    new SerializablePlaceholderResolverStrategy( ClassObjectMarshallingStrategyAcceptor.DEFAULT )} );

        final KnowledgeStoreService kstore = (KnowledgeStoreService) ctx.getBean( "kstore1" );
        final KnowledgeBase kbRollback = (KnowledgeBase) ctx.getBean( "kbRollback" );

        TransactionTemplate txTemplate = new TransactionTemplate( txManager );
        final StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) txTemplate.execute( new TransactionCallback() {

            public Object doInTransaction(TransactionStatus status) {
                StatefulKnowledgeSession kNewSession = kstore.newStatefulKnowledgeSession( kbRollback,
                                                                                           null,
                                                                                           env );
                kNewSession.setGlobal( "list",
                                       list );
                kNewSession.insert( 1 );
                kNewSession.insert( 2 );
                return kNewSession;
            }
        } );

        final int sessionId = ksession.getId();

        txTemplate = new TransactionTemplate( txManager );
        txTemplate.execute( new TransactionCallback() {

            public Object doInTransaction(TransactionStatus status) {
                ksession.insert( 3 );
                status.setRollbackOnly();
                return null;
            }
        } );

        txTemplate = new TransactionTemplate( txManager );
        txTemplate.execute( new TransactionCallback() {

            public Object doInTransaction(TransactionStatus status) {
                ksession.fireAllRules();
                return null;
            }
        } );

        assertEquals( 2,
                      list.size() );

        txTemplate = new TransactionTemplate( txManager );
        txTemplate.execute( new TransactionCallback() {

            public Object doInTransaction(TransactionStatus status) {
                ksession.insert( 3 );
                ksession.insert( 4 );
                return null;
            }
        } );

        txTemplate = new TransactionTemplate( txManager );
        txTemplate.execute( new TransactionCallback() {

            public Object doInTransaction(TransactionStatus status) {
                ksession.insert( 5 );
                ksession.insert( 6 );
                status.setRollbackOnly();
                return null;
            }
        } );

        txTemplate = new TransactionTemplate( txManager );
        txTemplate.execute( new TransactionCallback() {

            public Object doInTransaction(TransactionStatus status) {
                ksession.fireAllRules();
                return null;
            }
        } );

        assertEquals( 4,
                      list.size() );

        ksession.dispose();

        // now load the ksession
        final StatefulKnowledgeSession ksession2 = JPAKnowledgeService.loadStatefulKnowledgeSession( sessionId,
                                                                                                     kbRollback,
                                                                                                     null,
                                                                                                     env );

        txTemplate = new TransactionTemplate( txManager );
        txTemplate.execute( new TransactionCallback() {

            public Object doInTransaction(TransactionStatus status) {
                ksession2.setGlobal( "list",
                                     list );
                ksession2.insert( 7 );
                ksession2.insert( 8 );
                return null;
            }
        } );

        txTemplate.execute( new TransactionCallback() {
            public Object doInTransaction(TransactionStatus status) {
                ksession2.fireAllRules();
                return null;
            }
        } );
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.