Add repository config guards

- Add guard to RepositoryTransition
- New GuardRepository.
- Relates to #262
This commit is contained in:
Janne Valkealahti
2016-10-02 16:28:32 +01:00
parent ddf81c78a0
commit c016fd6e06
9 changed files with 210 additions and 2 deletions

View File

@@ -1,3 +1,18 @@
/*
* 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.jpa;
import org.springframework.statemachine.data.ActionRepository;

View File

@@ -0,0 +1,27 @@
/*
* 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.jpa;
import org.springframework.statemachine.data.GuardRepository;
/**
* A {@link GuardRepository} interface for JPA used for guards.
*
* @author Janne Valkealahti
*
*/
public interface JpaGuardRepository extends GuardRepository<JpaRepositoryGuard> {
}

View File

@@ -0,0 +1,58 @@
/*
* 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.jpa;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import org.springframework.statemachine.data.RepositoryGuard;
/**
* JPA entity for actions.
*
* @author Janne Valkealahti
*
*/
@Entity
public class JpaRepositoryGuard implements RepositoryGuard {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String name;
private String spel;
@Override
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String getSpel() {
return spel;
}
public void setSpel(String spel) {
this.spel = spel;
}
}

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.RepositoryTransition;
import org.springframework.statemachine.transition.TransitionKind;
@@ -50,6 +51,8 @@ public class JpaRepositoryTransition implements RepositoryTransition {
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private Set<JpaRepositoryAction> actions;
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private JpaRepositoryGuard guard;
/**
* Instantiates a new jpa repository transition.
@@ -143,6 +146,15 @@ public class JpaRepositoryTransition implements RepositoryTransition {
this.actions = actions;
}
@Override
public JpaRepositoryGuard getGuard() {
return guard;
}
public void setGuard(JpaRepositoryGuard guard) {
this.guard = guard;
}
@Override
public TransitionKind getKind() {
return kind;

View File

@@ -25,7 +25,11 @@
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryTransition",
"source": "S2",
"target": "S3",
"event": "E2"
"event": "E2",
"guard": {
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryGuard",
"spel": "true"
}
},
{
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryTransition",