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

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

Introduction

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

Prototype

public static List<?> list(Query query, Dialect dialect, int start, int end, boolean unmodifiable) 

Source Link

Usage

From source file:com.bemis.portal.order.service.persistence.impl.OrderPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the orders where bemisCustId = &#63;.
 *
 * <p>//  w  w w  .  j a  v  a 2  s  . com
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link OrderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param bemisCustId the bemis cust ID
 * @param start the lower bound of the range of orders
 * @param end the upper bound of the range of orders (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @param retrieveFromCache whether to retrieve from the finder cache
 * @return the ordered range of matching orders
 */
@Override
public List<Order> findByBemisCustId(String bemisCustId, int start, int end,
        OrderByComparator<Order> orderByComparator, boolean retrieveFromCache) {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BEMISCUSTID;
        finderArgs = new Object[] { bemisCustId };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_BEMISCUSTID;
        finderArgs = new Object[] { bemisCustId, start, end, orderByComparator };
    }

    List<Order> list = null;

    if (retrieveFromCache) {
        list = (List<Order>) finderCache.getResult(finderPath, finderArgs, this);

        if ((list != null) && !list.isEmpty()) {
            for (Order order : list) {
                if (!Objects.equals(bemisCustId, order.getBemisCustId())) {
                    list = null;

                    break;
                }
            }
        }
    }

    if (list == null) {
        StringBundler query = null;

        if (orderByComparator != null) {
            query = new StringBundler(3 + (orderByComparator.getOrderByFields().length * 2));
        } else {
            query = new StringBundler(3);
        }

        query.append(_SQL_SELECT_ORDER__WHERE);

        boolean bindBemisCustId = false;

        if (bemisCustId == null) {
            query.append(_FINDER_COLUMN_BEMISCUSTID_BEMISCUSTID_1);
        } else if (bemisCustId.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_BEMISCUSTID_BEMISCUSTID_3);
        } else {
            bindBemisCustId = true;

            query.append(_FINDER_COLUMN_BEMISCUSTID_BEMISCUSTID_2);
        }

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(OrderModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindBemisCustId) {
                qPos.add(bemisCustId);
            }

            if (!pagination) {
                list = (List<Order>) QueryUtil.list(q, getDialect(), start, end, false);

                Collections.sort(list);

                list = Collections.unmodifiableList(list);
            } else {
                list = (List<Order>) QueryUtil.list(q, getDialect(), start, end);
            }

            cacheResult(list);

            finderCache.putResult(finderPath, finderArgs, list);
        } catch (Exception e) {
            finderCache.removeResult(finderPath, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return list;
}

From source file:com.bemis.portal.order.service.persistence.impl.OrderPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the orders where itemNo = &#63;.
 *
 * <p>//from w ww  . j a  va  2  s  . c  o  m
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link OrderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param itemNo the item no
 * @param start the lower bound of the range of orders
 * @param end the upper bound of the range of orders (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @param retrieveFromCache whether to retrieve from the finder cache
 * @return the ordered range of matching orders
 */
@Override
public List<Order> findByItemNo(String itemNo, int start, int end, OrderByComparator<Order> orderByComparator,
        boolean retrieveFromCache) {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMNO;
        finderArgs = new Object[] { itemNo };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ITEMNO;
        finderArgs = new Object[] { itemNo, start, end, orderByComparator };
    }

    List<Order> list = null;

    if (retrieveFromCache) {
        list = (List<Order>) finderCache.getResult(finderPath, finderArgs, this);

        if ((list != null) && !list.isEmpty()) {
            for (Order order : list) {
                if (!Objects.equals(itemNo, order.getItemNo())) {
                    list = null;

                    break;
                }
            }
        }
    }

    if (list == null) {
        StringBundler query = null;

        if (orderByComparator != null) {
            query = new StringBundler(3 + (orderByComparator.getOrderByFields().length * 2));
        } else {
            query = new StringBundler(3);
        }

        query.append(_SQL_SELECT_ORDER__WHERE);

        boolean bindItemNo = false;

        if (itemNo == null) {
            query.append(_FINDER_COLUMN_ITEMNO_ITEMNO_1);
        } else if (itemNo.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_ITEMNO_ITEMNO_3);
        } else {
            bindItemNo = true;

            query.append(_FINDER_COLUMN_ITEMNO_ITEMNO_2);
        }

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(OrderModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindItemNo) {
                qPos.add(itemNo);
            }

            if (!pagination) {
                list = (List<Order>) QueryUtil.list(q, getDialect(), start, end, false);

                Collections.sort(list);

                list = Collections.unmodifiableList(list);
            } else {
                list = (List<Order>) QueryUtil.list(q, getDialect(), start, end);
            }

            cacheResult(list);

            finderCache.putResult(finderPath, finderArgs, list);
        } catch (Exception e) {
            finderCache.removeResult(finderPath, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return list;
}

From source file:com.bemis.portal.order.service.persistence.impl.OrderPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the orders where bemisProductId = &#63;.
 *
 * <p>/*  w w  w .  ja v  a2  s. c o m*/
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link OrderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param bemisProductId the bemis product ID
 * @param start the lower bound of the range of orders
 * @param end the upper bound of the range of orders (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @param retrieveFromCache whether to retrieve from the finder cache
 * @return the ordered range of matching orders
 */
@Override
public List<Order> findByProductId(String bemisProductId, int start, int end,
        OrderByComparator<Order> orderByComparator, boolean retrieveFromCache) {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PRODUCTID;
        finderArgs = new Object[] { bemisProductId };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_PRODUCTID;
        finderArgs = new Object[] { bemisProductId,

                start, end, orderByComparator };
    }

    List<Order> list = null;

    if (retrieveFromCache) {
        list = (List<Order>) finderCache.getResult(finderPath, finderArgs, this);

        if ((list != null) && !list.isEmpty()) {
            for (Order order : list) {
                if (!Objects.equals(bemisProductId, order.getBemisProductId())) {
                    list = null;

                    break;
                }
            }
        }
    }

    if (list == null) {
        StringBundler query = null;

        if (orderByComparator != null) {
            query = new StringBundler(3 + (orderByComparator.getOrderByFields().length * 2));
        } else {
            query = new StringBundler(3);
        }

        query.append(_SQL_SELECT_ORDER__WHERE);

        boolean bindBemisProductId = false;

        if (bemisProductId == null) {
            query.append(_FINDER_COLUMN_PRODUCTID_BEMISPRODUCTID_1);
        } else if (bemisProductId.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_PRODUCTID_BEMISPRODUCTID_3);
        } else {
            bindBemisProductId = true;

            query.append(_FINDER_COLUMN_PRODUCTID_BEMISPRODUCTID_2);
        }

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(OrderModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindBemisProductId) {
                qPos.add(bemisProductId);
            }

            if (!pagination) {
                list = (List<Order>) QueryUtil.list(q, getDialect(), start, end, false);

                Collections.sort(list);

                list = Collections.unmodifiableList(list);
            } else {
                list = (List<Order>) QueryUtil.list(q, getDialect(), start, end);
            }

            cacheResult(list);

            finderCache.putResult(finderPath, finderArgs, list);
        } catch (Exception e) {
            finderCache.removeResult(finderPath, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return list;
}

From source file:com.bemis.portal.order.service.persistence.impl.OrderPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the orders where purchaseOrderNo = &#63;.
 *
 * <p>/*from   w  ww.  j  av  a2s .  co m*/
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link OrderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param purchaseOrderNo the purchase order no
 * @param start the lower bound of the range of orders
 * @param end the upper bound of the range of orders (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @param retrieveFromCache whether to retrieve from the finder cache
 * @return the ordered range of matching orders
 */
@Override
public List<Order> findByPurchaseOrderNo(String purchaseOrderNo, int start, int end,
        OrderByComparator<Order> orderByComparator, boolean retrieveFromCache) {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PURCHASEORDERNO;
        finderArgs = new Object[] { purchaseOrderNo };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_PURCHASEORDERNO;
        finderArgs = new Object[] { purchaseOrderNo,

                start, end, orderByComparator };
    }

    List<Order> list = null;

    if (retrieveFromCache) {
        list = (List<Order>) finderCache.getResult(finderPath, finderArgs, this);

        if ((list != null) && !list.isEmpty()) {
            for (Order order : list) {
                if (!Objects.equals(purchaseOrderNo, order.getPurchaseOrderNo())) {
                    list = null;

                    break;
                }
            }
        }
    }

    if (list == null) {
        StringBundler query = null;

        if (orderByComparator != null) {
            query = new StringBundler(3 + (orderByComparator.getOrderByFields().length * 2));
        } else {
            query = new StringBundler(3);
        }

        query.append(_SQL_SELECT_ORDER__WHERE);

        boolean bindPurchaseOrderNo = false;

        if (purchaseOrderNo == null) {
            query.append(_FINDER_COLUMN_PURCHASEORDERNO_PURCHASEORDERNO_1);
        } else if (purchaseOrderNo.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_PURCHASEORDERNO_PURCHASEORDERNO_3);
        } else {
            bindPurchaseOrderNo = true;

            query.append(_FINDER_COLUMN_PURCHASEORDERNO_PURCHASEORDERNO_2);
        }

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(OrderModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindPurchaseOrderNo) {
                qPos.add(purchaseOrderNo);
            }

            if (!pagination) {
                list = (List<Order>) QueryUtil.list(q, getDialect(), start, end, false);

                Collections.sort(list);

                list = Collections.unmodifiableList(list);
            } else {
                list = (List<Order>) QueryUtil.list(q, getDialect(), start, end);
            }

            cacheResult(list);

            finderCache.putResult(finderPath, finderArgs, list);
        } catch (Exception e) {
            finderCache.removeResult(finderPath, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return list;
}

From source file:com.bemis.portal.order.service.persistence.impl.OrderPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the orders where shipToId = &#63;.
 *
 * <p>/*from  ww  w .  jav a2 s.c  o m*/
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link OrderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param shipToId the ship to ID
 * @param start the lower bound of the range of orders
 * @param end the upper bound of the range of orders (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @param retrieveFromCache whether to retrieve from the finder cache
 * @return the ordered range of matching orders
 */
@Override
public List<Order> findByShipToId(String shipToId, int start, int end,
        OrderByComparator<Order> orderByComparator, boolean retrieveFromCache) {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SHIPTOID;
        finderArgs = new Object[] { shipToId };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SHIPTOID;
        finderArgs = new Object[] { shipToId, start, end, orderByComparator };
    }

    List<Order> list = null;

    if (retrieveFromCache) {
        list = (List<Order>) finderCache.getResult(finderPath, finderArgs, this);

        if ((list != null) && !list.isEmpty()) {
            for (Order order : list) {
                if (!Objects.equals(shipToId, order.getShipToId())) {
                    list = null;

                    break;
                }
            }
        }
    }

    if (list == null) {
        StringBundler query = null;

        if (orderByComparator != null) {
            query = new StringBundler(3 + (orderByComparator.getOrderByFields().length * 2));
        } else {
            query = new StringBundler(3);
        }

        query.append(_SQL_SELECT_ORDER__WHERE);

        boolean bindShipToId = false;

        if (shipToId == null) {
            query.append(_FINDER_COLUMN_SHIPTOID_SHIPTOID_1);
        } else if (shipToId.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_SHIPTOID_SHIPTOID_3);
        } else {
            bindShipToId = true;

            query.append(_FINDER_COLUMN_SHIPTOID_SHIPTOID_2);
        }

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(OrderModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindShipToId) {
                qPos.add(shipToId);
            }

            if (!pagination) {
                list = (List<Order>) QueryUtil.list(q, getDialect(), start, end, false);

                Collections.sort(list);

                list = Collections.unmodifiableList(list);
            } else {
                list = (List<Order>) QueryUtil.list(q, getDialect(), start, end);
            }

            cacheResult(list);

            finderCache.putResult(finderPath, finderArgs, list);
        } catch (Exception e) {
            finderCache.removeResult(finderPath, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return list;
}

From source file:com.bemis.portal.order.service.persistence.impl.OrderPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the orders where bemisProductId = &#63; and itemNo = &#63;.
 *
 * <p>// ww w  .  j a v a 2 s.  c om
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link OrderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param bemisProductId the bemis product ID
 * @param itemNo the item no
 * @param start the lower bound of the range of orders
 * @param end the upper bound of the range of orders (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @param retrieveFromCache whether to retrieve from the finder cache
 * @return the ordered range of matching orders
 */
@Override
public List<Order> findByItemNo_ProductId(String bemisProductId, String itemNo, int start, int end,
        OrderByComparator<Order> orderByComparator, boolean retrieveFromCache) {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMNO_PRODUCTID;
        finderArgs = new Object[] { bemisProductId, itemNo };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ITEMNO_PRODUCTID;
        finderArgs = new Object[] { bemisProductId, itemNo,

                start, end, orderByComparator };
    }

    List<Order> list = null;

    if (retrieveFromCache) {
        list = (List<Order>) finderCache.getResult(finderPath, finderArgs, this);

        if ((list != null) && !list.isEmpty()) {
            for (Order order : list) {
                if (!Objects.equals(bemisProductId, order.getBemisProductId())
                        || !Objects.equals(itemNo, order.getItemNo())) {
                    list = null;

                    break;
                }
            }
        }
    }

    if (list == null) {
        StringBundler query = null;

        if (orderByComparator != null) {
            query = new StringBundler(4 + (orderByComparator.getOrderByFields().length * 2));
        } else {
            query = new StringBundler(4);
        }

        query.append(_SQL_SELECT_ORDER__WHERE);

        boolean bindBemisProductId = false;

        if (bemisProductId == null) {
            query.append(_FINDER_COLUMN_ITEMNO_PRODUCTID_BEMISPRODUCTID_1);
        } else if (bemisProductId.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_ITEMNO_PRODUCTID_BEMISPRODUCTID_3);
        } else {
            bindBemisProductId = true;

            query.append(_FINDER_COLUMN_ITEMNO_PRODUCTID_BEMISPRODUCTID_2);
        }

        boolean bindItemNo = false;

        if (itemNo == null) {
            query.append(_FINDER_COLUMN_ITEMNO_PRODUCTID_ITEMNO_1);
        } else if (itemNo.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_ITEMNO_PRODUCTID_ITEMNO_3);
        } else {
            bindItemNo = true;

            query.append(_FINDER_COLUMN_ITEMNO_PRODUCTID_ITEMNO_2);
        }

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(OrderModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindBemisProductId) {
                qPos.add(bemisProductId);
            }

            if (bindItemNo) {
                qPos.add(itemNo);
            }

            if (!pagination) {
                list = (List<Order>) QueryUtil.list(q, getDialect(), start, end, false);

                Collections.sort(list);

                list = Collections.unmodifiableList(list);
            } else {
                list = (List<Order>) QueryUtil.list(q, getDialect(), start, end);
            }

            cacheResult(list);

            finderCache.putResult(finderPath, finderArgs, list);
        } catch (Exception e) {
            finderCache.removeResult(finderPath, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return list;
}

From source file:com.bemis.portal.order.service.persistence.impl.OrderPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the orders where itemNo = &#63; and purchaseOrderNo = &#63;.
 *
 * <p>//  w ww.j  ava 2  s. c  o m
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link OrderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param itemNo the item no
 * @param purchaseOrderNo the purchase order no
 * @param start the lower bound of the range of orders
 * @param end the upper bound of the range of orders (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @param retrieveFromCache whether to retrieve from the finder cache
 * @return the ordered range of matching orders
 */
@Override
public List<Order> findByPOrderNo_ItemNo(String itemNo, String purchaseOrderNo, int start, int end,
        OrderByComparator<Order> orderByComparator, boolean retrieveFromCache) {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PORDERNO_ITEMNO;
        finderArgs = new Object[] { itemNo, purchaseOrderNo };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_PORDERNO_ITEMNO;
        finderArgs = new Object[] { itemNo, purchaseOrderNo,

                start, end, orderByComparator };
    }

    List<Order> list = null;

    if (retrieveFromCache) {
        list = (List<Order>) finderCache.getResult(finderPath, finderArgs, this);

        if ((list != null) && !list.isEmpty()) {
            for (Order order : list) {
                if (!Objects.equals(itemNo, order.getItemNo())
                        || !Objects.equals(purchaseOrderNo, order.getPurchaseOrderNo())) {
                    list = null;

                    break;
                }
            }
        }
    }

    if (list == null) {
        StringBundler query = null;

        if (orderByComparator != null) {
            query = new StringBundler(4 + (orderByComparator.getOrderByFields().length * 2));
        } else {
            query = new StringBundler(4);
        }

        query.append(_SQL_SELECT_ORDER__WHERE);

        boolean bindItemNo = false;

        if (itemNo == null) {
            query.append(_FINDER_COLUMN_PORDERNO_ITEMNO_ITEMNO_1);
        } else if (itemNo.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_PORDERNO_ITEMNO_ITEMNO_3);
        } else {
            bindItemNo = true;

            query.append(_FINDER_COLUMN_PORDERNO_ITEMNO_ITEMNO_2);
        }

        boolean bindPurchaseOrderNo = false;

        if (purchaseOrderNo == null) {
            query.append(_FINDER_COLUMN_PORDERNO_ITEMNO_PURCHASEORDERNO_1);
        } else if (purchaseOrderNo.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_PORDERNO_ITEMNO_PURCHASEORDERNO_3);
        } else {
            bindPurchaseOrderNo = true;

            query.append(_FINDER_COLUMN_PORDERNO_ITEMNO_PURCHASEORDERNO_2);
        }

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(OrderModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindItemNo) {
                qPos.add(itemNo);
            }

            if (bindPurchaseOrderNo) {
                qPos.add(purchaseOrderNo);
            }

            if (!pagination) {
                list = (List<Order>) QueryUtil.list(q, getDialect(), start, end, false);

                Collections.sort(list);

                list = Collections.unmodifiableList(list);
            } else {
                list = (List<Order>) QueryUtil.list(q, getDialect(), start, end);
            }

            cacheResult(list);

            finderCache.putResult(finderPath, finderArgs, list);
        } catch (Exception e) {
            finderCache.removeResult(finderPath, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return list;
}

From source file:com.bemis.portal.order.service.persistence.impl.OrderPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the orders where bemisCustId = &#63; and purchaseOrderNo = &#63;.
 *
 * <p>//from w ww .  ja v  a 2  s.  c o m
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link OrderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param bemisCustId the bemis cust ID
 * @param purchaseOrderNo the purchase order no
 * @param start the lower bound of the range of orders
 * @param end the upper bound of the range of orders (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @param retrieveFromCache whether to retrieve from the finder cache
 * @return the ordered range of matching orders
 */
@Override
public List<Order> findByPurchaseOrderNo_BemisCustId(String bemisCustId, String purchaseOrderNo, int start,
        int end, OrderByComparator<Order> orderByComparator, boolean retrieveFromCache) {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PURCHASEORDERNO_BEMISCUSTID;
        finderArgs = new Object[] { bemisCustId, purchaseOrderNo };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_PURCHASEORDERNO_BEMISCUSTID;
        finderArgs = new Object[] { bemisCustId, purchaseOrderNo,

                start, end, orderByComparator };
    }

    List<Order> list = null;

    if (retrieveFromCache) {
        list = (List<Order>) finderCache.getResult(finderPath, finderArgs, this);

        if ((list != null) && !list.isEmpty()) {
            for (Order order : list) {
                if (!Objects.equals(bemisCustId, order.getBemisCustId())
                        || !Objects.equals(purchaseOrderNo, order.getPurchaseOrderNo())) {
                    list = null;

                    break;
                }
            }
        }
    }

    if (list == null) {
        StringBundler query = null;

        if (orderByComparator != null) {
            query = new StringBundler(4 + (orderByComparator.getOrderByFields().length * 2));
        } else {
            query = new StringBundler(4);
        }

        query.append(_SQL_SELECT_ORDER__WHERE);

        boolean bindBemisCustId = false;

        if (bemisCustId == null) {
            query.append(_FINDER_COLUMN_PURCHASEORDERNO_BEMISCUSTID_BEMISCUSTID_1);
        } else if (bemisCustId.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_PURCHASEORDERNO_BEMISCUSTID_BEMISCUSTID_3);
        } else {
            bindBemisCustId = true;

            query.append(_FINDER_COLUMN_PURCHASEORDERNO_BEMISCUSTID_BEMISCUSTID_2);
        }

        boolean bindPurchaseOrderNo = false;

        if (purchaseOrderNo == null) {
            query.append(_FINDER_COLUMN_PURCHASEORDERNO_BEMISCUSTID_PURCHASEORDERNO_1);
        } else if (purchaseOrderNo.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_PURCHASEORDERNO_BEMISCUSTID_PURCHASEORDERNO_3);
        } else {
            bindPurchaseOrderNo = true;

            query.append(_FINDER_COLUMN_PURCHASEORDERNO_BEMISCUSTID_PURCHASEORDERNO_2);
        }

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(OrderModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindBemisCustId) {
                qPos.add(bemisCustId);
            }

            if (bindPurchaseOrderNo) {
                qPos.add(purchaseOrderNo);
            }

            if (!pagination) {
                list = (List<Order>) QueryUtil.list(q, getDialect(), start, end, false);

                Collections.sort(list);

                list = Collections.unmodifiableList(list);
            } else {
                list = (List<Order>) QueryUtil.list(q, getDialect(), start, end);
            }

            cacheResult(list);

            finderCache.putResult(finderPath, finderArgs, list);
        } catch (Exception e) {
            finderCache.removeResult(finderPath, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return list;
}