Important | |
---|---|
Repository abstraction support is still work in progress and scheduled to be complete in future milestones. |
It is also possible to keep machine configuration in an external storage where it will be loaded on demand instead of creating a static configuration either using JavaConfig or UML based config. This integration works via Spring Data Repository abstraction.
We have created special StateMachineModelFactory
implementation
called RepositoryStateMachineModelFactory
which is able to use base
repository interfaces StateRepository
and TransitionRepository
accompanied with base entity interfaces RepositoryState
and
RepositoryTransition
respectively.
Due to way how Entities and Repositories work in a Spring Data,
from a user perspective read access can be fully abstracted as it is
done in RepositoryStateMachineModelFactory
as there is no need to
know what is a real mapped Entity class Repository is working
with. Writing into a Repository is always dependant of using a real
Repository specific Entity class. From machine configuration point
of view we don’t need to know these, meaning we don’t need to know
actual implementation whether that is JPA, Mongo or anything else
what Spring Data supports. Using a real Repository related
Entity class comes into play when you manually try to write new
states or transitions into a backed repository.
Actual out of a box implementations are documented in below sections.
Currently one repository implementation exists which uses JPA to access configured database.
Actual Repository implementations for a JPA are
JpaStateRepository
and JpaTransitionRepository
which are backed by
Entity classes JpaRepositoryState
and JpaRepositoryTransition
respectively.
Generic way to update states and transition manually is shown below.
@Autowired StateRepository<JpaRepositoryState> stateRepository; @Autowired TransitionRepository<JpaRepositoryTransition> transitionRepository; void addConfig() { JpaRepositoryState state1 = new JpaRepositoryState("machine1", "S1", true); stateRepository.save(state1); JpaRepositoryState state2 = new JpaRepositoryState("machine2", "S2", false); stateRepository.save(state2); JpaRepositoryTransition transition1 = new JpaRepositoryTransition("machine1", "S1", "S2", "E1"); JpaRepositoryTransition transition2 = new JpaRepositoryTransition("machine2", "S3", "S4", "E2"); transitionRepository.save(transition1); transitionRepository.save(transition2); }
Complete example can be found from sample Chapter 45, JPA Config.