diff options
| author | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-11-22 15:07:27 +0100 |
|---|---|---|
| committer | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-11-23 15:57:23 +0100 |
| commit | df8c8d8eaa3fd74b2f6a76341611555ee6d8834d (patch) | |
| tree | 40e93e3b3674f32d4870486eb9f5870d9fe45b2b /src/jpa/Category.java | |
| download | JCatalog-df8c8d8eaa3fd74b2f6a76341611555ee6d8834d.tar.gz JCatalog-df8c8d8eaa3fd74b2f6a76341611555ee6d8834d.zip | |
Add initial files
Diffstat (limited to 'src/jpa/Category.java')
| -rw-r--r-- | src/jpa/Category.java | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/src/jpa/Category.java b/src/jpa/Category.java new file mode 100644 index 0000000..c29c1f7 --- /dev/null +++ b/src/jpa/Category.java @@ -0,0 +1,103 @@ +package jpa; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.Set; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.ManyToMany; + +@Entity +public class Category implements Serializable +{ + @Id + private int id; + + private String name; + + private String description; + + @ManyToMany(mappedBy = "categoryCollection") + private Set<Product> productCollection; + + private static final long serialVersionUID = 1L; + + public Category() + { + super(); + } + + public int getId() + { + return this.id; + } + + public void setId(int id) + { + this.id = id; + } + + public String getName() + { + return this.name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getDescription() + { + return this.description; + } + + public void setDescription(String description) + { + this.description = description; + } + + /** + * The method <code>getProductCollection()</code> returns a + * Collection object that is incompatible with JSF. + * + * @return collection of product objects. + */ + public Collection<Product> getProducts() + { + Collection<Product> c = new ArrayList<Product>(); + + for (Iterator iter = getProductCollection().iterator(); iter.hasNext();) + { + Product product = (Product) iter.next(); + c.add(product); +// System.out.println(product.getName()); + } + + return c; + } + + public Set<Product> getProductCollection() + { + return this.productCollection; + } + + public void setProductCollection(Set<Product> productCollection) + { + this.productCollection = productCollection; + } + + public void addProduct(Product product) + { + Set<Product> products = getProductCollection(); + if (!products.contains(product)) + { + products.add(product); + product.addCategory(this); + } + } + +} |
