Persist
sample is using PersistStateMachineHandler
recipe to update stuff in a db when state machine is transitioning between states. One important thing to remember in this recipe is that it is using interceptor instead of listener to hook into state changes. If db update is done within an interceptor callback, in case of error/exception, transition in a state machine is denied, while if one would use listener error would cause state machine and db become inconsistent between each others.
One other thing is that this recipe allows to reset
machine state into a particular state and then continue from there.
It really doesn't matter if new machine is created for every update if user doesn't care about speed and garbage. State machine instantiation is relatively expensive so simply using one instance and then reseting its state is relatively light operation.
How you interact with db from state machine hooks is very low level at this moment because you need to do everything manually in terms of how to interact with db. There's no automatic tweaks currently because we simply don't know what's in db and how rows would be updated.
jdbcTemplate
manually. It'd be nice if we could somehow do things automatically, so any ideas over this would be nice!