diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..0a8642f --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Zeppelin ignored files +/ZeppelinRemoteNotebooks/ diff --git a/.idea/jpa-buddy.xml b/.idea/jpa-buddy.xml new file mode 100644 index 0000000..d08f400 --- /dev/null +++ b/.idea/jpa-buddy.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/libraries/Java_EE_6_Java_EE_6.xml b/.idea/libraries/Java_EE_6_Java_EE_6.xml new file mode 100644 index 0000000..36175ea --- /dev/null +++ b/.idea/libraries/Java_EE_6_Java_EE_6.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/lib.xml b/.idea/libraries/lib.xml new file mode 100644 index 0000000..bd49071 --- /dev/null +++ b/.idea/libraries/lib.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..16f3465 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..dc8007c --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/build/web/WEB-INF/classes/DAO/Customer.class b/build/web/WEB-INF/classes/DAO/Customer.class index e02a521..3b279e9 100644 Binary files a/build/web/WEB-INF/classes/DAO/Customer.class and b/build/web/WEB-INF/classes/DAO/Customer.class differ diff --git a/build/web/WEB-INF/classes/DAO/Customer.hbm.xml b/build/web/WEB-INF/classes/DAO/Customer.hbm.xml index 066e26e..f1dc11c 100644 --- a/build/web/WEB-INF/classes/DAO/Customer.hbm.xml +++ b/build/web/WEB-INF/classes/DAO/Customer.hbm.xml @@ -1,45 +1,45 @@ + "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/build/web/WEB-INF/classes/DAO/DiscountCode.class b/build/web/WEB-INF/classes/DAO/DiscountCode.class index a5e517e..d1ef671 100644 Binary files a/build/web/WEB-INF/classes/DAO/DiscountCode.class and b/build/web/WEB-INF/classes/DAO/DiscountCode.class differ diff --git a/build/web/WEB-INF/classes/DAO/DiscountCode.hbm.xml b/build/web/WEB-INF/classes/DAO/DiscountCode.hbm.xml index 4246723..3b0c10e 100644 --- a/build/web/WEB-INF/classes/DAO/DiscountCode.hbm.xml +++ b/build/web/WEB-INF/classes/DAO/DiscountCode.hbm.xml @@ -1,15 +1,15 @@ + "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> - + - + diff --git a/build/web/WEB-INF/classes/DAO/MagasinHelper.class b/build/web/WEB-INF/classes/DAO/MagasinHelper.class index 9e73c1a..f26f8dd 100644 Binary files a/build/web/WEB-INF/classes/DAO/MagasinHelper.class and b/build/web/WEB-INF/classes/DAO/MagasinHelper.class differ diff --git a/build/web/WEB-INF/classes/DAO/Manufacturer.class b/build/web/WEB-INF/classes/DAO/Manufacturer.class index e8c8db0..e91c054 100644 Binary files a/build/web/WEB-INF/classes/DAO/Manufacturer.class and b/build/web/WEB-INF/classes/DAO/Manufacturer.class differ diff --git a/build/web/WEB-INF/classes/DAO/Manufacturer.hbm.xml b/build/web/WEB-INF/classes/DAO/Manufacturer.hbm.xml index 5b9100d..ac6a992 100644 --- a/build/web/WEB-INF/classes/DAO/Manufacturer.hbm.xml +++ b/build/web/WEB-INF/classes/DAO/Manufacturer.hbm.xml @@ -1,42 +1,42 @@ + "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> - + - + - + - + - + - + - + - + - + - + - + diff --git a/build/web/WEB-INF/classes/DAO/MicroMarket.class b/build/web/WEB-INF/classes/DAO/MicroMarket.class index 41fa13e..bb9869c 100644 Binary files a/build/web/WEB-INF/classes/DAO/MicroMarket.class and b/build/web/WEB-INF/classes/DAO/MicroMarket.class differ diff --git a/build/web/WEB-INF/classes/DAO/MicroMarket.hbm.xml b/build/web/WEB-INF/classes/DAO/MicroMarket.hbm.xml index 187bc77..f0e77e8 100644 --- a/build/web/WEB-INF/classes/DAO/MicroMarket.hbm.xml +++ b/build/web/WEB-INF/classes/DAO/MicroMarket.hbm.xml @@ -1,21 +1,21 @@ + "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> - + - + - + - + diff --git a/build/web/WEB-INF/classes/DAO/Product.class b/build/web/WEB-INF/classes/DAO/Product.class index a27863a..994b20d 100644 Binary files a/build/web/WEB-INF/classes/DAO/Product.class and b/build/web/WEB-INF/classes/DAO/Product.class differ diff --git a/build/web/WEB-INF/classes/DAO/Product.hbm.xml b/build/web/WEB-INF/classes/DAO/Product.hbm.xml index e3c2f73..30c6714 100644 --- a/build/web/WEB-INF/classes/DAO/Product.hbm.xml +++ b/build/web/WEB-INF/classes/DAO/Product.hbm.xml @@ -1,33 +1,33 @@ + "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> - + - + - + - + - + - + - + - + diff --git a/build/web/WEB-INF/classes/DAO/ProductCode.class b/build/web/WEB-INF/classes/DAO/ProductCode.class index efae21c..37b7549 100644 Binary files a/build/web/WEB-INF/classes/DAO/ProductCode.class and b/build/web/WEB-INF/classes/DAO/ProductCode.class differ diff --git a/build/web/WEB-INF/classes/DAO/ProductCode.hbm.xml b/build/web/WEB-INF/classes/DAO/ProductCode.hbm.xml index 55fc99c..fe8650e 100644 --- a/build/web/WEB-INF/classes/DAO/ProductCode.hbm.xml +++ b/build/web/WEB-INF/classes/DAO/ProductCode.hbm.xml @@ -1,18 +1,18 @@ + "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> - + - + - + diff --git a/build/web/WEB-INF/classes/DAO/PurchaseOrder.class b/build/web/WEB-INF/classes/DAO/PurchaseOrder.class index 0e7f6b1..44f6ee5 100644 Binary files a/build/web/WEB-INF/classes/DAO/PurchaseOrder.class and b/build/web/WEB-INF/classes/DAO/PurchaseOrder.class differ diff --git a/build/web/WEB-INF/classes/DAO/PurchaseOrder.hbm.xml b/build/web/WEB-INF/classes/DAO/PurchaseOrder.hbm.xml index f860281..58b6985 100644 --- a/build/web/WEB-INF/classes/DAO/PurchaseOrder.hbm.xml +++ b/build/web/WEB-INF/classes/DAO/PurchaseOrder.hbm.xml @@ -1,33 +1,33 @@ + "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> - + - + - + - + - + - + - + - + diff --git a/build/web/WEB-INF/classes/controller/BddController$1.class b/build/web/WEB-INF/classes/controller/BddController$1.class index a6a8dcc..4740742 100644 Binary files a/build/web/WEB-INF/classes/controller/BddController$1.class and b/build/web/WEB-INF/classes/controller/BddController$1.class differ diff --git a/build/web/WEB-INF/classes/controller/BddController.class b/build/web/WEB-INF/classes/controller/BddController.class index 537f2b4..6bd9f6b 100644 Binary files a/build/web/WEB-INF/classes/controller/BddController.class and b/build/web/WEB-INF/classes/controller/BddController.class differ diff --git a/build/web/WEB-INF/classes/hibernate.cfg.xml b/build/web/WEB-INF/classes/hibernate.cfg.xml index bc8638d..b1daed0 100644 --- a/build/web/WEB-INF/classes/hibernate.cfg.xml +++ b/build/web/WEB-INF/classes/hibernate.cfg.xml @@ -1,18 +1,19 @@ - + - - org.hibernate.dialect.DerbyDialect - org.apache.derby.jdbc.ClientDriver - jdbc:derby://localhost:1527/sample - app - app - - - - - - - - + + org.hibernate.dialect.DerbyDialect + org.apache.derby.jdbc.ClientDriver + jdbc:derby://localhost:1527/sample + app + app + + + + + + + + diff --git a/build/web/WEB-INF/classes/hibernate.reveng.xml b/build/web/WEB-INF/classes/hibernate.reveng.xml index 9f2a0f9..78e6d62 100644 --- a/build/web/WEB-INF/classes/hibernate.reveng.xml +++ b/build/web/WEB-INF/classes/hibernate.reveng.xml @@ -1,12 +1,13 @@ - + - - - - - - - - + + + + + + + + diff --git a/build/web/WEB-INF/classes/service/User.class b/build/web/WEB-INF/classes/service/User.class index d335310..ccecf83 100644 Binary files a/build/web/WEB-INF/classes/service/User.class and b/build/web/WEB-INF/classes/service/User.class differ diff --git a/jee-project.iml b/jee-project.iml new file mode 100644 index 0000000..b07d824 --- /dev/null +++ b/jee-project.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/javax.annotation.jar b/lib/javax.annotation.jar new file mode 100644 index 0000000..52dca7f Binary files /dev/null and b/lib/javax.annotation.jar differ diff --git a/lib/javax.ejb.jar b/lib/javax.ejb.jar new file mode 100644 index 0000000..4ebf5ec Binary files /dev/null and b/lib/javax.ejb.jar differ diff --git a/lib/javax.jms.jar b/lib/javax.jms.jar new file mode 100644 index 0000000..d31451a Binary files /dev/null and b/lib/javax.jms.jar differ diff --git a/lib/javax.persistence.jar b/lib/javax.persistence.jar new file mode 100644 index 0000000..21d80e0 Binary files /dev/null and b/lib/javax.persistence.jar differ diff --git a/lib/javax.resource.jar b/lib/javax.resource.jar new file mode 100644 index 0000000..696a234 Binary files /dev/null and b/lib/javax.resource.jar differ diff --git a/lib/javax.servlet.jar b/lib/javax.servlet.jar new file mode 100644 index 0000000..0519e4a Binary files /dev/null and b/lib/javax.servlet.jar differ diff --git a/lib/javax.servlet.jsp.jar b/lib/javax.servlet.jsp.jar new file mode 100644 index 0000000..9c0631c Binary files /dev/null and b/lib/javax.servlet.jsp.jar differ diff --git a/src/java/DAO/Customer.hbm.xml b/src/java/DAO/Customer.hbm.xml index 066e26e..f1dc11c 100644 --- a/src/java/DAO/Customer.hbm.xml +++ b/src/java/DAO/Customer.hbm.xml @@ -1,45 +1,45 @@ + "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/src/java/DAO/Customer.java b/src/java/DAO/Customer.java index b18c73b..e39e02d 100644 --- a/src/java/DAO/Customer.java +++ b/src/java/DAO/Customer.java @@ -2,148 +2,157 @@ package DAO; // Generated 8 avr. 2022 15:30:27 by Hibernate Tools 4.3.1 - /** * Customer generated by hbm2java */ -public class Customer implements java.io.Serializable { +public class Customer implements java.io.Serializable { - private int customerId; - private char discountCode; - private String zip; - private String name; - private String addressline1; - private String addressline2; - private String city; - private String state; - private String phone; - private String fax; - private String email; - private Integer creditLimit; + private int customerId; + private char discountCode; + private String zip; + private String name; + private String addressline1; + private String addressline2; + private String city; + private String state; + private String phone; + private String fax; + private String email; + private Integer creditLimit; public Customer() { } - + public Customer(int customerId, char discountCode, String zip) { this.customerId = customerId; this.discountCode = discountCode; this.zip = zip; } - public Customer(int customerId, char discountCode,String _name, String _adress, String _phone,String _email, String _zip) { + + public Customer(int customerId, char discountCode, String _name, String _adress, String _phone, String _email, String _zip) { this.customerId = customerId; this.discountCode = discountCode; - this.name=_name; - this.addressline1=_adress; - this.phone=_phone; - this.email=_email; + this.name = _name; + this.addressline1 = _adress; + this.phone = _phone; + this.email = _email; this.zip = _zip; } - + public Customer(int customerId, char discountCode, String zip, String name, String addressline1, String addressline2, String city, String state, String phone, String fax, String email, Integer creditLimit) { - this.customerId = customerId; - this.discountCode = discountCode; - this.zip = zip; - this.name = name; - this.addressline1 = addressline1; - this.addressline2 = addressline2; - this.city = city; - this.state = state; - this.phone = phone; - this.fax = fax; - this.email = email; - this.creditLimit = creditLimit; + this.customerId = customerId; + this.discountCode = discountCode; + this.zip = zip; + this.name = name; + this.addressline1 = addressline1; + this.addressline2 = addressline2; + this.city = city; + this.state = state; + this.phone = phone; + this.fax = fax; + this.email = email; + this.creditLimit = creditLimit; } - + public int getCustomerId() { return this.customerId; } - + public void setCustomerId(int customerId) { this.customerId = customerId; } + public char getDiscountCode() { return this.discountCode; } - + public void setDiscountCode(char discountCode) { this.discountCode = discountCode; } + public String getZip() { return this.zip; } - + public void setZip(String zip) { this.zip = zip; } + public String getName() { return this.name; } - + public void setName(String name) { this.name = name; } + public String getAddressline1() { return this.addressline1; } - + public void setAddressline1(String addressline1) { this.addressline1 = addressline1; } + public String getAddressline2() { return this.addressline2; } - + public void setAddressline2(String addressline2) { this.addressline2 = addressline2; } + public String getCity() { return this.city; } - + public void setCity(String city) { this.city = city; } + public String getState() { return this.state; } - + public void setState(String state) { this.state = state; } + public String getPhone() { return this.phone; } - + public void setPhone(String phone) { this.phone = phone; } + public String getFax() { return this.fax; } - + public void setFax(String fax) { this.fax = fax; } + public String getEmail() { return this.email; } - + public void setEmail(String email) { this.email = email; } + public Integer getCreditLimit() { return this.creditLimit; } - + public void setCreditLimit(Integer creditLimit) { this.creditLimit = creditLimit; } - - } diff --git a/src/java/DAO/DiscountCode.hbm.xml b/src/java/DAO/DiscountCode.hbm.xml index 4246723..3b0c10e 100644 --- a/src/java/DAO/DiscountCode.hbm.xml +++ b/src/java/DAO/DiscountCode.hbm.xml @@ -1,15 +1,15 @@ + "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> - + - + diff --git a/src/java/DAO/DiscountCode.java b/src/java/DAO/DiscountCode.java index ee0f264..f2148e1 100644 --- a/src/java/DAO/DiscountCode.java +++ b/src/java/DAO/DiscountCode.java @@ -7,42 +7,42 @@ import java.math.BigDecimal; /** * DiscountCode generated by hbm2java */ -public class DiscountCode implements java.io.Serializable { +public class DiscountCode implements java.io.Serializable { - private char discountCode; - private BigDecimal rate; + private char discountCode; + private BigDecimal rate; public DiscountCode() { } - + public DiscountCode(char discountCode) { this.discountCode = discountCode; } + public DiscountCode(char discountCode, BigDecimal rate) { - this.discountCode = discountCode; - this.rate = rate; + this.discountCode = discountCode; + this.rate = rate; } - + public char getDiscountCode() { return this.discountCode; } - + public void setDiscountCode(char discountCode) { this.discountCode = discountCode; } + public BigDecimal getRate() { return this.rate; } - + public void setRate(BigDecimal rate) { this.rate = rate; } - - } diff --git a/src/java/DAO/HibernateUtil.java b/src/java/DAO/HibernateUtil.java index 9eff547..700660d 100644 --- a/src/java/DAO/HibernateUtil.java +++ b/src/java/DAO/HibernateUtil.java @@ -5,8 +5,8 @@ */ package DAO; -import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.SessionFactory; +import org.hibernate.cfg.AnnotationConfiguration; /** @@ -18,21 +18,21 @@ import org.hibernate.SessionFactory; public class HibernateUtil { private static final SessionFactory sessionFactory; - + static { try { // Create the SessionFactory from standard (hibernate.cfg.xml) // config file. - sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory(); - - + sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory(); + + } catch (Throwable ex) { // Log the exception. System.err.println("Initial SessionFactory creation failed." + ex); throw new ExceptionInInitializerError(ex); } } - + public static SessionFactory getSessionFactory() { return sessionFactory; } diff --git a/src/java/DAO/MagasinHelper.java b/src/java/DAO/MagasinHelper.java index a0066e0..802d607 100644 --- a/src/java/DAO/MagasinHelper.java +++ b/src/java/DAO/MagasinHelper.java @@ -4,339 +4,306 @@ * and open the template in the editor. */ package DAO; -import org.hibernate.*; -import org.hibernate.cfg.Configuration; -import java.util.*; -import java.sql.*; + +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.Transaction; + +import java.util.ArrayList; +import java.util.List; /** - * * @author faycal */ public class MagasinHelper { - Session session = null; - - public List getColonnes() { - return colonnes; - } - ArrayList colonnes=new ArrayList(); + Session session; + List colonnes = new ArrayList(); public MagasinHelper() { this.session = HibernateUtil.getSessionFactory().openSession(); } - - public List getProducts(){ - List resultat=null; - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + + public List getColonnes() { + return colonnes; + } + + public List getProducts() { + List resultat = null; + + try { + if (!session.isOpen()) session = HibernateUtil.getSessionFactory().openSession(); session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery("select p.productId, p.manufacturerId, p.productCode, p.purchaseCost, p.quantityOnHand, p.markup, p.available, p.description from Product p"); - resultat=q.list(); - - + + session.beginTransaction(); + Query q = session.createQuery("select p.productId, p.manufacturerId, p.productCode, p.purchaseCost, p.quantityOnHand, p.markup, p.available, p.description from Product p"); + resultat = q.list(); } catch (Exception e) { e.printStackTrace(); - } finally{ - if (session.isOpen())session.close(); + } finally { + if (session.isOpen()) session.close(); } return resultat; } - - public Product getProduct(int id){ - Product resultat=null; - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + + public Product getProduct(int id) { + Product resultat = null; + + try { + if (!session.isOpen()) session = HibernateUtil.getSessionFactory().openSession(); session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery("from Product p where p.productId = :_id"); + + session.beginTransaction(); + Query q = session.createQuery("from Product p where p.productId = :_id"); q.setInteger("_id", id); - resultat=(Product)q.list().iterator().next(); - - + resultat = (Product) q.list().iterator().next(); } catch (Exception e) { e.printStackTrace(); - } finally{ - if (session.isOpen())session.close(); + } finally { + if (session.isOpen()) session.close(); } return resultat; } - - public List getClients(){ - List resultat=null; - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); - session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery("select a.customerId, a.name, a.addressline1,a.addressline2,a.zip,b.rate from Customer a, DiscountCode b where a.discountCode=b.discountCode"); - //Query q=session.createQuery("from Customer"); - resultat=q.list(); - - - } - catch (Exception e) { - e.printStackTrace(); - } - finally{ - if (session.isOpen())session.close(); - } - - return resultat; -} - public List getClients(String name){ - List resultat=null; - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); - session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery("select a.customerId, a.name, a.addressline1,a.addressline2,a.zip,b.rate from Customer a, DiscountCode b where a.discountCode=b.discountCode and a.name like :_name"); - //Query q=session.createQuery("from Customer"); - q.setString("_name",name); - resultat=q.list(); - } - catch (Exception e) { - e.printStackTrace(); - } - finally{ - if (session.isOpen())session.close(); - } - - return resultat; -} -public List getDiscountCode(){ -List resultat=null; - Transaction tx=null; - try{ - if(!session.isOpen()) - session=HibernateUtil.getSessionFactory().openSession(); - session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery("select a.discountCode from DiscountCode a"); - resultat=q.list(); - } - catch (Exception e) { - e.printStackTrace(); - } - finally{ - if (session.isOpen())session.close(); - - } - - return resultat; + public List getClients() { + List resultat = null; - -} -public List getMicroMarket(){ -List resultat=null; - Transaction tx=null; - try{ - //if(!session.isOpen()) - session=HibernateUtil.getSessionFactory().openSession(); + try { + if (!session.isOpen()) session = HibernateUtil.getSessionFactory().openSession(); session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery("from MicroMarket"); - resultat=q.list(); - } - catch (Exception e) { - e.printStackTrace(); - } - finally{ - if (session.isOpen())session.close(); - + + session.beginTransaction(); + Query q = session.createQuery("select a.customerId, a.name, a.addressline1,a.addressline2,a.zip,b.rate from Customer a, DiscountCode b where a.discountCode=b.discountCode"); + resultat = q.list(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (session.isOpen()) session.close(); } + return resultat; -} -public List getZipCode(){ -List resultat=null; - Transaction tx=null; - try{ - //if(!session.isOpen()) - session=HibernateUtil.getSessionFactory().openSession(); + } + + public List getClients(String name) { + List resultat = null; + + try { + if (!session.isOpen()) session = HibernateUtil.getSessionFactory().openSession(); session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery("select a.zipCode from MicroMarket a"); - resultat=q.list(); - } - catch (Exception e) { - e.printStackTrace(); - } - finally{ - if (session.isOpen())session.close(); - + + session.beginTransaction(); + Query q = session.createQuery("select a.customerId, a.name, a.addressline1,a.addressline2,a.zip,b.rate from Customer a, DiscountCode b where a.discountCode=b.discountCode and a.name like :_name"); + q.setString("_name", name); + resultat = q.list(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (session.isOpen()) session.close(); } + return resultat; -} -public void insertCustomer (int _customerId, char _discountCode, String _zip) { - - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + } + + public List getDiscountCode() { + List resultat = null; + + try { + if (!session.isOpen()) + session = HibernateUtil.getSessionFactory().openSession(); session.flush(); - - tx=session.beginTransaction(); - Customer a =new Customer(_customerId,_discountCode,_zip); - session.save(a); - tx.commit(); - } - catch (Exception e) { + + session.beginTransaction(); + Query q = session.createQuery("select a.discountCode from DiscountCode a"); + resultat = q.list(); + } catch (Exception e) { e.printStackTrace(); + } finally { + if (session.isOpen()) session.close(); + } + + return resultat; + + + } + + public List getMicroMarket() { + List resultat = null; + + try { + session = HibernateUtil.getSessionFactory().openSession(); + session.flush(); + + session.beginTransaction(); + Query q = session.createQuery("from MicroMarket"); + resultat = q.list(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (session.isOpen()) session.close(); + } + + return resultat; + } + + public List getZipCode() { + List resultat = null; + + try { + session = HibernateUtil.getSessionFactory().openSession(); + session.flush(); + + session.beginTransaction(); + Query q = session.createQuery("select a.zipCode from MicroMarket a"); + resultat = q.list(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (session.isOpen()) session.close(); + } + + return resultat; + } + + public void insertCustomer(int _customerId, char _discountCode, String _zip) { + Transaction tx = null; + + try { + if (!session.isOpen()) session = HibernateUtil.getSessionFactory().openSession(); + session.flush(); + + tx = session.beginTransaction(); + Customer a = new Customer(_customerId, _discountCode, _zip); + session.save(a); + tx.commit(); + } catch (Exception e) { + e.printStackTrace(); + assert tx != null; tx.rollback(); throw e; + } finally { + if (session.isOpen()) session.close(); } - finally{ - if (session.isOpen())session.close(); - } - -} + } -public void updateCustomer (int _customerId,char _discountCode, String _name, String _adress, String _phone,String _email, String _zip){ - - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + public void updateCustomer(int _customerId, char _discountCode, String _name, String _adress, String _phone, String _email, String _zip) { + Transaction tx = null; + + try { + if (!session.isOpen()) session = HibernateUtil.getSessionFactory().openSession(); session.flush(); - - tx=session.beginTransaction(); - - Customer a =new Customer(_customerId,_discountCode,_name, _adress, _phone,_email, _zip); - - session.update(a); - tx.commit(); - } - catch (Exception e) { + + tx = session.beginTransaction(); + Customer a = new Customer(_customerId, _discountCode, _name, _adress, _phone, _email, _zip); + session.update(a); + tx.commit(); + } catch (Exception e) { e.printStackTrace(); + assert tx != null; tx.rollback(); throw e; + } finally { + if (session.isOpen()) session.close(); } - finally{ - if (session.isOpen())session.close(); - } - -} -public Customer getClient(int id){ - - - Customer client=null; - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); - session.flush(); - tx=session.beginTransaction(); - Query q=session.createQuery(" from Customer a where a.customerId =:_id"); - q.setInteger("_id", id); - client=(Customer)q.list().iterator().next(); - } - catch (Exception e) { - e.printStackTrace(); - } - finally{ - if (session.isOpen())session.close(); - } - - return client; -} + } -public void deleteCustomer (int _id) { - - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + public Customer getClient(int id) { + Customer client = null; + + try { + if (!session.isOpen()) session = HibernateUtil.getSessionFactory().openSession(); session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery(" from Customer a where a.customerId =:_id"); - q.setInteger("_id",_id); - session.delete((Customer)q.list().iterator().next()); - tx.commit(); - } - catch (Exception e) { + session.beginTransaction(); + Query q = session.createQuery(" from Customer a where a.customerId =:_id"); + q.setInteger("_id", id); + client = (Customer) q.list().iterator().next(); + } catch (Exception e) { e.printStackTrace(); + } finally { + if (session.isOpen()) session.close(); + } + + return client; + } + + public void deleteCustomer(int _id) { + Transaction tx = null; + + try { + if (!session.isOpen()) session = HibernateUtil.getSessionFactory().openSession(); + session.flush(); + + tx = session.beginTransaction(); + Query q = session.createQuery(" from Customer a where a.customerId =:_id"); + q.setInteger("_id", _id); + session.delete(q.list().iterator().next()); + tx.commit(); + } catch (Exception e) { + e.printStackTrace(); + assert tx != null; tx.rollback(); throw e; + } finally { + if (session.isOpen()) session.close(); } - finally{ - if (session.isOpen())session.close(); - } - -} + } - public List getPurchase(){ - List resultat=null; - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); - session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery("select po.customerId, po.productId, po.quantity, po.shippingCost, po.salesDate, po.shippingDate, po.freightCompany from PurchaseOrder po"); - resultat=(List)q.list(); - } - catch (Exception e) { - e.printStackTrace(); - } - finally{ - if (session.isOpen())session.close(); - } - - return resultat; -} + public List getPurchase() { + List resultat = null; - public List getPurchase(int id){ - List resultat=null; - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + try { + if (!session.isOpen()) session = HibernateUtil.getSessionFactory().openSession(); session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery(" from PurchaseOrder a where a.customerId=:_id"); - q.setInteger("_id", id); - resultat=(List)q.list(); - } - catch (Exception e) { - e.printStackTrace(); - } - finally{ - if (session.isOpen())session.close(); - } - - return resultat; -} -public int getMaxId(){ - Transaction tx=null; - int resultat=-1; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + session.beginTransaction(); + Query q = session.createQuery("select po.customerId, po.productId, po.quantity, po.shippingCost, po.salesDate, po.shippingDate, po.freightCompany from PurchaseOrder po"); + resultat = q.list(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (session.isOpen()) session.close(); + } + + return resultat; + } + + public List getPurchase(int id) { + List resultat = null; + + try { + if (!session.isOpen()) session = HibernateUtil.getSessionFactory().openSession(); session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery("select MAX(a.customerId) from Customer a"); - - resultat=(int)q.list().iterator().next(); + + session.beginTransaction(); + Query q = session.createQuery(" from PurchaseOrder a where a.customerId=:_id"); + q.setInteger("_id", id); + resultat = q.list(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (session.isOpen()) session.close(); } - catch (Exception e) { - e.printStackTrace(); + + return resultat; + } + + public int getMaxId() { + int resultat = -1; + + try { + if (!session.isOpen()) session = HibernateUtil.getSessionFactory().openSession(); + session.flush(); + + session.beginTransaction(); + Query q = session.createQuery("select MAX(a.customerId) from Customer a"); + resultat = (int) q.list().iterator().next(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (session.isOpen()) session.close(); } - finally{ - if (session.isOpen())session.close(); - } - - return resultat; - -} + + return resultat; + + } } diff --git a/src/java/DAO/Manufacturer.hbm.xml b/src/java/DAO/Manufacturer.hbm.xml index 5b9100d..ac6a992 100644 --- a/src/java/DAO/Manufacturer.hbm.xml +++ b/src/java/DAO/Manufacturer.hbm.xml @@ -1,42 +1,42 @@ + "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> - + - + - + - + - + - + - + - + - + - + - + diff --git a/src/java/DAO/Manufacturer.java b/src/java/DAO/Manufacturer.java index c8ff5a5..5d01169 100644 --- a/src/java/DAO/Manufacturer.java +++ b/src/java/DAO/Manufacturer.java @@ -2,127 +2,135 @@ package DAO; // Generated 8 avr. 2022 15:30:27 by Hibernate Tools 4.3.1 - /** * Manufacturer generated by hbm2java */ -public class Manufacturer implements java.io.Serializable { +public class Manufacturer implements java.io.Serializable { - private int manufacturerId; - private String name; - private String addressline1; - private String addressline2; - private String city; - private String state; - private String zip; - private String phone; - private String fax; - private String email; - private String rep; + private int manufacturerId; + private String name; + private String addressline1; + private String addressline2; + private String city; + private String state; + private String zip; + private String phone; + private String fax; + private String email; + private String rep; public Manufacturer() { } - + public Manufacturer(int manufacturerId) { this.manufacturerId = manufacturerId; } + public Manufacturer(int manufacturerId, String name, String addressline1, String addressline2, String city, String state, String zip, String phone, String fax, String email, String rep) { - this.manufacturerId = manufacturerId; - this.name = name; - this.addressline1 = addressline1; - this.addressline2 = addressline2; - this.city = city; - this.state = state; - this.zip = zip; - this.phone = phone; - this.fax = fax; - this.email = email; - this.rep = rep; + this.manufacturerId = manufacturerId; + this.name = name; + this.addressline1 = addressline1; + this.addressline2 = addressline2; + this.city = city; + this.state = state; + this.zip = zip; + this.phone = phone; + this.fax = fax; + this.email = email; + this.rep = rep; } - + public int getManufacturerId() { return this.manufacturerId; } - + public void setManufacturerId(int manufacturerId) { this.manufacturerId = manufacturerId; } + public String getName() { return this.name; } - + public void setName(String name) { this.name = name; } + public String getAddressline1() { return this.addressline1; } - + public void setAddressline1(String addressline1) { this.addressline1 = addressline1; } + public String getAddressline2() { return this.addressline2; } - + public void setAddressline2(String addressline2) { this.addressline2 = addressline2; } + public String getCity() { return this.city; } - + public void setCity(String city) { this.city = city; } + public String getState() { return this.state; } - + public void setState(String state) { this.state = state; } + public String getZip() { return this.zip; } - + public void setZip(String zip) { this.zip = zip; } + public String getPhone() { return this.phone; } - + public void setPhone(String phone) { this.phone = phone; } + public String getFax() { return this.fax; } - + public void setFax(String fax) { this.fax = fax; } + public String getEmail() { return this.email; } - + public void setEmail(String email) { this.email = email; } + public String getRep() { return this.rep; } - + public void setRep(String rep) { this.rep = rep; } - - } diff --git a/src/java/DAO/MicroMarket.hbm.xml b/src/java/DAO/MicroMarket.hbm.xml index 187bc77..f0e77e8 100644 --- a/src/java/DAO/MicroMarket.hbm.xml +++ b/src/java/DAO/MicroMarket.hbm.xml @@ -1,21 +1,21 @@ + "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> - + - + - + - + diff --git a/src/java/DAO/MicroMarket.java b/src/java/DAO/MicroMarket.java index 9538bbd..670c254 100644 --- a/src/java/DAO/MicroMarket.java +++ b/src/java/DAO/MicroMarket.java @@ -2,64 +2,65 @@ package DAO; // Generated 8 avr. 2022 15:30:27 by Hibernate Tools 4.3.1 - /** * MicroMarket generated by hbm2java */ -public class MicroMarket implements java.io.Serializable { +public class MicroMarket implements java.io.Serializable { - private String zipCode; - private Double radius; - private Double areaLength; - private Double areaWidth; + private String zipCode; + private Double radius; + private Double areaLength; + private Double areaWidth; public MicroMarket() { } - + public MicroMarket(String zipCode) { this.zipCode = zipCode; } + public MicroMarket(String zipCode, Double radius, Double areaLength, Double areaWidth) { - this.zipCode = zipCode; - this.radius = radius; - this.areaLength = areaLength; - this.areaWidth = areaWidth; + this.zipCode = zipCode; + this.radius = radius; + this.areaLength = areaLength; + this.areaWidth = areaWidth; } - + public String getZipCode() { return this.zipCode; } - + public void setZipCode(String zipCode) { this.zipCode = zipCode; } + public Double getRadius() { return this.radius; } - + public void setRadius(Double radius) { this.radius = radius; } + public Double getAreaLength() { return this.areaLength; } - + public void setAreaLength(Double areaLength) { this.areaLength = areaLength; } + public Double getAreaWidth() { return this.areaWidth; } - + public void setAreaWidth(Double areaWidth) { this.areaWidth = areaWidth; } - - } diff --git a/src/java/DAO/Product.hbm.xml b/src/java/DAO/Product.hbm.xml index e3c2f73..30c6714 100644 --- a/src/java/DAO/Product.hbm.xml +++ b/src/java/DAO/Product.hbm.xml @@ -1,33 +1,33 @@ + "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> - + - + - + - + - + - + - + - + diff --git a/src/java/DAO/Product.java b/src/java/DAO/Product.java index 5b86a98..98ee268 100644 --- a/src/java/DAO/Product.java +++ b/src/java/DAO/Product.java @@ -7,98 +7,104 @@ import java.math.BigDecimal; /** * Product generated by hbm2java */ -public class Product implements java.io.Serializable { +public class Product implements java.io.Serializable { - private int productId; - private int manufacturerId; - private String productCode; - private BigDecimal purchaseCost; - private Integer quantityOnHand; - private BigDecimal markup; - private String available; - private String description; + private int productId; + private int manufacturerId; + private String productCode; + private BigDecimal purchaseCost; + private Integer quantityOnHand; + private BigDecimal markup; + private String available; + private String description; public Product() { } - + public Product(int productId, int manufacturerId, String productCode) { this.productId = productId; this.manufacturerId = manufacturerId; this.productCode = productCode; } + public Product(int productId, int manufacturerId, String productCode, BigDecimal purchaseCost, Integer quantityOnHand, BigDecimal markup, String available, String description) { - this.productId = productId; - this.manufacturerId = manufacturerId; - this.productCode = productCode; - this.purchaseCost = purchaseCost; - this.quantityOnHand = quantityOnHand; - this.markup = markup; - this.available = available; - this.description = description; + this.productId = productId; + this.manufacturerId = manufacturerId; + this.productCode = productCode; + this.purchaseCost = purchaseCost; + this.quantityOnHand = quantityOnHand; + this.markup = markup; + this.available = available; + this.description = description; } - + public int getProductId() { return this.productId; } - + public void setProductId(int productId) { this.productId = productId; } + public int getManufacturerId() { return this.manufacturerId; } - + public void setManufacturerId(int manufacturerId) { this.manufacturerId = manufacturerId; } + public String getProductCode() { return this.productCode; } - + public void setProductCode(String productCode) { this.productCode = productCode; } + public BigDecimal getPurchaseCost() { return this.purchaseCost; } - + public void setPurchaseCost(BigDecimal purchaseCost) { this.purchaseCost = purchaseCost; } + public Integer getQuantityOnHand() { return this.quantityOnHand; } - + public void setQuantityOnHand(Integer quantityOnHand) { this.quantityOnHand = quantityOnHand; } + public BigDecimal getMarkup() { return this.markup; } - + public void setMarkup(BigDecimal markup) { this.markup = markup; } + public String getAvailable() { return this.available; } - + public void setAvailable(String available) { this.available = available; } + public String getDescription() { return this.description; } - + public void setDescription(String description) { this.description = description; } - - } diff --git a/src/java/DAO/ProductCode.hbm.xml b/src/java/DAO/ProductCode.hbm.xml index 55fc99c..fe8650e 100644 --- a/src/java/DAO/ProductCode.hbm.xml +++ b/src/java/DAO/ProductCode.hbm.xml @@ -1,18 +1,18 @@ + "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> - + - + - + diff --git a/src/java/DAO/ProductCode.java b/src/java/DAO/ProductCode.java index 905cb38..7fa31e7 100644 --- a/src/java/DAO/ProductCode.java +++ b/src/java/DAO/ProductCode.java @@ -2,56 +2,56 @@ package DAO; // Generated 8 avr. 2022 15:30:27 by Hibernate Tools 4.3.1 - /** * ProductCode generated by hbm2java */ -public class ProductCode implements java.io.Serializable { +public class ProductCode implements java.io.Serializable { - private String prodCode; - private char discountCode; - private String description; + private String prodCode; + private char discountCode; + private String description; public ProductCode() { } - + public ProductCode(String prodCode, char discountCode) { this.prodCode = prodCode; this.discountCode = discountCode; } + public ProductCode(String prodCode, char discountCode, String description) { - this.prodCode = prodCode; - this.discountCode = discountCode; - this.description = description; + this.prodCode = prodCode; + this.discountCode = discountCode; + this.description = description; } - + public String getProdCode() { return this.prodCode; } - + public void setProdCode(String prodCode) { this.prodCode = prodCode; } + public char getDiscountCode() { return this.discountCode; } - + public void setDiscountCode(char discountCode) { this.discountCode = discountCode; } + public String getDescription() { return this.description; } - + public void setDescription(String description) { this.description = description; } - - } diff --git a/src/java/DAO/PurchaseOrder.hbm.xml b/src/java/DAO/PurchaseOrder.hbm.xml index f860281..58b6985 100644 --- a/src/java/DAO/PurchaseOrder.hbm.xml +++ b/src/java/DAO/PurchaseOrder.hbm.xml @@ -1,33 +1,33 @@ + "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> - + - + - + - + - + - + - + - + diff --git a/src/java/DAO/PurchaseOrder.java b/src/java/DAO/PurchaseOrder.java index 849a4f3..7269263 100644 --- a/src/java/DAO/PurchaseOrder.java +++ b/src/java/DAO/PurchaseOrder.java @@ -8,98 +8,104 @@ import java.util.Date; /** * PurchaseOrder generated by hbm2java */ -public class PurchaseOrder implements java.io.Serializable { +public class PurchaseOrder implements java.io.Serializable { - private int orderNum; - private int customerId; - private int productId; - private Short quantity; - private BigDecimal shippingCost; - private Date salesDate; - private Date shippingDate; - private String freightCompany; + private int orderNum; + private int customerId; + private int productId; + private Short quantity; + private BigDecimal shippingCost; + private Date salesDate; + private Date shippingDate; + private String freightCompany; public PurchaseOrder() { } - + public PurchaseOrder(int orderNum, int customerId, int productId) { this.orderNum = orderNum; this.customerId = customerId; this.productId = productId; } + public PurchaseOrder(int orderNum, int customerId, int productId, Short quantity, BigDecimal shippingCost, Date salesDate, Date shippingDate, String freightCompany) { - this.orderNum = orderNum; - this.customerId = customerId; - this.productId = productId; - this.quantity = quantity; - this.shippingCost = shippingCost; - this.salesDate = salesDate; - this.shippingDate = shippingDate; - this.freightCompany = freightCompany; + this.orderNum = orderNum; + this.customerId = customerId; + this.productId = productId; + this.quantity = quantity; + this.shippingCost = shippingCost; + this.salesDate = salesDate; + this.shippingDate = shippingDate; + this.freightCompany = freightCompany; } - + public int getOrderNum() { return this.orderNum; } - + public void setOrderNum(int orderNum) { this.orderNum = orderNum; } + public int getCustomerId() { return this.customerId; } - + public void setCustomerId(int customerId) { this.customerId = customerId; } + public int getProductId() { return this.productId; } - + public void setProductId(int productId) { this.productId = productId; } + public Short getQuantity() { return this.quantity; } - + public void setQuantity(Short quantity) { this.quantity = quantity; } + public BigDecimal getShippingCost() { return this.shippingCost; } - + public void setShippingCost(BigDecimal shippingCost) { this.shippingCost = shippingCost; } + public Date getSalesDate() { return this.salesDate; } - + public void setSalesDate(Date salesDate) { this.salesDate = salesDate; } + public Date getShippingDate() { return this.shippingDate; } - + public void setShippingDate(Date shippingDate) { this.shippingDate = shippingDate; } + public String getFreightCompany() { return this.freightCompany; } - + public void setFreightCompany(String freightCompany) { this.freightCompany = freightCompany; } - - } diff --git a/src/java/controller/BddController.java b/src/java/controller/BddController.java index a0913de..10cd126 100644 --- a/src/java/controller/BddController.java +++ b/src/java/controller/BddController.java @@ -4,79 +4,70 @@ * and open the template in the editor. */ package controller; -import DAO.*; + +import DAO.MagasinHelper; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.mvc.multiaction.MultiActionController; import service.User; -import java.util.*; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.context.ApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.web.servlet.mvc.multiaction.MultiActionController; -import javax.servlet.http.*; -import javax.servlet.*; - - +import javax.servlet.http.HttpSession; +import java.util.Arrays; +import java.util.HashMap; /** - * * @author faycal */ -public class BddController extends MultiActionController { +public class BddController extends MultiActionController { private String login; - private String pwd; private User utilisateur; private HttpSession session; - public BddController() {} - + private void sessionInit(HttpServletRequest request) { if (login == null) - login=request.getUserPrincipal().getName(); + login = request.getUserPrincipal().getName(); if (utilisateur == null) - utilisateur =new User(login); - + utilisateur = new User(login); + if (session == null) { - session=request.getSession(); + session = request.getSession(); session.setAttribute("user", utilisateur); } } - - public ModelAndView menu(HttpServletRequest request, - HttpServletResponse response){ + + public ModelAndView menu(HttpServletRequest request, HttpServletResponse response) { sessionInit(request); - System.out.println ("nbuser="+User.getCompteur()); - return new ModelAndView("menu").addObject("user",utilisateur); - + System.out.println("nbuser=" + User.getCompteur()); + return new ModelAndView("menu").addObject("user", utilisateur); + } - public ModelAndView logout(HttpServletRequest request, - HttpServletResponse response){ + + public ModelAndView logout(HttpServletRequest request, HttpServletResponse response) { sessionInit(request); request.getSession().invalidate(); - - - return new ModelAndView("deconnexion"); - + return new ModelAndView("deconnexion"); + } - - public ModelAndView list(HttpServletRequest request, - HttpServletResponse response) throws Exception { - sessionInit(request); - String type = request.getAttribute("type").toString(); - ModelAndView mv = new ModelAndView("resultat"); - mv.addObject("user",session.getAttribute("user")); - mv.addObject("type", type); - - switch (type) { - case "customer": + + public ModelAndView list(HttpServletRequest request, HttpServletResponse response) throws Exception { + sessionInit(request); + String type = request.getAttribute("type").toString(); + ModelAndView mv = new ModelAndView("resultat"); + mv.addObject("user", session.getAttribute("user")); + mv.addObject("type", type); + + switch (type) { + case "customer": mv.addObject("results", new MagasinHelper().getClients()); mv.addObject("colonnes", Arrays.asList("customerId", "name", "addressline1", "addressline2", "zip", "rate")); - break; - case "product": - mv.addObject("results", new MagasinHelper().getProducts()); - mv.addObject("colonnes", Arrays.asList("productId", "manufacturerId", "productCode", "purchaseCost", "quantityOnHand", "markup", "available", "description")); - break; - case "purchase": + break; + case "product": + mv.addObject("results", new MagasinHelper().getProducts()); + mv.addObject("colonnes", Arrays.asList("productId", "manufacturerId", "productCode", "purchaseCost", "quantityOnHand", "markup", "available", "description")); + break; + case "purchase": mv.addObject("results", new MagasinHelper().getPurchase()); mv.addObject("colonnes", Arrays.asList("customerId", "productId", "quantity", "shippingCost", "salesDate", "shippingDate", "freightCompany")); mv.addObject("relation", new HashMap() {{ @@ -84,130 +75,117 @@ public class BddController extends MultiActionController { put("productId", "product"); }}); break; - default: - mv.addObject("error", "Type not found"); - } - - return mv; - } - - public ModelAndView purchase(HttpServletRequest request, HttpServletResponse response) throws Exception { - request.setAttribute("type", "purchase"); - return list(request, response); - } - - public ModelAndView product(HttpServletRequest request, HttpServletResponse response) throws Exception { - request.setAttribute("type", "product"); - return list(request, response); - } - - public ModelAndView customer(HttpServletRequest request, HttpServletResponse response) throws Exception { - request.setAttribute("type", "customer"); - return list(request, response); - } - - public ModelAndView add(HttpServletRequest request, - HttpServletResponse response) throws Exception { - sessionInit(request); - - ModelAndView mv = new ModelAndView("form_inscription"); - - mv.addObject("user",session.getAttribute("user")); - mv.addObject("discount",new MagasinHelper().getDiscountCode()); - mv.addObject("code",new MagasinHelper().getZipCode()); - return mv; - } - public ModelAndView detail(HttpServletRequest request, - HttpServletResponse response) throws Exception { - sessionInit(request); - String type = request.getParameter("type"); - ModelAndView mv = new ModelAndView("detail"); - mv.addObject("user",session.getAttribute("user")); - mv.addObject("type", type); - - switch (type) { - case "customer": + default: + mv.addObject("error", "Type not found"); + } + + return mv; + } + + public ModelAndView purchase(HttpServletRequest request, HttpServletResponse response) throws Exception { + request.setAttribute("type", "purchase"); + return list(request, response); + } + + public ModelAndView product(HttpServletRequest request, HttpServletResponse response) throws Exception { + request.setAttribute("type", "product"); + return list(request, response); + } + + public ModelAndView customer(HttpServletRequest request, HttpServletResponse response) throws Exception { + request.setAttribute("type", "customer"); + return list(request, response); + } + + public ModelAndView add(HttpServletRequest request, HttpServletResponse response) throws Exception { + sessionInit(request); + ModelAndView mv = new ModelAndView("form_inscription"); + mv.addObject("user", session.getAttribute("user")); + mv.addObject("discount", new MagasinHelper().getDiscountCode()); + mv.addObject("code", new MagasinHelper().getZipCode()); + return mv; + } + + public ModelAndView detail(HttpServletRequest request, HttpServletResponse response) throws Exception { + sessionInit(request); + String type = request.getParameter("type"); + ModelAndView mv = new ModelAndView("detail"); + mv.addObject("user", session.getAttribute("user")); + mv.addObject("type", type); + + switch (type) { + case "customer": mv.addObject("result", new MagasinHelper().getClient(Integer.parseInt(request.getParameter("num")))); mv.addObject("colonnes", Arrays.asList("customerId", "name", "addressline1", "addressline2", "zip", "rate")); - mv.addObject("code",new MagasinHelper().getDiscountCode()); - mv.addObject("cpostaux",new MagasinHelper().getZipCode()); - break; - case "product": - mv.addObject("result", new MagasinHelper().getProduct(Integer.parseInt(request.getParameter("num")))); - mv.addObject("colonnes", Arrays.asList("productId", "manufacturerId", "productCode", "purchaseCost", "quantityOnHand", "markup", "available", "description")); - break; - case "purchase": + mv.addObject("code", new MagasinHelper().getDiscountCode()); + mv.addObject("cpostaux", new MagasinHelper().getZipCode()); + break; + case "product": + mv.addObject("result", new MagasinHelper().getProduct(Integer.parseInt(request.getParameter("num")))); + mv.addObject("colonnes", Arrays.asList("productId", "manufacturerId", "productCode", "purchaseCost", "quantityOnHand", "markup", "available", "description")); + break; + case "purchase": mv.addObject("result", new MagasinHelper().getPurchase(Integer.parseInt(request.getParameter("num")))); mv.addObject("colonnes", Arrays.asList("customerId", "productId", "quantity", "shippingCost", "salesDate", "shippingDate", "freightCompany")); break; - default: - mv.addObject("error", "Type not found"); - } + default: + mv.addObject("error", "Type not found"); + } - return mv; - } - public ModelAndView find(HttpServletRequest request, - HttpServletResponse response) throws Exception { - sessionInit(request); - - ModelAndView mv ; - MagasinHelper requeteur = new MagasinHelper(); - if (requeteur.getClients(request.getParameter("nom")).isEmpty() || request.getParameter("nom").equals("%") ){ - mv= new ModelAndView("error"); - mv.addObject("erreur", "0 enregistrement"); - - } - else{ - mv= new ModelAndView("resultat"); - mv.addObject("liste",requeteur.getClients(request.getParameter("nom"))); - - } - - mv.addObject("user",session.getAttribute("user")); - return mv; - } - public ModelAndView formfind(HttpServletRequest request, - HttpServletResponse response) throws Exception { - sessionInit(request); - return new ModelAndView("recherche"); - } - public ModelAndView achats(HttpServletRequest request, - HttpServletResponse response) throws Exception { - sessionInit(request); - - - ModelAndView mv = new ModelAndView("achats"); - - mv.addObject("user",session.getAttribute("user")); - System.out.println("num "+Integer.parseInt(request.getParameter("numero"))); - - mv.addObject("achats",new MagasinHelper().getPurchase(Integer.parseInt(request.getParameter("numero")))); - return mv; - } - - public ModelAndView save(HttpServletRequest request, - HttpServletResponse response) throws Exception { + return mv; + } + + public ModelAndView find(HttpServletRequest request, HttpServletResponse response) throws Exception { sessionInit(request); - String param1 = request.getParameter("nom"); + + ModelAndView mv; + MagasinHelper requeteur = new MagasinHelper(); + + if (requeteur.getClients(request.getParameter("nom")).isEmpty() || request.getParameter("nom").equals("%")) { + mv = new ModelAndView("error"); + mv.addObject("erreur", "0 enregistrement"); + } else { + mv = new ModelAndView("resultat"); + mv.addObject("liste", requeteur.getClients(request.getParameter("nom"))); + } + + mv.addObject("user", session.getAttribute("user")); + return mv; + } + + public ModelAndView formfind(HttpServletRequest request, HttpServletResponse response) throws Exception { + sessionInit(request); + return new ModelAndView("recherche"); + } + + public ModelAndView achats(HttpServletRequest request, HttpServletResponse response) throws Exception { + sessionInit(request); + ModelAndView mv = new ModelAndView("achats"); + mv.addObject("user", session.getAttribute("user")); + System.out.println("num " + Integer.parseInt(request.getParameter("numero"))); + mv.addObject("achats", new MagasinHelper().getPurchase(Integer.parseInt(request.getParameter("numero")))); + return mv; + } + + public ModelAndView save(HttpServletRequest request, HttpServletResponse response) throws Exception { + sessionInit(request); + String param1 = request.getParameter("nom"); String param2 = request.getParameter("adresse"); String param3 = request.getParameter("telephone"); String param4 = request.getParameter("email"); String param5 = request.getParameter("code_remise"); String param6 = request.getParameter("CP"); - new MagasinHelper().insertCustomer(new MagasinHelper().getMaxId()+1, param5.charAt(0), param6); - return new ModelAndView("confirm").addObject("confirm","enregistrement effectué"); - - } - public ModelAndView delete(HttpServletRequest request, - HttpServletResponse response) throws Exception { - sessionInit(request); - + new MagasinHelper().insertCustomer(new MagasinHelper().getMaxId() + 1, param5.charAt(0), param6); + return new ModelAndView("confirm").addObject("confirm", "enregistrement effectué"); + } + + public ModelAndView delete(HttpServletRequest request, HttpServletResponse response) throws Exception { + sessionInit(request); new MagasinHelper().deleteCustomer(Integer.parseInt(request.getParameter("numero"))); - return new ModelAndView("confirm").addObject("confirm","suppression effectuée"); - - } - public ModelAndView update(HttpServletRequest request, - HttpServletResponse response) throws Exception { + return new ModelAndView("confirm").addObject("confirm", "suppression effectuée"); + } + + public ModelAndView update(HttpServletRequest request, HttpServletResponse response) throws Exception { sessionInit(request); String param1 = request.getParameter("numero"); String param2 = request.getParameter("code_remise"); @@ -217,11 +195,9 @@ public class BddController extends MultiActionController { String param6 = request.getParameter("email"); String param7 = request.getParameter("CP"); System.out.println(request.getParameter("CP")); - - new MagasinHelper().updateCustomer(Integer.valueOf(param1),param2.charAt(0),param3,param4,param5,param6,param7); - return new ModelAndView("confirm").addObject("confirm","mise à jour effectuée"); - - } + new MagasinHelper().updateCustomer(Integer.parseInt(param1), param2.charAt(0), param3, param4, param5, param6, param7); + return new ModelAndView("confirm").addObject("confirm", "mise à jour effectuée"); + } } diff --git a/src/java/hibernate.cfg.xml b/src/java/hibernate.cfg.xml index bc8638d..b1daed0 100644 --- a/src/java/hibernate.cfg.xml +++ b/src/java/hibernate.cfg.xml @@ -1,18 +1,19 @@ - + - - org.hibernate.dialect.DerbyDialect - org.apache.derby.jdbc.ClientDriver - jdbc:derby://localhost:1527/sample - app - app - - - - - - - - + + org.hibernate.dialect.DerbyDialect + org.apache.derby.jdbc.ClientDriver + jdbc:derby://localhost:1527/sample + app + app + + + + + + + + diff --git a/src/java/hibernate.reveng.xml b/src/java/hibernate.reveng.xml index 9f2a0f9..78e6d62 100644 --- a/src/java/hibernate.reveng.xml +++ b/src/java/hibernate.reveng.xml @@ -1,12 +1,13 @@ - + - - - - - - - - + + + + + + + + diff --git a/src/java/service/User.java b/src/java/service/User.java index 55f3825..05e8799 100644 --- a/src/java/service/User.java +++ b/src/java/service/User.java @@ -4,39 +4,42 @@ * and open the template in the editor. */ package service; + import java.io.Serializable; + /** - * * @author faycal */ public class User implements Serializable { + static private int compteur = 0; + private final int userId; private String login; private String pwd; - private int userId; - static private int compteur=0; - - public static int getCompteur() { - return compteur; - } public User() { super(); - userId=compteur++; + userId = compteur++; } - public void finalize(){ - - compteur--; - } - public User(String login) { + + public User(String login) { this.login = login; - userId=compteur++; - + userId = compteur++; + } public User(String login, String pwd) { this.login = login; this.pwd = pwd; - userId=compteur++; + userId = compteur++; + } + + public static int getCompteur() { + return compteur; + } + + protected void finalize() { + + compteur--; } public String getLogin() { @@ -54,5 +57,4 @@ public class User implements Serializable { public void setPwd(String pwd) { this.pwd = pwd; } - }