Skip to content

Commit

Permalink
JPA entity changes
Browse files Browse the repository at this point in the history
- Modify existing JPA entity classes to
  have a fixed names for constraints and
  foreign key. Also name used tables so that
  we don't get crazy long names which are
  causing issues with some DB's
- Fixes #468
- Fixes #469
  • Loading branch information
jvalkeal committed Jan 17, 2018
1 parent 66174ad commit 0f7624a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2018 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.
Expand All @@ -19,6 +19,7 @@
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.springframework.statemachine.data.RepositoryAction;

Expand All @@ -32,6 +33,7 @@
*
*/
@Entity
@Table(name = "Action")
@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class)
public class JpaRepositoryAction extends RepositoryAction {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2018 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.
Expand All @@ -19,6 +19,7 @@
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.springframework.statemachine.data.RepositoryGuard;

Expand All @@ -32,6 +33,7 @@
*
*/
@Entity
@Table(name = "Guard")
@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class)
public class JpaRepositoryGuard extends RepositoryGuard {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2018 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.
Expand All @@ -17,14 +17,19 @@

import java.util.Set;

import javax.persistence.CollectionTable;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.springframework.statemachine.data.RepositoryAction;
import org.springframework.statemachine.data.RepositoryState;
Expand All @@ -40,6 +45,7 @@
*
*/
@Entity
@Table(name = "State")
@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class)
public class JpaRepositoryState extends RepositoryState {

Expand All @@ -55,21 +61,28 @@ public class JpaRepositoryState extends RepositoryState {
private String submachineId;

@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(foreignKey = @ForeignKey(name = "fk_state_initial_action"))
private JpaRepositoryAction initialAction;

@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(foreignKey = @ForeignKey(name = "fk_state_parent_state"))
private JpaRepositoryState parentState;

@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(foreignKey = @ForeignKey(name = "fk_state_state_actions_s"), inverseForeignKey = @ForeignKey(name = "fk_state_state_actions_a"))
private Set<JpaRepositoryAction> stateActions;

@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(foreignKey = @ForeignKey(name = "fk_state_entry_actions_s"), inverseForeignKey = @ForeignKey(name = "fk_state_entry_actions_a"))
private Set<JpaRepositoryAction> entryActions;

@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(foreignKey = @ForeignKey(name = "fk_state_exit_actions_s"), inverseForeignKey = @ForeignKey(name = "fk_state_exit_actions_a"))
private Set<JpaRepositoryAction> exitActions;

@ElementCollection(fetch = FetchType.EAGER, targetClass = String.class)
@CollectionTable(name="DeferredEvents")
@JoinColumn(foreignKey = @ForeignKey(name = "fk_state_deferred_events"))
private Set<String> deferredEvents;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2018 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.
Expand All @@ -18,6 +18,7 @@
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;

import org.springframework.statemachine.data.RepositoryStateMachine;

Expand All @@ -31,6 +32,7 @@
*
*/
@Entity
@Table(name = "StateMachine")
@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class)
public class JpaRepositoryStateMachine extends RepositoryStateMachine {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2018 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.
Expand All @@ -19,11 +19,15 @@

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.springframework.statemachine.data.RepositoryTransition;
import org.springframework.statemachine.transition.TransitionKind;
Expand All @@ -38,6 +42,7 @@
*
*/
@Entity
@Table(name = "Transition")
@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class)
public class JpaRepositoryTransition extends RepositoryTransition {

Expand All @@ -48,18 +53,22 @@ public class JpaRepositoryTransition extends RepositoryTransition {
private String machineId;

@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(foreignKey = @ForeignKey(name = "fk_transition_source"))
private JpaRepositoryState source;

@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(foreignKey = @ForeignKey(name = "fk_transition_target"))
private JpaRepositoryState target;

private String event;
private TransitionKind kind;

@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(foreignKey = @ForeignKey(name = "fk_transition_actions_t"), inverseForeignKey = @ForeignKey(name = "fk_transition_actions_a"))
private Set<JpaRepositoryAction> actions;

@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(foreignKey = @ForeignKey(name = "fk_transition_guard"))
private JpaRepositoryGuard guard;

/**
Expand Down

0 comments on commit 0f7624a

Please sign in to comment.