Example usage for org.hibernate.criterion DetachedCriteria forClass

List of usage examples for org.hibernate.criterion DetachedCriteria forClass

Introduction

In this page you can find the example usage for org.hibernate.criterion DetachedCriteria forClass.

Prototype

public static DetachedCriteria forClass(Class clazz) 

Source Link

Document

Static builder to create a DetachedCriteria for the given entity, by its Class.

Usage

From source file:com.perceptive.epm.perkolcentral.dataaccessor.ImageNowLicenseDataAccessor.java

public Imagenowlicenses getAllImageNowLicensesByRequestId(String requestId) throws ExceptionWrapper {

    try {/*from  w  w  w.j av a 2 s  . c  o  m*/
        DetachedCriteria criteria = DetachedCriteria.forClass(Imagenowlicenses.class);
        criteria.createAlias("employeeByRequestedByEmployeeId", "emp");
        criteria.createAlias("groups", "group");
        criteria.add(Restrictions.eq("imageNowLicenseRequestId", requestId.trim()));
        criteria.setFetchMode("emp", FetchMode.JOIN);
        criteria.setFetchMode("group", FetchMode.JOIN);

        return (Imagenowlicenses) hibernateTemplate.findByCriteria(criteria).get(0);

    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    }
}

From source file:com.perceptive.epm.perkolcentral.dataaccessor.ImageNowLicenseDataAccessor.java

public void addImageNowLicense(Imagenowlicenses imagenowlicenses, String groupRequestedFor,
        String employeeUIDWhoRequestedLicense) throws ExceptionWrapper {
    try {/*from   www.j a  va  2  s.  c  o  m*/
        //Get The Group Info
        DetachedCriteria criteria = DetachedCriteria.forClass(Groups.class);
        criteria.add(Restrictions.eq("groupId", Integer.valueOf(groupRequestedFor)));
        imagenowlicenses.setGroups((Groups) hibernateTemplate.findByCriteria(criteria).get(0));
        criteria = DetachedCriteria.forClass(Employee.class);
        criteria.add(Restrictions.eq("employeeUid", employeeUIDWhoRequestedLicense.trim()));
        imagenowlicenses.setEmployeeByRequestedByEmployeeId(
                (Employee) hibernateTemplate.findByCriteria(criteria).get(0));
        hibernateTemplate.save(imagenowlicenses);
    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    }
}

From source file:com.perceptive.epm.perkolcentral.dataaccessor.ImageNowLicenseDataAccessor.java

public void updateImageNowLicense(Imagenowlicenses imagenowlicenses, String providerEmpUID)
        throws ExceptionWrapper {
    try {//from ww w  . ja va2  s. c  o  m
        DetachedCriteria criteria = DetachedCriteria.forClass(Employee.class);
        criteria.add(Restrictions.eq("employeeUid", providerEmpUID.trim()));
        imagenowlicenses.setEmployeeByProvidedByEmployeeId(
                (Employee) hibernateTemplate.findByCriteria(criteria).get(0));
        hibernateTemplate.update(imagenowlicenses);
    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    }
}

From source file:com.perceptive.epm.perkolcentral.dataaccessor.LicenseMasterDataAccessor.java

public HashMap<String, LicenseBO> getAllLicenseType() throws ExceptionWrapper {
    HashMap<String, LicenseBO> licenseBOHashMap = new HashMap<String, LicenseBO>();
    try {/*from   w  w w.  j  a  v a 2  s  .c  om*/
        DetachedCriteria criteria = DetachedCriteria.forClass(Licensemaster.class);
        for (Object obj : hibernateTemplate.findByCriteria(criteria)) {
            LicenseBO licenseBO = new LicenseBO((Licensemaster) obj);
            licenseBOHashMap.put(licenseBO.getLicenseTypeId(), licenseBO);
        }
    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    }
    return licenseBOHashMap;
}

From source file:com.photon.phresco.eshop.service.EShopService.java

