BAEL-1176 Spring Cloud Connector Heroku (#2911)

* BAEL-1176 setting up base application with in memory database

* BAEL-1176 adding postgres stuff
This commit is contained in:
Tim Schimandle
2017-11-04 09:46:20 -06:00
committed by Grzegorz Piwowarek
parent 666206ce05
commit a9bea07bd5
8 changed files with 211 additions and 0 deletions
@@ -0,0 +1,12 @@
package com.baeldung.spring.cloud.connectors.heroku;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ConnectorsHerokuApplication {
public static void main(String[] args) {
SpringApplication.run(ConnectorsHerokuApplication.class, args);
}
}
@@ -0,0 +1,30 @@
package com.baeldung.spring.cloud.connectors.heroku.product;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long productId;
private String sku;
public Long getProductId() {
return productId;
}
public void setProductId(Long productId) {
this.productId = productId;
}
public String getSku() {
return sku;
}
public void setSku(String sku) {
this.sku = sku;
}
}
@@ -0,0 +1,26 @@
package com.baeldung.spring.cloud.connectors.heroku.product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/products")
public class ProductController {
private final ProductService productService;
@Autowired
public ProductController(ProductService productService) {
this.productService = productService;
}
@GetMapping("/{productId}")
public Product findProduct(@PathVariable Long productId) {
return productService.findProductById(productId);
}
@PostMapping
public Product createProduct(@RequestBody Product product) {
return productService.createProduct(product);
}
}
@@ -0,0 +1,6 @@
package com.baeldung.spring.cloud.connectors.heroku.product;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ProductRepository extends JpaRepository<Product, Long>{
}
@@ -0,0 +1,28 @@
package com.baeldung.spring.cloud.connectors.heroku.product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional(readOnly = true)
public class ProductService {
private final ProductRepository productRepository;
@Autowired
public ProductService(ProductRepository productRepository) {
this.productRepository = productRepository;
}
public Product findProductById(Long productId) {
return productRepository.findOne(productId);
}
@Transactional(propagation = Propagation.REQUIRED)
public Product createProduct(Product product) {
Product newProduct = new Product();
newProduct.setSku(product.getSku());
return productRepository.save(newProduct);
}
}
@@ -0,0 +1,8 @@
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.maxActive=10
spring.datasource.maxIdle=5
spring.datasource.minIdle=2
spring.datasource.initialSize=5
spring.datasource.removeAbandoned=true
spring.jpa.hibernate.ddl-auto=update