diff --git a/build.gradle b/build.gradle index de1c38e8..17386fdc 100644 --- a/build.gradle +++ b/build.gradle @@ -427,6 +427,8 @@ configure(rootProject) { from 'spring-statemachine-uml/src/test/java/org/springframework/statemachine/uml/docs' from 'spring-statemachine-uml/src/test/resources/org/springframework/statemachine/uml/docs' from 'spring-statemachine-data/jpa/src/test/java/org/springframework/statemachine/data/jpa/docs' + from 'spring-statemachine-data/redis/src/test/java/org/springframework/statemachine/data/redis/docs' + from 'spring-statemachine-data/mongodb/src/test/java/org/springframework/statemachine/data/mongodb/docs' from 'spring-statemachine-samples/src/main/java/' from 'spring-statemachine-samples/washer/src/main/java/' from 'spring-statemachine-samples/tasks/src/main/java/' diff --git a/docs/src/reference/asciidoc/images/sm-repository-simplemachine.png b/docs/src/reference/asciidoc/images/sm-repository-simplemachine.png new file mode 100644 index 00000000..8147c795 Binary files /dev/null and b/docs/src/reference/asciidoc/images/sm-repository-simplemachine.png differ diff --git a/docs/src/reference/asciidoc/sm.adoc b/docs/src/reference/asciidoc/sm.adoc index dc3564d0..f3723d0e 100644 --- a/docs/src/reference/asciidoc/sm.adoc +++ b/docs/src/reference/asciidoc/sm.adoc @@ -2149,7 +2149,12 @@ 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. +Actual out of a box implementations are documented in below sections +where images below are uml equivalent statecharts of a repository +configs. + +[[image-sm-repository-simplemachine]] +image::images/sm-repository-simplemachine.png[scaledwidth="100%", title="SimpleMachine"] [[sm-repository-jpa]] === JPA @@ -2159,7 +2164,9 @@ and `JpaGuardRepository` which are backed by _Entity_ classes `JpaRepositoryState`, `JpaRepositoryTransition`, `JpaRepositoryAction` and `JpaRepositoryGuard` respectively. -Generic way to update states and transition manually is shown below. +Generic way to update states and transition manually for jpa is shown +below. This is equivalent to machine shown in +<>. [source,java,indent=0] ---- @@ -2179,6 +2186,15 @@ and `RedisGuardRepository` which are backed by _Entity_ classes `RedisRepositoryState`, `RedisRepositoryTransition`, `RedisRepositoryAction` and `RedisRepositoryGuard` respectively. +Generic way to update states and transition manually for redis is shown +below. This is equivalent to machine shown in +<>. + +[source,java,indent=0] +---- +include::samples/DocsRedisRepositorySampleTests1.java[tags=snippetA] +---- + [[sm-repository-mongodb]] === MongoDB Actual _Repository_ implementations for a _MongoDB_ are @@ -2187,3 +2203,12 @@ and `MongoDbGuardRepository` which are backed by _Entity_ classes `MongoDbRepositoryState`, `MongoDbRepositoryTransition`, `MongoDbRepositoryAction` and `MongoDbRepositoryGuard` respectively. +Generic way to update states and transition manually for redis is shown +below. This is equivalent to machine shown in +<>. + +[source,java,indent=0] +---- +include::samples/DocsMongoDbRepositorySampleTests1.java[tags=snippetA] +---- + diff --git a/spring-statemachine-data/jpa/src/test/java/org/springframework/statemachine/data/jpa/docs/DocsJpaRepositorySampleTests1.java b/spring-statemachine-data/jpa/src/test/java/org/springframework/statemachine/data/jpa/docs/DocsJpaRepositorySampleTests1.java index 059f77fa..9f4a78b1 100644 --- a/spring-statemachine-data/jpa/src/test/java/org/springframework/statemachine/data/jpa/docs/DocsJpaRepositorySampleTests1.java +++ b/spring-statemachine-data/jpa/src/test/java/org/springframework/statemachine/data/jpa/docs/DocsJpaRepositorySampleTests1.java @@ -32,19 +32,19 @@ public class DocsJpaRepositorySampleTests1 { TransitionRepository transitionRepository; void addConfig() { - JpaRepositoryState state1 = new JpaRepositoryState("machine1", "S1", true); - JpaRepositoryState state2 = new JpaRepositoryState("machine2", "S2", false); - JpaRepositoryState state3 = new JpaRepositoryState("machine1", "S3", true); - JpaRepositoryState state4 = new JpaRepositoryState("machine2", "S4", false); - stateRepository.save(state1); - stateRepository.save(state2); - stateRepository.save(state3); - stateRepository.save(state4); + JpaRepositoryState stateS1 = new JpaRepositoryState("S1", true); + JpaRepositoryState stateS2 = new JpaRepositoryState("S2"); + JpaRepositoryState stateS3 = new JpaRepositoryState("S3"); - JpaRepositoryTransition transition1 = new JpaRepositoryTransition("machine1", state1, state2, "E1"); - JpaRepositoryTransition transition2 = new JpaRepositoryTransition("machine2", state3, state4, "E2"); - transitionRepository.save(transition1); - transitionRepository.save(transition2); + stateRepository.save(stateS1); + stateRepository.save(stateS2); + stateRepository.save(stateS3); + + JpaRepositoryTransition transitionS1ToS2 = new JpaRepositoryTransition(stateS1, stateS2, "E1"); + JpaRepositoryTransition transitionS2ToS3 = new JpaRepositoryTransition(stateS2, stateS3, "E2"); + + transitionRepository.save(transitionS1ToS2); + transitionRepository.save(transitionS2ToS3); } // end::snippetA[] } diff --git a/spring-statemachine-data/mongodb/src/test/java/org/springframework/statemachine/data/mongodb/docs/DocsMongoDbRepositorySampleTests1.java b/spring-statemachine-data/mongodb/src/test/java/org/springframework/statemachine/data/mongodb/docs/DocsMongoDbRepositorySampleTests1.java new file mode 100644 index 00000000..d8ce4e78 --- /dev/null +++ b/spring-statemachine-data/mongodb/src/test/java/org/springframework/statemachine/data/mongodb/docs/DocsMongoDbRepositorySampleTests1.java @@ -0,0 +1,51 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.statemachine.data.mongodb.docs; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.statemachine.data.StateRepository; +import org.springframework.statemachine.data.TransitionRepository; +import org.springframework.statemachine.data.mongodb.MongoDbRepositoryState; +import org.springframework.statemachine.data.mongodb.MongoDbRepositoryTransition; + +public class DocsMongoDbRepositorySampleTests1 { + + public static class Config1 { +// tag::snippetA[] + @Autowired + StateRepository stateRepository; + + @Autowired + TransitionRepository transitionRepository; + + void addConfig() { + MongoDbRepositoryState stateS1 = new MongoDbRepositoryState("S1", true); + MongoDbRepositoryState stateS2 = new MongoDbRepositoryState("S2"); + MongoDbRepositoryState stateS3 = new MongoDbRepositoryState("S3"); + + stateRepository.save(stateS1); + stateRepository.save(stateS2); + stateRepository.save(stateS3); + + MongoDbRepositoryTransition transitionS1ToS2 = new MongoDbRepositoryTransition(stateS1, stateS2, "E1"); + MongoDbRepositoryTransition transitionS2ToS3 = new MongoDbRepositoryTransition(stateS2, stateS3, "E2"); + + transitionRepository.save(transitionS1ToS2); + transitionRepository.save(transitionS2ToS3); + } +// end::snippetA[] + } +} diff --git a/spring-statemachine-data/redis/src/test/java/org/springframework/statemachine/data/redis/docs/DocsRedisRepositorySampleTests1.java b/spring-statemachine-data/redis/src/test/java/org/springframework/statemachine/data/redis/docs/DocsRedisRepositorySampleTests1.java new file mode 100644 index 00000000..cecd2176 --- /dev/null +++ b/spring-statemachine-data/redis/src/test/java/org/springframework/statemachine/data/redis/docs/DocsRedisRepositorySampleTests1.java @@ -0,0 +1,52 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.statemachine.data.redis.docs; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.statemachine.data.StateRepository; +import org.springframework.statemachine.data.TransitionRepository; +import org.springframework.statemachine.data.redis.RedisRepositoryState; +import org.springframework.statemachine.data.redis.RedisRepositoryTransition; + +public class DocsRedisRepositorySampleTests1 { + + public static class Config1 { +// tag::snippetA[] + @Autowired + StateRepository stateRepository; + + @Autowired + TransitionRepository transitionRepository; + + void addConfig() { + RedisRepositoryState stateS1 = new RedisRepositoryState("S1", true); + RedisRepositoryState stateS2 = new RedisRepositoryState("S2"); + RedisRepositoryState stateS3 = new RedisRepositoryState("S3"); + + stateRepository.save(stateS1); + stateRepository.save(stateS2); + stateRepository.save(stateS3); + + + RedisRepositoryTransition transitionS1ToS2 = new RedisRepositoryTransition(stateS1, stateS2, "E1"); + RedisRepositoryTransition transitionS2ToS3 = new RedisRepositoryTransition(stateS2, stateS3, "E2"); + + transitionRepository.save(transitionS1ToS2); + transitionRepository.save(transitionS2ToS3); + } +// end::snippetA[] + } +}