1. Nick Raptis
  2. DistributedLab

Commits

Nick Raptis  committed f987991

Renames and betterments :P

  • Participants
  • Parent commits 6514389
  • Branches default

Comments (0)

Files changed (43)

File CartWebService/nbproject/build-impl.xml

View file
         <!-- You can override this target in the ../build.xml file. -->
     </target>
     <target depends="compile,-library-inclusion-in-archive-weblogic,-library-inclusion-in-archive-by-user" name="library-inclusion-in-archive"/>
-    <target if="is.jars.in.ejbjar" name="-library-inclusion-in-archive-by-user"/>
+    <target if="is.jars.in.ejbjar" name="-library-inclusion-in-archive-by-user">
+        <copyfiles files="${libs.JAVADB_DRIVER_LABEL.classpath}" todir="${build.classes.dir}"/>
+    </target>
     <target if="is.server.weblogic" name="-library-inclusion-in-archive-weblogic">
-        <manifest file="${build.ear.classes.dir}/META-INF/MANIFEST.MF" mode="update"/>
+        <basename file="${libs.JAVADB_DRIVER_LABEL.classpath}" property="manifest.libs.JAVADB_DRIVER_LABEL.classpath"/>
+        <manifest file="${build.ear.classes.dir}/META-INF/MANIFEST.MF" mode="update">
+            <attribute name="Extension-List" value="jar-1 "/>
+            <attribute name="jar-1-Extension-Name" value="${manifest.libs.JAVADB_DRIVER_LABEL.classpath}"/>
+        </manifest>
     </target>
     <target depends="compile" name="library-inclusion-in-manifest">
+        <copyfiles files="${libs.JAVADB_DRIVER_LABEL.classpath}" todir="${dist.ear.dir}/lib"/>
         <manifest file="${build.ear.classes.dir}/META-INF/MANIFEST.MF" mode="update"/>
     </target>
     <target name="-copy-meta-inf">

File CartWebService/nbproject/genfiles.properties

View file
-build.xml.data.CRC32=643e73b7
+build.xml.data.CRC32=c5535e97
 build.xml.script.CRC32=38fe6ff1
 build.xml.stylesheet.CRC32=5910fda3@1.34.1
 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
 # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
-nbproject/build-impl.xml.data.CRC32=643e73b7
-nbproject/build-impl.xml.script.CRC32=58e99e5c
+nbproject/build-impl.xml.data.CRC32=c5535e97
+nbproject/build-impl.xml.script.CRC32=dafcf57f
 nbproject/build-impl.xml.stylesheet.CRC32=4014c974@1.34.1
 nbproject/jaxws-build.xml.stylesheet.CRC32=c70497e7

File CartWebService/nbproject/project.properties

View file
 j2ee.server.type=gfv3ee6
 jar.compress=false
 jar.name=CartWebService.jar
-javac.classpath=
+javac.classpath=\
+    ${libs.JAVADB_DRIVER_LABEL.classpath}
 javac.debug=true
 javac.deprecation=false
 javac.processorpath=\

File CartWebService/nbproject/project.xml

View file
         <data xmlns="http://www.netbeans.org/ns/j2ee-ejbjarproject/3">
             <name>CartWebService</name>
             <minimum-ant-version>1.6.5</minimum-ant-version>
+            <included-library dirs="200">libs.JAVADB_DRIVER_LABEL.classpath</included-library>
             <source-roots>
                 <root id="src.dir" name="Source Packages"/>
             </source-roots>

File CartWebService/src/conf/persistence.xml

View file
 <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
   <persistence-unit name="ask5PU" transaction-type="RESOURCE_LOCAL">
     <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
-    <class>ask5.Category</class>
-    <class>ask5.Product</class>
-    <class>ask5.Record</class>
-    <class>ask5.ShoppingCart</class>
+    <exclude-unlisted-classes>false</exclude-unlisted-classes>
     <properties>
       <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/ask5"/>
       <property name="javax.persistence.jdbc.password" value="ask5"/>
       <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
       <property name="javax.persistence.jdbc.user" value="ask5"/>
+      <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
     </properties>
   </persistence-unit>
   <persistence-unit name="CartWebServicePU" transaction-type="JTA">

File CartWebService/src/java/ask5/AbstractFacade.java

-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package ask5;
-
-import java.util.List;
-import javax.persistence.EntityManager;
-
-/**
- *
- * @author airscorp
- */
-public abstract class AbstractFacade<T> {
-    private Class<T> entityClass;
-
-    public AbstractFacade(Class<T> entityClass) {
-        this.entityClass = entityClass;
-    }
-
-    protected abstract EntityManager getEntityManager();
-
-    public void create(T entity) {
-        getEntityManager().persist(entity);
-    }
-
-    public void edit(T entity) {
-        getEntityManager().merge(entity);
-    }
-
-    public void remove(T entity) {
-        getEntityManager().remove(getEntityManager().merge(entity));
-    }
-
-    public T find(Object id) {
-        return getEntityManager().find(entityClass, id);
-    }
-
-    public List<T> findAll() {
-        javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
-        cq.select(cq.from(entityClass));
-        return getEntityManager().createQuery(cq).getResultList();
-    }
-
-    public List<T> findRange(int[] range) {
-        javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
-        cq.select(cq.from(entityClass));
-        javax.persistence.Query q = getEntityManager().createQuery(cq);
-        q.setMaxResults(range[1] - range[0]);
-        q.setFirstResult(range[0]);
-        return q.getResultList();
-    }
-
-    public int count() {
-        javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
-        javax.persistence.criteria.Root<T> rt = cq.from(entityClass);
-        cq.select(getEntityManager().getCriteriaBuilder().count(rt));
-        javax.persistence.Query q = getEntityManager().createQuery(cq);
-        return ((Long) q.getSingleResult()).intValue();
-    }
-
-}

