Example usage for org.hibernate.criterion Restrictions in

List of usage examples for org.hibernate.criterion Restrictions in

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions in.

Prototype

public static Criterion in(String propertyName, Collection values) 

Source Link

Document

Apply an "in" constraint to the named property.

Usage

From source file:com.rta.vsd.data.service.impl.ViolationDataServiceImpl.java

/**
 * //from  w  w w  . j  ava2s. co  m
 * Gets all the violations WithoutPlateConsfication for vehicles owned by the owner with the specified trade license number
 * 
 * @author Eldon Barrows
 * @param dsContext
 * @param retrieveArabicData
 * @param param
 * @return List<VsdViolation>
 * @throws VSDDataAccessException
 */
public List<VsdViolation> getViolationsWithoutPlateConsficationByTraficFileNumber(
        final DataServiceContext dsContext, boolean retrieveArabicData, String traficFileNo,
        PaginationParam param) throws VSDDataAccessException {
    logger.info("getViolationsWithoutPlateConsficationByTraficFileNumber -- START");
    List<VsdViolation> violations = null;
    try {
        Session session = (Session) dsContext.getInternalContext();
        ProjectionList projectionList = Projections.projectionList();
        projectionList.add(Projections.property("v.violationId"), "violationId");
        projectionList.add(Projections.property("v.reportedDate"), "reportedDate");
        violations = session.createCriteria(VsdViolation.class, "v")
                .add(Restrictions.eq("v.isDeleted", IDataService.BOOL_FALSE))
                .createCriteria("v.vsdInspections", "i", Criteria.LEFT_JOIN,
                        Restrictions.eq("i.isDeleted", IDataService.BOOL_FALSE))
                .add(Restrictions.eq("i.isPlateConfiscated", Constant.FALSE))
                .createCriteria("i.vsdVehicleInfo", "vi", Criteria.LEFT_JOIN,
                        Restrictions.eq("vi.isDeleted", IDataService.BOOL_FALSE))
                .createCriteria("vi.vsdOwnerInfos", "oi", Criteria.LEFT_JOIN,
                        Restrictions.eq("oi.isDeleted", IDataService.BOOL_FALSE))
                .add(Restrictions.eq("oi.trafficFileNumber", traficFileNo).ignoreCase())
                .createCriteria("v.vsdSeverityLevel", "vsl", Criteria.LEFT_JOIN,
                        Restrictions.eq("vsl.isDeleted", IDataService.BOOL_FALSE))
                .createCriteria("v.vsdViolationStatus", "vs", Criteria.LEFT_JOIN,
                        Restrictions.eq("vs.isDeleted", IDataService.BOOL_FALSE))
                .addOrder(Order.desc("v.reportedDate")).setProjection(Projections.distinct(projectionList))
                .setFirstResult(param.getFirstResult().intValue())
                .setMaxResults(param.getFetchedSize().intValue())
                .setResultTransformer(new AliasToBeanResultTransformer(VsdViolation.class)).list();

        if (violations == null || violations.size() == 0)
            return new ArrayList();
        Iterator iterator = violations.iterator();
        ArrayList innerQueryList = new ArrayList<Long>();
        while (iterator.hasNext()) {
            VsdViolation violation = (VsdViolation) iterator.next();
            innerQueryList.add(violation.getViolationId());
        }
        violations = session.createCriteria(VsdViolation.class, "v")
                .add(Restrictions.eq("v.isDeleted", IDataService.BOOL_FALSE))
                .createCriteria("v.vsdInspections", "i", Criteria.LEFT_JOIN,
                        Restrictions.eq("i.isDeleted", IDataService.BOOL_FALSE))
                .add(Restrictions.eq("i.isPlateConfiscated", Constant.FALSE))
                .createCriteria("i.vsdVehicleInfo", "vi", Criteria.LEFT_JOIN,
                        Restrictions.eq("vi.isDeleted", IDataService.BOOL_FALSE))
                .createCriteria("vi.vsdOwnerInfos", "oi", Criteria.LEFT_JOIN,
                        Restrictions.eq("oi.isDeleted", IDataService.BOOL_FALSE))
                .add(Restrictions.eq("oi.trafficFileNumber", traficFileNo).ignoreCase())
                .createCriteria("v.vsdSeverityLevel", "vsl", Criteria.LEFT_JOIN,
                        Restrictions.eq("vsl.isDeleted", IDataService.BOOL_FALSE))
                .createCriteria("v.vsdViolationStatus", "vs", Criteria.LEFT_JOIN,
                        Restrictions.eq("vs.isDeleted", IDataService.BOOL_FALSE))
                .add(Restrictions.in("v.violationId", innerQueryList)).addOrder(Order.desc("v.reportedDate"))
                .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();
        logger.info("getViolationsWithoutPlateConsficationByTraficFileNumber -- END");
        return violations;
    } catch (Exception ex) {
        logger.error("An error occured in getViolationsWithoutPlateConsficationByTraficFileNumber()");
        logger.error(ex);
        throw new VSDDataAccessException(ex.getMessage(), ex);
    }
}

