Example usage for org.springframework.transaction.support TransactionCallback TransactionCallback

List of usage examples for org.springframework.transaction.support TransactionCallback TransactionCallback

Introduction

In this page you can find the example usage for org.springframework.transaction.support TransactionCallback TransactionCallback.

Prototype

TransactionCallback

Source Link

Usage

From source file:org.fireflow.server.WorkflowServerInternalImpl.java

@SuppressWarnings("unchecked")
public WorkItemImpl claimWorkItem(String sessionId, final String workItemId) {
    final WorkflowSessionLocalImpl session = validateSession(sessionId);
    final WorkflowStatementLocalImpl statement = (WorkflowStatementLocalImpl) session.createWorkflowStatement();
    @SuppressWarnings("rawtypes")
    WorkItemImpl workItem = (WorkItemImpl) springTransactionTemplate.execute(new TransactionCallback() {

        public Object doInTransaction(TransactionStatus status) {
            WorkItem workItem = null;//from  w  w w. j av a  2 s.  c  om
            try {
                workItem = statement.claimWorkItem(workItemId);
            } catch (InvalidOperationException e) {
                throw new EngineException(e);
            }
            return workItem;
        }

    });
    return workItem;
}

From source file:org.fireflow.server.WorkflowServerInternalImpl.java

@SuppressWarnings("unchecked")
public WorkItemImpl withdrawWorkItem(String sessionId, final String workItemId) {
    final WorkflowSessionLocalImpl session = validateSession(sessionId);
    final WorkflowStatementLocalImpl statement = (WorkflowStatementLocalImpl) session.createWorkflowStatement();
    @SuppressWarnings("rawtypes")
    WorkItemImpl workItem = (WorkItemImpl) springTransactionTemplate.execute(new TransactionCallback() {

        public Object doInTransaction(TransactionStatus status) {
            WorkItem workItem = null;/*from w  w w  .  j a v a  2 s  .  co  m*/
            try {
                workItem = statement.withdrawWorkItem(workItemId);
            } catch (InvalidOperationException e) {
                throw new EngineException(e);
            }
            return workItem;
        }

    });
    return workItem;
}

From source file:org.fireflow.server.WorkflowServerInternalImpl.java

@SuppressWarnings("unchecked")
public WorkItemImpl disclaimWorkItem(String sessionId, final String workItemId, final String attachmentId,
        final String attachmentType, final String note) {

    final WorkflowSessionLocalImpl session = validateSession(sessionId);
    final WorkflowStatementLocalImpl statement = (WorkflowStatementLocalImpl) session.createWorkflowStatement();
    @SuppressWarnings("rawtypes")
    WorkItemImpl workItem = (WorkItemImpl) springTransactionTemplate.execute(new TransactionCallback() {

        public Object doInTransaction(TransactionStatus status) {
            WorkItem workItem = null;// w ww . j  av a  2  s  . co m
            try {
                workItem = statement.disclaimWorkItem(workItemId, attachmentId, attachmentType, note);
            } catch (InvalidOperationException e) {
                throw new EngineException(e);
            }
            return workItem;
        }

    });
    return workItem;

}

From source file:org.fireflow.server.WorkflowServerInternalImpl.java

@SuppressWarnings("unchecked")
public WorkItemImpl completeWorkItem1(String sessionId, final String workItemId, final String attachmentId,
        final String attachmentType, final String note) {

    final WorkflowSessionLocalImpl session = validateSession(sessionId);
    final WorkflowStatementLocalImpl statement = (WorkflowStatementLocalImpl) session.createWorkflowStatement();
    @SuppressWarnings("rawtypes")
    WorkItemImpl workItem = (WorkItemImpl) springTransactionTemplate.execute(new TransactionCallback() {

        public Object doInTransaction(TransactionStatus status) {
            WorkItem workItem = null;/*w w w  .  j  a v  a  2s  .com*/
            try {
                workItem = statement.completeWorkItem(workItemId, attachmentId, attachmentType, note);
            } catch (InvalidOperationException e) {
                throw new EngineException(e);
            }
            return workItem;
        }

    });
    return workItem;

}

From source file:org.fireflow.server.WorkflowServerInternalImpl.java

@SuppressWarnings("unchecked")
public WorkItemImpl completeWorkItem2(String sessionId, final String workItemId,
        final MapConvertor mapConvertor, final String attachmentId, final String attachmentType,
        final String note) {

    final WorkflowSessionLocalImpl session = validateSession(sessionId);
    final WorkflowStatementLocalImpl statement = (WorkflowStatementLocalImpl) session.createWorkflowStatement();
    @SuppressWarnings("rawtypes")
    WorkItemImpl workItem = (WorkItemImpl) springTransactionTemplate.execute(new TransactionCallback() {

        public Object doInTransaction(TransactionStatus status) {
            WorkItem workItem = null;// ww w.j  a  v a 2  s. c o  m
            try {
                workItem = statement.completeWorkItem(workItemId, mapConvertor.getMap(), attachmentId,
                        attachmentType, note);
            } catch (InvalidOperationException e) {
                throw new EngineException(e);
            }
            return workItem;
        }

    });
    return workItem;

}

