Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions Adresse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.fasoyaar.entity.client;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="t_adresse")
public class Adresse implements Serializable{

/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long idAddress;
@Column(name="ville",length=60)
private String city;
@Column(name="rue",length=60)
private String street;
@Column(name="pays",length=60)
private String Country;





public Long getIdAddress() {
return idAddress;
}
public void setIdAddress(Long idAddress) {
this.idAddress = idAddress;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCountry() {
return Country;
}
public void setCountry(String country) {
Country = country;
}
/**
*
*/
public Adresse() {
super();
}
/**
* @param idAddress
* @param city
* @param street
* @param country
*/
public Adresse(String city, String street, String country) {
super();
this.city = city;
this.street = street;
Country = country;
}
}
91 changes: 91 additions & 0 deletions Article.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package com.fasoyaar.entity.categorie;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name="t_article")
public class Article implements Serializable{

/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long idArt;
@Column(name="nom_article",length=60)
private String nomArt;
@Column(name="prix_unitaire")
private Float pu;
@Column(name="chemin_image",length=255)
private String imagePath;
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="produit_fk")
private Produit produit;

public Produit getProduit() {
return produit;
}
public void setProduit(Produit produit) {
this.produit = produit;
}
/**
* @param idArt
* @param nomArt
* @param pu
* @param imagePath
*/
public Article( String nomArt, Float pu, String imagePath) {
super();
this.nomArt = nomArt;
this.pu = pu;
this.imagePath = imagePath;
}
/**
*
*/
public Article() {
super();
}
@Override
public String toString() {
return "Article [idArt=" + idArt + ", nomArt=" + nomArt + ", pu=" + pu + ", imagePath=" + imagePath + "]";
}
public Long getIdArt() {
return idArt;
}
public void setIdArt(Long idArt) {
this.idArt = idArt;
}
public String getNomArt() {
return nomArt;
}
public void setNomArt(String nomArt) {
this.nomArt = nomArt;
}
public Float getPu() {
return pu;
}
public void setPu(Float pu) {
this.pu = pu;
}
public String getImagePath() {
return imagePath;
}
public void setImagePath(String imagePath) {
this.imagePath = imagePath;
}



}
184 changes: 184 additions & 0 deletions CatalogueImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
package com.fasoyaar.session.catalogue;


import java.util.ArrayList;
import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.fasoyaar.entity.categorie.Article;
import com.fasoyaar.entity.categorie.Categorie;
import com.fasoyaar.entity.categorie.Produit;

@Stateless(name="CatalogueMetier")
public class CatalogueImpl implements ICatalogueLocal,ICatalogueRemote{

@PersistenceContext(unitName="UP_FasoYaar")
private EntityManager em;
@Override
public Categorie createCategorie(Categorie cat) {
// TODO Auto-generated method stub
em.persist(cat);
return cat;
}

@Override
public void deleteCategorie(Long idCat) {
// TODO Auto-generated method stub
Categorie c= em.find(Categorie.class, idCat);
if(c==null) throw new RuntimeException("Categorie introuvable");
else
em.remove(c);
}

@Override
public Categorie updateCategorie(Categorie cat) {
// TODO Auto-generated method stub
Categorie categ=em.find(Categorie.class, cat.getIdCat());
categ.setNomCat(cat.getNomCat());
categ.setDescCat(cat.getDescCat());
em.persist(cat);
return categ;

}

@SuppressWarnings("unchecked")
@Override
public List<Categorie> getAllCategories() {
// TODO Auto-generated method stub
Query request=em.createQuery("select c from Categorie c");
return request.getResultList();

}

@Override
public Produit createProduit(Produit p,Long idCat) {
// TODO Auto-generated method stub
p.setCategorie(em.find(Categorie.class, idCat));
em.persist(p);
return p;
}

@Override
public void deleteProduit(Long idPrct) {
// TODO Auto-generated method stub
Produit p= em.find(Produit.class, idPrct);
if(p==null) throw new RuntimeException("Produit introuvable");
else
em.remove(p);
}

@Override
public Produit updateProduit(Produit p) {
// TODO Auto-generated method stub
em.merge(p);
Produit prd=em.find(Produit.class, p.getIdPrct());
prd.setNomPrct(p.getNomPrct());
prd.setDescPrct(p.getDescPrct());
em.persist(p);
return prd;
}

@SuppressWarnings("unchecked")
@Override
public List<Produit> getAllProduits(Long idCat){
// TODO Auto-generated method stub
Query request=em.createQuery("select p from Produit p where p.categorie.idCat="+idCat+"");
return request.getResultList();
}

@Override
public Article createArticle(Article a,Long idPrct) {
// TODO Auto-generated method stub
a.setProduit(em.find(Produit.class,idPrct));
em.persist(a);
return a;
}

@Override
public void deleteArticle(Long idArt) {
// TODO Auto-generated method stub
Article a= em.find(Article.class, idArt);
if(a==null) throw new RuntimeException("Article introuvable");
else
em.remove(a);
}

@Override
public Article updateArticle(Article a) {
// TODO Auto-generated method stub
em.merge(a);
Article art=em.find(Article.class, a.getIdArt());
art.setNomArt(a.getNomArt());
art.setPu(a.getPu());
art.setImagePath(a.getImagePath());
em.persist(a);
return art;
}

@SuppressWarnings("unchecked")
@Override
public List<Article> getAllArticles(Long idCat) {
// TODO Auto-generated method stub
List<Article> arts =this.getAllArticle(idCat);
return arts;
}


@Override
public Categorie findCategorie(Long idCat) {
// TODO Auto-generated method stub

return em.find(Categorie.class, idCat);
}

@Override
public Produit findProduit(Long idPrct) {
// TODO Auto-generated method stub

return em.find(Produit.class, idPrct);
}

@Override
public Article findArticle(Long idArt) {
// TODO Auto-generated method stub
Article art=em.find(Article.class, idArt);
return art;
}

@Override
public Produit addArticle(Produit p, Article a) {
// TODO Auto-generated method stub
em.find(Produit.class, p.getIdPrct());
em.flush();
em.find(Article.class, a.getIdArt());
a.setProduit(p);


return p;

}
@SuppressWarnings("unchecked")
public List<Article> getAllArticle(Long idCat) {
// TODO Auto-generated method stub
List<Article> arts;
Query request=em.createQuery("SELECT c FROM Article c where c.produit.categorie.idCat="+idCat+"");
arts=request.getResultList();
return (arts);
}

@SuppressWarnings("unchecked")
@Override
public List<Article> getAllArticles() {
// TODO Auto-generated method stub
List<Article> arts;
Query request=em.createQuery("SELECT c FROM Article c ");

return request.getResultList();
}


}
Loading