Package org.springframework.transaction.support

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


    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

                                                                    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

    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

        return answer;
    }

    public TransactionTemplate getTemplate() {
        if (template == null) {
            template = new TransactionTemplate(transactionManager);
            if (propagationBehaviorName != null) {
                template.setPropagationBehaviorName(propagationBehaviorName);
            }
        }
        return template;
View Full Code Here

        overdueEndpoint.assertIsSatisfied();
    }

    protected void sendAMessages() {
        TransactionTemplate transaction = getMandatoryBean(TransactionTemplate.class, "transactionTemplate");
        transaction.execute(new TransactionCallbackWithoutResult() {
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                template.sendBody("seda:a", "<hello id='123'>A</hello>");
                template.sendBody("seda:a", "<hello id='124'>B</hello>");
                template.sendBody("seda:a", "<hello id='125'>C</hello>");
            }
View Full Code Here

            }
        });
    }

    protected void sendBMessages() {
        TransactionTemplate transaction = getMandatoryBean(TransactionTemplate.class, "transactionTemplate");
        transaction.execute(new TransactionCallbackWithoutResult() {
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                template.sendBody("seda:b", "<hello id='123'>A</hello>");
                template.sendBody("seda:b", "<hello id='125'>C</hello>");
            }
        });
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

    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

    }

    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

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.