AnsweredAssumed Answered

Setting a custom IdGenerator

Question asked by marcus1 on Sep 15, 2011
Latest reply on Sep 19, 2011 by marcus1
Activiti allows the user to configure a custom IdGenerator in ProcessEngineConfigurationImpl. This is useful for me since I want to use the adapted DbIdGenerator from http://jira.codehaus.org/browse/ACT-789. As I understand it these changes have not been applied to the Trunk since Tom felt it needed more testing in a production environment, which has not happened yet.

So I thought, I’ll just copy the patched code to my own DbBlockIdGenerator and configure the engine to use it instead of the default. However, this does not work.

The problem is that the BlockIdGenerator needs a CommandExecutor. This executor is set on the default IdGenerator the following code in ProcessEngineConfigurationImpl:
protected void initIdGenerator() {
   if (idGenerator==null) {
       DbIdGenerator dbIdGenerator = new DbIdGenerator();
       dbIdGenerator.setIdBlockSize(idBlockSize);
       dbIdGenerator.setCommandExecutor(commandExecutorTxRequiresNew);
       idGenerator = dbIdGenerator;
   }
}
Obviously this will not work if I want to supply my own IdGenerator. Therefore I made some changes and created a patch.

- I added the interface CommandExecutorAware with the sole method setCommandExecutor. I could have simply added the method to IdGenerator, but that would not be backwards compatible (since people may already have made their own implementation of the interface). I’m sure you will feel free to change this if you feel it is more appropriate :)

- initIdGenerator in ProcessEngineConfigurationImpl now checks for this interface:
if (idGenerator==null) {
    DbIdGenerator dbIdGenerator = new DbIdGenerator();
    dbIdGenerator.setIdBlockSize(idBlockSize);
    idGenerator = dbIdGenerator;
}
if (idGenerator instanceof CommandExecutorAware) {
    ((CommandExecutorAware) idGenerator).setCommandExecutor(commandExecutorTxRequiresNew);
}

- I added the DbBlockIdGenerator (which is the DbIdGenerator with the changes from ACT-789).

- The default DbIdGenerator and the new DbBlockIdGenerator now implement CommandExecutorAware.

See http://jira.codehaus.org/browse/ACT-902 for the patch.

Outcomes