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.bcnet.portlet.biobank.service.persistence.ContactPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the contacts.
 *
 * <p>//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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.bcnet.portlet.biobank.model.impl.ContactModelImpl}. 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 contacts
 * @param end the upper bound of the range of contacts (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of contacts
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Contact> findAll(int start, int end, OrderByComparator orderByComparator) throws SystemException {
    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<Contact> list = (List<Contact>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

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

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

            query.append(_SQL_SELECT_CONTACT);

            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);

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

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

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

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

                Collections.sort(list);

                list = new UnmodifiableList<Contact>(list);
            } else {
                list = (List<Contact>) QueryUtil.list(q, getDialect(), start, end);
            }

            cacheResult(list);

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

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

    return list;
}

From source file:com.bcnet.portlet.biobank.service.persistence.CountryPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the countries.
 *
 * <p>//ww w  .j  av  a  2s .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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.bcnet.portlet.biobank.model.impl.CountryModelImpl}. 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 countries
 * @param end the upper bound of the range of countries (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of countries
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Country> findAll(int start, int end, OrderByComparator orderByComparator) throws SystemException {
    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<Country> list = (List<Country>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

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

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

            query.append(_SQL_SELECT_COUNTRY);

            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);

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

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

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

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

                Collections.sort(list);

                list = new UnmodifiableList<Country>(list);
            } else {
                list = (List<Country>) QueryUtil.list(q, getDialect(), start, end);
            }

            cacheResult(list);

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

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

    return list;
}

From source file:com.bcnet.portlet.biobank.service.persistence.JuristicPersonPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the juristic persons.
 *
 * <p>//  w ww  .j  a  va 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.bcnet.portlet.biobank.model.impl.JuristicPersonModelImpl}. 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 juristic persons
 * @param end the upper bound of the range of juristic persons (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of juristic persons
 * @throws SystemException if a system exception occurred
 */
@Override
public List<JuristicPerson> findAll(int start, int end, OrderByComparator orderByComparator)
        throws SystemException {
    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<JuristicPerson> list = (List<JuristicPerson>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

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

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

            query.append(_SQL_SELECT_JURISTICPERSON);

            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);

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

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

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

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

                Collections.sort(list);

                list = new UnmodifiableList<JuristicPerson>(list);
            } else {
                list = (List<JuristicPerson>) QueryUtil.list(q, getDialect(), start, end);
            }

            cacheResult(list);

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

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

    return list;
}

From source file:com.bemis.portal.carriers.service.persistence.impl.CarrierPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the carriers where uuid = &#63;.
 *
 * <p>/*from  w  w  w.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 CarrierModelImpl}. 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 uuid the uuid
 * @param start the lower bound of the range of carriers
 * @param end the upper bound of the range of carriers (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 carriers
 */
@Override
public List<Carrier> findByUuid(String uuid, int start, int end, OrderByComparator<Carrier> 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_UUID;
        finderArgs = new Object[] { uuid };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
        finderArgs = new Object[] { uuid, start, end, orderByComparator };
    }

    List<Carrier> list = null;

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

        if ((list != null) && !list.isEmpty()) {
            for (Carrier carrier : list) {
                if (!Objects.equals(uuid, carrier.getUuid())) {
                    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_CARRIER_WHERE);

        boolean bindUuid = false;

        if (uuid == null) {
            query.append(_FINDER_COLUMN_UUID_UUID_1);
        } else if (uuid.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_UUID_UUID_3);
        } else {
            bindUuid = true;

            query.append(_FINDER_COLUMN_UUID_UUID_2);
        }

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindUuid) {
                qPos.add(uuid);
            }

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

                Collections.sort(list);

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

License:Open Source License

/**
 * Returns an ordered range of all the carriers where uuid = &#63; and companyId = &#63;.
 *
 * <p>/*from  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 CarrierModelImpl}. 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 uuid the uuid
 * @param companyId the company ID
 * @param start the lower bound of the range of carriers
 * @param end the upper bound of the range of carriers (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 carriers
 */