From source file:com.rta.vsd.data.service.impl.ViolationDataServiceImpl.java

/**
 * /*from  ww  w.  j av  a 2  s.c om*/
 * Get a list of violations by the status id provided and the start and end date provided
 * 
 * @author Eldon Barrows
 * @param dsContext
 * @param retrieveArabicData
 * @param startDate
 * @param endDate
 * @param violationStatusIds
 * @return List<VsdViolation>
 * @throws VSDDataAccessException
 */
public List<VsdViolation> getViolationsByViolationStatusIdAndUpdatedTimestamp(
        final DataServiceContext dsContext, boolean retrieveArabicData, Date startDate, Date endDate,
        List<Long> violationStatusIds) throws VSDDataAccessException {
    logger.info("getViolationsByViolationStatusIdAndUpdatedTimestamp -- START");
    List<VsdViolation> violations = null;
    try {
        //         Calendar sDate = Calendar.getInstance();
        //         sDate.setTime(startDate);
        //         sDate.set(Calendar.HOUR_OF_DAY, 0);
        //         sDate.set(Calendar.MINUTE, 0);
        //         sDate.set(Calendar.SECOND, 0);         
        //         sDate.set(Calendar.MILLISECOND, 0);
        //         
        //         Calendar eDate = Calendar.getInstance();
        //         eDate.setTime(endDate);
        //         eDate.set(Calendar.HOUR_OF_DAY, 23);
        //         eDate.set(Calendar.MINUTE, 59);
        //         eDate.set(Calendar.SECOND, 59);
        //         eDate.set(Calendar.MILLISECOND, 999);

        Session session = (Session) dsContext.getInternalContext();
        violations = session.createCriteria(VsdViolation.class, "v")
                .add(Restrictions.eq("v.isDeleted", IDataService.BOOL_FALSE))
                .add(Restrictions.between("v.upatedTimestamp", startDate, endDate))
                .createCriteria("v.vsdViolationStatus", "vs", Criteria.LEFT_JOIN,
                        Restrictions.eq("vs.isDeleted", IDataService.BOOL_FALSE))
                .add(Restrictions.in("vs.violationStatusId", violationStatusIds))
                .createCriteria("v.vsdInspections", "i", Criteria.LEFT_JOIN,
                        Restrictions.eq("i.isDeleted", IDataService.BOOL_FALSE))
                .createCriteria("i.vsdVehicleInfo", "vi", Criteria.LEFT_JOIN,
                        Restrictions.eq("vi.isDeleted", IDataService.BOOL_FALSE))
                .createCriteria("vi.vsdOwnerInfos", "oi", Criteria.LEFT_JOIN,
                        Restrictions.eq("oi.isDeleted", IDataService.BOOL_FALSE))
                .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();
    } catch (Exception ex) {
        logger.error("An error occured in getViolationsByViolationStatusIdAndUpdatedTimestamp()");
        throw new VSDDataAccessException(ex.getMessage(), ex);
    }
    logger.info("getViolationsByViolationStatusIdAndUpdatedTimestamp -- END");
    return violations;
}

From source file:com.salesmanager.core.service.catalog.impl.db.dao.CategoryDao.java

License:Open Source License

public List<Category> findByMerchantId(int merchantid) {
    try {//from  w w  w.jav  a  2  s  . com
        List values = new ArrayList();
        values.add(Constants.GLOBAL_MERCHANT_ID);
        values.add(merchantid);
        List list = super.getSession().createCriteria(Category.class).add(Restrictions.in("merchantId", values))
                .list();

        return list;
    } catch (RuntimeException re) {
        log.error("get failed", re);
        throw re;
    }
}

