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.customer.service.persistence.impl.CustomerLocationPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the customer locations.
 *
 * <p>/*from w  w  w  .  ja va 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 CustomerLocationModelImpl}. 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 start the lower bound of the range of customer locations
 * @param end the upper bound of the range of customer locations (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 customer locations
 */
@Override
public List<CustomerLocation> findAll(int start, int end, OrderByComparator<CustomerLocation> 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_ALL;
        finderArgs = FINDER_ARGS_EMPTY;
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
        finderArgs = new Object[] { start, end, orderByComparator };
    }

    List<CustomerLocation> list = null;

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

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

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

            query.append(_SQL_SELECT_CUSTOMERLOCATION);

            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);

            sql = query.toString();
        } else {
            sql = _SQL_SELECT_CUSTOMERLOCATION;

            if (pagination) {
                sql = sql.concat(CustomerLocationModelImpl.ORDER_BY_JPQL);
            }
        }

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

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

                Collections.sort(list);

                list = Collections.unmodifiableList(list);
            } else {
                list = (List<CustomerLocation>) 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.inventory.service.persistence.impl.OrderInventoryBatchPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the order inventory batchs where orderInventoryId = &#63;.
 *
 * <p>// ww  w  . jav a 2s.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 OrderInventoryBatchModelImpl}. 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 orderInventoryId the order inventory ID
 * @param start the lower bound of the range of order inventory batchs
 * @param end the upper bound of the range of order inventory batchs (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 order inventory batchs
 */
@Override
public List<OrderInventoryBatch> findByOrderInventoryId(long orderInventoryId, int start, int end,
        OrderByComparator<OrderInventoryBatch> 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_ORDERINVENTORYID;
        finderArgs = new Object[] { orderInventoryId };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ORDERINVENTORYID;
        finderArgs = new Object[] { orderInventoryId,

                start, end, orderByComparator };
    }

    List<OrderInventoryBatch> list = null;

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

        if ((list != null) && !list.isEmpty()) {
            for (OrderInventoryBatch orderInventoryBatch : list) {
                if ((orderInventoryId != orderInventoryBatch.getOrderInventoryId())) {
                    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_ORDERINVENTORYBATCH_WHERE);

        query.append(_FINDER_COLUMN_ORDERINVENTORYID_ORDERINVENTORYID_2);

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(orderInventoryId);

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

                Collections.sort(list);

                list = Collections.unmodifiableList(list);
            } else {
                list = (List<OrderInventoryBatch>) 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.inventory.service.persistence.impl.OrderInventoryBatchPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the order inventory batchs.
 *
 * <p>//from   w ww.j  a  v  a2 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 OrderInventoryBatchModelImpl}. 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 start the lower bound of the range of order inventory batchs
 * @param end the upper bound of the range of order inventory batchs (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 order inventory batchs
 */
@Override
public List<OrderInventoryBatch> findAll(int start, int end,
        OrderByComparator<OrderInventoryBatch> 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_ALL;
        finderArgs = FINDER_ARGS_EMPTY;
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
        finderArgs = new Object[] { start, end, orderByComparator };
    }

    List<OrderInventoryBatch> list = null;

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

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

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

            query.append(_SQL_SELECT_ORDERINVENTORYBATCH);

            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);

            sql = query.toString();
        } else {
            sql = _SQL_SELECT_ORDERINVENTORYBATCH;

            if (pagination) {
                sql = sql.concat(OrderInventoryBatchModelImpl.ORDER_BY_JPQL);
            }
        }

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

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

                Collections.sort(list);

                list = Collections.unmodifiableList(list);
            } else {
                list = (List<OrderInventoryBatch>) 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.inventory.service.persistence.impl.OrderInventoryPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the order inventories where orderId = &#63;.
 *
 * <p>/*  w  w  w .  j  av a  2s  .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 OrderInventoryModelImpl}. 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 orderId the order ID
 * @param start the lower bound of the range of order inventories
 * @param end the upper bound of the range of order inventories (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 order inventories
 */
@Override
public List<OrderInventory> findByOrderId(long orderId, int start, int end,
        OrderByComparator<OrderInventory> 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_ORDERID;
        finderArgs = new Object[] { orderId };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ORDERID;
        finderArgs = new Object[] { orderId, start, end, orderByComparator };
    }

    List<OrderInventory> list = null;

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

        if ((list != null) && !list.isEmpty()) {
            for (OrderInventory orderInventory : list) {
                if ((orderId != orderInventory.getOrderId())) {
                    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_ORDERINVENTORY_WHERE);

        query.append(_FINDER_COLUMN_ORDERID_ORDERID_2);

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(orderId);

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

                Collections.sort(list);

                list = Collections.unmodifiableList(list);
            } else {
                list = (List<OrderInventory>) 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.inventory.service.persistence.impl.OrderInventoryPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the order inventories.
 *
 * <p>/*from w w w . j  av  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 OrderInventoryModelImpl}. 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 start the lower bound of the range of order inventories
 * @param end the upper bound of the range of order inventories (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 order inventories
 */
@Override
public List<OrderInventory> findAll(int start, int end, OrderByComparator<OrderInventory> 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_ALL;
        finderArgs = FINDER_ARGS_EMPTY;
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
        finderArgs = new Object[] { start, end, orderByComparator };
    }

    List<OrderInventory> list = null;

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

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

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

            query.append(_SQL_SELECT_ORDERINVENTORY);

            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);

            sql = query.toString();
        } else {
            sql = _SQL_SELECT_ORDERINVENTORY;

            if (pagination) {
                sql = sql.concat(OrderInventoryModelImpl.ORDER_BY_JPQL);
            }
        }

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

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

                Collections.sort(list);

                list = Collections.unmodifiableList(list);
            } else {
                list = (List<OrderInventory>) 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.migration.customer.service.persistence.impl.CustomerOrgPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the customer orgs where bemisParentId = &#63;.
 *
 * <p>//from w w w .j av a2 s. 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 CustomerOrgModelImpl}. 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 bemisParentId the bemis parent ID
 * @param start the lower bound of the range of customer orgs
 * @param end the upper bound of the range of customer orgs (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 customer orgs
 */
@Override
public List<CustomerOrg> findByBemisParentId(String bemisParentId, int start, int end,
        OrderByComparator<CustomerOrg> 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_BEMISPARENTID;
        finderArgs = new Object[] { bemisParentId };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_BEMISPARENTID;
        finderArgs = new Object[] { bemisParentId,

                start, end, orderByComparator };
    }

    List<CustomerOrg> list = null;

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

        if ((list != null) && !list.isEmpty()) {
            for (CustomerOrg customerOrg : list) {
                if (!Objects.equals(bemisParentId, customerOrg.getBemisParentId())) {
                    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_CUSTOMERORG_WHERE);

        boolean bindBemisParentId = false;

        if (bemisParentId == null) {
            query.append(_FINDER_COLUMN_BEMISPARENTID_BEMISPARENTID_1);
        } else if (bemisParentId.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_BEMISPARENTID_BEMISPARENTID_3);
        } else {
            bindBemisParentId = true;

            query.append(_FINDER_COLUMN_BEMISPARENTID_BEMISPARENTID_2);
        }

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindBemisParentId) {
                qPos.add(bemisParentId);
            }

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

                Collections.sort(list);

                list = Collections.unmodifiableList(list);
            } else {
                list = (List<CustomerOrg>) 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.migration.customer.service.persistence.impl.CustomerOrgPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the customer orgs where bemisParentId = &#63;.
 *
 * <p>//from ww w .  j  av  a 2s  . 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 CustomerOrgModelImpl}. 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 bemisParentId the bemis parent ID
 * @param start the lower bound of the range of customer orgs
 * @param end the upper bound of the range of customer orgs (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 customer orgs
 */
@Override
public List<CustomerOrg> findByParentsOnly(String bemisParentId, int start, int end,
        OrderByComparator<CustomerOrg> 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_PARENTSONLY;
        finderArgs = new Object[] { bemisParentId };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_PARENTSONLY;
        finderArgs = new Object[] { bemisParentId,

                start, end, orderByComparator };
    }

    List<CustomerOrg> list = null;

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

        if ((list != null) && !list.isEmpty()) {
            for (CustomerOrg customerOrg : list) {
                if (!Objects.equals(bemisParentId, customerOrg.getBemisParentId())) {
                    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_CUSTOMERORG_WHERE);

        boolean bindBemisParentId = false;

        if (bemisParentId == null) {
            query.append(_FINDER_COLUMN_PARENTSONLY_BEMISPARENTID_1);
        } else if (bemisParentId.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_PARENTSONLY_BEMISPARENTID_3);
        } else {
            bindBemisParentId = true;

            query.append(_FINDER_COLUMN_PARENTSONLY_BEMISPARENTID_2);
        }

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindBemisParentId) {
                qPos.add(bemisParentId);
            }

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

                Collections.sort(list);

                list = Collections.unmodifiableList(list);
            } else {
                list = (List<CustomerOrg>) 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.migration.customer.service.persistence.impl.CustomerOrgPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the customer orgs.
 *
 * <p>//w  w  w . j a va2s  . 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 CustomerOrgModelImpl}. 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 start the lower bound of the range of customer orgs
 * @param end the upper bound of the range of customer orgs (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 customer orgs
 */
@Override
public List<CustomerOrg> findAll(int start, int end, OrderByComparator<CustomerOrg> 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_ALL;
        finderArgs = FINDER_ARGS_EMPTY;
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
        finderArgs = new Object[] { start, end, orderByComparator };
    }

    List<CustomerOrg> list = null;

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

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

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

            query.append(_SQL_SELECT_CUSTOMERORG);

            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);

            sql = query.toString();
        } else {
            sql = _SQL_SELECT_CUSTOMERORG;

            if (pagination) {
                sql = sql.concat(CustomerOrgModelImpl.ORDER_BY_JPQL);
            }
        }

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

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

                Collections.sort(list);

                list = Collections.unmodifiableList(list);
            } else {
                list = (List<CustomerOrg>) 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.migration.customer.service.persistence.impl.CustomerUserPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the customer users where modifiedDate &ge; &#63;.
 *
 * <p>/*w w  w  .j  a  v a2s .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 CustomerUserModelImpl}. 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 modifiedDate the modified date
 * @param start the lower bound of the range of customer users
 * @param end the upper bound of the range of customer users (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 customer users
 */
@Override
public List<CustomerUser> findBylastModifiedDate(Date modifiedDate, int start, int end,
        OrderByComparator<CustomerUser> orderByComparator, boolean retrieveFromCache) {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LASTMODIFIEDDATE;
    finderArgs = new Object[] { modifiedDate, start, end, orderByComparator };

    List<CustomerUser> list = null;

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

        if ((list != null) && !list.isEmpty()) {
            for (CustomerUser customerUser : list) {
                if ((modifiedDate.getTime() > customerUser.getModifiedDate().getTime())) {
                    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_CUSTOMERUSER_WHERE);

        boolean bindModifiedDate = false;

        if (modifiedDate == null) {
            query.append(_FINDER_COLUMN_LASTMODIFIEDDATE_MODIFIEDDATE_1);
        } else {
            bindModifiedDate = true;

            query.append(_FINDER_COLUMN_LASTMODIFIEDDATE_MODIFIEDDATE_2);
        }

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindModifiedDate) {
                qPos.add(new Timestamp(modifiedDate.getTime()));
            }

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

                Collections.sort(list);

                list = Collections.unmodifiableList(list);
            } else {
                list = (List<CustomerUser>) 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.migration.customer.service.persistence.impl.CustomerUserPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the customer users.
 *
 * <p>/*  w  w w . j a va2s.  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 CustomerUserModelImpl}. 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 start the lower bound of the range of customer users
 * @param end the upper bound of the range of customer users (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 customer users
 */
@Override
public List<CustomerUser> findAll(int start, int end, OrderByComparator<CustomerUser> 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_ALL;
        finderArgs = FINDER_ARGS_EMPTY;
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
        finderArgs = new Object[] { start, end, orderByComparator };
    }

    List<CustomerUser> list = null;

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

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

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

            query.append(_SQL_SELECT_CUSTOMERUSER);

            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);

            sql = query.toString();
        } else {
            sql = _SQL_SELECT_CUSTOMERUSER;

            if (pagination) {
                sql = sql.concat(CustomerUserModelImpl.ORDER_BY_JPQL);
            }
        }

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

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

                Collections.sort(list);

                list = Collections.unmodifiableList(list);
            } else {
                list = (List<CustomerUser>) 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;
}