Package org.springframework.transaction.support

Examples of org.springframework.transaction.support.AbstractPlatformTransactionManager


        context = new ClassPathXmlApplicationContext("jbpm/jpa-local-lane/jpa-spring.xml");


        EntityManagerFactory emf = (EntityManagerFactory) context.getBean("jbpmEMF");
        AbstractPlatformTransactionManager aptm = (AbstractPlatformTransactionManager) context.getBean( "jbpmTxManager" );

        Properties auth = new Properties();
        auth.setProperty("max", "Standard");

        UserGroupCallback userGroupCallback = new JBossUserGroupCallbackImpl(auth);

        RuntimeEnvironment environment = RuntimeEnvironmentBuilder.getDefault()
                .entityManagerFactory(emf)
                .userGroupCallback(userGroupCallback)
                .addAsset(ResourceFactory.newClassPathResource("jbpm/processes/sample1.bpmn2"), ResourceType.BPMN2)
                .addEnvironmentEntry(EnvironmentName.TRANSACTION_MANAGER, aptm)
                .get();

        RuntimeManager manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
        RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());

        KieSession ksession = engine.getKieSession();
        TaskService taskService = engine.getTaskService();

        Map<String,Object> params = new HashMap<String,Object>();
        params.put("userid", "max");
        ProcessInstance processInstance = ksession.startProcess("agu.samples.sample1", params);

        AuditLogService logService = (AuditLogService) context.getBean("logService");
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        TransactionStatus status = aptm.getTransaction(def);
        ProcessInstanceLog log = logService.findProcessInstance(processInstance.getId());
        assertNotNull(log);
        aptm.commit(status);

        List<TaskSummary> tasks = taskService.getTasksOwned("max", "en-UK");
        System.out.println("Found " + tasks.size() + " task(s) for user 'max'");

        long taskId = tasks.get(0).getId();
View Full Code Here


    public void testSpringWithJTAAndEMF() throws Exception{


        context = new ClassPathXmlApplicationContext("jbpm/local-emf/local-emf-spring.xml");

        AbstractPlatformTransactionManager aptm = (AbstractPlatformTransactionManager) context.getBean( "jbpmTxManager" );
        RuntimeManager manager = (RuntimeManager) context.getBean("runtimeManager");

        RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
        KieSession ksession = engine.getKieSession();
        TaskService taskService = engine.getTaskService();

        int ksessionId = ksession.getId();

        ProcessInstance processInstance = ksession.startProcess("com.sample.bpmn.hello");

        System.out.println("Process started");

        manager.disposeRuntimeEngine(engine);

        engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
        ksession = engine.getKieSession();
        taskService = engine.getTaskService();

        assertEquals(ksessionId, ksession.getId());

        AuditLogService logService = (AuditLogService) context.getBean("logService");
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        TransactionStatus status = aptm.getTransaction(def);
        ProcessInstanceLog log = logService.findProcessInstance(processInstance.getId());
        aptm.commit(status);
        assertNotNull(log);

        List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
        System.out.println("Found " + tasks.size() + " task(s) for user 'john'");
        assertEquals(1, tasks.size());
View Full Code Here

    public void testSpringWithJTAAndEMFwithRollback() throws Exception{


        context = new ClassPathXmlApplicationContext("jbpm/local-emf/local-emf-spring.xml");

        AbstractPlatformTransactionManager aptm = (AbstractPlatformTransactionManager) context.getBean( "jbpmTxManager" );
        RuntimeManager manager = (RuntimeManager) context.getBean("runtimeManager");

        RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
        KieSession ksession = engine.getKieSession();
        TaskService taskService = engine.getTaskService();


        AuditLogService logService = (AuditLogService) context.getBean("logService");

        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        TransactionStatus status = aptm.getTransaction(def);
        ProcessInstance processInstance = ksession.startProcess("com.sample.bpmn.hello");
        long processInstanceId = processInstance.getId();
        aptm.rollback(status);

        processInstance = ksession.getProcessInstance(processInstanceId);

        if (processInstance == null) {
            System.out.println("Process instance rolled back");
        } else {
            throw new IllegalArgumentException("Process instance not rolled back");
        }

        List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
        System.out.println("Found " + tasks.size() + " task(s) for user 'john'");
        assertEquals(0, tasks.size());

        def = new DefaultTransactionDefinition();
        status = aptm.getTransaction(def);
        ProcessInstanceLog log = logService.findProcessInstance(processInstanceId);
        aptm.commit(status);
        assertNull(log);
    }
View Full Code Here

        // check that there is no sessions in db
        List<?> sessions = em.createQuery("from SessionInfo").getResultList();
        assertNotNull(sessions);
        assertEquals(0, sessions.size());

        AbstractPlatformTransactionManager aptm = (AbstractPlatformTransactionManager) context.getBean( "jbpmTxManager" );
        RuntimeManager manager = (RuntimeManager) context.getBean("runtimeManager");

        // after creating per process instance manager init creates temp session that shall be directly destroyed
        sessions = em.createQuery("from SessionInfo").getResultList();
        assertNotNull(sessions);
        assertEquals(0, sessions.size());

        RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
        KieSession ksession = engine.getKieSession();
        TaskService taskService = engine.getTaskService();

        ProcessInstance processInstance = ksession.startProcess("com.sample.bpmn.hello");

        System.out.println("Process started");

        AuditLogService logService = (AuditLogService) context.getBean("logService");
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        TransactionStatus status = aptm.getTransaction(def);
        ProcessInstanceLog log = logService.findProcessInstance(processInstance.getId());
        aptm.commit(status);
        assertNotNull(log);

        List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
        System.out.println("Found " + tasks.size() + " task(s) for user 'john'");
        assertEquals(1, tasks.size());
View Full Code Here

    public void testSpringWithJTAAndEMwithRollback() throws Exception{


        context = new ClassPathXmlApplicationContext("jbpm/local-em/local-em-spring.xml");

        AbstractPlatformTransactionManager aptm = (AbstractPlatformTransactionManager) context.getBean( "jbpmTxManager" );
        RuntimeManager manager = (RuntimeManager) context.getBean("runtimeManager");

        RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
        KieSession ksession = engine.getKieSession();
        TaskService taskService = engine.getTaskService();


        AuditLogService logService = (AuditLogService) context.getBean("logService");

        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        TransactionStatus status = aptm.getTransaction(def);
        ProcessInstance processInstance = ksession.startProcess("com.sample.bpmn.hello");
        long processInstanceId = processInstance.getId();
        aptm.rollback(status);

        processInstance = ksession.getProcessInstance(processInstanceId);

        if (processInstance == null) {
            System.out.println("Process instance rolled back");
        } else {
            throw new IllegalArgumentException("Process instance not rolled back");
        }

        List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
        System.out.println("Found " + tasks.size() + " task(s) for user 'john'");
        assertEquals(0, tasks.size());

        def = new DefaultTransactionDefinition();
        status = aptm.getTransaction(def);
        ProcessInstanceLog log = logService.findProcessInstance(processInstanceId);
        aptm.commit(status);
        assertNull(log);
    }
View Full Code Here

  protected int springPropagationBehaviour = TransactionDefinition.PROPAGATION_REQUIRED;
  private String transactionManagerName;

  @SuppressWarnings("unchecked")
  public <T> T execute(Command<T> command) {
    AbstractPlatformTransactionManager platformTransactionManager = (AbstractPlatformTransactionManager) resolveTransactionManager();
    TransactionTemplate template = new TransactionTemplate(platformTransactionManager);
    template.setPropagationBehavior(springPropagationBehaviour);
    return (T) template.execute(new SpringCommandCallback(next, command));
   
//    TransactionStatus transactionStatus = platformTransactionManager.getTransaction(transactionDefinition);
View Full Code Here

   * @return the transaction manager, not null
   */
  protected PlatformTransactionManager createTransactionManager(SessionFactory sessionFactory) {
    PlatformTransactionManager transMgr = getTransactionManager();
    if (transMgr == null) {
      AbstractPlatformTransactionManager newTransMgr;
      if (sessionFactory != null) {
        newTransMgr = new HibernateTransactionManager(sessionFactory);
      } else {
        newTransMgr = new DataSourceTransactionManager(getDataSource());
      }
      newTransMgr.setNestedTransactionAllowed(true);
      transMgr = newTransMgr;
    }
    return transMgr;
  }
View Full Code Here

   *
   * @param hibernateSessionFactory  the Hibernate session factory, may be null
   * @return the transaction manager, not null
   */
  protected PlatformTransactionManager createTransactionManager(SessionFactory hibernateSessionFactory) {
    AbstractPlatformTransactionManager newTransMgr;
    if (hibernateSessionFactory == null) {
      newTransMgr = new DataSourceTransactionManager(getDataSource());
    } else {
      newTransMgr = new HibernateTransactionManager(hibernateSessionFactory);
    }
    newTransMgr.setNestedTransactionAllowed(true);
    return newTransMgr;
  }
View Full Code Here

public class RabbitTemplateTests {

  @Test
  public void returnConnectionAfterCommit() throws Exception {
    @SuppressWarnings("serial")
    TransactionTemplate txTemplate = new TransactionTemplate(new AbstractPlatformTransactionManager() {

      @Override
      protected Object doGetTransaction() throws TransactionException {
        return new Object();
      }
View Full Code Here

TOP

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

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.