Switch to records.

See #606.
This commit is contained in:
Mark Paluch
2021-04-28 09:25:28 +02:00
parent 32d118f046
commit 23dcae3a17
13 changed files with 30 additions and 57 deletions

View File

@@ -15,12 +15,8 @@
*/
package example.springdata.jdbc.jmolecules.customer;
import lombok.Value;
import org.jmolecules.ddd.annotation.ValueObject;
@Value
@ValueObject
public class Address {
private final String street, city, zipCode;
public record Address(String street, String city, String zipCode) {
}

View File

@@ -48,7 +48,7 @@ public class Customer implements AggregateRoot<Customer, CustomerId> {
Assert.notNull(address, "Address must not be null!");
this.id = CustomerId.of(UUID.randomUUID().toString());
this.id = new CustomerId(UUID.randomUUID().toString());
this.firstname = firstname;
this.lastname = lastname;
@@ -57,8 +57,6 @@ public class Customer implements AggregateRoot<Customer, CustomerId> {
this.addresses.add(address);
}
@Value(staticConstructor = "of")
public static class CustomerId implements Identifier {
private final String id;
public record CustomerId(String id) implements Identifier {
}
}

View File

@@ -15,12 +15,8 @@
*/
package example.springdata.jdbc.jmolecules.order;
import lombok.Value;
import org.jmolecules.ddd.annotation.ValueObject;
@Value
@ValueObject
public class LineItem {
String description;
public record LineItem(String description) {
}

View File

@@ -20,7 +20,6 @@ import example.springdata.jdbc.jmolecules.customer.Customer.CustomerId;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import lombok.Value;
import java.util.ArrayList;
import java.util.List;
@@ -47,7 +46,7 @@ public class Order implements AggregateRoot<Order, Order.OrderId> {
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,10 @@ public class Order implements AggregateRoot<Order, Order.OrderId> {
return this;
}
@Value(staticConstructor = "of")
public static class OrderId implements Identifier {
private final UUID orderId;
public record OrderId(UUID orderId) implements Identifier {
public static OrderId create() {
return OrderId.of(UUID.randomUUID());
return new OrderId(UUID.randomUUID());
}
}
}

View File

@@ -28,17 +28,12 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
/**
* @author Oliver Drotbohm
*/
@SpringBootTest
@RequiredArgsConstructor
class ApplicationIntegrationTests {
private final ConfigurableApplicationContext context;
record ApplicationIntegrationTests(ConfigurableApplicationContext context) {
@Test
void exposesAssociationInMetamodel() {