From 125764a369723170966e1752e1b621f5c23a3f10 Mon Sep 17 00:00:00 2001 From: Joep de Jong Date: Tue, 21 May 2024 11:57:04 +0300 Subject: [PATCH] Add sequence strategy to generated values --- .../wisv/events/core/model/customer/Customer.java | 9 +++------ .../wisv/events/core/model/document/Document.java | 3 ++- .../java/ch/wisv/events/core/model/event/Event.java | 13 +++---------- .../java/ch/wisv/events/core/model/order/Order.java | 12 +++--------- .../wisv/events/core/model/order/OrderProduct.java | 2 +- .../ch/wisv/events/core/model/product/Product.java | 2 +- .../ch/wisv/events/core/model/ticket/Ticket.java | 8 +++----- .../ch/wisv/events/core/model/webhook/Webhook.java | 8 +++----- .../wisv/events/core/model/webhook/WebhookTask.java | 9 +++------ 9 files changed, 22 insertions(+), 44 deletions(-) diff --git a/src/main/java/ch/wisv/events/core/model/customer/Customer.java b/src/main/java/ch/wisv/events/core/model/customer/Customer.java index 3bfd0ecd..fbe89238 100644 --- a/src/main/java/ch/wisv/events/core/model/customer/Customer.java +++ b/src/main/java/ch/wisv/events/core/model/customer/Customer.java @@ -5,11 +5,8 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; -import jakarta.persistence.Column; -import jakarta.persistence.ElementCollection; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; + +import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Data; import lombok.Getter; @@ -26,7 +23,7 @@ public class Customer { * Field id of the customer. */ @Id - @GeneratedValue + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "customer_seq") @Setter(AccessLevel.NONE) private Integer id; diff --git a/src/main/java/ch/wisv/events/core/model/document/Document.java b/src/main/java/ch/wisv/events/core/model/document/Document.java index 6baa8960..97a3b539 100644 --- a/src/main/java/ch/wisv/events/core/model/document/Document.java +++ b/src/main/java/ch/wisv/events/core/model/document/Document.java @@ -2,6 +2,7 @@ import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import lombok.Data; @@ -16,7 +17,7 @@ public class Document { * Id of the element. */ @Id - @GeneratedValue + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "document_seq") private Long id; /** diff --git a/src/main/java/ch/wisv/events/core/model/event/Event.java b/src/main/java/ch/wisv/events/core/model/event/Event.java index 41e6d7e7..d6359fac 100644 --- a/src/main/java/ch/wisv/events/core/model/event/Event.java +++ b/src/main/java/ch/wisv/events/core/model/event/Event.java @@ -6,15 +6,8 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; -import jakarta.persistence.CascadeType; -import jakarta.persistence.Column; -import jakarta.persistence.ElementCollection; -import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.OneToMany; -import jakarta.persistence.OrderBy; + +import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import lombok.AccessLevel; @@ -37,7 +30,7 @@ public class Event { * ID of the event, getter only so it can not be changed. */ @Id - @GeneratedValue + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "event_seq") @Setter(AccessLevel.NONE) private Integer id; diff --git a/src/main/java/ch/wisv/events/core/model/order/Order.java b/src/main/java/ch/wisv/events/core/model/order/Order.java index a56a1c62..b2351e2a 100644 --- a/src/main/java/ch/wisv/events/core/model/order/Order.java +++ b/src/main/java/ch/wisv/events/core/model/order/Order.java @@ -6,14 +6,8 @@ import java.util.HashMap; import java.util.List; import java.util.UUID; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToMany; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; + +import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; @@ -37,7 +31,7 @@ public class Order { * Field id id of the Order. */ @Id - @GeneratedValue + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "order_seq") @Setter(AccessLevel.NONE) private Integer id; diff --git a/src/main/java/ch/wisv/events/core/model/order/OrderProduct.java b/src/main/java/ch/wisv/events/core/model/order/OrderProduct.java index a88a84b3..297ae73a 100644 --- a/src/main/java/ch/wisv/events/core/model/order/OrderProduct.java +++ b/src/main/java/ch/wisv/events/core/model/order/OrderProduct.java @@ -20,7 +20,7 @@ public class OrderProduct { * Field id. */ @Id - @GeneratedValue + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "order_product_seq") @Setter(AccessLevel.NONE) private Integer id; diff --git a/src/main/java/ch/wisv/events/core/model/product/Product.java b/src/main/java/ch/wisv/events/core/model/product/Product.java index 65782ac9..93f630ca 100644 --- a/src/main/java/ch/wisv/events/core/model/product/Product.java +++ b/src/main/java/ch/wisv/events/core/model/product/Product.java @@ -27,7 +27,7 @@ public class Product { * ID of the product, getter only so it can not be changed. */ @Id - @GeneratedValue + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "product_seq") @Setter(AccessLevel.NONE) public Integer id; diff --git a/src/main/java/ch/wisv/events/core/model/ticket/Ticket.java b/src/main/java/ch/wisv/events/core/model/ticket/Ticket.java index 69ce0643..68baad1a 100644 --- a/src/main/java/ch/wisv/events/core/model/ticket/Ticket.java +++ b/src/main/java/ch/wisv/events/core/model/ticket/Ticket.java @@ -8,10 +8,8 @@ import java.time.LocalDateTime; import java.util.UUID; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; + +import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import lombok.AccessLevel; @@ -26,7 +24,7 @@ public class Ticket { * ID of the ticket, getter only so it can not be changed. */ @Id - @GeneratedValue + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ticket_seq") @Setter(AccessLevel.NONE) public Integer id; diff --git a/src/main/java/ch/wisv/events/core/model/webhook/Webhook.java b/src/main/java/ch/wisv/events/core/model/webhook/Webhook.java index 40278ac0..2762ae1b 100644 --- a/src/main/java/ch/wisv/events/core/model/webhook/Webhook.java +++ b/src/main/java/ch/wisv/events/core/model/webhook/Webhook.java @@ -3,10 +3,8 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; -import jakarta.persistence.ElementCollection; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; + +import jakarta.persistence.*; import lombok.Data; @Entity @@ -17,7 +15,7 @@ public class Webhook { * ID of the product, getter only so it can not be changed. */ @Id - @GeneratedValue + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "webhook_seq") private Integer id; /** diff --git a/src/main/java/ch/wisv/events/core/model/webhook/WebhookTask.java b/src/main/java/ch/wisv/events/core/model/webhook/WebhookTask.java index 5fc89edb..2719b38b 100644 --- a/src/main/java/ch/wisv/events/core/model/webhook/WebhookTask.java +++ b/src/main/java/ch/wisv/events/core/model/webhook/WebhookTask.java @@ -1,11 +1,8 @@ package ch.wisv.events.core.model.webhook; import java.time.LocalDateTime; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; + +import jakarta.persistence.*; import lombok.Data; import org.json.simple.JSONObject; @@ -17,7 +14,7 @@ public class WebhookTask { * ID of the product, getter only so it can not be changed. */ @Id - @GeneratedValue + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "webhook_task_seq") private Integer id; /**