@Override
public List<Carrier> findByUuid_C(String uuid, long companyId, int start, int end,
        OrderByComparator<Carrier> 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_UUID_C;
        finderArgs = new Object[] { uuid, companyId };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
        finderArgs = new Object[] { uuid, companyId,

                start, end, orderByComparator };
    }

    List<Carrier> list = null;

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

        if ((list != null) && !list.isEmpty()) {
            for (Carrier carrier : list) {
                if (!Objects.equals(uuid, carrier.getUuid()) || (companyId != carrier.getCompanyId())) {
                    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_CARRIER_WHERE);

        boolean bindUuid = false;

        if (uuid == null) {
            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
        } else if (uuid.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
        } else {
            bindUuid = true;

            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
        }

        query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindUuid) {
                qPos.add(uuid);
            }

            qPos.add(companyId);

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

                Collections.sort(list);

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

License:Open Source License

/**
 * Returns an ordered range of all the carriers where groupId = &#63;.
 *
 * <p>/*  w w  w  . j  av 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 CarrierModelImpl}. 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 groupId the group ID
 * @param start the lower bound of the range of carriers
 * @param end the upper bound of the range of carriers (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 carriers
 */
@Override
public List<Carrier> findByGroupId(long groupId, int start, int end,
        OrderByComparator<Carrier> 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_GROUPID;
        finderArgs = new Object[] { groupId };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
        finderArgs = new Object[] { groupId, start, end, orderByComparator };
    }

    List<Carrier> list = null;

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

        if ((list != null) && !list.isEmpty()) {
            for (Carrier carrier : list) {
                if ((groupId != carrier.getGroupId())) {
                    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_CARRIER_WHERE);

        query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(CarrierModelImpl.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(groupId);

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

                Collections.sort(list);

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

License:Open Source License

/**
 * Returns an ordered range of all the carriers.
 *
 * <p>/*from w  w w . jav 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 CarrierModelImpl}. 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 carriers
 * @param end the upper bound of the range of carriers (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 carriers
 */
@Override
public List<Carrier> findAll(int start, int end, OrderByComparator<Carrier> 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<Carrier> list = null;

    if (retrieveFromCache) {
        list = (List<Carrier>) 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_CARRIER);

            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);

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

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

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

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

                Collections.sort(list);

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

License:Open Source License

/**
 * Returns an ordered range of all the customer locations where bemisParentId = &#63;.
 *
 * <p>/*w w  w.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 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 bemisParentId the bemis parent ID
 * @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 matching customer locations
 */
@Override
public List<CustomerLocation> findByBemisParentId(String bemisParentId, 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_BY_BEMISPARENTID;
        finderArgs = new Object[] { bemisParentId };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_BEMISPARENTID;
        finderArgs = new Object[] { bemisParentId,

                start, end, orderByComparator };
    }

    List<CustomerLocation> list = null;

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

        if ((list != null) && !list.isEmpty()) {
            for (CustomerLocation customerLocation : list) {
                if (!Objects.equals(bemisParentId, customerLocation.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_CUSTOMERLOCATION_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(CustomerLocationModelImpl.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<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.customer.service.persistence.impl.CustomerLocationPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the customer locations where customerActiveStatusCde = &#63;.
 *
 * <p>//w w  w  .  j  a 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 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 customerActiveStatusCde the customer active status cde
 * @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 matching customer locations
 */
@Override
public List<CustomerLocation> findByCustomerActiveStatusCde(String customerActiveStatusCde, 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_BY_CUSTOMERACTIVESTATUSCDE;
        finderArgs = new Object[] { customerActiveStatusCde };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CUSTOMERACTIVESTATUSCDE;
        finderArgs = new Object[] { customerActiveStatusCde,

                start, end, orderByComparator };
    }

    List<CustomerLocation> list = null;

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

        if ((list != null) && !list.isEmpty()) {
            for (CustomerLocation customerLocation : list) {
                if (!Objects.equals(customerActiveStatusCde, customerLocation.getCustomerActiveStatusCde())) {
                    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_CUSTOMERLOCATION_WHERE);

        boolean bindCustomerActiveStatusCde = false;

        if (customerActiveStatusCde == null) {
            query.append(_FINDER_COLUMN_CUSTOMERACTIVESTATUSCDE_CUSTOMERACTIVESTATUSCDE_1);
        } else if (customerActiveStatusCde.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_CUSTOMERACTIVESTATUSCDE_CUSTOMERACTIVESTATUSCDE_3);
        } else {
            bindCustomerActiveStatusCde = true;

            query.append(_FINDER_COLUMN_CUSTOMERACTIVESTATUSCDE_CUSTOMERACTIVESTATUSCDE_2);
        }

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindCustomerActiveStatusCde) {
                qPos.add(customerActiveStatusCde);
            }

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

License:Open Source License

/**
 * Returns an ordered range of all the customer locations where customerName = &#63; and customerCity = &#63;.
 *
 * <p>//from   w w  w.  j  ava2 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 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 customerName the customer name
 * @param customerCity the customer city
 * @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 matching customer locations
 */
@Override
public List<CustomerLocation> findByCustomerName_CustomerCity(String customerName, String customerCity,
        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_BY_CUSTOMERNAME_CUSTOMERCITY;
        finderArgs = new Object[] { customerName, customerCity };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CUSTOMERNAME_CUSTOMERCITY;
        finderArgs = new Object[] { customerName, customerCity,

                start, end, orderByComparator };
    }

    List<CustomerLocation> list = null;

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

        if ((list != null) && !list.isEmpty()) {
            for (CustomerLocation customerLocation : list) {
                if (!Objects.equals(customerName, customerLocation.getCustomerName())
                        || !Objects.equals(customerCity, customerLocation.getCustomerCity())) {
                    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_CUSTOMERLOCATION_WHERE);

        boolean bindCustomerName = false;

        if (customerName == null) {
            query.append(_FINDER_COLUMN_CUSTOMERNAME_CUSTOMERCITY_CUSTOMERNAME_1);
        } else if (customerName.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_CUSTOMERNAME_CUSTOMERCITY_CUSTOMERNAME_3);
        } else {
            bindCustomerName = true;

            query.append(_FINDER_COLUMN_CUSTOMERNAME_CUSTOMERCITY_CUSTOMERNAME_2);
        }

        boolean bindCustomerCity = false;

        if (customerCity == null) {
            query.append(_FINDER_COLUMN_CUSTOMERNAME_CUSTOMERCITY_CUSTOMERCITY_1);
        } else if (customerCity.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_CUSTOMERNAME_CUSTOMERCITY_CUSTOMERCITY_3);
        } else {
            bindCustomerCity = true;

            query.append(_FINDER_COLUMN_CUSTOMERNAME_CUSTOMERCITY_CUSTOMERCITY_2);
        }

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindCustomerName) {
                qPos.add(customerName);
            }

            if (bindCustomerCity) {
                qPos.add(customerCity);
            }

            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;
}