File CartWebService/src/java/ask5/Ask5.java

-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package ask5;
-
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
-
-/**
- *
- * @author nr1550
- */
-public class Ask5 {
-
-    /**
-     * @param args the command line arguments
-     */
-    public static void main(String[] args) {
-        Category category1 = new Category();
-        category1.setName("frouta");
-        
-        Product product1 = new Product();
-        product1.setName("banana");
-        product1.setPrice(1F);
-        product1.setDealer("Chiquita");
-        product1.setCategory(category1);
-        
-        Record record1 = new Record();
-        record1.setProduct(product1);
-        record1.setQuantity(2);
-
-        ShoppingCart cart1 = new ShoppingCart();
-        cart1.setFullName("Nikous Raptous");
-        cart1.setAddress("Apedw kiapekei");
-        cart1.setVatNumber("0123456789");
-        cart1.getRecords().add(record1);
-        //record1.setCart(cart1);
-        
-        
-        EntityManagerFactory emf = Persistence.createEntityManagerFactory("ask5PU");
-        
-        ShoppingCartJpaController contr1 = new ShoppingCartJpaController(emf);
-        contr1.create(cart1);
-        
-    }
-}

File CartWebService/src/java/ask5/Category.java

-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package ask5;
-
-import java.io.Serializable;
-import java.util.List;
-import javax.persistence.CascadeType;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.OneToMany;
-
-/**
- *
- * @author nr1550
- */
-@Entity
-public class Category implements Serializable {
-    private static final long serialVersionUID = 1L;
-    @Id
-    @GeneratedValue(strategy = GenerationType.AUTO)
-    private Long id;
-    private String name;
-    @OneToMany(mappedBy = "category", cascade=CascadeType.ALL)
-    private List<Product> products;
-
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    public Long getId() {
-        return id;
-    }
-
-    public void setId(Long id) {
-        this.id = id;
-    }
-    
-    public List<Product> getProducts() {
-        return products;
-    }
-
-    /*
-    @Override
-    public int hashCode() {
-        int hash = 0;
-        hash += (id != null ? id.hashCode() : 0);
-        return hash;
-    }
-
-    @Override
-    public boolean equals(Object object) {
-        // TODO: Warning - this method won't work in the case the id fields are not set
-        if (!(object instanceof Category)) {
-            return false;
-        }
-        Category other = (Category) object;
-        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
-            return false;
-        }
-        return true;
-    }
-
-    @Override
-    public String toString() {
-        return "ask5.Category[ id=" + id + " ]";
-    }
-*/  
-}

File CartWebService/src/java/ask5/CategoryFacade.java

-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package ask5;
-
-import javax.ejb.Stateless;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-
-/**
- *
- * @author airscorp
- */
-@Stateless
-public class CategoryFacade extends AbstractFacade<Category> {
-    @PersistenceContext(unitName = "CartWebServicePU")
-    private EntityManager em;
-
-    @Override
-    protected EntityManager getEntityManager() {
-        return em;
-    }
-
-    public CategoryFacade() {
-        super(Category.class);
-    }
-
-}

File CartWebService/src/java/ask5/CategoryJpaController.java

-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package ask5;
-
-import ask5.exceptions.NonexistentEntityException;
-import java.io.Serializable;
-import java.util.List;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Query;
-import javax.persistence.EntityNotFoundException;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Root;
-
-/**
- *
- * @author nr1550
- */
-public class CategoryJpaController implements Serializable {
-
-    public CategoryJpaController(EntityManagerFactory emf) {
-        this.emf = emf;
-    }
-    private EntityManagerFactory emf = null;
-
-    public EntityManager getEntityManager() {
-        return emf.createEntityManager();
-    }
-
-    public void create(Category category) {
-        EntityManager em = null;
-        try {
-            em = getEntityManager();
-            em.getTransaction().begin();
-            em.persist(category);
-            em.getTransaction().commit();
-        } finally {
-            if (em != null) {
-                em.close();
-            }
-        }
-    }
-
-    public void edit(Category category) throws NonexistentEntityException, Exception {
-        EntityManager em = null;
-        try {
-            em = getEntityManager();
-            em.getTransaction().begin();
-            category = em.merge(category);
-            em.getTransaction().commit();
-        } catch (Exception ex) {
-            String msg = ex.getLocalizedMessage();
-            if (msg == null || msg.length() == 0) {
-                Long id = category.getId();
-                if (findCategory(id) == null) {
-                    throw new NonexistentEntityException("The category with id " + id + " no longer exists.");
-                }
-            }
-            throw ex;
-        } finally {
-            if (em != null) {
-                em.close();
-            }
-        }
-    }
-
-    public void destroy(Long id) throws NonexistentEntityException {
-        EntityManager em = null;
-        try {
-            em = getEntityManager();
-            em.getTransaction().begin();
-            Category category;
-            try {
-                category = em.getReference(Category.class, id);
-                category.getId();
-            } catch (EntityNotFoundException enfe) {
-                throw new NonexistentEntityException("The category with id " + id + " no longer exists.", enfe);
-            }
-            em.remove(category);
-            em.getTransaction().commit();
-        } finally {
-            if (em != null) {
-                em.close();
-            }
-        }
-    }
-
-    public List<Category> findCategoryEntities() {
-        return findCategoryEntities(true, -1, -1);
-    }
-
-    public List<Category> findCategoryEntities(int maxResults, int firstResult) {
-        return findCategoryEntities(false, maxResults, firstResult);
-    }
-
-    private List<Category> findCategoryEntities(boolean all, int maxResults, int firstResult) {
-        EntityManager em = getEntityManager();
-        try {
-            CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
-            cq.select(cq.from(Category.class));
-            Query q = em.createQuery(cq);
-            if (!all) {
-                q.setMaxResults(maxResults);
-                q.setFirstResult(firstResult);
-            }
-            return q.getResultList();
-        } finally {
-            em.close();
-        }
-    }
-
-    public Category findCategory(Long id) {
-        EntityManager em = getEntityManager();
-        try {
-            return em.find(Category.class, id);
-        } finally {
-            em.close();
-        }
-    }
-
-    public int getCategoryCount() {
-        EntityManager em = getEntityManager();
-        try {
-            CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
-            Root<Category> rt = cq.from(Category.class);
-            cq.select(em.getCriteriaBuilder().count(rt));
-            Query q = em.createQuery(cq);
-            return ((Long) q.getSingleResult()).intValue();
-        } finally {
-            em.close();
-        }
-    }
-    
-}

