Created
July 27, 2018 12:34
-
-
Save aludwiko/80dcbc35a62d4595622d5d95aaba5e25 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import javax.persistence.*; | |
| import java.util.List; | |
| import static java.util.Collections.unmodifiableList; | |
| import static javax.persistence.GenerationType.AUTO; | |
| @Entity | |
| public class Issue { | |
| @EmbeddedId | |
| private IssueId id; | |
| private String name; | |
| private IssueStatus status; | |
| @OneToMany(cascade = CascadeType.MERGE) | |
| private List<IssueComment> comments; | |
| ... | |
| public void changeStatusTo(IssueStatus newStatus) { | |
| if (this.status == IssueStatus.DONE && newStatus == IssueStatus.NEW || this.status == IssueStatus.NEW && newStatus == IssueStatus.DONE) { | |
| throw new RuntimeException(String.format("Cannot change issue status from %s to %s", this.status, newStatus)); | |
| } | |
| this.status = newStatus; | |
| } | |
| ... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment