Package org.springframework.transaction.support

Examples of org.springframework.transaction.support.TransactionCallback


    l.add("test");

    assertTrue(!TransactionSynchronizationManager.hasResource(factory));
    assertTrue(!TransactionSynchronizationManager.isSynchronizationActive());

    Object result = tt.execute(new TransactionCallback() {
      public Object doInTransaction(TransactionStatus status) {
        assertTrue(TransactionSynchronizationManager.hasResource(factory));
        assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
        return template.execute(new JpaCallback() {
          public Object doInJpa(EntityManager em) {
View Full Code Here


   
    TransactionTemplate transactionTemplate =
      new TransactionTemplate(transactionManager);
   
    transactionTemplate.execute(
        new TransactionCallback() {
          public Object doInTransaction(TransactionStatus ts) {
            Employee employee =  employeeDao.readExclusive(testEmployees.get(0).getId());
            AssertJUnit.assertNotNull("Employee for id=1 not read.", employee);
            return null;
          }
View Full Code Here

   
  @Test (groups="createsObjectInDB")
    public void testStoreMultiple() {
        employeeDao.flushAndClear();
      TransactionTemplate xTemplate = new TransactionTemplate(transactionManager);
      xTemplate.execute(new TransactionCallback() {
   
      public Object doInTransaction(TransactionStatus arg0) {
            List<Employee> employees =Arrays.asList(
                new Employee[] {
                    new Employee("StoreMultipleOne", "Hightower"),
View Full Code Here

        final String sql = "INSERT INTO " + this.currentTable + " (" + columns + ") VALUES (" + parameters + ")";
        if (this.logger.isInfoEnabled()) {
            this.logger.info(sql + "\t" + Arrays.asList(values) + "\t" + Arrays.asList(ArrayUtils.toObject(types)));
        }

        this.transactionTemplate.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

    return new String[] { "org/jencks/samples/outbound/jencks-genericjmsra.xml" };
  }

  protected void checkIfMessageExist(final String sentMessage) {
    TransactionTemplate tt = new TransactionTemplate(getTransactionManager());
    tt.execute(new TransactionCallback() {
      public Object doInTransaction(TransactionStatus status) {
        JmsTemplate template=new JmsTemplate(getConnectionFactory());
        template.setReceiveTimeout(10);
        String receivedMessage=(String)template.receiveAndConvert(getQueue());
        assertEquals(sentMessage,receivedMessage);
View Full Code Here

    });
  }

  protected void checkIfMessageNotExist() {
    TransactionTemplate tt = new TransactionTemplate(getTransactionManager());
    tt.execute(new TransactionCallback() {
      public Object doInTransaction(TransactionStatus status) {
        JmsTemplate template=new JmsTemplate(getConnectionFactory());
        template.setReceiveTimeout(10);
        String receivedMessage=null;
        receivedMessage=(String)template.receiveAndConvert(getQueue());
View Full Code Here

     * 创建流程实例,并执行实例的run方法。
     */
    @Test
    public void testStartNewProcess() {
        System.out.println("--------------Start a new process ----------------");
        currentProcessInstance = (IProcessInstance) transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    //启动"/workflowdefinition/example_workflow.xml"中的“送货流程”
View Full Code Here

    /**
     * 在当前workitem 还处于活动状态时作取回操作,该操作应该不成功。
     */
    @Test(expected=RuntimeException.class)
    public void testWithdrawPaymentWorkItem(){
      currentProcessInstance = (IProcessInstance) transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    //启动"/workflowdefinition/example_workflow.xml"中的“送货流程”
View Full Code Here

     * 结束"收银岗"的workItem
     */
    @Test
    public void testCompletePaymentWorkItem() {
      fail("本测试用例没有测试通过,测试用例有问题");
      currentProcessInstance = (IProcessInstance) transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    //启动"/workflowdefinition/example_workflow.xml"中的“送货流程”
View Full Code Here

     * 测试撤销操作,此操作应该成功。
     */
    @Test
    public void testWithdrawPaymentWorkItem2(){
      fail("本测试用例没有测试通过,测试用例有问题");
      currentProcessInstance = (IProcessInstance) transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    //启动"/workflowdefinition/example_workflow.xml"中的“送货流程”
                    IProcessInstance processInstance = workflowSession.createProcessInstance("Goods_Deliver_Process","fireflowTester");
                    processInstance.setProcessInstanceVariable("mobile", mobile);
                    processInstance.run();
                    return processInstance;
                } catch (EngineException ex) {
                    Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
                } catch (KernelException ex) {
                    Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
                }
                return null;
            }
        });
        assertNotNull(currentProcessInstance);

        IPersistenceService persistenceService = runtimeContext.getPersistenceService();
        List taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "Goods_Deliver_Process.PaymentActivity");
        assertNotNull(taskInstanceList);
        assertEquals(1, taskInstanceList.size());
        assertEquals(new Integer(ITaskInstance.RUNNING), ((ITaskInstance) taskInstanceList.get(0)).getState());

        List workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "Goods_Deliver_Process", "Goods_Deliver_Process.PaymentActivity.Payment_Task");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(ITaskInstance.RUNNING), ((IWorkItem) workItemList.get(0)).getState());

        paymentWorkItemId = ((IWorkItem) workItemList.get(0)).getId();
      //---------------------------------------------------------
        System.out.println("--------------Withdraw Payment WorkItem ----------------");
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {

            @Override
            protected void doInTransactionWithoutResult(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem paymentTaskWorkItem = workflowSession.findWorkItemById(paymentWorkItemId);
                    paymentTaskWorkItem.withdraw();
                } catch (EngineException ex) {
                    Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
                    throw new RuntimeException(ex.getMessage());
                } catch (KernelException ex) {
                    Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
      //----------------------------------------------------------
        System.out.println("--------------Complete Payment WorkItem ----------------");
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {

            @Override
            protected void doInTransactionWithoutResult(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem paymentTaskWorkItem = workflowSession.findWorkItemById(paymentWorkItemId);
                    paymentTaskWorkItem.complete();
                } catch (EngineException ex) {
                    Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
                } catch (KernelException ex) {
                    Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });

        IWorkItem wi = persistenceService.findWorkItemById(paymentWorkItemId);
        assertEquals(new Integer(IWorkItem.COMPLETED), wi.getState());

        List tokensList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokensList);
        assertEquals(1, tokensList.size());

        List todoWorkItemsList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "Goods_Deliver_Process", "Goods_Deliver_Process.PrepareGoodsTask");
        assertNotNull(todoWorkItemsList);
        assertEquals(1, todoWorkItemsList.size());
        prepareGoodsWorkItemId = ((IWorkItem) todoWorkItemsList.get(0)).getId();
      //--------------------------------------------------------
        System.out.println("--------------Withdraw Payment WorkItem After It Has Bean Completed----------------");
        IWorkItem newWorkItem = (IWorkItem)transactionTemplate.execute(new TransactionCallback() {


            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
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.