File CartWebService/src/java/ask5/Product.java

-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package ask5;
-
-import java.io.Serializable;
-import java.util.List;
-import javax.persistence.CascadeType;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.ManyToOne;
-import javax.persistence.OneToMany;
-
-/**
- *
- * @author nr1550
- */
-@Entity
-public class Product implements Serializable {
-    private static final long serialVersionUID = 1L;
-    @Id
-    @GeneratedValue(strategy = GenerationType.AUTO)
-    private Long id;
-    private String name;
-    private float price;
-    private String dealer;
-    @ManyToOne(cascade=CascadeType.ALL)
-    private Category category;
-    @OneToMany(mappedBy = "product", cascade=CascadeType.ALL)
-    private List<Record> records;
-
-    public Long getId() {
-        return id;
-    }
-
-    public void setId(Long id) {
-        this.id = id;
-    }
-
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    public float getPrice() {
-        return price;
-    }
-
-    public void setPrice(float price) {
-        this.price = price;
-    }
-
-    public String getDealer() {
-        return dealer;
-    }
-
-    public void setDealer(String dealer) {
-        this.dealer = dealer;
-    }
-
-    public Category getCategory() {
-        return category;
-    }
-
-    public void setCategory(Category category) {
-        this.category = category;
-    }
-
-    public List<Record> getRecords() {
-        return records;
-    }
-/*
-    @Override
-    public int hashCode() {
-        int hash = 0;
-        hash += (id != null ? id.hashCode() : 0);
-        return hash;
-    }
-
-    @Override
-    public boolean equals(Object object) {
-        // TODO: Warning - this method won't work in the case the id fields are not set
-        if (!(object instanceof Product)) {
-            return false;
-        }
-        Product other = (Product) object;
-        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
-            return false;
-        }
-        return true;
-    }
-
-    @Override
-    public String toString() {
-        return "ask5.Product[ id=" + id + " ]";
-    }
-*/    
-}

File CartWebService/src/java/ask5/ProductFacade.java

-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package ask5;
-
-import javax.ejb.Stateless;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-
-/**
- *
- * @author airscorp
- */
-@Stateless
-public class ProductFacade extends AbstractFacade<Product> {
-    @PersistenceContext(unitName = "CartWebServicePU")
-    private EntityManager em;
-
-    @Override
-    protected EntityManager getEntityManager() {
-        return em;
-    }
-
-    public ProductFacade() {
-        super(Product.class);
-    }
-
-}

File CartWebService/src/java/ask5/ProductJpaController.java

