Skip to content

Commit

Permalink
Add auto increment field and sort on that. (#4497)
Browse files Browse the repository at this point in the history
Co-authored-by: kbirk <[email protected]>
  • Loading branch information
kbirk and kbirk authored Aug 19, 2024
1 parent d5e103f commit 9aedf12
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/client/hmi-client/src/types/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ export interface Simulation extends TerariumAsset {
}

export interface SimulationUpdate extends TerariumEntity {
sequenceNumber: number;
data: any;
simulation: Simulation;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
package software.uncharted.terarium.hmiserver.models.dataservice.simulation;

import java.io.Serial;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.hibernate.annotations.Type;

import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.fasterxml.jackson.databind.JsonNode;

import io.hypersistence.utils.hibernate.type.json.JsonType;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.CascadeType;
Expand All @@ -14,15 +23,9 @@
import jakarta.persistence.FetchType;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OrderBy;
import java.io.Serial;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.hibernate.annotations.Type;
import software.uncharted.terarium.hmiserver.annotations.TSModel;
import software.uncharted.terarium.hmiserver.annotations.TSOptional;
import software.uncharted.terarium.hmiserver.models.TerariumAsset;
Expand Down Expand Up @@ -88,7 +91,7 @@ public class Simulation extends TerariumAsset {
private UUID projectId;

@OneToMany(mappedBy = "simulation", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@OrderBy("createdOn DESC")
@OrderBy("sequenceNumber DESC")
@JsonManagedReference
private List<SimulationUpdate> updates = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package software.uncharted.terarium.hmiserver.models.dataservice.simulation;

import java.io.Serial;
import java.util.UUID;

import org.hibernate.annotations.Type;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.databind.JsonNode;

import io.hypersistence.utils.hibernate.type.json.JsonType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.SequenceGenerator;
import jakarta.validation.constraints.NotNull;
import java.io.Serial;
import java.util.UUID;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Type;
import software.uncharted.terarium.hmiserver.annotations.TSModel;
import software.uncharted.terarium.hmiserver.models.TerariumEntity;

Expand All @@ -29,6 +35,11 @@ public class SimulationUpdate extends TerariumEntity {
@NotNull
private Simulation simulation;

@Column(name = "sequence_number", nullable = false, unique = true)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_gen")
@SequenceGenerator(name = "seq_gen", sequenceName = "sequence_number_seq", allocationSize = 1)
private Integer sequenceNumber;

@Type(JsonType.class)
@Column(columnDefinition = "json")
private JsonNode data;
Expand Down

0 comments on commit 9aedf12

Please sign in to comment.