Skip to content

Commit 4868a18

Browse files
author
fer
committed
- Init version
1 parent 88f2951 commit 4868a18

18 files changed

Lines changed: 755 additions & 4 deletions

pom.xml

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>br.com.blz</groupId>
77
<artifactId>test-java</artifactId>
8-
<version>0.0.1-SNAPSHOT</version>
8+
<version>1.0-SNAPSHOT</version>
99
<packaging>jar</packaging>
1010

1111
<name>test-java</name>
@@ -14,7 +14,7 @@
1414
<parent>
1515
<groupId>org.springframework.boot</groupId>
1616
<artifactId>spring-boot-starter-parent</artifactId>
17-
<version>1.5.12.RELEASE</version>
17+
<version>2.1.6.RELEASE</version> <!-- <version>1.5.12.RELEASE</version>-->
1818
<relativePath/> <!-- lookup parent from repository -->
1919
</parent>
2020

@@ -29,12 +29,46 @@
2929
<groupId>org.springframework.boot</groupId>
3030
<artifactId>spring-boot-starter-web</artifactId>
3131
</dependency>
32+
33+
<dependency>
34+
<groupId>commons-lang</groupId>
35+
<artifactId>commons-lang</artifactId>
36+
<version>2.4</version>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-starter-data-jpa</artifactId>
42+
</dependency>
43+
44+
<dependency>
45+
<groupId>com.h2database</groupId>
46+
<artifactId>h2</artifactId>
47+
</dependency>
48+
49+
<dependency>
50+
<groupId>org.modelmapper</groupId>
51+
<artifactId>modelmapper</artifactId>
52+
<version>2.3.5</version>
53+
</dependency>
54+
55+
<dependency>
56+
<groupId>io.springfox</groupId>
57+
<artifactId>springfox-swagger2</artifactId>
58+
<version>2.9.2</version>
59+
</dependency>
60+
<dependency>
61+
<groupId>io.springfox</groupId>
62+
<artifactId>springfox-swagger-ui</artifactId>
63+
<version>2.9.2</version>
64+
</dependency>
3265

3366
<dependency>
3467
<groupId>org.springframework.boot</groupId>
3568
<artifactId>spring-boot-starter-test</artifactId>
3669
<scope>test</scope>
3770
</dependency>
71+
3872
</dependencies>
3973

4074
<build>

src/main/java/br/com/blz/testjava/TestJavaApplication.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.boot.autoconfigure.domain.EntityScan;
6+
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
57

