From cd9d62986882b298948dff96f8bc4d18a086f90d Mon Sep 17 00:00:00 2001 From: Stefan Suhren Date: Mon, 23 Nov 2015 15:40:44 +0100 Subject: Format files and organize imports --- src/jpa/Category.java | 116 ++++++++++++++++------------- src/jpa/JPATest.java | 56 +++++++------- src/jpa/Product.java | 199 +++++++++++++++++++++++++++----------------------- src/jpa/User.java | 67 +++++++++-------- 4 files changed, 239 insertions(+), 199 deletions(-) (limited to 'src/jpa') diff --git a/src/jpa/Category.java b/src/jpa/Category.java index 195b6e8..bbd832d 100644 --- a/src/jpa/Category.java +++ b/src/jpa/Category.java @@ -1,64 +1,78 @@ package jpa; import java.io.Serializable; -import javax.persistence.*; import java.util.Set; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.ManyToMany; +import javax.persistence.NamedQuery; +import javax.persistence.Table; /** * The persistent class for the category database table. * */ @Entity -@Table(name="category") -@NamedQuery(name="Category.findAll", query="SELECT c FROM Category c") -public class Category implements Serializable { - private static final long serialVersionUID = 1L; - - @Id - private int id; - - private String description; - - private String name; - - //bi-directional many-to-many association to Product - @ManyToMany(mappedBy="categories") - private Set products; - - public Category() { - } - - public int getId() { - return this.id; - } - - public void setId(int id) { - this.id = id; - } - - public String getDescription() { - return this.description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - - public Set getProducts() { - return this.products; - } - - public void setProducts(Set products) { - this.products = products; - } +@Table(name = "category") +@NamedQuery(name = "Category.findAll", query = "SELECT c FROM Category c") +public class Category implements Serializable +{ + private static final long serialVersionUID = 1L; + + @Id + private int id; + + private String description; + + private String name; + + // bi-directional many-to-many association to Product + @ManyToMany(mappedBy = "categories") + private Set products; + + public Category() + { + } + + public int getId() + { + return this.id; + } + + public void setId(int id) + { + this.id = id; + } + + public String getDescription() + { + return this.description; + } + + public void setDescription(String description) + { + this.description = description; + } + + public String getName() + { + return this.name; + } + + public void setName(String name) + { + this.name = name; + } + + public Set getProducts() + { + return this.products; + } + + public void setProducts(Set products) + { + this.products = products; + } } \ No newline at end of file diff --git a/src/jpa/JPATest.java b/src/jpa/JPATest.java index 5a4749e..1407c6c 100644 --- a/src/jpa/JPATest.java +++ b/src/jpa/JPATest.java @@ -19,25 +19,25 @@ public class JPATest tx.begin(); try { -// Product product = manager.find(Product.class, "7"); -// Category newCategory = manager.find(Category.class, 4); -// product.addCategory(newCategory); -// manager.persist(product); -// Collection categories = product.getCategoryCollection(); -// for (Category category : categories) -// { -// System.out.println(category.getName()); -// } + // Product product = manager.find(Product.class, "7"); + // Category newCategory = manager.find(Category.class, 4); + // product.addCategory(newCategory); + // manager.persist(product); + // Collection categories = product.getCategoryCollection(); + // for (Category category : categories) + // { + // System.out.println(category.getName()); + // } Product product = new Product(); product.setDescription("Noch ein Testprodukt"); product.setName("Produkt"); manager.persist(product); -// User user = new User(); -// user.setUsername("bestertester2"); -// System.out.println(DigestUtils.md5("masterkey")); -// user.setPassword(DigestUtils.md5("masterkey")); -// manager.persist(user); - + // User user = new User(); + // user.setUsername("bestertester2"); + // System.out.println(DigestUtils.md5("masterkey")); + // user.setPassword(DigestUtils.md5("masterkey")); + // manager.persist(user); + tx.commit(); } catch (Exception ex) @@ -45,18 +45,18 @@ public class JPATest ex.printStackTrace(System.err); tx.rollback(); } - -// CategoryManager cm = new CategoryManager(); -// Collection categories = cm.getCategories(); -// for (Category category : categories) -// { -// System.out.println(category.getName()); -// Set products = category.getProductCollection(); -// for (Product product : products) -// { -// System.out.println("\t" + product.getName()); -// } -// -// } + + // CategoryManager cm = new CategoryManager(); + // Collection categories = cm.getCategories(); + // for (Category category : categories) + // { + // System.out.println(category.getName()); + // Set products = category.getProductCollection(); + // for (Product product : products) + // { + // System.out.println("\t" + product.getName()); + // } + // + // } } } diff --git a/src/jpa/Product.java b/src/jpa/Product.java index baf29ca..8196b73 100644 --- a/src/jpa/Product.java +++ b/src/jpa/Product.java @@ -1,105 +1,122 @@ package jpa; import java.io.Serializable; -import javax.persistence.*; import java.math.BigDecimal; import java.util.Set; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.Lob; +import javax.persistence.ManyToMany; +import javax.persistence.NamedQuery; +import javax.persistence.Table; /** * The persistent class for the product database table. * */ @Entity -@Table(name="product") -@NamedQuery(name="Product.findAll", query="SELECT p FROM Product p") -public class Product implements Serializable { - private static final long serialVersionUID = 1L; - - @Id - private int id; - - @Lob - private String description; - - private BigDecimal height; - - private String name; - - private BigDecimal price; - - private BigDecimal width; - - //bi-directional many-to-many association to Category - @ManyToMany - @JoinTable( - name="product_category" - , joinColumns={ - @JoinColumn(name="product_id") - } - , inverseJoinColumns={ - @JoinColumn(name="category_id") - } - ) - private Set categories; - - public Product() { - } - - public int getId() { - return this.id; - } - - public void setId(int id) { - this.id = id; - } - - public String getDescription() { - return this.description; - } - - public void setDescription(String description) { - this.description = description; - } - - public BigDecimal getHeight() { - return this.height; - } - - public void setHeight(BigDecimal height) { - this.height = height; - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - - public BigDecimal getPrice() { - return this.price; - } - - public void setPrice(BigDecimal price) { - this.price = price; - } - - public BigDecimal getWidth() { - return this.width; - } - - public void setWidth(BigDecimal width) { - this.width = width; - } - - public Set getCategories() { - return this.categories; - } - - public void setCategories(Set categories) { - this.categories = categories; - } +@Table(name = "product") +@NamedQuery(name = "Product.findAll", query = "SELECT p FROM Product p") +public class Product implements Serializable +{ + private static final long serialVersionUID = 1L; + + @Id + private int id; + + @Lob + private String description; + + private BigDecimal height; + + private String name; + + private BigDecimal price; + + private BigDecimal width; + + // bi-directional many-to-many association to Category + @ManyToMany + @JoinTable(name = "product_category", joinColumns = { + @JoinColumn(name = "product_id") }, inverseJoinColumns = { + @JoinColumn(name = "category_id") }) + private Set categories; + + public Product() + { + } + + public int getId() + { + return this.id; + } + + public void setId(int id) + { + this.id = id; + } + + public String getDescription() + { + return this.description; + } + + public void setDescription(String description) + { + this.description = description; + } + + public BigDecimal getHeight() + { + return this.height; + } + + public void setHeight(BigDecimal height) + { + this.height = height; + } + + public String getName() + { + return this.name; + } + + public void setName(String name) + { + this.name = name; + } + + public BigDecimal getPrice() + { + return this.price; + } + + public void setPrice(BigDecimal price) + { + this.price = price; + } + + public BigDecimal getWidth() + { + return this.width; + } + + public void setWidth(BigDecimal width) + { + this.width = width; + } + + public Set getCategories() + { + return this.categories; + } + + public void setCategories(Set categories) + { + this.categories = categories; + } } \ No newline at end of file diff --git a/src/jpa/User.java b/src/jpa/User.java index d96d27e..c3e9f75 100644 --- a/src/jpa/User.java +++ b/src/jpa/User.java @@ -1,41 +1,50 @@ package jpa; import java.io.Serializable; -import javax.persistence.*; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.Table; /** * The persistent class for the user database table. * */ @Entity -@Table(name="user") -@NamedQuery(name="User.findAll", query="SELECT u FROM User u") -public class User implements Serializable { - private static final long serialVersionUID = 1L; - - @Id - private String username; - - private String password; - - public User() { - } - - public String getUsername() { - return this.username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getPassword() { - return this.password; - } - - public void setPassword(String password) { - this.password = password; - } +@Table(name = "user") +@NamedQuery(name = "User.findAll", query = "SELECT u FROM User u") +public class User implements Serializable +{ + private static final long serialVersionUID = 1L; + + @Id + private String username; + + private String password; + + public User() + { + } + + public String getUsername() + { + return this.username; + } + + public void setUsername(String username) + { + this.username = username; + } + + public String getPassword() + { + return this.password; + } + + public void setPassword(String password) + { + this.password = password; + } } \ No newline at end of file -- cgit v1.2.3-70-g09d2