02-12-2013 05:44 AM
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:main/TransactionExample-context.xml");
BeanFactory factory = context;
StartSpringExample springExample = (StartSpringExample) factory.getBean("StartSpringExample");
springExample.testingTransaction();
@Service
public class StartSpringExample {
// Will be injected by spring
// Activiti Services and the ProcessEngine
ProcessEngine processEngine;
RepositoryService repositoryService;
RuntimeService runtimeService;
@Autowired
public void setProcessEngine(ProcessEngine processEngine) {
this.processEngine = processEngine;
}
@Autowired
public void setRepositoryService(RepositoryService repositoryService) {
this.repositoryService = repositoryService;
}
@Autowired
public void setRuntimeService(RuntimeService runtimeService) {
this.runtimeService = runtimeService;
}
public void testingTransaction() {
try {
repositoryService
.createDeployment()
.addInputStream("Transaction.bpmn20.xml",
new FileInputStream(new File("src/main/resources/diagrams/Transaction.bpmn20.xml")))
.deploy();
} catch (FileNotFoundException e) {
e.printStackTrace();
return;
}
try {
start(false);
start(true);
} catch (Exception e) {
//Should role back!!
}
//Only one instance should be exists
}
@Transactional
private void start(boolean b) {
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("employeeName", "testUser");
// running instance, till arriving the usertask
ProcessInstance startProcessInstanceByKey = runtimeService.startProcessInstanceByKey("Transaction",variables);
if (b) throw new UnsupportedOperationException(startProcessInstanceByKey.getId().toString());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<bean id="dataSource"
class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
<property name="driverClass" value="org.h2.Driver" />
<property name="url" value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<property name="dataSource" ref="dataSource" />
<property name="transactionManager" ref="transactionManager" />
<property name="databaseSchemaUpdate" value="true" />
<property name="jobExecutorActivate" value="false" />
</bean>
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>
<bean id="repositoryService" factory-bean="processEngine"
factory-method="getRepositoryService" />
<bean id="runtimeService" factory-bean="processEngine"
factory-method="getRuntimeService" />
<bean id="taskService" factory-bean="processEngine"
factory-method="getTaskService" />
<bean id="historyService" factory-bean="processEngine"
factory-method="getHistoryService" />
<bean id="managementService" factory-bean="processEngine"
factory-method="getManagementService" />
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="StartSpringExample" class="main.StartSpringExample">
<property name="repositoryService" ref="repositoryService" />
<property name="runtimeService" ref="runtimeService" />
<property name="processEngine" ref="processEngine" />
</bean>
</beans>
02-12-2013 10:36 AM
@Transactional
private void start(boolean b) {
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("employeeName", "testUser");
// running instance, till arriving the usertask
ProcessInstance startProcessInstanceByKey = runtimeService.startProcessInstanceByKey("Transaction",variables);
if (b) throw new UnsupportedOperationException(startProcessInstanceByKey.getId().toString());
}
02-15-2013 03:28 AM
02-15-2013 08:04 AM
02-17-2013 06:02 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.