@@ -65,7 +65,7 @@ public class AggregateConfiguration extends AbstractJdbcConfiguration {
|
||||
legoSet.setId(id.incrementAndGet());
|
||||
}
|
||||
|
||||
Manual manual = legoSet.getManual();
|
||||
var manual = legoSet.getManual();
|
||||
|
||||
if (manual != null) {
|
||||
manual.setId((long) legoSet.getId());
|
||||
@@ -102,11 +102,11 @@ public class AggregateConfiguration extends AbstractJdbcConfiguration {
|
||||
@Bean
|
||||
DataSourceInitializer initializer(DataSource dataSource) {
|
||||
|
||||
DataSourceInitializer initializer = new DataSourceInitializer();
|
||||
var initializer = new DataSourceInitializer();
|
||||
initializer.setDataSource(dataSource);
|
||||
|
||||
ClassPathResource script = new ClassPathResource("schema.sql");
|
||||
ResourceDatabasePopulator populator = new ResourceDatabasePopulator(script);
|
||||
var script = new ClassPathResource("schema.sql");
|
||||
var populator = new ResourceDatabasePopulator(script);
|
||||
initializer.setDatabasePopulator(populator);
|
||||
|
||||
return initializer;
|
||||
|
||||
@@ -92,7 +92,7 @@ public class LegoSet {
|
||||
|
||||
public void addModel(String name, String description) {
|
||||
|
||||
Model model = new Model(name, description);
|
||||
var model = new Model(name, description);
|
||||
models.put(name, model);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Output {
|
||||
|
||||
public static void list(Iterable<?> categories, String title) {
|
||||
|
||||
StringBuilder message = new StringBuilder(String.format("==== %s ====\n", title));
|
||||
var message = new StringBuilder(String.format("==== %s ====\n", title));
|
||||
|
||||
categories.forEach(category -> message.append(category.toString().replace(", ", ",\n\t")));
|
||||
|
||||
|
||||
@@ -47,13 +47,13 @@ class AggregateTests {
|
||||
@Test
|
||||
void exerciseSomewhatComplexEntity() {
|
||||
|
||||
LegoSet smallCar = createLegoSet("Small Car 01", 5, 12);
|
||||
var smallCar = createLegoSet("Small Car 01", 5, 12);
|
||||
smallCar.setManual(new Manual("Just put all the pieces together in the right order", "Jens Schauder"));
|
||||
smallCar.addModel("suv", "SUV with sliding doors.");
|
||||
smallCar.addModel("roadster", "Slick red roadster.");
|
||||
|
||||
repository.save(smallCar);
|
||||
Iterable<LegoSet> legoSets = repository.findAll();
|
||||
var legoSets = repository.findAll();
|
||||
Output.list(legoSets, "Original LegoSet");
|
||||
checkLegoSets(legoSets, "Just put all the pieces together in the right order", 2);
|
||||
|
||||
@@ -76,18 +76,18 @@ class AggregateTests {
|
||||
@Test
|
||||
void customQueries() {
|
||||
|
||||
String smallCarsSetName = "Small Car - 01";
|
||||
LegoSet smallCars = createLegoSet(smallCarsSetName, 5, 10);
|
||||
var smallCarsSetName = "Small Car - 01";
|
||||
var smallCars = createLegoSet(smallCarsSetName, 5, 10);
|
||||
smallCars.setManual(new Manual("Just put all the pieces together in the right order", "Jens Schauder"));
|
||||
|
||||
smallCars.addModel("SUV", "SUV with sliding doors.");
|
||||
smallCars.addModel("roadster", "Slick red roadster.");
|
||||
|
||||
LegoSet f1Racer = createLegoSet("F1 Racer", 6, 15);
|
||||
var f1Racer = createLegoSet("F1 Racer", 6, 15);
|
||||
f1Racer.setManual(new Manual("Build a helicopter or a plane", "M. Shoemaker"));
|
||||
f1Racer.addModel("F1 Ferrari 2018", "A very fast red car.");
|
||||
|
||||
LegoSet constructionVehicles = createLegoSet("Construction Vehicles", 3, 6);
|
||||
var constructionVehicles = createLegoSet("Construction Vehicles", 3, 6);
|
||||
constructionVehicles.setManual(
|
||||
new Manual("Build a Road Roler, a Mobile Crane, a Tracked Dumper, or a Backhoe Loader ", "Bob the Builder"));
|
||||
|
||||
@@ -99,23 +99,23 @@ class AggregateTests {
|
||||
|
||||
repository.saveAll(Arrays.asList(smallCars, f1Racer, constructionVehicles));
|
||||
|
||||
List<ModelReport> report = repository.reportModelForAge(6);
|
||||
var report = repository.reportModelForAge(6);
|
||||
Output.list(report, "Model Report");
|
||||
|
||||
assertThat(report).hasSize(7)
|
||||
.allMatch(m -> m.getDescription() != null && m.getModelName() != null && m.getSetName() != null);
|
||||
|
||||
int updated = repository.lowerCaseMapKeys();
|
||||
var updated = repository.lowerCaseMapKeys();
|
||||
// SUV, F1 Ferrari 2018 and Muck get updated
|
||||
assertThat(updated).isEqualTo(3);
|
||||
|
||||
final List<LegoSet> legoSetsByName = repository.findByName(smallCarsSetName);
|
||||
final var legoSetsByName = repository.findByName(smallCarsSetName);
|
||||
assertThat(legoSetsByName).hasSize(1);
|
||||
}
|
||||
|
||||
private LegoSet createLegoSet(String name, int minimumAge, int maximumAge) {
|
||||
|
||||
LegoSet smallCar = new LegoSet();
|
||||
var smallCar = new LegoSet();
|
||||
|
||||
smallCar.setName(name);
|
||||
smallCar.setMinimumAge(Period.ofYears(minimumAge));
|
||||
|
||||
@@ -42,8 +42,8 @@ class SimpleEntityTests {
|
||||
void exerciseRepositoryForSimpleEntity() {
|
||||
|
||||
// create some categories
|
||||
Category cars = repository.save(new Category("Cars", "Anything that has approximately 4 wheels.", AgeGroup._3to8));
|
||||
Category buildings = repository.save(new Category("Buildings", null, AgeGroup._12andOlder));
|
||||
var cars = repository.save(new Category("Cars", "Anything that has approximately 4 wheels.", AgeGroup._3to8));
|
||||
var buildings = repository.save(new Category("Buildings", null, AgeGroup._12andOlder));
|
||||
|
||||
// save categories
|
||||
Output.list(repository.findAll(), "`Cars` and `Buildings` got saved");
|
||||
@@ -64,7 +64,7 @@ class SimpleEntityTests {
|
||||
@Test
|
||||
void directInsert() {
|
||||
|
||||
Category cars = new Category("Cars", "Anything that has approximately 4 wheels.", AgeGroup._3to8).withId(23L);
|
||||
var cars = new Category("Cars", "Anything that has approximately 4 wheels.", AgeGroup._3to8).withId(23L);
|
||||
repository.insert(cars);
|
||||
|
||||
Output.list(repository.findAll(), "`Cars` inserted with id 23L");
|
||||
|
||||
@@ -42,7 +42,7 @@ public class Customer implements AggregateRoot<Customer, CustomerId> {
|
||||
|
||||
private final CustomerId id;
|
||||
private @Setter String firstname, lastname;
|
||||
private List<Address> addresses;
|
||||
private final List<Address> addresses;
|
||||
|
||||
public Customer(String firstname, String lastname, Address address) {
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ public class Order implements AggregateRoot<Order, Order.OrderId> {
|
||||
|
||||
public Order addLineItem(String description) {
|
||||
|
||||
LineItem item = new LineItem(description);
|
||||
var item = new LineItem(description);
|
||||
|
||||
this.lineItems.add(item);
|
||||
|
||||
|
||||
@@ -43,9 +43,9 @@ class ApplicationIntegrationTests {
|
||||
@Test
|
||||
void exposesAssociationInMetamodel() {
|
||||
|
||||
JdbcMappingContext mapping = context.getBean(JdbcMappingContext.class);
|
||||
RelationalPersistentEntity<?> entity = mapping.getRequiredPersistentEntity(Order.class);
|
||||
RelationalPersistentProperty customer = entity.getRequiredPersistentProperty("customer");
|
||||
var mapping = context.getBean(JdbcMappingContext.class);
|
||||
var entity = mapping.getRequiredPersistentEntity(Order.class);
|
||||
var customer = entity.getRequiredPersistentProperty("customer");
|
||||
|
||||
assertThat(customer.isAssociation()).isTrue();
|
||||
}
|
||||
@@ -53,21 +53,21 @@ class ApplicationIntegrationTests {
|
||||
@Test
|
||||
void persistsDomainModel() {
|
||||
|
||||
Address address = new Address("41 Greystreet", "Dreaming Tree", "2731");
|
||||
var address = new Address("41 Greystreet", "Dreaming Tree", "2731");
|
||||
|
||||
Customers customers = context.getBean(Customers.class);
|
||||
Customer customer = customers.save(new Customer("Dave", "Matthews", address));
|
||||
var customers = context.getBean(Customers.class);
|
||||
var customer = customers.save(new Customer("Dave", "Matthews", address));
|
||||
|
||||
customer.setFirstname("Carter");
|
||||
customer = customers.save(customer);
|
||||
|
||||
Orders orders = context.getBean(Orders.class);
|
||||
var orders = context.getBean(Orders.class);
|
||||
|
||||
Order order = new Order(customer)
|
||||
var order = new Order(customer)
|
||||
.addLineItem("Foo")
|
||||
.addLineItem("Bar");
|
||||
|
||||
Order result = orders.save(order);
|
||||
var result = orders.save(order);
|
||||
|
||||
assertThat(customers.resolveRequired(result.getCustomer()));
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class CategoryConfiguration extends AbstractJdbcConfiguration {
|
||||
}
|
||||
|
||||
public DefaultConfiguration configuration() {
|
||||
DefaultConfiguration jooqConfiguration = new DefaultConfiguration();
|
||||
var jooqConfiguration = new DefaultConfiguration();
|
||||
jooqConfiguration.set(connectionProvider());
|
||||
return jooqConfiguration;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Output {
|
||||
|
||||
public static void list(Iterable<?> categories, String title) {
|
||||
|
||||
StringBuilder message = new StringBuilder(String.format("==== %s ====\n", title));
|
||||
var message = new StringBuilder(String.format("==== %s ====\n", title));
|
||||
|
||||
categories.forEach(category -> message.append(category.toString().replace(", ", ",\n\t")));
|
||||
|
||||
|
||||
@@ -45,12 +45,12 @@ class SimpleEntityTests {
|
||||
void exerciseRepositoryForSimpleEntity() {
|
||||
|
||||
// create some categories
|
||||
Category cars = new Category(null, "Cars", "Anything that has approximately 4 wheels", AgeGroup._3to8);
|
||||
var cars = new Category(null, "Cars", "Anything that has approximately 4 wheels", AgeGroup._3to8);
|
||||
|
||||
Category buildings = new Category(null, "Buildings", null, AgeGroup._12andOlder);
|
||||
var buildings = new Category(null, "Buildings", null, AgeGroup._12andOlder);
|
||||
|
||||
// save categories
|
||||
Iterable<Category> saved = repository.saveAll(asList(cars, buildings));
|
||||
var saved = repository.saveAll(asList(cars, buildings));
|
||||
Output.list(repository.findAll(), "`Cars` and `Buildings` got saved");
|
||||
|
||||
assertThat(saved).extracting(c -> c.getId()).isNotNull();
|
||||
@@ -60,7 +60,7 @@ class SimpleEntityTests {
|
||||
repository.save(buildings);
|
||||
Output.list(repository.findAll(), "`Buildings` has a description");
|
||||
|
||||
List<Category> categoryList = repository.getCategoriesWithAgeGroup(AgeGroup._3to8);
|
||||
var categoryList = repository.getCategoriesWithAgeGroup(AgeGroup._3to8);
|
||||
|
||||
assertThat(categoryList) //
|
||||
.extracting(Category::getName, Category::getDescription, Category::getAgeGroup) //
|
||||
|
||||
@@ -38,7 +38,7 @@ public class LegoSet {
|
||||
|
||||
public void addModel(String name, String description) {
|
||||
|
||||
Model model = new Model();
|
||||
var model = new Model();
|
||||
model.name = name;
|
||||
model.description = description;
|
||||
models.put(name, model);
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Output {
|
||||
|
||||
public static void list(Iterable<?> categories, String title) {
|
||||
|
||||
StringBuilder message = new StringBuilder(String.format("==== %s ====\n", title));
|
||||
var message = new StringBuilder(String.format("==== %s ====\n", title));
|
||||
|
||||
categories.forEach(category -> {
|
||||
message.append(category.toString().replace(", ", ",\n\t"));
|
||||
|
||||
@@ -40,7 +40,7 @@ class MyBatisTests {
|
||||
@Test
|
||||
void exerciseSomewhatComplexEntity() {
|
||||
|
||||
LegoSet smallCar = createLegoSet();
|
||||
var smallCar = createLegoSet();
|
||||
|
||||
smallCar.setManual(new Manual("Just put all the pieces together in the right order", "Jens Schauder"));
|
||||
smallCar.addModel("suv", "SUV with sliding doors.");
|
||||
@@ -69,7 +69,7 @@ class MyBatisTests {
|
||||
|
||||
private static LegoSet createLegoSet() {
|
||||
|
||||
LegoSet smallCar = new LegoSet();
|
||||
var smallCar = new LegoSet();
|
||||
smallCar.setName("Small Car 01");
|
||||
return smallCar;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user