Example usage for com.liferay.portal.kernel.dao.orm QueryUtil randomList

List of usage examples for com.liferay.portal.kernel.dao.orm QueryUtil randomList

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.dao.orm QueryUtil randomList.

Prototype

public static List<?> randomList(Query query, Dialect dialect, int total, int num) 

Source Link

Usage

From source file:com.liferay.portlet.shopping.service.persistence.ShoppingItemFinderImpl.java

License:Open Source License

public List<ShoppingItem> findByFeatured(long groupId, long[] categoryIds, int numOfItems)
        throws SystemException {

    int countByFeatured = countByFeatured(groupId, categoryIds);

    Session session = null;//from ww w. j  a  v  a2  s.co  m

    try {
        session = openSession();

        StringBundler query = new StringBundler();

        query.append("SELECT {ShoppingItem.*} FROM ShoppingItem ");
        query.append("WHERE ");
        query.append("ShoppingItem.groupId = ? AND (");

        if ((categoryIds != null) && (categoryIds.length > 0)) {
            query.append("(");

            for (int i = 0; i < categoryIds.length; i++) {
                query.append("ShoppingItem.categoryId = ? ");

                if (i + 1 < categoryIds.length) {
                    query.append("OR ");
                }
            }

            query.append(") AND ");
        }

        query.append("ShoppingItem.featured = ? AND ");
        query.append("ShoppingItem.smallImage = ?");

        SQLQuery q = session.createSQLQuery(query.toString());

        q.addEntity("ShoppingItem", ShoppingItemImpl.class);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        for (long categoryId : categoryIds) {
            qPos.add(categoryId);
        }

        qPos.add(true);
        qPos.add(true);

        return (List<ShoppingItem>) QueryUtil.randomList(q, getDialect(), countByFeatured, numOfItems);
    } catch (Exception e) {
        throw new SystemException(e);
    } finally {
        closeSession(session);
    }
}

From source file:com.liferay.portlet.shopping.service.persistence.ShoppingItemFinderImpl.java

License:Open Source License

public List<ShoppingItem> findBySale(long groupId, long[] categoryIds, int numOfItems) throws SystemException {

    int countBySale = countBySale(groupId, categoryIds);

    Session session = null;/*from   w w w.  ja  va  2s  .  c  o m*/

    try {
        session = openSession();

        StringBundler query = new StringBundler();

        query.append("SELECT {ShoppingItem.*} FROM ShoppingItem ");
        query.append("WHERE ");
        query.append("ShoppingItem.groupId = ? AND (");

        if ((categoryIds != null) && (categoryIds.length > 0)) {
            query.append("(");

            for (int i = 0; i < categoryIds.length; i++) {
                query.append("ShoppingItem.categoryId = ? ");

                if (i + 1 < categoryIds.length) {
                    query.append("OR ");
                }
            }

            query.append(") AND ");
        }

        query.append("ShoppingItem.sale = ? AND ");
        query.append("ShoppingItem.smallImage = ?");

        SQLQuery q = session.createSQLQuery(query.toString());

        q.addEntity("ShoppingItem", ShoppingItemImpl.class);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        for (long categoryId : categoryIds) {
            qPos.add(categoryId);
        }

        qPos.add(true);
        qPos.add(true);

        return (List<ShoppingItem>) QueryUtil.randomList(q, getDialect(), countBySale, numOfItems);
    } catch (Exception e) {
        throw new SystemException(e);
    } finally {
        closeSession(session);
    }
}

From source file:com.liferay.shopping.service.persistence.ShoppingItemFinderImpl.java

License:Open Source License

public List<ShoppingItem> findByFeatured(long groupId, long[] categoryIds, int numOfItems)
        throws SystemException {

    int countByFeatured = countByFeatured(groupId, categoryIds);

    Session session = null;//from w w w.j a  v  a 2 s .c  om

    try {
        session = openSession();

        StringBundler query = new StringBundler();

        query.append("SELECT {Shopping_ShoppingItem.*} FROM Shopping_ShoppingItem ");
        query.append("WHERE ");
        query.append("Shopping_ShoppingItem.groupId = ? AND (");

        if ((categoryIds != null) && (categoryIds.length > 0)) {
            query.append("(");

            for (int i = 0; i < categoryIds.length; i++) {
                query.append("Shopping_ShoppingItem.categoryId = ? ");

                if (i + 1 < categoryIds.length) {
                    query.append("OR ");
                }
            }

            query.append(") AND ");
        }

        query.append("Shopping_ShoppingItem.featured = ? AND ");
        query.append("Shopping_ShoppingItem.smallImage = ?");

        SQLQuery q = session.createSQLQuery(query.toString());

        q.addEntity("Shopping_ShoppingItem", ShoppingItemImpl.class);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        for (long categoryId : categoryIds) {
            qPos.add(categoryId);
        }

        qPos.add(true);
        qPos.add(true);

        return (List<ShoppingItem>) QueryUtil.randomList(q, getDialect(), countByFeatured, numOfItems);
    } catch (Exception e) {
        throw new SystemException(e);
    } finally {
        closeSession(session);
    }
}

From source file:com.liferay.shopping.service.persistence.ShoppingItemFinderImpl.java

License:Open Source License

public List<ShoppingItem> findBySale(long groupId, long[] categoryIds, int numOfItems) throws SystemException {

    int countBySale = countBySale(groupId, categoryIds);

    Session session = null;//from  www  .ja  va  2  s.c  o  m

    try {
        session = openSession();

        StringBundler query = new StringBundler();

        query.append("SELECT {Shopping_ShoppingItem.*} FROM Shopping_ShoppingItem ");
        query.append("WHERE ");
        query.append("Shopping_ShoppingItem.groupId = ? AND (");

        if ((categoryIds != null) && (categoryIds.length > 0)) {
            query.append("(");

            for (int i = 0; i < categoryIds.length; i++) {
                query.append("Shopping_ShoppingItem.categoryId = ? ");

                if (i + 1 < categoryIds.length) {
                    query.append("OR ");
                }
            }

            query.append(") AND ");
        }

        query.append("Shopping_ShoppingItem.sale = ? AND ");
        query.append("Shopping_ShoppingItem.smallImage = ?");

        SQLQuery q = session.createSQLQuery(query.toString());

        q.addEntity("Shopping_ShoppingItem", ShoppingItemImpl.class);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        for (long categoryId : categoryIds) {
            qPos.add(categoryId);
        }

        qPos.add(true);
        qPos.add(true);

        return (List<ShoppingItem>) QueryUtil.randomList(q, getDialect(), countBySale, numOfItems);
    } catch (Exception e) {
        throw new SystemException(e);
    } finally {
        closeSession(session);
    }
}