package net.safedata.springboot.training.d02.s05.config;

import net.safedata.springboot.training.d02.s05.model.Product;
import net.safedata.springboot.training.d02.s05.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.annotation.PostConstruct;

/**
 * A simple {@link javax.sql.DataSource} configuration, which:
 * <ul>
 *     <li>configures the JPA repositories, using the {@link EnableJpaRepositories} annotation</li>
 *     <li>inserts a simple {@link Product} in the database, using the auto-configured {@link javax.sql.DataSource}</li>
 * </ul>
 */
@Configuration
@EnableJpaRepositories(basePackages = "net.safedata.springboot.training.d02.s05.repository")
@EnableTransactionManagement
public class DataSourceConfig {

    private final ProductService productService;

    @Autowired
    public DataSourceConfig(final ProductService productService) {
        this.productService = productService;
    }

    @PostConstruct
    public void init() {
        final Product product = new Product();
        product.setName("A default product");
        productService.create(product);
    }
}

@@ -505,16 +505,76 @@
 nstruct;
+%0Aimport java.util.Random;%0Aimport java.util.stream.IntStream;
 %0A%0A/**%0A *
@@ -1046,16 +1046,75 @@
 nfig %7B%0A%0A
+    private static final Random RANDOM = new Random(200);%0A%0A
     priv
@@ -1330,24 +1330,105 @@
 id init() %7B%0A
+        IntStream.range(0, 20)%0A                 .forEach(value -%3E %7B%0A             
         fina
@@ -1462,16 +1462,29 @@
 duct();%0A
+             
         
@@ -1521,12 +1521,57 @@
 duct
-%22);%0A
+ with the ID %22 + RANDOM.nextInt());%0A             
     
@@ -1606,16 +1606,37 @@
 oduct);%0A
+                 %7D);%0A
     %7D%0A%7D%0A

Insert several products in the database