-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package ask5;
-
-import ask5.exceptions.NonexistentEntityException;
-import java.io.Serializable;
-import java.util.List;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Query;
-import javax.persistence.EntityNotFoundException;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Root;
-
-/**
- *
- * @author nr1550
- */
-public class ProductJpaController implements Serializable {
-
-    public ProductJpaController(EntityManagerFactory emf) {
-        this.emf = emf;
-    }
-    private EntityManagerFactory emf = null;
-
-    public EntityManager getEntityManager() {
-        return emf.createEntityManager();
-    }
-
-    public void create(Product product) {
-        EntityManager em = null;
-        try {
-            em = getEntityManager();
-            em.getTransaction().begin();
-            em.persist(product);
-            em.getTransaction().commit();
-        } finally {
-            if (em != null) {
-                em.close();
-            }
-        }
-    }
-
-    public void edit(Product product) throws NonexistentEntityException, Exception {
-        EntityManager em = null;
-        try {
-            em = getEntityManager();
-            em.getTransaction().begin();
-            product = em.merge(product);
-            em.getTransaction().commit();
-        } catch (Exception ex) {
-            String msg = ex.getLocalizedMessage();
-            if (msg == null || msg.length() == 0) {
-                Long id = product.getId();
-                if (findProduct(id) == null) {
-                    throw new NonexistentEntityException("The product with id " + id + " no longer exists.");
-                }
-            }
-            throw ex;
-        } finally {
-            if (em != null) {
-                em.close();
-            }
-        }
-    }
-
-    public void destroy(Long id) throws NonexistentEntityException {
-        EntityManager em = null;
-        try {
-            em = getEntityManager();
-            em.getTransaction().begin();
-            Product product;
-            try {
-                product = em.getReference(Product.class, id);
-                product.getId();
-            } catch (EntityNotFoundException enfe) {
-                throw new NonexistentEntityException("The product with id " + id + " no longer exists.", enfe);
-            }
-            em.remove(product);
-            em.getTransaction().commit();
-        } finally {
-            if (em != null) {
-                em.close();
-            }
-        }
-    }
-
-    public List<Product> findProductEntities() {
-        return findProductEntities(true, -1, -1);
-    }
-
-    public List<Product> findProductEntities(int maxResults, int firstResult) {
-        return findProductEntities(false, maxResults, firstResult);
-    }
-
-    private List<Product> findProductEntities(boolean all, int maxResults, int firstResult) {
-        EntityManager em = getEntityManager();
-        try {
-            CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
-            cq.select(cq.from(Product.class));
-            Query q = em.createQuery(cq);
-            if (!all) {
-                q.setMaxResults(maxResults);
-                q.setFirstResult(firstResult);
-            }
-            return q.getResultList();
-        } finally {
-            em.close();
-        }
-    }
-
-    public Product findProduct(Long id) {
-        EntityManager em = getEntityManager();
-        try {
-            return em.find(Product.class, id);
-        } finally {
-            em.close();
-        }
-    }
-
-    public int getProductCount() {
-        EntityManager em = getEntityManager();
-        try {
-            CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
-            Root<Product> rt = cq.from(Product.class);
-            cq.select(em.getCriteriaBuilder().count(rt));
-            Query q = em.createQuery(cq);
-            return ((Long) q.getSingleResult()).intValue();
-        } finally {
-            em.close();
-        }
-    }
-    
-}

File CartWebService/src/java/ask5/Record.java

-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package ask5;
-
-import java.io.Serializable;
-import javax.persistence.CascadeType;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.ManyToOne;
-
-/**
- *
- * @author nr1550
- */
-@Entity
-public class Record implements Serializable {
-    private static final long serialVersionUID = 1L;
-    @Id
-    @GeneratedValue(strategy = GenerationType.AUTO)
-    private Long id;
-    @ManyToOne(cascade=CascadeType.ALL)
-    private ShoppingCart cart;
-    @ManyToOne(cascade=CascadeType.ALL)
-    private Product product;
-    private Integer quantity;
-
-    public Long getId() {
-        return id;
-    }
-
-    public void setId(Long id) {
-        this.id = id;
-    }
-
-    public Product getProduct() {
-        return product;
-    }
-
-    public void setProduct(Product product) {
-        this.product = product;
-    }
-
-    public Integer getQuantity() {
-        return quantity;
-    }
-
-    public void setQuantity(Integer quantity) {
-        this.quantity = quantity;
-    }
-
-    public ShoppingCart getCart() {
-        return cart;
-    }
-
-    public void setCart(ShoppingCart cart) {
-        this.cart = cart;
-    }
-
-/*
-    @Override
-    public int hashCode() {
-        int hash = 0;
-        hash += (id != null ? id.hashCode() : 0);
-        return hash;
-    }
-
-    @Override
-    public boolean equals(Object object) {
-        // TODO: Warning - this method won't work in the case the id fields are not set
-        if (!(object instanceof Record)) {
-            return false;
-        }
-        Record other = (Record) object;
-        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
-            return false;
-        }
-        return true;
-    }
-
-    @Override
-    public String toString() {
-        return "ask5.Record[ id=" + id + " ]";
-    }
-*/    
-}

File CartWebService/src/java/ask5/RecordFacade.java

-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package ask5;
-
-import javax.ejb.Stateless;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-
-/**
- *
- * @author airscorp
- */
-@Stateless
-public class RecordFacade extends AbstractFacade<Record> {
-    @PersistenceContext(unitName = "CartWebServicePU")
-    private EntityManager em;
-
-    @Override
-    protected EntityManager getEntityManager() {
-        return em;
-    }
-
-    public RecordFacade() {
-        super(Record.class);
-    }
-
-}

File CartWebService/src/java/ask5/RecordJpaController.java

