Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auto increment field and sort on that. #4497

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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