Package org.springframework.transaction.support

Examples of org.springframework.transaction.support.TransactionCallback


  public static final String HIBERNATE_HOTEL_ADDRESS = "Hibernate Address";

  private TransactionTemplate hibernateTransactionTemplate;

  public void testHibernateIntegration() {
    hibernateTransactionTemplate.execute(new TransactionCallback() {
      public Object doInTransaction(TransactionStatus status) {
        // Testing access through HibernateTemplate
        Hotel hotel = (Hotel)getHibernateTemplate().execute(new HibernateCallback() {
          public Object doInHibernate(org.hibernate.Session session) throws HibernateException, SQLException {
            return getFirstHotel(session);
          }
        });
        hotel.setName(HIBERNATE_HOTEL_NAME);
        return null;
      }
    });
    hibernateTransactionTemplate.execute(new TransactionCallback() {
      public Object doInTransaction(TransactionStatus status) {
        // Testing access through SessionFactory.getCurrentSession()
        Hotel hotel = getFirstHotel(getSessionFactory().getCurrentSession());
        if (!HIBERNATE_HOTEL_NAME.equals(hotel.getName())) {
          throw new RuntimeException("Hotel name not set.  Hibernate integration not working.");
        }
        hotel.setAddress(HIBERNATE_HOTEL_ADDRESS);
        return null;
      }
    });
    hibernateTransactionTemplate.execute(new TransactionCallback() {
      public Object doInTransaction(TransactionStatus status) {
        // Testing access through SessionFactory.getCurrentSession()
        Hotel hotel = getFirstHotel(getSessionFactory().getCurrentSession());
        if (!HIBERNATE_HOTEL_ADDRESS.equals(hotel.getAddress())) {
          throw new RuntimeException("Hotel address not set.  Hibernate integration not working.");
View Full Code Here


  public void testStatefulInTransaction() {
    final Jsr94Template template = getTemplate("ruleSource");
    final Jsr94TransactionManager transactionManager = new Jsr94TransactionManager();
    transactionManager.setRuleSource(template.getRuleSource());
    final TransactionTemplate txTemplate = new TransactionTemplate(transactionManager);
    List result = (List) txTemplate.execute(new TransactionCallback() {

          /* (non-Javadoc)
           * @see org.springframework.transaction.support.TransactionCallback#doInTransaction(org.springframework.transaction.TransactionStatus)
           */
          public Object doInTransaction(TransactionStatus status) {
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

   *
   */
  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

        return transactionTemplate;
    }

    public boolean contains(final String messageId) {
        // Run this in single transaction.
        Boolean rc = (Boolean)transactionTemplate.execute(new TransactionCallback() {
            public Object doInTransaction(TransactionStatus arg0) {

                List list = jpaTemplate.find(QUERY_STRING, processorName, messageId);
                if (list.isEmpty()) {
                    MessageProcessed processed = new MessageProcessed();
View Full Code Here

        Object entity = null;
        for (int i = 0; entity == null && i < maximumRetries; i++) {
            if (i > 0) {
                LOG.info("Retry attempt due to duplicate row: " + i);
            }
            entity = transactionTemplate.execute(new TransactionCallback() {
                public Object doInTransaction(TransactionStatus status) {
                    try {
                        Object key = getCorrelationKey(exchange);

                        T entity = loadEntity(exchange, key);
View Full Code Here

        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

        return new JpaTemplateTransactionStrategy(template, tranasctionTemplate);
    }

    public Object execute(final JpaCallback callback) {
        return transactionTemplate.execute(new TransactionCallback() {
            public Object doInTransaction(TransactionStatus status) {
                return jpaTemplate.execute(new JpaCallback() {
                    public Object doInJpa(EntityManager entityManager) throws PersistenceException {
                        return callback.doInJpa(entityManager);
                    }
View Full Code Here

        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

                } catch (InterruptedException e) {
                    LOG.debug("Caught: " + e, e);
                }
            }
            try {
                transactionTemplate.execute(new TransactionCallback() {
                    public Object doInTransaction(TransactionStatus status) {
                        try {
                            Object key = getCorrelationKey(exchange);

                            T entity = loadEntity(exchange, key);
View Full Code Here

TOP

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

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.