-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package ask5;
-
-import ask5.exceptions.NonexistentEntityException;
-import java.io.Serializable;
-import java.util.List;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Query;
-import javax.persistence.EntityNotFoundException;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Root;
-
-/**
- *
- * @author nr1550
- */
-public class RecordJpaController implements Serializable {
-
-    public RecordJpaController(EntityManagerFactory emf) {
-        this.emf = emf;
-    }
-    private EntityManagerFactory emf = null;
-
-    public EntityManager getEntityManager() {
-        return emf.createEntityManager();
-    }
-
-    public void create(Record record) {
-        EntityManager em = null;
-        try {
-            em = getEntityManager();
-            em.getTransaction().begin();
-            em.persist(record);
-            em.getTransaction().commit();
-        } finally {
-            if (em != null) {
-                em.close();
-            }
-        }
-    }
-
-    public void edit(Record record) throws NonexistentEntityException, Exception {
-        EntityManager em = null;
-        try {
-            em = getEntityManager();
-            em.getTransaction().begin();
-            record = em.merge(record);
-            em.getTransaction().commit();
-        } catch (Exception ex) {
-            String msg = ex.getLocalizedMessage();
-            if (msg == null || msg.length() == 0) {
-                Long id = record.getId();
-                if (findRecord(id) == null) {
-                    throw new NonexistentEntityException("The record with id " + id + " no longer exists.");
-                }
-            }
-            throw ex;
-        } finally {
-            if (em != null) {
-                em.close();
-            }
-        }
-    }
-
-    public void destroy(Long id) throws NonexistentEntityException {
-        EntityManager em = null;
-        try {
-            em = getEntityManager();
-            em.getTransaction().begin();
-            Record record;
-            try {
-                record = em.getReference(Record.class, id);
-                record.getId();
-            } catch (EntityNotFoundException enfe) {
-                throw new NonexistentEntityException("The record with id " + id + " no longer exists.", enfe);
-            }
-            em.remove(record);
-            em.getTransaction().commit();
-        } finally {
-            if (em != null) {
-                em.close();
-            }
-        }
-    }
-
-    public List<Record> findRecordEntities() {
-        return findRecordEntities(true, -1, -1);
-    }
-
-    public List<Record> findRecordEntities(int maxResults, int firstResult) {
-        return findRecordEntities(false, maxResults, firstResult);
-    }
-
-    private List<Record> findRecordEntities(boolean all, int maxResults, int firstResult) {
-        EntityManager em = getEntityManager();
-        try {
-            CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
-            cq.select(cq.from(Record.class));
-            Query q = em.createQuery(cq);
-            if (!all) {
-                q.setMaxResults(maxResults);
-                q.setFirstResult(firstResult);
-            }
-            return q.getResultList();
-        } finally {
-            em.close();
-        }
-    }
-
-    public Record findRecord(Long id) {
-        EntityManager em = getEntityManager();
-        try {
-            return em.find(Record.class, id);
-        } finally {
-            em.close();
-        }
-    }
-
-    public int getRecordCount() {
-        EntityManager em = getEntityManager();
-        try {
-            CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
-            Root<Record> rt = cq.from(Record.class);
-            cq.select(em.getCriteriaBuilder().count(rt));
-            Query q = em.createQuery(cq);
-            return ((Long) q.getSingleResult()).intValue();
-        } finally {
-            em.close();
-        }
-    }
-    
-}

File CartWebService/src/java/ask5/ShoppingCart.java

-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package ask5;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-import javax.persistence.CascadeType;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.OneToMany;
-
-/**
- *
- * @author nr1550
- */
-@Entity
-public class ShoppingCart implements Serializable {
-    private static final long serialVersionUID = 1L;
-    @Id
-    @GeneratedValue(strategy = GenerationType.AUTO)
-    private Long id;
-    private String fullName;
-    private String address;
-    private String vatNumber;
-    @OneToMany(mappedBy = "cart", cascade=CascadeType.ALL)
-    private List<Record> records = new ArrayList<Record>();
-
-    public Long getId() {
-        return id;
-    }
-
-    public void setId(Long id) {
-        this.id = id;
-    }
-
-    public String getFullName() {
-        return fullName;
-    }
-
-    public void setFullName(String fullName) {
-        this.fullName = fullName;
-    }
-
-    public String getAddress() {
-        return address;
-    }
-
-    public void setAddress(String address) {
-        this.address = address;
-    }
-
-    public String getVatNumber() {
-        return vatNumber;
-    }
-
-    public void setVatNumber(String vatNumber) {
-        this.vatNumber = vatNumber;
-    }
-
-    public List<Record> getRecords() {
-        return records;
-    }
-
-/*
-    @Override
-    public int hashCode() {
-        int hash = 0;
-        hash += (id != null ? id.hashCode() : 0);
-        return hash;
-    }
-
-    @Override
-    public boolean equals(Object object) {
-        // TODO: Warning - this method won't work in the case the id fields are not set
-        if (!(object instanceof ShoppingCart)) {
-            return false;
-        }
-        ShoppingCart other = (ShoppingCart) object;
-        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
-            return false;
-        }
-        return true;
-    }
-
-    @Override
-    public String toString() {
-        return "ask5.ShoppingCart[ id=" + id + " ]";
-    }
-*/    
-}

File CartWebService/src/java/ask5/ShoppingCartFacade.java

-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package ask5;
-
-import javax.ejb.Stateless;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-
-/**
- *
- * @author airscorp
- */
-@Stateless
-public class ShoppingCartFacade extends AbstractFacade<ShoppingCart> {
-    @PersistenceContext(unitName = "CartWebServicePU")
-    private EntityManager em;
-
-    @Override
-    protected EntityManager getEntityManager() {
-        return em;
-    }
-
-    public ShoppingCartFacade() {
-        super(ShoppingCart.class);
-    }
-
-}

File CartWebService/src/java/ask5/ShoppingCartJpaController.java

