summaryrefslogtreecommitdiffstats
path: root/src/jpa/Product.java
blob: dc0b3f809dd2b5d4d1541a53bbd80c8877247672 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package jpa;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;

@Entity
public class Product implements Serializable {
	@Id
	@GeneratedValue(strategy=GenerationType.SEQUENCE)
	private String id;

	private String description;

	private BigDecimal price;

	private String name;

	private BigDecimal width;

	private BigDecimal height;

	@ManyToMany
	@JoinTable(
		joinColumns=@JoinColumn(name="product_id"),
		inverseJoinColumns=@JoinColumn(name="category_id"))
	private Set<Category> categoryCollection;

	private static final long serialVersionUID = 1L;

	public Product() {
		super();
	}

	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public BigDecimal getPrice() {
		return this.price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public BigDecimal getWidth() {
		return this.width;
	}

	public void setWidth(BigDecimal width) {
		this.width = width;
	}

	public BigDecimal getHeight() {
		return this.height;
	}

	public void setHeight(BigDecimal height) {
		this.height = height;
	}

    public Collection getCategories() {
        return this.getCategoryCollection();
    }

	public Set<Category> getCategoryCollection() {
		return this.categoryCollection;
	}

	public void setCategoryCollection(Set<Category> categoryCollection) {
		this.categoryCollection = categoryCollection;
	}

    public void addCategory(Category category)
    {
       Set<Category> categories = getCategoryCollection();
       if (!categories.contains(category))
       {
          categories.add(category);
          category.addProduct(this);
       }
    }
}