License:Apache License

public List<CategoryHBM> getCategories() throws EShopException {
    @SuppressWarnings("unchecked")
    List<CategoryHBM> categoryList = (List<CategoryHBM>) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            DetachedCriteria criteria = DetachedCriteria.forClass(CategoryHBM.class);
            List<CategoryHBM> categoryHBMs = template.findByCriteria(criteria);
            List<CategoryHBM> categoryHBMList = new ArrayList<CategoryHBM>(10);

            for (CategoryHBM categoryHBM : categoryHBMs) {
                List<Integer> count = session.createCriteria(ProductHBM.class)
                        .setProjection(Projections.rowCount())
                        .add(Restrictions.eq("categoryId", categoryHBM.getCategoryId())).list();

                System.out.println("Count = " + count);
                categoryHBM.setTotalProducts((int) count.get(0));
                categoryHBMList.add(categoryHBM);
            }/*  www  .ja  va  2 s  . co  m*/

            return categoryHBMList;
        }
    });

    return categoryList;
}

From source file:com.photon.phresco.eshop.service.EShopService.java

License:Apache License

public List<ProductHBM> getProducts(final int categoryId) throws EShopException {
    @SuppressWarnings("unchecked")
    List<ProductHBM> productList = (List<ProductHBM>) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            DetachedCriteria criteria = DetachedCriteria.forClass(ProductHBM.class)
                    .add(Restrictions.eq("categoryId", categoryId));

            List<ProductHBM> productHBMs = template.findByCriteria(criteria);
            List<ProductHBM> productHBMList = new ArrayList<ProductHBM>(10);

            for (ProductHBM productHBM : productHBMs) {
                Object[] values = { 1, 2, 3, 4, 5 };
                List<ReviewHBM> reviewHBMs = session.createCriteria(ReviewHBM.class)
                        .add(Restrictions.in("ratings", values))
                        .add(Restrictions.eq("productId", productHBM.getProductId())).list();

                int rating = 0;

                // TODO average rating calculation not working
                if (reviewHBMs != null && reviewHBMs.size() > 0) {
                    ReviewHBM reviewHBM = reviewHBMs.get(0);
                    rating = ServiceUtil.getRating(reviewHBM.getRatings());
                }/*from ww  w  .j  a  v  a 2s.  c om*/

                productHBM.setRating(rating);
                productHBMList.add(productHBM);
            }

            return productHBMList;
        }
    });

    return productList;
}

From source file:com.photon.phresco.eshop.service.EShopService.java

License:Apache License

public List<ProductHBM> getProducts() throws EShopException {
    @SuppressWarnings("unchecked")
    List<ProductHBM> productList = (List<ProductHBM>) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            DetachedCriteria criteria = DetachedCriteria.forClass(ProductHBM.class);

            List<ProductHBM> productHBMs = template.findByCriteria(criteria);
            List<ProductHBM> productHBMList = new ArrayList<ProductHBM>(100);

            for (ProductHBM productHBM : productHBMs) {
                Object[] values = { 1, 2, 3, 4, 5 };
                List<ReviewHBM> reviewHBMs = session.createCriteria(ReviewHBM.class)
                        .add(Restrictions.in("ratings", values))
                        .add(Restrictions.eq("productId", productHBM.getProductId())).list();
                int rating = 0;

                // TODO average rating calculation not working
                if (reviewHBMs != null && reviewHBMs.size() > 0) {
                    ReviewHBM reviewHBM = reviewHBMs.get(0);
                    rating = ServiceUtil.getRating(reviewHBM.getRatings());
                }//  w w  w  . ja  v  a 2  s .c om

                productHBM.setRating(rating);
                productHBMList.add(productHBM);
            }

            return productHBMList;
        }
    });

    return productList;
}

From source file:com.photon.phresco.eshop.service.EShopService.java

License:Apache License