-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package ask5;
-
-import ask5.exceptions.NonexistentEntityException;
-import java.io.Serializable;
-import java.util.List;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Query;
-import javax.persistence.EntityNotFoundException;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Root;
-
-/**
- *
- * @author nr1550
- */
-public class ShoppingCartJpaController implements Serializable {
-
-    public ShoppingCartJpaController(EntityManagerFactory emf) {
-        this.emf = emf;
-    }
-    private EntityManagerFactory emf = null;
-
-    public EntityManager getEntityManager() {
-        return emf.createEntityManager();
-    }
-
-    public void create(ShoppingCart shoppingCart) {
-        EntityManager em = null;
-        try {
-            em = getEntityManager();
-            em.getTransaction().begin();
-            em.persist(shoppingCart);
-            em.getTransaction().commit();
-        } finally {
-            if (em != null) {
-                em.close();
-            }
-        }
-    }
-
-    public void edit(ShoppingCart shoppingCart) throws NonexistentEntityException, Exception {
-        EntityManager em = null;
-        try {
-            em = getEntityManager();
-            em.getTransaction().begin();
-            shoppingCart = em.merge(shoppingCart);
-            em.getTransaction().commit();
-        } catch (Exception ex) {
-            String msg = ex.getLocalizedMessage();
-            if (msg == null || msg.length() == 0) {
-                Long id = shoppingCart.getId();
-                if (findShoppingCart(id) == null) {
-                    throw new NonexistentEntityException("The shoppingCart with id " + id + " no longer exists.");
-                }
-            }
-            throw ex;
-        } finally {
-            if (em != null) {
-                em.close();
-            }
-        }
-    }
-
-    public void destroy(Long id) throws NonexistentEntityException {
-        EntityManager em = null;
-        try {
-            em = getEntityManager();
-            em.getTransaction().begin();
-            ShoppingCart shoppingCart;
-            try {
-                shoppingCart = em.getReference(ShoppingCart.class, id);
-                shoppingCart.getId();
-            } catch (EntityNotFoundException enfe) {
-                throw new NonexistentEntityException("The shoppingCart with id " + id + " no longer exists.", enfe);
-            }
-            em.remove(shoppingCart);
-            em.getTransaction().commit();
-        } finally {
-            if (em != null) {
-                em.close();
-            }
-        }
-    }
-
-    public List<ShoppingCart> findShoppingCartEntities() {
-        return findShoppingCartEntities(true, -1, -1);
-    }
-
-    public List<ShoppingCart> findShoppingCartEntities(int maxResults, int firstResult) {
-        return findShoppingCartEntities(false, maxResults, firstResult);
-    }
-
-    private List<ShoppingCart> findShoppingCartEntities(boolean all, int maxResults, int firstResult) {
-        EntityManager em = getEntityManager();
-        try {
-            CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
-            cq.select(cq.from(ShoppingCart.class));
-            Query q = em.createQuery(cq);
-            if (!all) {
-                q.setMaxResults(maxResults);
-                q.setFirstResult(firstResult);
-            }
-            return q.getResultList();
-        } finally {
-            em.close();
-        }
-    }
-
-    public ShoppingCart findShoppingCart(Long id) {
-        EntityManager em = getEntityManager();
-        try {
-            return em.find(ShoppingCart.class, id);
-        } finally {
-            em.close();
-        }
-    }
-
-    public int getShoppingCartCount() {
-        EntityManager em = getEntityManager();
-        try {
-            CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
-            Root<ShoppingCart> rt = cq.from(ShoppingCart.class);
-            cq.select(em.getCriteriaBuilder().count(rt));
-            Query q = em.createQuery(cq);
-            return ((Long) q.getSingleResult()).intValue();
-        } finally {
-            em.close();
-        }
-    }
-    
-}

File CartWebService/src/java/ask5/exceptions/IllegalOrphanException.java

-package ask5.exceptions;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class IllegalOrphanException extends Exception {
-    private List<String> messages;
-    public IllegalOrphanException(List<String> messages) {
-        super((messages != null && messages.size() > 0 ? messages.get(0) : null));
-        if (messages == null) {
-            this.messages = new ArrayList<String>();
-        }
-        else {
-            this.messages = messages;
-        }
-    }
-    public List<String> getMessages() {
-        return messages;
-    }
-}

File CartWebService/src/java/ask5/exceptions/NonexistentEntityException.java

-package ask5.exceptions;
-
-public class NonexistentEntityException extends Exception {
-    public NonexistentEntityException(String message, Throwable cause) {
-        super(message, cause);
-    }
-    public NonexistentEntityException(String message) {
-        super(message);
-    }
-}

File CartWebService/src/java/ask5/exceptions/PreexistingEntityException.java

-package ask5.exceptions;
-
-public class PreexistingEntityException extends Exception {
-    public PreexistingEntityException(String message, Throwable cause) {
-        super(message, cause);
-    }
-    public PreexistingEntityException(String message) {
-        super(message);
-    }
-}

File CartWebService/src/java/entities/AbstractFacade.java

View file
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package entities;
+
+import java.util.List;
+import javax.persistence.EntityManager;
+
+/**
+ *
+ * @author airscorp
+ */
+public abstract class AbstractFacade<T> {
+    private Class<T> entityClass;
+
+    public AbstractFacade(Class<T> entityClass) {
+        this.entityClass = entityClass;
+    }
+
+    protected abstract EntityManager getEntityManager();
+
+    public void create(T entity) {
+        getEntityManager().persist(entity);
+    }
+
+    public void edit(T entity) {
+        getEntityManager().merge(entity);
+    }
+
+    public void remove(T entity) {
+        getEntityManager().remove(getEntityManager().merge(entity));
+    }
+
+    public T find(Object id) {
+        return getEntityManager().find(entityClass, id);
+    }
+
+    public List<T> findAll() {
+        javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
+        cq.select(cq.from(entityClass));
+        return getEntityManager().createQuery(cq).getResultList();
+    }
+
+    public List<T> findRange(int[] range) {
+        javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
+        cq.select(cq.from(entityClass));
+        javax.persistence.Query q = getEntityManager().createQuery(cq);
+        q.setMaxResults(range[1] - range[0]);
+        q.setFirstResult(range[0]);
+        return q.getResultList();
+    }
+
+    public int count() {
+        javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
+        javax.persistence.criteria.Root<T> rt = cq.from(entityClass);
+        cq.select(getEntityManager().getCriteriaBuilder().count(rt));
+        javax.persistence.Query q = getEntityManager().createQuery(cq);
+        return ((Long) q.getSingleResult()).intValue();
+    }
+
+}

