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:br.com.prodevelopment.lapidarios.loja.service.persistence.LojaPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the lojas where companyId = &#63; and groupId = &#63; and razaoSocial LIKE &#63; and status = &#63;.
 *
 * <p>//from   w ww.ja  v  a2 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 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 br.com.prodevelopment.lapidarios.loja.model.impl.LojaModelImpl}. 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 companyId the company ID
 * @param groupId the group ID
 * @param razaoSocial the razao social
 * @param status the status
 * @param start the lower bound of the range of lojas
 * @param end the upper bound of the range of lojas (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching lojas
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Loja> findByCG_RazaoSocial(long companyId, long groupId, String razaoSocial, int status, int start,
        int end, OrderByComparator orderByComparator) throws SystemException {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CG_RAZAOSOCIAL;
    finderArgs = new Object[] { companyId, groupId, razaoSocial, status,

            start, end, orderByComparator };

    List<Loja> list = (List<Loja>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (Loja loja : list) {
            if ((companyId != loja.getCompanyId())
                    || (groupId != loja.getGroupId()) || !StringUtil.wildcardMatches(loja.getRazaoSocial(),
                            razaoSocial, CharPool.UNDERLINE, CharPool.PERCENT, CharPool.BACK_SLASH, true)
                    || (status != loja.getStatus())) {
                list = null;

                break;
            }
        }
    }

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

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

        query.append(_SQL_SELECT_LOJA_WHERE);

        query.append(_FINDER_COLUMN_CG_RAZAOSOCIAL_COMPANYID_2);

        query.append(_FINDER_COLUMN_CG_RAZAOSOCIAL_GROUPID_2);

        boolean bindRazaoSocial = false;

        if (razaoSocial == null) {
            query.append(_FINDER_COLUMN_CG_RAZAOSOCIAL_RAZAOSOCIAL_1);
        } else if (razaoSocial.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_CG_RAZAOSOCIAL_RAZAOSOCIAL_3);
        } else {
            bindRazaoSocial = true;

            query.append(_FINDER_COLUMN_CG_RAZAOSOCIAL_RAZAOSOCIAL_2);
        }

        query.append(_FINDER_COLUMN_CG_RAZAOSOCIAL_STATUS_2);

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

            qPos.add(groupId);

            if (bindRazaoSocial) {
                qPos.add(razaoSocial);
            }

            qPos.add(status);

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

                Collections.sort(list);

                list = new UnmodifiableList<Loja>(list);
            } else {
                list = (List<Loja>) 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:br.com.prodevelopment.lapidarios.loja.service.persistence.LojaPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the lojas where companyId = &#63; and groupId = &#63; and razaoSocial LIKE &#63; and status = any &#63;.
 *
 * <p>/*from   www. j a  va2  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 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 br.com.prodevelopment.lapidarios.loja.model.impl.LojaModelImpl}. 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 companyId the company ID
 * @param groupId the group ID
 * @param razaoSocial the razao social
 * @param statuses the statuses
 * @param start the lower bound of the range of lojas
 * @param end the upper bound of the range of lojas (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching lojas
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Loja> findByCG_RazaoSocial(long companyId, long groupId, String razaoSocial, int[] statuses,
        int start, int end, OrderByComparator orderByComparator) throws SystemException {
    if ((statuses != null) && (statuses.length == 1)) {
        return findByCG_RazaoSocial(companyId, groupId, razaoSocial, statuses[0], start, end,
                orderByComparator);
    }

    boolean pagination = true;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderArgs = new Object[] { companyId, groupId, razaoSocial, StringUtil.merge(statuses) };
    } else {
        finderArgs = new Object[] { companyId, groupId, razaoSocial, StringUtil.merge(statuses),

                start, end, orderByComparator };
    }

    List<Loja> list = (List<Loja>) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_CG_RAZAOSOCIAL,
            finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (Loja loja : list) {
            if ((companyId != loja.getCompanyId()) || (groupId != loja.getGroupId())
                    || !StringUtil.wildcardMatches(loja.getRazaoSocial(), razaoSocial, CharPool.UNDERLINE,
                            CharPool.PERCENT, CharPool.BACK_SLASH, true)
                    || !ArrayUtil.contains(statuses, loja.getStatus())) {
                list = null;

                break;
            }
        }
    }

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

        query.append(_SQL_SELECT_LOJA_WHERE);

        boolean conjunctionable = false;

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_CG_RAZAOSOCIAL_COMPANYID_5);

        conjunctionable = true;

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_CG_RAZAOSOCIAL_GROUPID_5);

        conjunctionable = true;

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        boolean bindRazaoSocial = false;

        if (razaoSocial == null) {
            query.append(_FINDER_COLUMN_CG_RAZAOSOCIAL_RAZAOSOCIAL_4);
        } else if (razaoSocial.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_CG_RAZAOSOCIAL_RAZAOSOCIAL_6);
        } else {
            bindRazaoSocial = true;

            query.append(_FINDER_COLUMN_CG_RAZAOSOCIAL_RAZAOSOCIAL_5);
        }

        conjunctionable = true;

        if ((statuses == null) || (statuses.length > 0)) {
            if (conjunctionable) {
                query.append(WHERE_AND);
            }

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < statuses.length; i++) {
                query.append(_FINDER_COLUMN_CG_RAZAOSOCIAL_STATUS_5);

                if ((i + 1) < statuses.length) {
                    query.append(WHERE_OR);
                }
            }

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

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

            qPos.add(groupId);

            if (bindRazaoSocial) {
                qPos.add(razaoSocial);
            }

            if (statuses != null) {
                qPos.add(statuses);
            }

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

                Collections.sort(list);

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

            cacheResult(list);

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

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

    return list;
}

From source file:br.com.prodevelopment.lapidarios.loja.service.persistence.LojaPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the lojas where nomeFantasia LIKE &#63;.
 *
 * <p>//  w w 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 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 br.com.prodevelopment.lapidarios.loja.model.impl.LojaModelImpl}. 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 nomeFantasia the nome fantasia
 * @param start the lower bound of the range of lojas
 * @param end the upper bound of the range of lojas (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching lojas
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Loja> findByNomeFantasia(String nomeFantasia, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NOMEFANTASIA;
    finderArgs = new Object[] { nomeFantasia, start, end, orderByComparator };

    List<Loja> list = (List<Loja>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (Loja loja : list) {
            if (!StringUtil.wildcardMatches(loja.getNomeFantasia(), nomeFantasia, CharPool.UNDERLINE,
                    CharPool.PERCENT, CharPool.BACK_SLASH, true)) {
                list = null;

                break;
            }
        }
    }

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

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

        query.append(_SQL_SELECT_LOJA_WHERE);

        boolean bindNomeFantasia = false;

        if (nomeFantasia == null) {
            query.append(_FINDER_COLUMN_NOMEFANTASIA_NOMEFANTASIA_1);
        } else if (nomeFantasia.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_NOMEFANTASIA_NOMEFANTASIA_3);
        } else {
            bindNomeFantasia = true;

            query.append(_FINDER_COLUMN_NOMEFANTASIA_NOMEFANTASIA_2);
        }

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindNomeFantasia) {
                qPos.add(nomeFantasia);
            }

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

                Collections.sort(list);

                list = new UnmodifiableList<Loja>(list);
            } else {
                list = (List<Loja>) 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:br.com.prodevelopment.lapidarios.loja.service.persistence.LojaPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the lojas where companyId = &#63; and groupId = &#63; and nomeFantasia LIKE &#63; and status = &#63;.
 *
 * <p>//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 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 br.com.prodevelopment.lapidarios.loja.model.impl.LojaModelImpl}. 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 companyId the company ID
 * @param groupId the group ID
 * @param nomeFantasia the nome fantasia
 * @param status the status
 * @param start the lower bound of the range of lojas
 * @param end the upper bound of the range of lojas (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching lojas
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Loja> findByCG_NomeFantasia(long companyId, long groupId, String nomeFantasia, int status,
        int start, int end, OrderByComparator orderByComparator) throws SystemException {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CG_NOMEFANTASIA;
    finderArgs = new Object[] { companyId, groupId, nomeFantasia, status,

            start, end, orderByComparator };

    List<Loja> list = (List<Loja>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (Loja loja : list) {
            if ((companyId != loja.getCompanyId())
                    || (groupId != loja.getGroupId()) || !StringUtil.wildcardMatches(loja.getNomeFantasia(),
                            nomeFantasia, CharPool.UNDERLINE, CharPool.PERCENT, CharPool.BACK_SLASH, true)
                    || (status != loja.getStatus())) {
                list = null;

                break;
            }
        }
    }

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

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

        query.append(_SQL_SELECT_LOJA_WHERE);

        query.append(_FINDER_COLUMN_CG_NOMEFANTASIA_COMPANYID_2);

        query.append(_FINDER_COLUMN_CG_NOMEFANTASIA_GROUPID_2);

        boolean bindNomeFantasia = false;

        if (nomeFantasia == null) {
            query.append(_FINDER_COLUMN_CG_NOMEFANTASIA_NOMEFANTASIA_1);
        } else if (nomeFantasia.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_CG_NOMEFANTASIA_NOMEFANTASIA_3);
        } else {
            bindNomeFantasia = true;

            query.append(_FINDER_COLUMN_CG_NOMEFANTASIA_NOMEFANTASIA_2);
        }

        query.append(_FINDER_COLUMN_CG_NOMEFANTASIA_STATUS_2);

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

            qPos.add(groupId);

            if (bindNomeFantasia) {
                qPos.add(nomeFantasia);
            }

            qPos.add(status);

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

                Collections.sort(list);

                list = new UnmodifiableList<Loja>(list);
            } else {
                list = (List<Loja>) 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:br.com.prodevelopment.lapidarios.loja.service.persistence.LojaPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the lojas where companyId = &#63; and groupId = &#63; and nomeFantasia LIKE &#63; and status = any &#63;.
 *
 * <p>/*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 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 br.com.prodevelopment.lapidarios.loja.model.impl.LojaModelImpl}. 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 companyId the company ID
 * @param groupId the group ID
 * @param nomeFantasia the nome fantasia
 * @param statuses the statuses
 * @param start the lower bound of the range of lojas
 * @param end the upper bound of the range of lojas (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching lojas
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Loja> findByCG_NomeFantasia(long companyId, long groupId, String nomeFantasia, int[] statuses,
        int start, int end, OrderByComparator orderByComparator) throws SystemException {
    if ((statuses != null) && (statuses.length == 1)) {
        return findByCG_NomeFantasia(companyId, groupId, nomeFantasia, statuses[0], start, end,
                orderByComparator);
    }

    boolean pagination = true;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderArgs = new Object[] { companyId, groupId, nomeFantasia, StringUtil.merge(statuses) };
    } else {
        finderArgs = new Object[] { companyId, groupId, nomeFantasia, StringUtil.merge(statuses),

                start, end, orderByComparator };
    }

    List<Loja> list = (List<Loja>) FinderCacheUtil
            .getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_CG_NOMEFANTASIA, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (Loja loja : list) {
            if ((companyId != loja.getCompanyId()) || (groupId != loja.getGroupId())
                    || !StringUtil.wildcardMatches(loja.getNomeFantasia(), nomeFantasia, CharPool.UNDERLINE,
                            CharPool.PERCENT, CharPool.BACK_SLASH, true)
                    || !ArrayUtil.contains(statuses, loja.getStatus())) {
                list = null;

                break;
            }
        }
    }

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

        query.append(_SQL_SELECT_LOJA_WHERE);

        boolean conjunctionable = false;

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_CG_NOMEFANTASIA_COMPANYID_5);

        conjunctionable = true;

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_CG_NOMEFANTASIA_GROUPID_5);

        conjunctionable = true;

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        boolean bindNomeFantasia = false;

        if (nomeFantasia == null) {
            query.append(_FINDER_COLUMN_CG_NOMEFANTASIA_NOMEFANTASIA_4);
        } else if (nomeFantasia.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_CG_NOMEFANTASIA_NOMEFANTASIA_6);
        } else {
            bindNomeFantasia = true;

            query.append(_FINDER_COLUMN_CG_NOMEFANTASIA_NOMEFANTASIA_5);
        }

        conjunctionable = true;

        if ((statuses == null) || (statuses.length > 0)) {
            if (conjunctionable) {
                query.append(WHERE_AND);
            }

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < statuses.length; i++) {
                query.append(_FINDER_COLUMN_CG_NOMEFANTASIA_STATUS_5);

                if ((i + 1) < statuses.length) {
                    query.append(WHERE_OR);
                }
            }

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

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

            qPos.add(groupId);

            if (bindNomeFantasia) {
                qPos.add(nomeFantasia);
            }

            if (statuses != null) {
                qPos.add(statuses);
            }

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

                Collections.sort(list);

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

            cacheResult(list);

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

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

    return list;
}

From source file:br.com.prodevelopment.lapidarios.loja.service.persistence.LojaPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the lojas where companyId = &#63; and groupId = &#63; and ordemIndicada = &#63; and status = &#63;.
 *
 * <p>// w  w  w. java2  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 br.com.prodevelopment.lapidarios.loja.model.impl.LojaModelImpl}. 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 companyId the company ID
 * @param groupId the group ID
 * @param ordemIndicada the ordem indicada
 * @param status the status
 * @param start the lower bound of the range of lojas
 * @param end the upper bound of the range of lojas (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching lojas
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Loja> findByCG_OrdemIndicada(long companyId, long groupId, int ordemIndicada, int status, 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_BY_CG_ORDEMINDICADA;
        finderArgs = new Object[] { companyId, groupId, ordemIndicada, status };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CG_ORDEMINDICADA;
        finderArgs = new Object[] { companyId, groupId, ordemIndicada, status,

                start, end, orderByComparator };
    }

    List<Loja> list = (List<Loja>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (Loja loja : list) {
            if ((companyId != loja.getCompanyId()) || (groupId != loja.getGroupId())
                    || (ordemIndicada != loja.getOrdemIndicada()) || (status != loja.getStatus())) {
                list = null;

                break;
            }
        }
    }

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

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

        query.append(_SQL_SELECT_LOJA_WHERE);

        query.append(_FINDER_COLUMN_CG_ORDEMINDICADA_COMPANYID_2);

        query.append(_FINDER_COLUMN_CG_ORDEMINDICADA_GROUPID_2);

        query.append(_FINDER_COLUMN_CG_ORDEMINDICADA_ORDEMINDICADA_2);

        query.append(_FINDER_COLUMN_CG_ORDEMINDICADA_STATUS_2);

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

            qPos.add(groupId);

            qPos.add(ordemIndicada);

            qPos.add(status);

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

                Collections.sort(list);

                list = new UnmodifiableList<Loja>(list);
            } else {
                list = (List<Loja>) 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:br.com.prodevelopment.lapidarios.loja.service.persistence.LojaPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the lojas where companyId = &#63; and groupId = &#63; and ordemIndicada = &#63; and status = any &#63;.
 *
 * <p>/*from 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 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 br.com.prodevelopment.lapidarios.loja.model.impl.LojaModelImpl}. 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 companyId the company ID
 * @param groupId the group ID
 * @param ordemIndicada the ordem indicada
 * @param statuses the statuses
 * @param start the lower bound of the range of lojas
 * @param end the upper bound of the range of lojas (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching lojas
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Loja> findByCG_OrdemIndicada(long companyId, long groupId, int ordemIndicada, int[] statuses,
        int start, int end, OrderByComparator orderByComparator) throws SystemException {
    if ((statuses != null) && (statuses.length == 1)) {
        return findByCG_OrdemIndicada(companyId, groupId, ordemIndicada, statuses[0], start, end,
                orderByComparator);
    }

    boolean pagination = true;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderArgs = new Object[] { companyId, groupId, ordemIndicada, StringUtil.merge(statuses) };
    } else {
        finderArgs = new Object[] { companyId, groupId, ordemIndicada, StringUtil.merge(statuses),

                start, end, orderByComparator };
    }

    List<Loja> list = (List<Loja>) FinderCacheUtil
            .getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_CG_ORDEMINDICADA, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (Loja loja : list) {
            if ((companyId != loja.getCompanyId()) || (groupId != loja.getGroupId())
                    || (ordemIndicada != loja.getOrdemIndicada())
                    || !ArrayUtil.contains(statuses, loja.getStatus())) {
                list = null;

                break;
            }
        }
    }

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

        query.append(_SQL_SELECT_LOJA_WHERE);

        boolean conjunctionable = false;

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_CG_ORDEMINDICADA_COMPANYID_5);

        conjunctionable = true;

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_CG_ORDEMINDICADA_GROUPID_5);

        conjunctionable = true;

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_CG_ORDEMINDICADA_ORDEMINDICADA_5);

        conjunctionable = true;

        if ((statuses == null) || (statuses.length > 0)) {
            if (conjunctionable) {
                query.append(WHERE_AND);
            }

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < statuses.length; i++) {
                query.append(_FINDER_COLUMN_CG_ORDEMINDICADA_STATUS_5);

                if ((i + 1) < statuses.length) {
                    query.append(WHERE_OR);
                }
            }

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

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

            qPos.add(groupId);

            qPos.add(ordemIndicada);

            if (statuses != null) {
                qPos.add(statuses);
            }

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

                Collections.sort(list);

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

            cacheResult(list);

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

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

    return list;
}

From source file:br.com.prodevelopment.lapidarios.loja.service.persistence.LojaPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the lojas where companyId = &#63; and groupId = &#63; and classNameId = &#63; and status = &#63;.
 *
 * <p>//from  w  ww  .  j av  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 br.com.prodevelopment.lapidarios.loja.model.impl.LojaModelImpl}. 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 companyId the company ID
 * @param groupId the group ID
 * @param classNameId the class name ID
 * @param status the status
 * @param start the lower bound of the range of lojas
 * @param end the upper bound of the range of lojas (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching lojas
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Loja> findByCG_ClassName(long companyId, long groupId, long classNameId, int status, 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_BY_CG_CLASSNAME;
        finderArgs = new Object[] { companyId, groupId, classNameId, status };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CG_CLASSNAME;
        finderArgs = new Object[] { companyId, groupId, classNameId, status,

                start, end, orderByComparator };
    }

    List<Loja> list = (List<Loja>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (Loja loja : list) {
            if ((companyId != loja.getCompanyId()) || (groupId != loja.getGroupId())
                    || (classNameId != loja.getClassNameId()) || (status != loja.getStatus())) {
                list = null;

                break;
            }
        }
    }

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

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

        query.append(_SQL_SELECT_LOJA_WHERE);

        query.append(_FINDER_COLUMN_CG_CLASSNAME_COMPANYID_2);

        query.append(_FINDER_COLUMN_CG_CLASSNAME_GROUPID_2);

        query.append(_FINDER_COLUMN_CG_CLASSNAME_CLASSNAMEID_2);

        query.append(_FINDER_COLUMN_CG_CLASSNAME_STATUS_2);

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

            qPos.add(groupId);

            qPos.add(classNameId);

            qPos.add(status);

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

                Collections.sort(list);

                list = new UnmodifiableList<Loja>(list);
            } else {
                list = (List<Loja>) 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:br.com.prodevelopment.lapidarios.loja.service.persistence.LojaPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the lojas where companyId = &#63; and groupId = &#63; and classNameId = &#63; and status = any &#63;.
 *
 * <p>/*from  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 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 br.com.prodevelopment.lapidarios.loja.model.impl.LojaModelImpl}. 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 companyId the company ID
 * @param groupId the group ID
 * @param classNameId the class name ID
 * @param statuses the statuses
 * @param start the lower bound of the range of lojas
 * @param end the upper bound of the range of lojas (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching lojas
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Loja> findByCG_ClassName(long companyId, long groupId, long classNameId, int[] statuses, int start,
        int end, OrderByComparator orderByComparator) throws SystemException {
    if ((statuses != null) && (statuses.length == 1)) {
        return findByCG_ClassName(companyId, groupId, classNameId, statuses[0], start, end, orderByComparator);
    }

    boolean pagination = true;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderArgs = new Object[] { companyId, groupId, classNameId, StringUtil.merge(statuses) };
    } else {
        finderArgs = new Object[] { companyId, groupId, classNameId, StringUtil.merge(statuses),

                start, end, orderByComparator };
    }

    List<Loja> list = (List<Loja>) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_CG_CLASSNAME,
            finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (Loja loja : list) {
            if ((companyId != loja.getCompanyId()) || (groupId != loja.getGroupId())
                    || (classNameId != loja.getClassNameId())
                    || !ArrayUtil.contains(statuses, loja.getStatus())) {
                list = null;

                break;
            }
        }
    }

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

        query.append(_SQL_SELECT_LOJA_WHERE);

        boolean conjunctionable = false;

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_CG_CLASSNAME_COMPANYID_5);

        conjunctionable = true;

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_CG_CLASSNAME_GROUPID_5);

        conjunctionable = true;

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_CG_CLASSNAME_CLASSNAMEID_5);

        conjunctionable = true;

        if ((statuses == null) || (statuses.length > 0)) {
            if (conjunctionable) {
                query.append(WHERE_AND);
            }

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < statuses.length; i++) {
                query.append(_FINDER_COLUMN_CG_CLASSNAME_STATUS_5);

                if ((i + 1) < statuses.length) {
                    query.append(WHERE_OR);
                }
            }

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

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

            qPos.add(groupId);

            qPos.add(classNameId);

            if (statuses != null) {
                qPos.add(statuses);
            }

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

                Collections.sort(list);

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

            cacheResult(list);

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

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

    return list;
}

From source file:br.com.prodevelopment.lapidarios.loja.service.persistence.LojaPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the lojas where companyId = &#63; and groupId = &#63; and classNameId = &#63; and nomeFantasia LIKE &#63; and status = &#63;.
 *
 * <p>/* w w  w. jav  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 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 br.com.prodevelopment.lapidarios.loja.model.impl.LojaModelImpl}. 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 companyId the company ID
 * @param groupId the group ID
 * @param classNameId the class name ID
 * @param nomeFantasia the nome fantasia
 * @param status the status
 * @param start the lower bound of the range of lojas
 * @param end the upper bound of the range of lojas (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching lojas
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Loja> findByCG_ClassNameNomeFantasia(long companyId, long groupId, long classNameId,
        String nomeFantasia, int status, int start, int end, OrderByComparator orderByComparator)
        throws SystemException {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CG_CLASSNAMENOMEFANTASIA;
    finderArgs = new Object[] { companyId, groupId, classNameId, nomeFantasia, status,

            start, end, orderByComparator };

    List<Loja> list = (List<Loja>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (Loja loja : list) {
            if ((companyId != loja.getCompanyId()) || (groupId != loja.getGroupId())
                    || (classNameId != loja.getClassNameId())
                    || !StringUtil.wildcardMatches(loja.getNomeFantasia(), nomeFantasia, CharPool.UNDERLINE,
                            CharPool.PERCENT, CharPool.BACK_SLASH, true)
                    || (status != loja.getStatus())) {
                list = null;

                break;
            }
        }
    }

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

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

        query.append(_SQL_SELECT_LOJA_WHERE);

        query.append(_FINDER_COLUMN_CG_CLASSNAMENOMEFANTASIA_COMPANYID_2);

        query.append(_FINDER_COLUMN_CG_CLASSNAMENOMEFANTASIA_GROUPID_2);

        query.append(_FINDER_COLUMN_CG_CLASSNAMENOMEFANTASIA_CLASSNAMEID_2);

        boolean bindNomeFantasia = false;

        if (nomeFantasia == null) {
            query.append(_FINDER_COLUMN_CG_CLASSNAMENOMEFANTASIA_NOMEFANTASIA_1);
        } else if (nomeFantasia.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_CG_CLASSNAMENOMEFANTASIA_NOMEFANTASIA_3);
        } else {
            bindNomeFantasia = true;

            query.append(_FINDER_COLUMN_CG_CLASSNAMENOMEFANTASIA_NOMEFANTASIA_2);
        }

        query.append(_FINDER_COLUMN_CG_CLASSNAMENOMEFANTASIA_STATUS_2);

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

            qPos.add(groupId);

            qPos.add(classNameId);

            if (bindNomeFantasia) {
                qPos.add(nomeFantasia);
            }

            qPos.add(status);

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

                Collections.sort(list);

                list = new UnmodifiableList<Loja>(list);
            } else {
                list = (List<Loja>) 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;
}