Reputation: 315
Whenever I need to make a change in the process definition I have to re deploy the process definition.It seems that creates a new version of the process definition.
Is there a way where I can update the existing process definition and not create a new version all the time.
What will happen to the old process instances if there is a new version of process definition in place.
Any help on the above queries is appreciated.
Upvotes: 2
Views: 2534
Reputation: 4188
As matts said, you can use org.activiti.engine.impl.cmd.SetProcessDefinitionVersionCmd
.
Following code is to update latest process definition id.
String PROCESS_DEFINITION_NAME = processdefID;
DesEncrypter de = new DesEncrypter();
String password = "yourpwd";
ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration()
.setJdbcUrl("database.url")
.setJdbcUsername("database.username").setJdbcPassword("database.password")
.setJdbcDriver("database.driver")
.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE);
ProcessEngine processEngine = cfg.buildProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
RuntimeService runtimeService = processEngine.getRuntimeService();
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().latestVersion()
.processDefinitionKey(PROCESS_DEFINITION_NAME).singleResult();
if (processDefinition == null) {
System.out.println("Cannot find Process Def ID " + PROCESS_DEFINITION_NAME);
} else {
System.out.println("Latest Process Definition Version: " + processDefinition.getVersion());
long counter = runtimeService.createProcessInstanceQuery().active()
.processDefinitionKey(PROCESS_DEFINITION_NAME).count();
List < ProcessInstance > processInstanceList = runtimeService.createProcessInstanceQuery().active()
.processDefinitionKey(PROCESS_DEFINITION_NAME).list();
System.out.println(counter);
System.out.println("Total process instances: " + counter);
System.out.println("Total process instances retrieved: " + processInstanceList.size());
int index = 1;
for (ProcessInstance oneInstance: processInstanceList) {
try {
CommandConfig commandConfig = new CommandConfig();
// Execute the command asynchronously to prevent that
// one error updating a process instance stops the
// entire batch
cfg.getAsyncExecutor().getProcessEngineConfiguration().getCommandExecutor()
.execute(commandConfig.transactionNotSupported(), new SetProcessDefinitionVersionCmd(
oneInstance.getId(), processDefinition.getVersion()));
System.out.println(index++ + " - Process instance UPDATED: " + oneInstance.getId() +
", previous definition ID: " + oneInstance.getProcessDefinitionVersion());
} catch (Exception e) {
System.out.println(index++ + " - Process instance FAILED: " + oneInstance.getId() +
", previous definition ID: " + oneInstance.getProcessDefinitionVersion() +
", Cause: " + e.getMessage());
}
}
System.out.println("********* Completed Successfully. *********");
System.in.read();
}
Upvotes: 0
Reputation: 6897
I don't think the Activiti API provides a way to replace an existing process definition without deploying a new version.
When you deploy a new version of a process, any existing process instances on the old version continue running on the old version.
However, there is a SetProcessDefinitionVersionCmd
class you can use to change the process version on a process instance. It's not "smart", though; it simply changes the version number, and doesn't change any other runtime data, so it can break process instances if you make an incompatible change in the process definition.
Upvotes: 5