From 3e71ec637cfed50b5202c8f403e75d95ce95145f Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Fri, 30 Apr 2021 00:42:42 +0200 Subject: [PATCH] Switch to jMolecules integrations 0.4. To allow records to be used as Identifier implementations (xmolecules/jmolecules-integrations#43). Updated MongoDB and JDBC samples accordingly. --- jdbc/jmolecules/pom.xml | 2 +- .../jdbc/jmolecules/customer/Customer.java | 6 ++---- .../springdata/jdbc/jmolecules/order/Order.java | 13 ++----------- mongodb/jmolecules/pom.xml | 2 +- .../springdata/mongodb/customer/Customer.java | 8 ++------ .../example/springdata/mongodb/order/Order.java | 13 ++----------- 6 files changed, 10 insertions(+), 34 deletions(-) diff --git a/jdbc/jmolecules/pom.xml b/jdbc/jmolecules/pom.xml index 05e160a1..39265ab0 100644 --- a/jdbc/jmolecules/pom.xml +++ b/jdbc/jmolecules/pom.xml @@ -15,7 +15,7 @@ 2021.0.0-SNAPSHOT 1.2.0 - 0.2.0 + 0.4.0-SNAPSHOT diff --git a/jdbc/jmolecules/src/main/java/example/springdata/jdbc/jmolecules/customer/Customer.java b/jdbc/jmolecules/src/main/java/example/springdata/jdbc/jmolecules/customer/Customer.java index 30b279ed..98dafb05 100644 --- a/jdbc/jmolecules/src/main/java/example/springdata/jdbc/jmolecules/customer/Customer.java +++ b/jdbc/jmolecules/src/main/java/example/springdata/jdbc/jmolecules/customer/Customer.java @@ -21,7 +21,6 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; import lombok.ToString; -import lombok.Value; import java.util.ArrayList; import java.util.List; @@ -48,7 +47,7 @@ public class Customer implements AggregateRoot { Assert.notNull(address, "Address must not be null!"); - this.id = new CustomerId(UUID.randomUUID().toString()); + this.id = new CustomerId(UUID.randomUUID()); this.firstname = firstname; this.lastname = lastname; @@ -57,6 +56,5 @@ public class Customer implements AggregateRoot { this.addresses.add(address); } - public record CustomerId(String id) implements Identifier { - } + public record CustomerId(UUID id) implements Identifier {} } diff --git a/jdbc/jmolecules/src/main/java/example/springdata/jdbc/jmolecules/order/Order.java b/jdbc/jmolecules/src/main/java/example/springdata/jdbc/jmolecules/order/Order.java index 77b34ef2..2a377dc3 100644 --- a/jdbc/jmolecules/src/main/java/example/springdata/jdbc/jmolecules/order/Order.java +++ b/jdbc/jmolecules/src/main/java/example/springdata/jdbc/jmolecules/order/Order.java @@ -25,7 +25,6 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; -import lombok.Value; import org.jmolecules.ddd.types.AggregateRoot; import org.jmolecules.ddd.types.Association; import org.jmolecules.ddd.types.Identifier; @@ -47,7 +46,7 @@ public class Order implements AggregateRoot { public Order(Customer customer) { - this.id = OrderId.of(UUID.randomUUID()); + this.id = new OrderId(UUID.randomUUID()); this.customer = Association.forAggregate(customer); this.lineItems = new ArrayList<>(); } @@ -61,13 +60,5 @@ public class Order implements AggregateRoot { return this; } - @Value(staticConstructor = "of") - public static class OrderId implements Identifier { - - UUID orderId; - - public static OrderId create() { - return OrderId.of(UUID.randomUUID()); - } - } + public record OrderId(UUID id) implements Identifier {} } diff --git a/mongodb/jmolecules/pom.xml b/mongodb/jmolecules/pom.xml index fb4ae9fb..a6dd21a3 100644 --- a/mongodb/jmolecules/pom.xml +++ b/mongodb/jmolecules/pom.xml @@ -15,7 +15,7 @@ 2021.0.0-SNAPSHOT 1.2.0 - 0.2.0 + 0.4.0-SNAPSHOT diff --git a/mongodb/jmolecules/src/main/java/example/springdata/mongodb/customer/Customer.java b/mongodb/jmolecules/src/main/java/example/springdata/mongodb/customer/Customer.java index 7046bbee..722bcbf9 100644 --- a/mongodb/jmolecules/src/main/java/example/springdata/mongodb/customer/Customer.java +++ b/mongodb/jmolecules/src/main/java/example/springdata/mongodb/customer/Customer.java @@ -20,7 +20,6 @@ import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.ToString; -import lombok.Value; import java.util.ArrayList; import java.util.List; @@ -47,7 +46,7 @@ public class Customer implements AggregateRoot { Assert.notNull(address, "Address must not be null!"); - this.id = CustomerId.of(UUID.randomUUID()); + this.id = new CustomerId(UUID.randomUUID()); this.firstname = firstname; this.lastname = lastname; @@ -56,8 +55,5 @@ public class Customer implements AggregateRoot { this.addresses.add(address); } - @Value(staticConstructor = "of") - public static class CustomerId implements Identifier { - private final UUID id; - } + public record CustomerId(UUID id) implements Identifier {} } diff --git a/mongodb/jmolecules/src/main/java/example/springdata/mongodb/order/Order.java b/mongodb/jmolecules/src/main/java/example/springdata/mongodb/order/Order.java index 455f63e8..9294d487 100644 --- a/mongodb/jmolecules/src/main/java/example/springdata/mongodb/order/Order.java +++ b/mongodb/jmolecules/src/main/java/example/springdata/mongodb/order/Order.java @@ -20,7 +20,6 @@ import example.springdata.mongodb.customer.Customer.CustomerId; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.ToString; -import lombok.Value; import java.util.ArrayList; import java.util.List; @@ -44,7 +43,7 @@ public class Order implements AggregateRoot { public Order(Customer customer) { - this.id = OrderId.of(UUID.randomUUID()); + this.id = new OrderId(UUID.randomUUID()); this.customer = Association.forAggregate(customer); this.lineItems = new ArrayList<>(); } @@ -58,13 +57,5 @@ public class Order implements AggregateRoot { return this; } - @Value(staticConstructor = "of") - public static class OrderId implements Identifier { - - UUID orderId; - - public static OrderId create() { - return OrderId.of(UUID.randomUUID()); - } - } + public static record OrderId(UUID id) implements Identifier {} }