File CartWebService/src/java/entities/Category.java

View file
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package entities;
+
+import java.io.Serializable;
+import java.util.List;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+/**
+ *
+ * @author nr1550
+ */
+@Entity
+public class Category implements Serializable {
+    private static final long serialVersionUID = 1L;
+    @Id
+    @GeneratedValue(strategy = GenerationType.AUTO)
+    private Long id;
+    private String name;
+    @OneToMany(mappedBy = "category")
+    private List<Product> products;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public List<Product> getProducts() {
+        return products;
+    }
+
+
+    @Override
+    public int hashCode() {
+        int hash = 0;
+        hash += (id != null ? id.hashCode() : 0);
+        return hash;
+    }
+
+    @Override
+    public boolean equals(Object object) {
+        // TODO: Warning - this method won't work in the case the id fields are not set
+        if (!(object instanceof Category)) {
+            return false;
+        }
+        Category other = (Category) object;
+        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        return "ask5.Category[ id=" + id + " ]";
+    }
+
+}

File CartWebService/src/java/entities/CategoryFacade.java

View file
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package entities;
+
+import javax.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+/**
+ *
+ * @author airscorp
+ */
+@Stateless
+public class CategoryFacade extends AbstractFacade<Category> {
+    @PersistenceContext(unitName = "CartWebServicePU")
+    private EntityManager em;
+
+    @Override
+    protected EntityManager getEntityManager() {
+        return em;
+    }
+
+    public CategoryFacade() {
+        super(Category.class);
+    }
+
+}

File CartWebService/src/java/entities/CategoryJpaController.java

View file
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package entities;
+
+import entities.exceptions.NonexistentEntityException;
+import java.io.Serializable;
+import java.util.List;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Query;
+import javax.persistence.EntityNotFoundException;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Root;
+
+/**
+ *
+ * @author nr1550
+ */
+public class CategoryJpaController implements Serializable {
+
+    public CategoryJpaController(EntityManagerFactory emf) {
+        this.emf = emf;
+    }
+    private EntityManagerFactory emf = null;
+
+    public EntityManager getEntityManager() {
+        return emf.createEntityManager();
+    }
+
+    public void create(Category category) {
+        EntityManager em = null;
+        try {
+            em = getEntityManager();
+            em.getTransaction().begin();
+            em.persist(category);
+            em.getTransaction().commit();
+        } finally {
+            if (em != null) {
+                em.close();
+            }
+        }
+    }
+
+    public void edit(Category category) throws NonexistentEntityException, Exception {
+        EntityManager em = null;
+        try {
+            em = getEntityManager();
+            em.getTransaction().begin();
+            category = em.merge(category);
+            em.getTransaction().commit();
+        } catch (Exception ex) {
+            String msg = ex.getLocalizedMessage();
+            if (msg == null || msg.length() == 0) {
+                Long id = category.getId();
+                if (findCategory(id) == null) {
+                    throw new NonexistentEntityException("The category with id " + id + " no longer exists.");
+                }
+            }
+            throw ex;
+        } finally {
+            if (em != null) {
+                em.close();
+            }
+        }
+    }
+
+    public void destroy(Long id) throws NonexistentEntityException {
+        EntityManager em = null;
+        try {
+            em = getEntityManager();
+            em.getTransaction().begin();
+            Category category;
+            try {
+                category = em.getReference(Category.class, id);
+                category.getId();
+            } catch (EntityNotFoundException enfe) {
+                throw new NonexistentEntityException("The category with id " + id + " no longer exists.", enfe);
+            }
+            em.remove(category);
+            em.getTransaction().commit();
+        } finally {
+            if (em != null) {
+                em.close();
+            }
+        }
+    }
+
+    public List<Category> findCategoryEntities() {
+        return findCategoryEntities(true, -1, -1);
+    }
+
+    public List<Category> findCategoryEntities(int maxResults, int firstResult) {
+        return findCategoryEntities(false, maxResults, firstResult);
+    }
+
+    private List<Category> findCategoryEntities(boolean all, int maxResults, int firstResult) {
+        EntityManager em = getEntityManager();
+        try {
+            CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
+            cq.select(cq.from(Category.class));
+            Query q = em.createQuery(cq);
+            if (!all) {
+                q.setMaxResults(maxResults);
+                q.setFirstResult(firstResult);
+            }
+            return q.getResultList();
+        } finally {
+            em.close();
+        }
+    }
+
+    public Category findCategory(Long id) {
+        EntityManager em = getEntityManager();
+        try {
+            return em.find(Category.class, id);
+        } finally {
+            em.close();
+        }
+    }
+
+    public int getCategoryCount() {
+        EntityManager em = getEntityManager();
+        try {
+            CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
+            Root<Category> rt = cq.from(Category.class);
+            cq.select(em.getCriteriaBuilder().count(rt));
+            Query q = em.createQuery(cq);
+            return ((Long) q.getSingleResult()).intValue();
+        } finally {
+            em.close();
+        }
+    }
+
+}

