From 25ae0a23d15383df7f84ad51ee8f078c519ed963 Mon Sep 17 00:00:00 2001 From: Stefan Suhren Date: Sun, 22 Nov 2015 17:02:23 +0100 Subject: Get it to run on newest versions --- .classpath | 12 +- .metadata/WebContent/WEB-INF/faces-config.pageflow | 51 +++++ .settings/org.eclipse.jdt.core.prefs | 7 +- .settings/org.eclipse.jpt.core.prefs | 3 + .../org.eclipse.jpt.entitygen.jcatalog.jcatalog | Bin 0 -> 1597 bytes ...org.eclipse.jst.common.project.facet.core.prefs | 4 - ...eclipse.wst.common.project.facet.core.prefs.xml | 12 ++ .../org.eclipse.wst.common.project.facet.core.xml | 8 +- .settings/org.eclipse.wst.ws.service.policy.prefs | 2 + WebContent/WEB-INF/faces-config.xml | 211 --------------------- .../lib/mysql-connector-java-5.1.37-bin.jar | Bin 0 -> 985603 bytes WebContent/WEB-INF/web.xml | 8 +- src/META-INF/persistence.xml | 13 +- src/beans/CategoryManager.java | 8 +- src/beans/ContactManager.java | 5 + src/beans/ProductManager.java | 8 +- src/beans/UserManager.java | 176 +++++++++-------- src/jpa/Category.java | 153 ++++++--------- src/jpa/Product.java | 94 +++++---- src/jpa/User.java | 17 +- 20 files changed, 319 insertions(+), 473 deletions(-) create mode 100644 .metadata/WebContent/WEB-INF/faces-config.pageflow create mode 100644 .settings/org.eclipse.jpt.core.prefs create mode 100644 .settings/org.eclipse.jpt.entitygen.jcatalog.jcatalog delete mode 100644 .settings/org.eclipse.jst.common.project.facet.core.prefs create mode 100644 .settings/org.eclipse.wst.common.project.facet.core.prefs.xml create mode 100644 .settings/org.eclipse.wst.ws.service.policy.prefs delete mode 100644 WebContent/WEB-INF/faces-config.xml create mode 100644 WebContent/WEB-INF/lib/mysql-connector-java-5.1.37-bin.jar diff --git a/.classpath b/.classpath index fa0a137..0168508 100644 --- a/.classpath +++ b/.classpath @@ -1,8 +1,16 @@ - - + + + + + + + + + + diff --git a/.metadata/WebContent/WEB-INF/faces-config.pageflow b/.metadata/WebContent/WEB-INF/faces-config.pageflow new file mode 100644 index 0000000..96f5427 --- /dev/null +++ b/.metadata/WebContent/WEB-INF/faces-config.pageflow @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index d04de3a..f42de36 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,8 +1,7 @@ -#Mon Jun 25 14:38:55 CEST 2007 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.5 +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/.settings/org.eclipse.jpt.core.prefs b/.settings/org.eclipse.jpt.core.prefs new file mode 100644 index 0000000..bc24399 --- /dev/null +++ b/.settings/org.eclipse.jpt.core.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +org.eclipse.jpt.core.platform=eclipselink2_5 +org.eclipse.jpt.jpa.core.discoverAnnotatedClasses=true diff --git a/.settings/org.eclipse.jpt.entitygen.jcatalog.jcatalog b/.settings/org.eclipse.jpt.entitygen.jcatalog.jcatalog new file mode 100644 index 0000000..3c33b98 Binary files /dev/null and b/.settings/org.eclipse.jpt.entitygen.jcatalog.jcatalog differ diff --git a/.settings/org.eclipse.jst.common.project.facet.core.prefs b/.settings/org.eclipse.jst.common.project.facet.core.prefs deleted file mode 100644 index faee126..0000000 --- a/.settings/org.eclipse.jst.common.project.facet.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -#Tue Dec 05 14:34:55 CET 2006 -classpath.helper/org.eclipse.jdt.launching.JRE_CONTAINER/owners=jst.java\:5.0 -classpath.helper/org.eclipse.jst.server.core.container\:\:org.eclipse.jst.server.tomcat.runtimeTarget\:\:Apache\ Tomcat\ v5.5/owners=jst.web\:2.4 -eclipse.preferences.version=1 diff --git a/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml b/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml new file mode 100644 index 0000000..32f0f3a --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml index 2a3c4eb..9d885a4 100644 --- a/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -1,8 +1,10 @@ - + - - + + + + diff --git a/.settings/org.eclipse.wst.ws.service.policy.prefs b/.settings/org.eclipse.wst.ws.service.policy.prefs new file mode 100644 index 0000000..9cfcabe --- /dev/null +++ b/.settings/org.eclipse.wst.ws.service.policy.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.wst.ws.service.policy.projectEnabled=false diff --git a/WebContent/WEB-INF/faces-config.xml b/WebContent/WEB-INF/faces-config.xml deleted file mode 100644 index 06265ca..0000000 --- a/WebContent/WEB-INF/faces-config.xml +++ /dev/null @@ -1,211 +0,0 @@ - - - - - - - UserManager - beans.UserManager - session - - - - CategoryManager - beans.CategoryManager - session - - - - ContactManager - beans.ContactManager - session - - - - ProductManager - beans.ProductManager - session - - - - - /pages/home.xhtml - - - contact - /pages/contact.xhtml - - - - login - /pages/login.xhtml - - - - categories - /pages/categories.xhtml - - - - - - - /pages/login.xhtml - - - contact - /pages/contact.xhtml - - - - login - /pages/login.xhtml - - - - categories - /pages/categories.xhtml - - - - failure - /pages/login.xhtml - - - - success - /pages/greeting.xhtml - - - - - - - - /pages/categories.xhtml - - - contact - /pages/contact.xhtml - - - - login - /pages/login.xhtml - - - - categories - /pages/categories.xhtml - - - - select - /pages/products.xhtml - - - - - - - /pages/greeting.xhtml - - - contact - /pages/contact.xhtml - - - - categories - /pages/categories.xhtml - - - - home - /pages/home.xhtml - - - - - - - /pages/contact.xhtml - - - contact - /pages/contact.xhtml - - - - categories - /pages/categories.xhtml - - - - login - /pages/login.xhtml - - - - - - - /pages/products.xhtml - - - contact - /pages/contact.xhtml - - - - categories - /pages/categories.xhtml - - - - login - /pages/login.xhtml - - - - - - - /pages/product.xhtml - - - products - /pages/products.xhtml - - - - contact - /pages/contact.xhtml - - - - categories - /pages/categories.xhtml - - - - login - /pages/login.xhtml - - - - - - - com.sun.facelets.FaceletViewHandler - - - de_DE - - - - - - \ No newline at end of file diff --git a/WebContent/WEB-INF/lib/mysql-connector-java-5.1.37-bin.jar b/WebContent/WEB-INF/lib/mysql-connector-java-5.1.37-bin.jar new file mode 100644 index 0000000..465af67 Binary files /dev/null and b/WebContent/WEB-INF/lib/mysql-connector-java-5.1.37-bin.jar differ diff --git a/WebContent/WEB-INF/web.xml b/WebContent/WEB-INF/web.xml index ee62240..28e4dc6 100644 --- a/WebContent/WEB-INF/web.xml +++ b/WebContent/WEB-INF/web.xml @@ -1,12 +1,12 @@ - + Facelets JCatalog Application javax.faces.DEFAULT_SUFFIX .xhtml - facelets.REFRESH_PERIOD + facelets.FACELETS_REFRESH_PERIOD 2 @@ -21,10 +21,6 @@ com.sun.faces.validateXml true - - com.sun.faces.verifyObjects - true - Faces Servlet javax.faces.webapp.FacesServlet diff --git a/src/META-INF/persistence.xml b/src/META-INF/persistence.xml index 039a45e..fef05c4 100644 --- a/src/META-INF/persistence.xml +++ b/src/META-INF/persistence.xml @@ -1,15 +1,12 @@ -jpa.User -jpa.Category -jpa.Product +org.eclipse.persistence.jpa.PersistenceProvider +false - - - - - + + + diff --git a/src/beans/CategoryManager.java b/src/beans/CategoryManager.java index 7b96d2f..fc3d438 100644 --- a/src/beans/CategoryManager.java +++ b/src/beans/CategoryManager.java @@ -13,6 +13,8 @@ import java.io.IOException; import java.util.Collection; import java.util.Map; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.SessionScoped; import javax.faces.context.FacesContext; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; @@ -21,6 +23,8 @@ import javax.persistence.Persistence; import jpa.Category; +@ManagedBean(name = "CategoryManager") +@SessionScoped public class CategoryManager { private Category current; @@ -48,7 +52,7 @@ public class CategoryManager FacesContext facesContext = FacesContext.getCurrentInstance(); Map params = facesContext.getExternalContext().getRequestParameterMap(); Integer selectedId = Integer.valueOf((String) params.get("selectedId")); -// System.out.println(selectedId); + // System.out.println(selectedId); EntityManagerFactory factory = Persistence .createEntityManagerFactory("catalog"); @@ -59,7 +63,7 @@ public class CategoryManager try { current = manager.find(Category.class, selectedId); -// System.out.println(current.getName()); + // System.out.println(current.getName()); tx.commit(); } catch (Exception ex) diff --git a/src/beans/ContactManager.java b/src/beans/ContactManager.java index 43c96e0..4625848 100644 --- a/src/beans/ContactManager.java +++ b/src/beans/ContactManager.java @@ -9,6 +9,11 @@ */ package beans; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.SessionScoped; + +@ManagedBean(name = "ContactManager") +@SessionScoped public class ContactManager { // nothing implemented yet diff --git a/src/beans/ProductManager.java b/src/beans/ProductManager.java index cc0dcaa..d499e3c 100644 --- a/src/beans/ProductManager.java +++ b/src/beans/ProductManager.java @@ -12,6 +12,8 @@ package beans; import java.io.IOException; import java.util.Map; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.SessionScoped; import javax.faces.context.FacesContext; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; @@ -20,10 +22,12 @@ import javax.persistence.Persistence; import jpa.Product; +@ManagedBean(name = "ProductManager") +@SessionScoped public class ProductManager { private Product current; - + public Product getCurrent() { return current; @@ -34,7 +38,7 @@ public class ProductManager FacesContext facesContext = FacesContext.getCurrentInstance(); Map params = facesContext.getExternalContext().getRequestParameterMap(); String selectedId = (String) params.get("selectedId"); -// System.out.println(selectedId); + // System.out.println(selectedId); EntityManagerFactory factory = Persistence .createEntityManagerFactory("catalog"); diff --git a/src/beans/UserManager.java b/src/beans/UserManager.java index 9e08543..190926b 100644 --- a/src/beans/UserManager.java +++ b/src/beans/UserManager.java @@ -9,8 +9,12 @@ */ package beans; +import static util.DigestUtils.md5; + import java.util.List; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.SessionScoped; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.EntityTransaction; @@ -18,83 +22,99 @@ import javax.persistence.Persistence; import javax.persistence.Query; import jpa.User; -import static util.DigestUtils.md5; -public class UserManager { - private User current; - - private boolean loggedIn; - - public UserManager() { - current = new User(); - } - - public String login() { - String outcome = "failure"; - if (current.getUsername() != null && current.getUsername().length() > 0 - && current.getPassword() != null - && current.getPassword().length() > 0) { - EntityManagerFactory factory = Persistence - .createEntityManagerFactory("catalog"); - EntityManager manager = factory.createEntityManager(); - Query query = manager - .createQuery("SELECT u FROM User u where u.username = :username and u.password = :password"); - query.setParameter("username", current.getUsername()); - query.setParameter("password", md5(current.getPassword())); - List results = query.getResultList(); - - if (!results.isEmpty()) { - loggedIn = true; - current = (User) results.get(0); - outcome = "success"; - } - } - // System.out.println(outcome); - return outcome; - } - - public String logout() { - loggedIn = false; - current = new User(); - return "home"; - } - - public void setUsername(String username) { - current.setUsername(username); - } - - public String getUsername() { - return current.getUsername(); - } - - public void setPassword(String password) { - current.setPassword(password); - } - - public String getPassword() { - return current.getPassword(); - } - - public boolean isLoggedIn() { - return loggedIn; - } - - public User getCurrent() { - EntityManagerFactory factory = Persistence - .createEntityManagerFactory("catalog"); - EntityManager manager = factory.createEntityManager(); - - EntityTransaction tx = manager.getTransaction(); - tx.begin(); - try { - current = manager.find(User.class, getUsername()); - - tx.commit(); - } catch (Exception ex) { - ex.printStackTrace(System.err); - tx.rollback(); - } - - return current; - } +@ManagedBean(name = "UserManager") +@SessionScoped +public class UserManager +{ + private User current; + + private boolean loggedIn; + + public UserManager() + { + current = new User(); + } + + public String login() + { + String outcome = "failure"; + if (current.getUsername() != null && current.getUsername().length() > 0 + && current.getPassword() != null + && current.getPassword().length() > 0) + { + EntityManagerFactory factory = Persistence + .createEntityManagerFactory("catalog"); + EntityManager manager = factory.createEntityManager(); + Query query = manager.createQuery( + "SELECT u FROM User u where u.username = :username and u.password = :password"); + query.setParameter("username", current.getUsername()); + query.setParameter("password", md5(current.getPassword())); + List results = query.getResultList(); + + if (!results.isEmpty()) + { + loggedIn = true; + current = (User) results.get(0); + outcome = "success"; + } + } + // System.out.println(outcome); + return outcome; + } + + public String logout() + { + loggedIn = false; + current = new User(); + return "home"; + } + + public void setUsername(String username) + { + current.setUsername(username); + } + + public String getUsername() + { + return current.getUsername(); + } + + public void setPassword(String password) + { + current.setPassword(password); + } + + public String getPassword() + { + return current.getPassword(); + } + + public boolean isLoggedIn() + { + return loggedIn; + } + + public User getCurrent() + { + EntityManagerFactory factory = Persistence + .createEntityManagerFactory("catalog"); + EntityManager manager = factory.createEntityManager(); + + EntityTransaction tx = manager.getTransaction(); + tx.begin(); + try + { + current = manager.find(User.class, getUsername()); + + tx.commit(); + } + catch (Exception ex) + { + ex.printStackTrace(System.err); + tx.rollback(); + } + + return current; + } } diff --git a/src/jpa/Category.java b/src/jpa/Category.java index c29c1f7..195b6e8 100644 --- a/src/jpa/Category.java +++ b/src/jpa/Category.java @@ -1,103 +1,64 @@ package jpa; import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; +import javax.persistence.*; import java.util.Set; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.ManyToMany; +/** + * The persistent class for the category database table. + * + */ @Entity -public class Category implements Serializable -{ - @Id - private int id; - - private String name; - - private String description; - - @ManyToMany(mappedBy = "categoryCollection") - private Set 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 getProductCollection() returns a - * Collection object that is incompatible with JSF. - * - * @return collection of product objects. - */ - public Collection getProducts() - { - Collection c = new ArrayList(); - - for (Iterator iter = getProductCollection().iterator(); iter.hasNext();) - { - Product product = (Product) iter.next(); - c.add(product); -// System.out.println(product.getName()); - } - - return c; - } - - public Set getProductCollection() - { - return this.productCollection; - } - - public void setProductCollection(Set productCollection) - { - this.productCollection = productCollection; - } - - public void addProduct(Product product) - { - Set products = getProductCollection(); - if (!products.contains(product)) - { - products.add(product); - product.addCategory(this); - } - } - -} +@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/Product.java b/src/jpa/Product.java index dc0b3f8..baf29ca 100644 --- a/src/jpa/Product.java +++ b/src/jpa/Product.java @@ -1,51 +1,56 @@ package jpa; import java.io.Serializable; +import javax.persistence.*; 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; +/** + * 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 - @GeneratedValue(strategy=GenerationType.SEQUENCE) - private String id; + private int id; + @Lob private String description; - private BigDecimal price; + private BigDecimal height; private String name; - private BigDecimal width; + private BigDecimal price; - private BigDecimal height; + private BigDecimal width; + //bi-directional many-to-many association to Category @ManyToMany @JoinTable( - joinColumns=@JoinColumn(name="product_id"), - inverseJoinColumns=@JoinColumn(name="category_id")) - private Set categoryCollection; - - private static final long serialVersionUID = 1L; + name="product_category" + , joinColumns={ + @JoinColumn(name="product_id") + } + , inverseJoinColumns={ + @JoinColumn(name="category_id") + } + ) + private Set categories; public Product() { - super(); } - public String getId() { + public int getId() { return this.id; } - public void setId(String id) { + public void setId(int id) { this.id = id; } @@ -57,12 +62,12 @@ public class Product implements Serializable { this.description = description; } - public BigDecimal getPrice() { - return this.price; + public BigDecimal getHeight() { + return this.height; } - public void setPrice(BigDecimal price) { - this.price = price; + public void setHeight(BigDecimal height) { + this.height = height; } public String getName() { @@ -73,41 +78,28 @@ public class Product implements Serializable { this.name = name; } - public BigDecimal getWidth() { - return this.width; + public BigDecimal getPrice() { + return this.price; } - public void setWidth(BigDecimal width) { - this.width = width; + public void setPrice(BigDecimal price) { + this.price = price; } - public BigDecimal getHeight() { - return this.height; + public BigDecimal getWidth() { + return this.width; } - public void setHeight(BigDecimal height) { - this.height = height; + public void setWidth(BigDecimal width) { + this.width = width; } - public Collection getCategories() { - return this.getCategoryCollection(); - } - - public Set getCategoryCollection() { - return this.categoryCollection; + public Set getCategories() { + return this.categories; } - public void setCategoryCollection(Set categoryCollection) { - this.categoryCollection = categoryCollection; + public void setCategories(Set categories) { + this.categories = categories; } - public void addCategory(Category category) - { - Set categories = getCategoryCollection(); - if (!categories.contains(category)) - { - categories.add(category); - category.addProduct(this); - } - } -} +} \ No newline at end of file diff --git a/src/jpa/User.java b/src/jpa/User.java index 32d2af8..d96d27e 100644 --- a/src/jpa/User.java +++ b/src/jpa/User.java @@ -1,20 +1,25 @@ package jpa; import java.io.Serializable; -import javax.persistence.Entity; -import javax.persistence.Id; +import javax.persistence.*; + +/** + * 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; - private static final long serialVersionUID = 1L; - public User() { - super(); } public String getUsername() { @@ -33,4 +38,4 @@ public class User implements Serializable { this.password = password; } -} +} \ No newline at end of file -- cgit v1.2.3-70-g09d2