public List<ProductHBM> getSpecialProducts() throws EShopException {
    @SuppressWarnings("unchecked")
    List<ProductHBM> productList = (List<ProductHBM>) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            DetachedCriteria criteria = DetachedCriteria.forClass(ProductHBM.class)
                    .add(Restrictions.eq("specialProduct", 1));

            List<ProductHBM> productHBMs = template.findByCriteria(criteria);
            List<ProductHBM> productHBMList = new ArrayList<ProductHBM>(10);

            for (ProductHBM productHBM : productHBMs) {
                Object[] values = { 1, 2, 3, 4, 5 };
                List<ReviewHBM> reviewHBMs = session.createCriteria(ReviewHBM.class)
                        .add(Restrictions.in("ratings", values))
                        .add(Restrictions.eq("productId", productHBM.getProductId())).list();

                int rating = 0;

                // TODO average rating calculation not working
                if (reviewHBMs != null && reviewHBMs.size() > 0) {
                    ReviewHBM reviewHBM = reviewHBMs.get(0);
                    rating = ServiceUtil.getRating(reviewHBM.getRatings());
                }//from w w  w. j  av a  2s.c om

                productHBM.setRating(rating);
                productHBMList.add(productHBM);
            }

            return productHBMList;
        }
    });

    return productList;
}

From source file:com.photon.phresco.eshop.service.EShopService.java

License:Apache License

public List<ProductHBM> getNewProducts() throws EShopException {
    @SuppressWarnings("unchecked")
    List<ProductHBM> productList = (List<ProductHBM>) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            DetachedCriteria criteria = DetachedCriteria.forClass(ProductHBM.class)
                    .add(Restrictions.eq("newProduct", 1));

            List<ProductHBM> productHBMs = template.findByCriteria(criteria);
            List<ProductHBM> productHBMList = new ArrayList<ProductHBM>(10);

            for (ProductHBM productHBM : productHBMs) {
                Object[] values = { 1, 2, 3, 4, 5 };
                List<ReviewHBM> reviewHBMs = session.createCriteria(ReviewHBM.class)
                        .add(Restrictions.in("ratings", values))
                        .add(Restrictions.eq("productId", productHBM.getProductId())).list();

                int rating = 0;

                // TODO average rating calculation not working
                if (reviewHBMs != null && reviewHBMs.size() > 0) {
                    ReviewHBM reviewHBM = reviewHBMs.get(0);
                    rating = ServiceUtil.getRating(reviewHBM.getRatings());
                }//  w  w w.j  a  v  a  2s  .c  om

                productHBM.setRating(rating);
                productHBMList.add(productHBM);
            }

            return productHBMList;
        }
    });

    return productList;
}

From source file:com.photon.phresco.eshop.service.EShopService.java

License:Apache License

public ProductHBM getProduct(final int productId) throws EShopException {
    @SuppressWarnings("unchecked")
    ProductHBM productHBM = (ProductHBM) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            DetachedCriteria criteria = DetachedCriteria.forClass(ProductHBM.class)
                    .add(Restrictions.eq("productId", productId));

            List<ProductHBM> productHBMs = template.findByCriteria(criteria);
            ProductHBM productHBM = null;

            if (productHBMs.size() > 0) {
                productHBM = productHBMs.get(0);
                Object[] values = { 1, 2, 3, 4, 5 };

                List<ReviewHBM> reviewHBMs = session.createCriteria(ReviewHBM.class)
                        .add(Restrictions.in("ratings", values))
                        .add(Restrictions.eq("productId", productHBM.getProductId())).list();

                int rating = 0;

                // TODO average rating calculation not working
                if (reviewHBMs != null && reviewHBMs.size() > 0) {
                    ReviewHBM reviewHBM = reviewHBMs.get(0);
                    rating = ServiceUtil.getRating(reviewHBM.getRatings());
                }//ww w.ja  v  a  2  s . c o m

                productHBM.setRating(rating);
            }

            return productHBM;
        }
    });

    return productHBM;
}