File CartWebService/src/java/entities/Product.java

View file
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package entities;
+
+import java.io.Serializable;
+import java.util.List;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+
+/**
+ *
+ * @author nr1550
+ */
+@Entity
+public class Product implements Serializable {
+    private static final long serialVersionUID = 1L;
+    @Id
+    @GeneratedValue(strategy = GenerationType.AUTO)
+    private Long id;
+    private String name;
+    private float price;
+    private String dealer;
+    @ManyToOne
+    private Category category;
+    @OneToMany(mappedBy = "product")
+    private List<Record> records;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public float getPrice() {
+        return price;
+    }
+
+    public void setPrice(float price) {
+        this.price = price;
+    }
+
+    public String getDealer() {
+        return dealer;
+    }
+
+    public void setDealer(String dealer) {
+        this.dealer = dealer;
+    }
+
+    public Category getCategory() {
+        return category;
+    }
+
+    public void setCategory(Category category) {
+        this.category = category;
+    }
+
+    public List<Record> getRecords() {
+        return records;
+    }
+
+    @Override
+    public int hashCode() {
+        int hash = 0;
+        hash += (id != null ? id.hashCode() : 0);
+        return hash;
+    }
+
+    @Override
+    public boolean equals(Object object) {
+        // TODO: Warning - this method won't work in the case the id fields are not set
+        if (!(object instanceof Product)) {
+            return false;
+        }
+        Product other = (Product) object;
+        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        return "ask5.Product[ id=" + id + " ]";
+    }
+
+}

File CartWebService/src/java/entities/ProductFacade.java

View file
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package entities;
+
+import javax.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+/**
+ *
+ * @author airscorp
+ */
+@Stateless
+public class ProductFacade extends AbstractFacade<Product> {
+    @PersistenceContext(unitName = "CartWebServicePU")
+    private EntityManager em;
+
+    @Override
+    protected EntityManager getEntityManager() {
+        return em;
+    }
+
+    public ProductFacade() {
+        super(Product.class);
+    }
+
+}

File CartWebService/src/java/entities/ProductJpaController.java

View file
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package entities;
+
+import entities.exceptions.NonexistentEntityException;
+import java.io.Serializable;
+import java.util.List;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Query;
+import javax.persistence.EntityNotFoundException;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Root;
+
+/**
+ *
+ * @author nr1550
+ */
+public class ProductJpaController implements Serializable {
+
+    public ProductJpaController(EntityManagerFactory emf) {
+        this.emf = emf;
+    }
+    private EntityManagerFactory emf = null;
+
+    public EntityManager getEntityManager() {
+        return emf.createEntityManager();
+    }
+
+    public void create(Product product) {
+        EntityManager em = null;
+        try {
+            em = getEntityManager();
+            em.getTransaction().begin();
+            em.persist(product);
+            em.getTransaction().commit();
+        } finally {
+            if (em != null) {
+                em.close();
+            }
+        }
+    }
+
+    public void edit(Product product) throws NonexistentEntityException, Exception {
+        EntityManager em = null;
+        try {
+            em = getEntityManager();
+            em.getTransaction().begin();
+            product = em.merge(product);
+            em.getTransaction().commit();
+        } catch (Exception ex) {
+            String msg = ex.getLocalizedMessage();
+            if (msg == null || msg.length() == 0) {
+                Long id = product.getId();
+                if (findProduct(id) == null) {
+                    throw new NonexistentEntityException("The product with id " + id + " no longer exists.");
+                }
+            }
+            throw ex;
+        } finally {
+            if (em != null) {
+                em.close();
+            }
+        }
+    }
+
+    public void destroy(Long id) throws NonexistentEntityException {
+        EntityManager em = null;
+        try {
+            em = getEntityManager();
+            em.getTransaction().begin();
+            Product product;
+            try {
+                product = em.getReference(Product.class, id);
+                product.getId();
+            } catch (EntityNotFoundException enfe) {
+                throw new NonexistentEntityException("The product with id " + id + " no longer exists.", enfe);
+            }
+            em.remove(product);
+            em.getTransaction().commit();
+        } finally {
+            if (em != null) {
+                em.close();
+            }
+        }
+    }
+
+    public List<Product> findProductEntities() {
+        return findProductEntities(true, -1, -1);
+    }
+
+    public List<Product> findProductEntities(int maxResults, int firstResult) {
+        return findProductEntities(false, maxResults, firstResult);
+    }
+
+    private List<Product> findProductEntities(boolean all, int maxResults, int firstResult) {
+        EntityManager em = getEntityManager();
+        try {
+            CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
+            cq.select(cq.from(Product.class));
+            Query q = em.createQuery(cq);
+            if (!all) {
+                q.setMaxResults(maxResults);
+                q.setFirstResult(firstResult);
+            }
+            return q.getResultList();
+        } finally {
+            em.close();
+        }
+    }
+
+    public Product findProduct(Long id) {
+        EntityManager em = getEntityManager();
+        try {
+            return em.find(Product.class, id);
+        } finally {
+            em.close();
+        }
+    }
+
+    public int getProductCount() {
+        EntityManager em = getEntityManager();
+        try {
+            CriteriaQuery cq = em.getCriteriaBuilder().createQuery();