From source file:com.salesmanager.core.service.catalog.impl.db.dao.ProductDao.java

License:Open Source License

public SearchProductResponse searchProduct(SearchProductCriteria searchCriteria) {

    try {/*  ww  w .  j ava  2 s  . c  o  m*/

        Criteria criteria = super.getSession()
                .createCriteria(com.salesmanager.core.entity.catalog.Product.class)
                .add(Restrictions.eq("merchantId", searchCriteria.getMerchantId()));
        // .setFetchMode("descriptions", FetchMode.JOIN);

        // select p from Product p left join fetch p.descriptions s left
        // join fetch p.specials y left join fetch p.prices r left join
        // fetch r.priceDescriptions rd left join fetch r.special x where
        // p.merchantId=:mId and p.masterCategoryId in(:cId) and
        // s.id.languageId=:lId order by p.productSortOrder
        StringBuffer q = new StringBuffer();
        q.append(
                "select p from Product p left join fetch p.descriptions s left join fetch p.specials y left join fetch p.prices r left join fetch r.priceDescriptions rd left join fetch r.special x where p.merchantId=:mId and s.id.languageId=:lId");

        List inlist = null;
        if (searchCriteria.getCategoryid() != -1) {

            // only products in categories
            CatalogService cservice = (CatalogService) ServiceFactory.getService(ServiceFactory.CatalogService);
            Map categories = cservice.getCategoriesByLang(searchCriteria.getMerchantId(),
                    LanguageUtil.getLanguageStringCode(searchCriteria.getLanguageId()));
            Category c = (Category) categories.get(searchCriteria.getCategoryid());
            // StringBuffer inlist = null;
            // if(c.getParentId()==0) {
            // List subcategs =
            // cservice.getCategoriesIdPerSubCategories(LanguageUtil.getLanguageStringCode(searchCriteria.getLanguageId()),c);
            List subcategs = cservice.findSubCategories(c.getCategoryId());
            if (subcategs != null && subcategs.size() > 0) {
                inlist = new ArrayList();
                inlist.add(searchCriteria.getCategoryid());
                Iterator it = subcategs.iterator();
                while (it.hasNext()) {
                    Category category = (Category) it.next();
                    long cid = category.getCategoryId();
                    inlist.add(cid);
                }
            }
            // }
        }

        if (searchCriteria != null) {

            if (inlist != null) {
                q.append(" and p.masterCategoryId in(:mcIds)");
            } else if (searchCriteria.getCategoryid() != -1 && inlist == null) {
                q.append(" and p.masterCategoryId = :mcId");
            }

            if (searchCriteria.getVisible() != SearchProductCriteria.VISIBLEALL) {// visibility

                if (searchCriteria.getVisible() == SearchProductCriteria.VISIBLETRUE) {

                    q.append(" and p.productDateAvailable <= :dt");

                } else {

                    q.append(" and p.productDateAvailable > :dt");

                }
            }
            if (searchCriteria.getStatus() != SearchProductCriteria.STATUSALL) {// availability

                q.append(" and p.productStatus = :st");
            }
            if (!StringUtils.isBlank(searchCriteria.getDescription())) {

                q.append(" and s.productName like :pName");
                // q.append(" and s.productName like '%lounge%'");

            }

        }

        /*
         * Criteria query = super.getSession()
         * .createCriteria(com.salesmanager
         * .core.entity.catalog.Product.class)
         * .add(Restrictions.eq("merchantId",
         * searchCriteria.getMerchantId())) //.setFetchMode("descriptions",
         * FetchMode.JOIN)
         * .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
         */

        Query c = super.getSession().createQuery(q.toString());
        c.setInteger("mId", searchCriteria.getMerchantId());
        c.setInteger("lId", searchCriteria.getLanguageId());

        /*
         * Criteria descCriteria = criteria.createCriteria("descriptions")
         * .add(Restrictions.eq("id.languageId",
         * searchCriteria.getLanguageId()));
         * 
         * Criteria descCriteriaQ = query.createCriteria("descriptions")
         * .add(Restrictions.eq("id.languageId",
         * searchCriteria.getLanguageId()));
         */

        if (searchCriteria != null) {

            if (inlist != null) {

                criteria.add(Restrictions.in("masterCategoryId", inlist));
                // query.add(Restrictions.in("masterCategoryId", inlist));
                c.setParameterList("mcIds", inlist);

            } else if (searchCriteria.getCategoryid() != -1 && inlist == null) {

                criteria.add(Restrictions.eq("masterCategoryId", searchCriteria.getCategoryid()));
                // query.add(Restrictions.eq("masterCategoryId",
                // searchCriteria.getCategoryid()));
                c.setLong("mcId", searchCriteria.getCategoryid());

                // wherecategory =
                // " and products_view.master_categories_id IN " +
                // inlist.toString();
            }

        }

        if (searchCriteria.getVisible() != SearchProductCriteria.VISIBLEALL) {// visibility

            if (searchCriteria.getVisible() == SearchProductCriteria.VISIBLETRUE) {
                // wherevisible =
                // " and products_view.products_date_available IS NOT NULL and products_view.products_date_available < now()";

                criteria.add(Expression.isNotNull("productDateAvailable"));
                criteria.add(Expression.lt("productDateAvailable",
                        new java.util.Date(new java.util.Date().getTime())));
                // query.add(Expression.isNotNull("productDateAvailable"));
                // query.add(Expression.lt("productDateAvailable",new
                // java.util.Date(new java.util.Date().getTime())));

                c.setParameter("dt", new Date());

            } else {
                // wherevisible =
                // " and (products_view.products_date_available IS NULL or products_view.products_date_available > now())";
                criteria.add(Restrictions.or(Expression.isNull("productDateAvailable"), Expression
                        .gt("productDateAvailable", new java.util.Date(new java.util.Date().getTime()))));
                // query.add(Restrictions.or(Expression.isNull("productDateAvailable"),Expression.gt("productDateAvailable",new
                // java.util.Date(new java.util.Date().getTime()))));

                c.setParameter("dt", new Date());

            }
        }
        if (searchCriteria.getStatus() != SearchProductCriteria.STATUSALL) {// availability
            criteria.add(Restrictions.eq("productStatus",
                    searchCriteria.getStatus() == SearchProductCriteria.STATUSINSTOCK ? new Boolean("true")
                            : new Boolean("false")));
            // query.add(Restrictions.eq("productStatus",
            // searchCriteria.getStatus()==SearchProductCriteria.STATUSINSTOCK?new
            // Boolean("true"):new Boolean("false")));
            // wherestatus = " and products_view.products_status=" +
            // criteria.getStatus();
            c.setBoolean("st",
                    searchCriteria.getStatus() == SearchProductCriteria.STATUSINSTOCK ? new Boolean("true")
                            : new Boolean("false"));
        }
        if (!StringUtils.isBlank(searchCriteria.getDescription())) {
            criteria.createAlias("descriptions", "description")
                    .add(Restrictions.eq("description.id.languageId", searchCriteria.getLanguageId()))
                    .add(Restrictions.like("description.productName",
                            "%" + searchCriteria.getDescription() + "%"));
            // query.createAlias("descriptions",
            // "description").add(Restrictions.eq("description.id.languageId",
            // searchCriteria.getLanguageId())).add(Restrictions.like("description.productName",
            // "%"+searchCriteria.getDescription()+"%"));
            // descCriteria.add((Restrictions.like("productName",
            // "%"+searchCriteria.getDescription()+"%")));
            // descCriteriaQ.add((Restrictions.like("productName",
            // "%"+searchCriteria.getDescription()+"%")));
            // wherename = " and products_description.products_name LIKE '%"
            // + criteria.getName() + "%'";
            c.setString("pName", "%" + searchCriteria.getDescription() + "%");

        }

        criteria.setProjection(Projections.rowCount());
        Integer count = (Integer) criteria.uniqueResult();

        criteria.setProjection(null);

        int max = searchCriteria.getQuantity();

        /*
         * List list = query
         * .setMaxResults(searchCriteria.getUpperLimit(count))
         * .setFirstResult(searchCriteria.getLowerLimit()).list();
         */

        List list = null;
        // .setMaxResults(searchCriteria.getUpperLimit(count))
        // .setFirstResult(searchCriteria.getLowerLimit()).list();

        if (max != -1 && count > 0) {
            c.setMaxResults(searchCriteria.getUpperLimit(count));
            c.setFirstResult(searchCriteria.getLowerLimit());
            list = c.list();
        } else {
            list = c.list();
        }

        /*
         * //set short name if(list != null) { Iterator i = list.iterator();
         * while(i.hasNext()) { com.salesmanager.core.entity.catalog.Product
         * v = (com.salesmanager.core.entity.catalog.Product)i.next();
         * v.setName(v.getDescription()); Set descs = v.getDescriptions();
         * String shortName = ""; if(descs!=null) { Iterator di =
         * descs.iterator(); while(di.hasNext()) { ProductDescription pd =
         * (ProductDescription)di.next(); ProductDescriptionId id =
         * pd.getId();
         * if(id.getLanguageId()==searchCriteria.getLanguageId()) {
         * shortName = pd.getProductName(); break; } } }
         * v.setName(shortName); } }
         */

        SearchProductResponse response = new SearchProductResponse();
        response.setCount(count);

        response.setProducts(list);

        return response;

    } catch (Exception e) {
        throw new RuntimeException(e);
    }

}