From source file:org.fireflow.server.WorkflowServerInternalImpl.java

@SuppressWarnings("unchecked")
public WorkItemImpl completeWorkItemAndJumpTo1(String sessionId, final String workItemId,
        final String targetActivityId, final String attachmentId, final String attachmentType,
        final String note) {

    final WorkflowSessionLocalImpl session = validateSession(sessionId);
    final WorkflowStatementLocalImpl statement = (WorkflowStatementLocalImpl) session.createWorkflowStatement();
    @SuppressWarnings("rawtypes")
    WorkItemImpl workItem = (WorkItemImpl) springTransactionTemplate.execute(new TransactionCallback() {

        public Object doInTransaction(TransactionStatus status) {
            WorkItem workItem = null;/* ww  w .  java2s  . c  o m*/
            try {
                workItem = statement.completeWorkItemAndJumpTo(workItemId, targetActivityId, attachmentId,
                        attachmentType, note);
            } catch (InvalidOperationException e) {
                throw new EngineException(e);
            }
            return workItem;
        }

    });
    return workItem;

}

From source file:org.fireflow.server.WorkflowServerInternalImpl.java

@SuppressWarnings("unchecked")
public WorkItemImpl completeWorkItemAndJumpTo2(String sessionId, final String workItemId,
        final String targetActivityId, final MapConvertor assignmentStrategy, final String attachmentId,
        final String attachmentType, final String note) {

    final WorkflowSessionLocalImpl session = validateSession(sessionId);
    final WorkflowStatementLocalImpl statement = (WorkflowStatementLocalImpl) session.createWorkflowStatement();
    @SuppressWarnings("rawtypes")
    WorkItemImpl workItem = (WorkItemImpl) springTransactionTemplate.execute(new TransactionCallback() {

        public Object doInTransaction(TransactionStatus status) {
            WorkItem workItem = null;//  www  .j  a v a2  s  . c  o m
            try {
                workItem = statement.completeWorkItemAndJumpTo(workItemId, targetActivityId,
                        assignmentStrategy.getMap(), attachmentId, attachmentType, note);
            } catch (InvalidOperationException e) {
                throw new EngineException(e);
            }
            return workItem;
        }

    });
    return workItem;

}

From source file:org.fireflow.server.WorkflowServerInternalImpl.java

@SuppressWarnings("unchecked")
public WorkItemImpl reassignWorkItemTo(String sessionId, final String workItemId,
        final ReassignmentHandler handler, final String attachmentId, final String attachmentType,
        final String note) {

    final WorkflowSessionLocalImpl session = validateSession(sessionId);
    final WorkflowStatementLocalImpl statement = (WorkflowStatementLocalImpl) session.createWorkflowStatement();
    @SuppressWarnings("rawtypes")
    WorkItemImpl workItem = (WorkItemImpl) springTransactionTemplate.execute(new TransactionCallback() {

        public Object doInTransaction(TransactionStatus status) {
            WorkItem workItem = null;//  w ww  . j  a v  a  2s  . c o m
            try {
                workItem = statement.reassignWorkItemTo(workItemId, handler, attachmentId, attachmentType,
                        note);
            } catch (InvalidOperationException e) {
                throw new EngineException(e);
            }
            return workItem;
        }

    });
    return workItem;

}

From source file:org.fireflow.service.callback.ProcessServiceProvider.java

