Rename sample datajpapersist to datapersist
- As it now supports mongo/redis using profiles, remove jpa from name. - Change build and docs. - Backport #509
This commit is contained in:
@@ -451,7 +451,7 @@ configure(rootProject) {
|
|||||||
from 'spring-statemachine-samples/eventservice/src/main/java/'
|
from 'spring-statemachine-samples/eventservice/src/main/java/'
|
||||||
from 'spring-statemachine-samples/datajpa/src/main/java/'
|
from 'spring-statemachine-samples/datajpa/src/main/java/'
|
||||||
from 'spring-statemachine-samples/datajpa/src/main/resources/'
|
from 'spring-statemachine-samples/datajpa/src/main/resources/'
|
||||||
from 'spring-statemachine-samples/datajpapersist/src/main/java/'
|
from 'spring-statemachine-samples/datapersist/src/main/java/'
|
||||||
from 'spring-statemachine-samples/monitoring/src/main/java/'
|
from 'spring-statemachine-samples/monitoring/src/main/java/'
|
||||||
include '**/*.java'
|
include '**/*.java'
|
||||||
include '**/*.uml'
|
include '**/*.uml'
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ normal build cycle. Samples in this chapter are:
|
|||||||
|
|
||||||
<<statemachine-examples-datajpa>> JPA Config.
|
<<statemachine-examples-datajpa>> JPA Config.
|
||||||
|
|
||||||
<<statemachine-examples-datajpapersist>> JPA Persist.
|
<<statemachine-examples-datapersist>> Data Persist.
|
||||||
|
|
||||||
<<statemachine-examples-monitoring>> Monitoring.
|
<<statemachine-examples-monitoring>> Monitoring.
|
||||||
|
|
||||||
@@ -1497,12 +1497,12 @@ Actual source for populator data is shown below.
|
|||||||
include::samples/data.json[]
|
include::samples/data.json[]
|
||||||
----
|
----
|
||||||
|
|
||||||
[[statemachine-examples-datajpapersist]]
|
[[statemachine-examples-datapersist]]
|
||||||
== JPA Persist
|
== Data Persist
|
||||||
JPA Persist is an example how state machine concepts can be used
|
Data Persist is an example how state machine concepts can be used
|
||||||
with persisting machine in a database. This sample is using
|
with persisting machine in an external repository. This sample is using
|
||||||
embedded _H2_ database with a _H2 Console_ to ease playing with a
|
embedded _H2_ database with a _H2 Console_ to ease playing with a
|
||||||
database.
|
database. Optionally it's also possible to enable _Redis_ or _MongoDB_.
|
||||||
|
|
||||||
This sample uses `spring-statemachine-boot` which on default
|
This sample uses `spring-statemachine-boot` which on default
|
||||||
auto-configures repositories and entity classes needed for JPA.
|
auto-configures repositories and entity classes needed for JPA.
|
||||||
@@ -1510,25 +1510,39 @@ Thus only `@SpringBootApplication` is needed.
|
|||||||
|
|
||||||
[source,java,indent=0]
|
[source,java,indent=0]
|
||||||
----
|
----
|
||||||
include::samples/demo/datajpapersist/Application.java[tags=snippetA]
|
include::samples/demo/datapersist/Application.java[tags=snippetA]
|
||||||
----
|
----
|
||||||
|
|
||||||
`StateMachineRuntimePersister` is a new interface working on a runtime
|
`StateMachineRuntimePersister` is a new interface working on a runtime
|
||||||
level of a 'StateMachine' and its implementation
|
level of a `StateMachine` and its implementation
|
||||||
`JpaPersistingStateMachineInterceptor` is meant to be used with a
|
`JpaPersistingStateMachineInterceptor` is meant to be used with a
|
||||||
'JPA'.
|
_JPA_.
|
||||||
|
|
||||||
[source,java,indent=0]
|
[source,java,indent=0]
|
||||||
----
|
----
|
||||||
include::samples/demo/datajpapersist/StateMachineConfig.java[tags=snippetA]
|
include::samples/demo/datapersist/StateMachineConfig.java[tags=snippetA]
|
||||||
----
|
----
|
||||||
|
|
||||||
'StateMachine' can be configured to use runtime persistence by using
|
Same configuration optionally enabled with _mongo_ profile.
|
||||||
|
|
||||||
|
[source,java,indent=0]
|
||||||
|
----
|
||||||
|
include::samples/demo/datapersist/StateMachineConfig.java[tags=snippetB]
|
||||||
|
----
|
||||||
|
|
||||||
|
Same configuration optionally enabled with _redis_ profile.
|
||||||
|
|
||||||
|
[source,java,indent=0]
|
||||||
|
----
|
||||||
|
include::samples/demo/datapersist/StateMachineConfig.java[tags=snippetC]
|
||||||
|
----
|
||||||
|
|
||||||
|
`StateMachine` can be configured to use runtime persistence by using
|
||||||
`withPersistence` config method.
|
`withPersistence` config method.
|
||||||
|
|
||||||
[source,java,indent=0]
|
[source,java,indent=0]
|
||||||
----
|
----
|
||||||
include::samples/demo/datajpapersist/StateMachineConfig.java[tags=snippetB]
|
include::samples/demo/datapersist/StateMachineConfig.java[tags=snippetD]
|
||||||
----
|
----
|
||||||
|
|
||||||
In this sample we also use `DefaultStateMachineService` which makes it
|
In this sample we also use `DefaultStateMachineService` which makes it
|
||||||
@@ -1536,21 +1550,34 @@ easier to work with multiple machines
|
|||||||
|
|
||||||
[source,java,indent=0]
|
[source,java,indent=0]
|
||||||
----
|
----
|
||||||
include::samples/demo/datajpapersist/StateMachineConfig.java[tags=snippetC]
|
include::samples/demo/datapersist/StateMachineConfig.java[tags=snippetE]
|
||||||
----
|
----
|
||||||
|
|
||||||
A logic using a `StateMachineService` in this sample is show below.
|
A logic using a `StateMachineService` in this sample is show below.
|
||||||
|
|
||||||
[source,java,indent=0]
|
[source,java,indent=0]
|
||||||
----
|
----
|
||||||
include::samples/demo/datajpapersist/StateMachineController.java[tags=snippetA]
|
include::samples/demo/datapersist/StateMachineController.java[tags=snippetA]
|
||||||
----
|
----
|
||||||
|
|
||||||
Let's get into actual demo. Run the boot based sample application:
|
Let's get into actual demo. Run the boot based sample application:
|
||||||
|
|
||||||
[source,text,subs="attributes"]
|
[source,text,subs="attributes"]
|
||||||
----
|
----
|
||||||
# java -jar spring-statemachine-samples-datajpapersist-{revnumber}.jar
|
# java -jar spring-statemachine-samples-datapersist-{revnumber}.jar
|
||||||
|
----
|
||||||
|
|
||||||
|
[NOTE]
|
||||||
|
====
|
||||||
|
Profile _jpa_ is enabled on default in _application.yml_. If you want to try
|
||||||
|
other backends, enable _mongo_ or _redis_ profile.
|
||||||
|
====
|
||||||
|
|
||||||
|
[source,text,subs="attributes"]
|
||||||
|
----
|
||||||
|
# java -jar spring-statemachine-samples-datapersist-{revnumber}.jar --spring.profiles.active=jpa
|
||||||
|
# java -jar spring-statemachine-samples-datapersist-{revnumber}.jar --spring.profiles.active=mongo
|
||||||
|
# java -jar spring-statemachine-samples-datapersist-{revnumber}.jar --spring.profiles.active=redis
|
||||||
----
|
----
|
||||||
|
|
||||||
Accessing application via _http://localhost:8080_ brings up a new
|
Accessing application via _http://localhost:8080_ brings up a new
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ include 'spring-statemachine-samples:eventservice'
|
|||||||
include 'spring-statemachine-samples:deploy'
|
include 'spring-statemachine-samples:deploy'
|
||||||
include 'spring-statemachine-samples:ordershipping'
|
include 'spring-statemachine-samples:ordershipping'
|
||||||
include 'spring-statemachine-samples:datajpa'
|
include 'spring-statemachine-samples:datajpa'
|
||||||
include 'spring-statemachine-samples:datajpapersist'
|
include 'spring-statemachine-samples:datapersist'
|
||||||
include 'spring-statemachine-samples:monitoring'
|
include 'spring-statemachine-samples:monitoring'
|
||||||
|
|
||||||
include 'spring-statemachine-data'
|
include 'spring-statemachine-data'
|
||||||
|
|||||||
@@ -121,8 +121,8 @@ project('spring-statemachine-samples-datajpa') {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
project('spring-statemachine-samples-datajpapersist') {
|
project('spring-statemachine-samples-datapersist') {
|
||||||
description = 'Spring State Machine Data Jpa Persist Sample'
|
description = 'Spring State Machine Data Persist Sample'
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(":spring-statemachine-boot")
|
compile project(":spring-statemachine-boot")
|
||||||
compile project(":spring-statemachine-data-common:spring-statemachine-data-jpa")
|
compile project(":spring-statemachine-data-common:spring-statemachine-data-jpa")
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package demo.datajpapersist;
|
package demo.datapersist;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package demo.datajpapersist;
|
package demo.datapersist;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package demo.datajpapersist;
|
package demo.datapersist;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -29,8 +29,8 @@ import org.springframework.util.ObjectUtils;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
import demo.datajpapersist.StateMachineConfig.Events;
|
import demo.datapersist.StateMachineConfig.Events;
|
||||||
import demo.datajpapersist.StateMachineConfig.States;
|
import demo.datapersist.StateMachineConfig.States;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class StateMachineController {
|
public class StateMachineController {
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package demo.datajpapersist;
|
package demo.datapersist;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -22,8 +22,8 @@ import org.springframework.statemachine.StateContext;
|
|||||||
import org.springframework.statemachine.StateContext.Stage;
|
import org.springframework.statemachine.StateContext.Stage;
|
||||||
import org.springframework.statemachine.listener.StateMachineListenerAdapter;
|
import org.springframework.statemachine.listener.StateMachineListenerAdapter;
|
||||||
|
|
||||||
import demo.datajpapersist.StateMachineConfig.Events;
|
import demo.datapersist.StateMachineConfig.Events;
|
||||||
import demo.datajpapersist.StateMachineConfig.States;
|
import demo.datapersist.StateMachineConfig.States;
|
||||||
|
|
||||||
public class StateMachineLogListener extends StateMachineListenerAdapter<States, Events> {
|
public class StateMachineLogListener extends StateMachineListenerAdapter<States, Events> {
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package demo.datajpapersist;
|
package demo.datapersist;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.allOf;
|
import static org.hamcrest.Matchers.allOf;
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
@@ -34,7 +34,8 @@ import org.springframework.test.web.servlet.MockMvc;
|
|||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
|
||||||
import demo.datajpapersist.Application;
|
import demo.datapersist.Application;
|
||||||
|
import demo.datapersist.StateMachineController;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@SpringBootTest(classes = { Application.class })
|
@SpringBootTest(classes = { Application.class })
|
||||||
Reference in New Issue
Block a user