From source file:com.salesmanager.core.service.catalog.impl.db.dao.ProductDescriptionDao.java

License:Open Source License

public Collection<ProductDescription> findByProductsId(Collection<Long> ids, int languageId) {
    try {// w w  w  .j  a va  2  s . com
        return super.getSession().createCriteria(ProductDescription.class)
                .add(Restrictions.in("id.productId", ids)).add(Restrictions.eq("id.languageId", languageId))
                .list();

    } catch (RuntimeException re) {
        log.error("get failed", re);
        throw re;
    }
}

From source file:com.salesmanager.core.service.catalog.impl.db.dao.ProductOptionDao.java

License:Open Source License

public Collection<ProductOption> findByMerchantId(int merchantId) {

    try {// www . j  a  v  a2  s. c om

        List values = new ArrayList();
        values.add(0);
        values.add(merchantId);
        List list = super.getSession().createCriteria(ProductOption.class)
                .add(Restrictions.in("merchantId", values)).addOrder(Order.asc("productOptionSortOrder"))
                .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
                // .setFetchMode("descriptions",FetchMode.JOIN)
                .list();

        return list;
    } catch (RuntimeException re) {
        log.error("get failed", re);
        throw re;
    }
}

From source file:com.salesmanager.core.service.catalog.impl.db.dao.ProductOptionValueDao.java