public Source invoke(Source request) {
    Expression correlation = callbackService.getCorrelation();

    final QName responseRootElementQName = new QName(callbackService.getTargetNamespaceUri(),
            this.serviceBinding.getOperationName() + "Response");

    //??/*from  ww  w.  j av a 2 s.  co  m*/
    /*
    try{
       Transformer transformer = transformerFactory.newTransformer();
       transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
       transformer.setOutputProperty(OutputKeys.INDENT, "yes");
       transformer.setOutputProperty(
       "{http://xml.apache.org/xslt}indent-amount", "2");
       ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
       // transformer.transform()  XML Source? Result
       transformer.transform(request, new StreamResult(
       outputStream));
       System.out.println( outputStream.toString());
    }catch(Exception e){
       e.printStackTrace();
    }
    */

    final Document requestDOM;
    try {
        Transformer transformer = transformerFactory.newTransformer();
        DOMResult domResult = new DOMResult();
        transformer.transform(request, domResult);
        requestDOM = (Document) domResult.getNode();//reuqestDOM   
    } catch (TransformerException e) {
        throw new WebServiceException("Can NOT transform request to DOM.", e);
    }

    final WorkflowSession session = WorkflowSessionFactory.createWorkflowSession(workflowRuntimeContext,
            FireWorkflowSystem.getInstance());
    if (!startNewProcess) {//?
        if (correlation == null || StringUtils.isEmpty(correlation.getBody())) {
            throw new WebServiceException(
                    "The correlation can NOT be empty; the callbackservice is " + callbackService.getName());
        }
        //1?serviceIdservice versioncandidate activityInstance
        WorkflowQuery<ActivityInstance> query = session.createWorkflowQuery(ActivityInstance.class);
        List<ActivityInstance> candidates = query
                .add(Restrictions.eq(ActivityInstanceProperty.SERVICE_ID, callbackService.getId()))
                .add(Restrictions.eq(ActivityInstanceProperty.SERVICE_VERSION, callbackService.getVersion()))
                .add(Restrictions.eq(ActivityInstanceProperty.STATE, ActivityInstanceState.RUNNING)).list();

        //2??correlation
        //correlationbool?processVars.var1==xpath(requestDom,'method1Request/id')
        ProcessInstance theProcessInstance = null;
        ActivityInstance theActivityInstance = null;
        if (candidates != null && candidates.size() > 0) {
            for (ActivityInstance activityInstance : candidates) {
                ProcessInstance processInstance = activityInstance.getProcessInstance(session);
                ((WorkflowSessionLocalImpl) session).setCurrentProcessInstance(processInstance);
                ((WorkflowSessionLocalImpl) session).setCurrentActivityInstance(activityInstance);

                Map<String, Object> varContext = ScriptEngineHelper.fulfillScriptContext(session,
                        workflowRuntimeContext, processInstance, activityInstance);
                varContext.put(ScriptContextVariableNames.INPUTS, requestDOM);

                Object result = ScriptEngineHelper.evaluateExpression(workflowRuntimeContext, correlation,
                        varContext);
                if (result != null && (result instanceof Boolean)) {
                    if ((Boolean) result) {
                        theActivityInstance = activityInstance;
                        theProcessInstance = processInstance;
                        break;
                    }
                }

            }
        }

        final ActivityInstance theMatchedActivityInstance = theActivityInstance;//?activityInstance
        final ProcessInstance theMatchedProcessInstance = theProcessInstance;

        if (theMatchedActivityInstance != null) {

            //1?currentProcessInstanceCurrentActivityInstance
            ((WorkflowSessionLocalImpl) session).setCurrentActivityInstance(theMatchedActivityInstance);
            ((WorkflowSessionLocalImpl) session).setCurrentProcessInstance(theMatchedProcessInstance);

            try {
                this.transactionTemplate.execute(new TransactionCallback() {
                    public Object doInTransaction(TransactionStatus status) {
                        //2????
                        List<Assignment> inputAssignments_ = serviceBinding.getInputAssignments();
                        Map<String, Object> scriptContext = new HashMap<String, Object>();
                        scriptContext.put(ScriptContextVariableNames.INPUTS, requestDOM);
                        try {
                            ScriptEngineHelper.assignOutputToVariable(session, workflowRuntimeContext,
                                    theMatchedProcessInstance, theMatchedActivityInstance, inputAssignments_,
                                    scriptContext);
                        } catch (ScriptException e) {
                            throw new RuntimeException(
                                    "Can NOT assign inputs to process instance varialbes,the callback service is  "
                                            + callbackService.getName(),
                                    e);
                        }

                        //3?closeActivity?   
                        ActivityInstanceManager actInstMgr = workflowRuntimeContext.getEngineModule(
                                ActivityInstanceManager.class, theMatchedProcessInstance.getProcessType());
                        actInstMgr.onServiceCompleted(session, theMatchedActivityInstance);

                        return null;
                    }

                });
            } catch (TransactionException e) {
                throw new WebServiceException(e);
            }
            //4?
            try {
                Map<String, Object> allTheVars = ScriptEngineHelper.fulfillScriptContext(session,
                        workflowRuntimeContext, theMatchedProcessInstance, theMatchedActivityInstance);
                List<Assignment> outputAssignments = serviceBinding.getOutputAssignments();
                Document doc = DOMInitializer.generateDocument(callbackService.getXmlSchemaCollection(),
                        responseRootElementQName);
                allTheVars.put(ScriptContextVariableNames.OUTPUTS, doc);
                Map<String, Object> tmp = ScriptEngineHelper.resolveAssignments(workflowRuntimeContext,
                        outputAssignments, allTheVars);
                Document resultDOM = (Document) tmp.get(ScriptContextVariableNames.OUTPUTS);

                return new DOMSource(resultDOM);
            } catch (ScriptException e) {
                throw new WebServiceException(
                        "Can NOT assign process instance varialbes to output,the callback service is  "
                                + callbackService.getName(),
                        e);
            } catch (ParserConfigurationException e) {
                throw new WebServiceException(
                        "Can NOT init output DOM,the callback service is  " + callbackService.getName(), e);
            }
        } else {
            throw new WebServiceException(
                    "Process instance NOT found for the conditions as follows,service id='"
                            + callbackService.getId() + "' and service version='" + callbackService.getVersion()
                            + "' and correlation='" + correlation.getBody() + "'");
        }
    }

    else {//??

        //1????bizId
        final Map<String, Object> processVars;
        final String bizId;
        try {
            List<Assignment> inputAssignments_ = serviceBinding.getInputAssignments();
            Map<String, Object> scriptContext = new HashMap<String, Object>();
            scriptContext.put(ScriptContextVariableNames.INPUTS, requestDOM);

            Map<String, Object> temp = ScriptEngineHelper.resolveAssignments(workflowRuntimeContext,
                    inputAssignments_, scriptContext);
            processVars = (Map<String, Object>) temp.get(ScriptContextVariableNames.PROCESS_VARIABLES);

            Map<String, Object> varContext = new HashMap<String, Object>();
            varContext.put(ScriptContextVariableNames.INPUTS, requestDOM);

            Object result = ScriptEngineHelper.evaluateExpression(workflowRuntimeContext, correlation,
                    varContext);
            bizId = result == null ? null : result.toString();
        } catch (ScriptException e) {
            throw new WebServiceException(
                    "Can NOT assign inputs to process instance varialbes,the callback service is  "
                            + callbackService.getName(),
                    e);
        }

        //2???
        ProcessInstance processInstance = null;
        try {
            processInstance = (ProcessInstance) transactionTemplate.execute(new TransactionCallback() {
                public Object doInTransaction(TransactionStatus status) {
                    WorkflowStatement stmt = session.createWorkflowStatement(processType);

                    ProcessInstance procInst = null;
                    try {
                        procInst = stmt.startProcess(processId, bizId, processVars);
                    } catch (InvalidModelException e1) {
                        throw new RuntimeException("Start process instance error! The callback service is "
                                + callbackService.getName() + "; the process is " + processId, e1);
                    } catch (WorkflowProcessNotFoundException e1) {
                        throw new RuntimeException("Start process instance error! The callback service is "
                                + callbackService.getName() + "; the process is " + processId, e1);

                    } catch (InvalidOperationException e1) {
                        throw new RuntimeException("Start process instance error! The callback service is "
                                + callbackService.getName() + "; the process is " + processId, e1);

                    }
                    return procInst;
                }

            });
        } catch (TransactionException e) {
            throw new WebServiceException(e);
        }

        //3?
        try {
            Map<String, Object> allTheVars = ScriptEngineHelper.fulfillScriptContext(session,
                    workflowRuntimeContext, processInstance, null);
            List<Assignment> outputAssignments = serviceBinding.getOutputAssignments();
            //  ?DOM
            Document doc = DOMInitializer.generateDocument(callbackService.getXmlSchemaCollection(),
                    responseRootElementQName);
            allTheVars.put(ScriptContextVariableNames.OUTPUTS, doc);
            Map<String, Object> tmp = ScriptEngineHelper.resolveAssignments(workflowRuntimeContext,
                    outputAssignments, allTheVars);
            Document resultDOM = (Document) tmp.get(ScriptContextVariableNames.OUTPUTS);

            return new DOMSource(resultDOM);
        } catch (ScriptException e) {
            throw new WebServiceException(
                    "Can NOT assign process instance varialbes to output,the callback service is  "
                            + callbackService.getName(),
                    e);
        } catch (ParserConfigurationException e) {
            throw new WebServiceException(
                    "Can NOT init output DOM,the callback service is  " + callbackService.getName(), e);
        }

    }

}

From source file:org.hyperic.hibernate.id.HQMultipleHiLoPerTableGenerator.java

private int executeInNewTransaction(TransactionTemplate transactionTemplate, final SessionImplementor session) {
    if (transactionTemplate != null) {
        return transactionTemplate.execute(new TransactionCallback<Integer>() {
            //We are in a Spring managed environment
            public Integer doInTransaction(TransactionStatus status) {
                try {
                    return updateSequence(Bootstrap.getBean(DBUtil.class).getConnection());
                } catch (SQLException sqle) {
                    throw JDBCExceptionHelper.convert(session.getFactory().getSQLExceptionConverter(), sqle,
                            "could not get or update next value", null);
                }/* w w w.  j  a va 2 s  .c o m*/
            }
        });
    } else {
        //Use Hibernate's JDBC delegation
        return (Integer) doWorkInNewTransaction(session);
    }
}