8+
@EnableJpaRepositories("br.com.blz.testjava.dao.repository")
9+
@EntityScan("br.com.blz.testjava.dao.entity")
610
@SpringBootApplication(scanBasePackageClasses = TestJavaApplication.class)
711
public class TestJavaApplication {
812

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package br.com.blz.testjava.config;
2+
3+
import org.modelmapper.ModelMapper;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
7+
@Configuration
8+
public class AppConfig {
9+
@Bean
10+
public ModelMapper modelMapper() {
11+
return new ModelMapper();
12+
}
13+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
2+
package br.com.blz.testjava.dao.entity;
3+
4+
import java.io.Serializable;
5+
import java.util.List;
6+
7+
import javax.persistence.CascadeType;
8+
import javax.persistence.Column;
9+
import javax.persistence.Entity;
10+
import javax.persistence.FetchType;
11+
import javax.persistence.GeneratedValue;
12+
import javax.persistence.GenerationType;
13+
import javax.persistence.Id;
14+
import javax.persistence.OneToMany;
15+
16+
import org.apache.commons.lang.builder.EqualsBuilder;
17+
import org.apache.commons.lang.builder.HashCodeBuilder;
18+
import org.apache.commons.lang.builder.ToStringBuilder;
19+
20+
@Entity
21+
public class Inventory implements Serializable {
22+
@Id
23+
@Column(name = "ID", nullable = false)
24+
@GeneratedValue(strategy = GenerationType.AUTO)
25+
private Long id;
26+
private Integer quantity;
27+
@OneToMany(cascade=CascadeType.ALL, targetEntity=Warehouse.class, fetch=FetchType.EAGER)
28+
private List<Warehouse> warehouses;
29+
private final static long serialVersionUID = -5067163988590103177L;
30+
31+
/**
32+
* No args constructor for use in serialization
33+
*
34+
*/
35+
public Inventory() {
36+
}
37+
38+
/**
39+
*
40+
* @param quantity
41+
* @param warehouses
42+
*/
43+
public Inventory(Integer quantity, List<Warehouse> warehouses) {
44+
super();
45+
this.quantity = quantity;
46+
this.warehouses = warehouses;
47+
}
48+
49+
public Long getId() {
50+
return id;
51+
}
52+
53+
public void setId(Long id) {
54+
this.id = id;
55+
}
56+
57+
public Integer getQuantity() {
58+
return quantity;
59+
}
60+
61+
public void setQuantity(Integer quantity) {
62+
this.quantity = quantity;
63+
}
64+
65+
public Inventory withQuantity(Integer quantity) {
66+
this.quantity = quantity;
67+
return this;
68+
}
69+
70+
public List<Warehouse> getWarehouses() {
71+
return warehouses;
72+
}
73+
74+
public void setWarehouses(List<Warehouse> warehouses) {
75+
this.warehouses = warehouses;
76+
}
77+
78+
public Inventory withWarehouses(List<Warehouse> warehouses) {
79+
this.warehouses = warehouses;
80+
return this;
81+
}
82+
83+
@Override
84+
public String toString() {
85+
return new ToStringBuilder(this).append("id", id).append("quantity", quantity).append("warehouses", warehouses).toString();
86+
}
87+
88+
@Override
89+
public int hashCode() {
90+
return new HashCodeBuilder().append(warehouses).append(id).append(quantity).toHashCode();
91+
}
92+
93+
@Override
94+
public boolean equals(Object other) {
95+
if (other == this) {
96+
return true;
97+
}
98+
if ((other instanceof Inventory) == false) {
99+
return false;
100+
}
101+
Inventory rhs = ((Inventory) other);
102+
return new EqualsBuilder().append(warehouses, rhs.warehouses).append(id, rhs.id).append(quantity, rhs.quantity).isEquals();
103+
}
104+
105+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
2+
package br.com.blz.testjava.dao.entity;
3+
4+
import java.io.Serializable;
5+
import java.util.Objects;
6+
7+
import javax.persistence.CascadeType;
8+
import javax.persistence.EmbeddedId;
9+
import javax.persistence.Entity;
10+
import javax.persistence.FetchType;
11+
import javax.persistence.OneToOne;
12+
@Entity
13+
public class Product implements Serializable {
14+
@EmbeddedId
15+
private ProductEntryPK sku;
16+
private String name;
17+
@OneToOne(cascade=CascadeType.ALL, targetEntity=Inventory.class, fetch = FetchType.EAGER)
18+
private Inventory inventory;
19+
private Boolean isMarketable;
20+
private final static long serialVersionUID = -2026203869071939291L;
21+
22+
public ProductEntryPK getSku() {
23+
return sku;
24+
}
25+
public void setSku(ProductEntryPK sku) {
26+
this.sku = sku;
27+
}
28+
public String getName() {
29+
return name;
30+
}
31+
public void setName(String name) {
32+
this.name = name;
33+
}
34+
public Inventory getInventory() {
35+
return inventory;
36+
}
37+
public void setInventory(Inventory inventory) {
38+
this.inventory = inventory;
39+
}
40+
public Boolean getIsMarketable() {
41+
return isMarketable;
42+
}
43+
public void setIsMarketable(Boolean isMarketable) {
44+
this.isMarketable = isMarketable;
45+
}
46+
public static long getSerialversionuid() {
47+
return serialVersionUID;
48+
}
49+
@Override
50+
public int hashCode() {
51+
return Objects.hash(inventory, isMarketable, name, sku);
52+
}
53+
@Override
54+
public boolean equals(Object obj) {
55+
if (this == obj)
56+
return true;
57+
if (obj == null)
58+
return false;
59+
if (getClass() != obj.getClass())
60+
return false;
61+
Product other = (Product) obj;
62+
return Objects.equals(inventory, other.inventory) && Objects.equals(isMarketable, other.isMarketable)
63+
&& Objects.equals(name, other.name) && Objects.equals(sku, other.sku);
64+
}
65+
66+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package br.com.blz.testjava.dao.entity;
2+
3+
import java.io.Serializable;
4+
5+
import javax.persistence.Embeddable;
6+
7+
@Embeddable
8+
public class ProductEntryPK implements Serializable {
9+
10+
private Long sku;
11+
12+
public Long getSku() {
13+
return sku;
14+
}
15+
16+
public void setSku(Long sku) {
17+
this.sku = sku;
18+
}
19+
20+
@Override
21+
public int hashCode() {
22+
final int prime = 31;
23+
int result = 1;
24+
result = prime * result + ((sku == null) ? 0 : sku.hashCode());
25+
return result;
26+
}
27+
28+
@Override
29+
public boolean equals(Object obj) {
30+
if (this == obj)
31+
return true;
32+
if (obj == null)
33+
return false;
34+
if (getClass() != obj.getClass())
35+
return false;
36+
ProductEntryPK other = (ProductEntryPK) obj;
37+
if (sku == null) {
38+
if (other.sku != null)
39+
return false;
40+
} else if (!sku.equals(other.sku))
41+
return false;
42+
return true;
43+
}
44+
}

0 commit comments

Comments
 (0)