License:Open Source License

public Collection<ProductOptionValue> findByMerchantId(int merchantId) {

    try {//  w ww.j a  va2  s  .c o  m

        List values = new ArrayList();
        values.add(0);
        values.add(merchantId);
        List list = super.getSession().createCriteria(ProductOptionValue.class)
                .add(Restrictions.in("merchantId", values)).addOrder(Order.asc("productOptionValueSortOrder"))
                // .setProjection(Projections.groupProperty(""))
                .list();

        return list;
    } catch (RuntimeException re) {
        log.error("get failed", re);
        throw re;
    }

}

From source file:com.salesmanager.core.service.order.impl.dao.OrderProductPriceSpecialDao.java

License:Open Source License

public void deleteByOrderProductPriceIds(List ids) {

    try {/*from  w w  w .  j a va 2 s.co  m*/

        List list = super.getSession().createCriteria(OrderProductPriceSpecial.class)
                .add(Restrictions.in("orderProductPrice", ids)).list();

        this.deleteAll(list);
    } catch (RuntimeException re) {
        log.error("get failed", re);
        throw re;
    }

}

From source file:com.salesmanager.core.service.tax.impl.dao.TaxClassDao.java

License:Open Source License

public List<TaxClass> findByMerchantId(int merchantid) {

    try {//w  ww. jav a  2  s .com

        List values = new ArrayList();
        values.add(0);
        values.add(merchantid);
        List tx = super.getSession().createCriteria(TaxClass.class).add(Restrictions.in("merchantId", values))
                .list();

        return tx;
    } catch (RuntimeException re) {
        log.error("get failed", re);
        throw re;
    }
}