Fix parent state ref

- For RepositoryState, its parent state is now
  defined as RepositoryState as well allowing
  to reference from a json files.
- Relates to #262
This commit is contained in:
Janne Valkealahti
2016-10-09 17:04:36 +01:00
parent c7951c5001
commit 3cc33a6fef
4 changed files with 14 additions and 9 deletions

View File

@@ -24,6 +24,7 @@ import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import org.springframework.statemachine.data.RepositoryState;
@@ -45,10 +46,12 @@ public class JpaRepositoryState extends RepositoryState {
private long id;
private String machineId;
private String parentState;
private String state;
private boolean initial;
@OneToOne(fetch = FetchType.EAGER)
private JpaRepositoryState parentState;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private Set<JpaRepositoryAction> stateActions;
@@ -102,7 +105,7 @@ public class JpaRepositoryState extends RepositoryState {
* @param state the state
* @param initial the initial
*/
public JpaRepositoryState(String machineId, String parentState, String state, boolean initial) {
public JpaRepositoryState(String machineId, JpaRepositoryState parentState, String state, boolean initial) {
this(machineId, parentState, state, initial, null, null, null);
}
@@ -117,7 +120,7 @@ public class JpaRepositoryState extends RepositoryState {
* @param entryActions the entry actions
* @param exitActions the exit actions
*/
public JpaRepositoryState(String machineId, String parentState, String state, boolean initial, Set<JpaRepositoryAction> stateActions,
public JpaRepositoryState(String machineId, JpaRepositoryState parentState, String state, boolean initial, Set<JpaRepositoryAction> stateActions,
Set<JpaRepositoryAction> entryActions, Set<JpaRepositoryAction> exitActions) {
this.machineId = machineId;
this.parentState = parentState;
@@ -138,11 +141,11 @@ public class JpaRepositoryState extends RepositoryState {
}
@Override
public String getParentState() {
public JpaRepositoryState getParentState() {
return parentState;
}
public void setParentState(String parentState) {
public void setParentState(JpaRepositoryState parentState) {
this.parentState = parentState;
}

View File

@@ -15,14 +15,14 @@
"@id": "3",
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryState",
"initial": true,
"parentState": "S2",
"parentState": "2",
"state": "S20"
},
{
"@id": "4",
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryState",
"initial": false,
"parentState": "S2",
"parentState": "2",
"state": "S21"
},
{

View File

@@ -30,7 +30,7 @@ public abstract class RepositoryState extends BaseRepositoryEntity {
*
* @return the parent state
*/
public abstract String getParentState();
public abstract RepositoryState getParentState();
/**
* Gets the machine id.

View File

@@ -132,7 +132,9 @@ public class RepositoryStateMachineModelFactory extends AbstractStateMachineMode
}
}
StateData<String,String> stateData = new StateData<String, String>(s.getParentState(), null, s.getState(), s.isInitial());
RepositoryState parentState = s.getParentState();
StateData<String, String> stateData = new StateData<String, String>(parentState != null ? parentState.getState() : null, null,
s.getState(), s.isInitial());
stateData.setStateActions(stateActions);
stateData.setEntryActions(entryActions);
stateData.setExitActions(exitActions);