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 classNameId = &#63; and nomeFantasia LIKE &#63; and status = any &#63;.
 *
 * <p>/*from   ww w  .  java 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 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_ClassNameNomeFantasia(long companyId, long groupId, long classNameId,
        String nomeFantasia, int[] statuses, int start, int end, OrderByComparator orderByComparator)
        throws SystemException {
    if ((statuses != null) && (statuses.length == 1)) {
        return findByCG_ClassNameNomeFantasia(companyId, groupId, classNameId, 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, classNameId, nomeFantasia, StringUtil.merge(statuses) };
    } else {
        finderArgs = new Object[] { companyId, groupId, classNameId, nomeFantasia, StringUtil.merge(statuses),

                start, end, orderByComparator };
    }

    List<Loja> list = (List<Loja>) FinderCacheUtil
            .getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_CG_CLASSNAMENOMEFANTASIA, 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)
                    || !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_CLASSNAMENOMEFANTASIA_COMPANYID_5);

        conjunctionable = true;

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

        query.append(_FINDER_COLUMN_CG_CLASSNAMENOMEFANTASIA_GROUPID_5);

        conjunctionable = true;

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

        query.append(_FINDER_COLUMN_CG_CLASSNAMENOMEFANTASIA_CLASSNAMEID_5);

        conjunctionable = true;

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

        boolean bindNomeFantasia = false;

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

            query.append(_FINDER_COLUMN_CG_CLASSNAMENOMEFANTASIA_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_CLASSNAMENOMEFANTASIA_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 (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_CLASSNAMENOMEFANTASIA, finderArgs,
                    list);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_CG_CLASSNAMENOMEFANTASIA,
                    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.
 *
 * <p>//from   w ww  . j a  va 2 s.co m
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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 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 lojas
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Loja> 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<Loja> list = (List<Loja>) 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_LOJA);

            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);

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

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

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            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.lojaindicada.service.persistence.LojaIndicadaPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the loja indicadas where uuid = &#63;.
 *
 * <p>/*w  ww .j  a v a  2 s  .  com*/
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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.lojaindicada.model.impl.LojaIndicadaModelImpl}. 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 loja indicadas
 * @param end the upper bound of the range of loja indicadas (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching loja indicadas
 * @throws SystemException if a system exception occurred
 */
@Override
public List<LojaIndicada> findByUuid(String uuid, 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_UUID;
        finderArgs = new Object[] { uuid };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
        finderArgs = new Object[] { uuid, start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (LojaIndicada lojaIndicada : list) {
            if (!Validator.equals(uuid, lojaIndicada.getUuid())) {
                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_LOJAINDICADA_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(LojaIndicadaModelImpl.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<LojaIndicada>) QueryUtil.list(q, getDialect(), start, end, false);

                Collections.sort(list);

                list = new UnmodifiableList<LojaIndicada>(list);
            } else {
                list = (List<LojaIndicada>) 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.lojaindicada.service.persistence.LojaIndicadaPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the loja indicadas where uuid = &#63; and companyId = &#63;.
 *
 * <p>//  www. j a  va 2  s .co  m
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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.lojaindicada.model.impl.LojaIndicadaModelImpl}. 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 loja indicadas
 * @param end the upper bound of the range of loja indicadas (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching loja indicadas
 * @throws SystemException if a system exception occurred
 */
@Override
public List<LojaIndicada> findByUuid_C(String uuid, long companyId, 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_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<LojaIndicada> list = (List<LojaIndicada>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (LojaIndicada lojaIndicada : list) {
            if (!Validator.equals(uuid, lojaIndicada.getUuid()) || (companyId != lojaIndicada.getCompanyId())) {
                list = null;

                break;
            }
        }
    }

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

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

        query.append(_SQL_SELECT_LOJAINDICADA_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(LojaIndicadaModelImpl.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<LojaIndicada>) QueryUtil.list(q, getDialect(), start, end, false);

                Collections.sort(list);

                list = new UnmodifiableList<LojaIndicada>(list);
            } else {
                list = (List<LojaIndicada>) 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.lojaindicada.service.persistence.LojaIndicadaPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the loja indicadas where companyId = &#63;.
 *
 * <p>//w  w  w.j  a v a 2s  .c  om
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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.lojaindicada.model.impl.LojaIndicadaModelImpl}. 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 start the lower bound of the range of loja indicadas
 * @param end the upper bound of the range of loja indicadas (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching loja indicadas
 * @throws SystemException if a system exception occurred
 */
@Override
public List<LojaIndicada> findByCompany(long companyId, 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_COMPANY;
        finderArgs = new Object[] { companyId };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANY;
        finderArgs = new Object[] { companyId, start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (LojaIndicada lojaIndicada : list) {
            if ((companyId != lojaIndicada.getCompanyId())) {
                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_LOJAINDICADA_WHERE);

        query.append(_FINDER_COLUMN_COMPANY_COMPANYID_2);

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

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

                Collections.sort(list);

                list = new UnmodifiableList<LojaIndicada>(list);
            } else {
                list = (List<LojaIndicada>) 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.lojaindicada.service.persistence.LojaIndicadaPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the loja indicadas where companyId = &#63; and groupId = &#63;.
 *
 * <p>//from  w w 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 br.com.prodevelopment.lapidarios.lojaindicada.model.impl.LojaIndicadaModelImpl}. 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 start the lower bound of the range of loja indicadas
 * @param end the upper bound of the range of loja indicadas (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching loja indicadas
 * @throws SystemException if a system exception occurred
 */
@Override
public List<LojaIndicada> findByCG(long companyId, long groupId, 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;
        finderArgs = new Object[] { companyId, groupId };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CG;
        finderArgs = new Object[] { companyId, groupId,

                start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (LojaIndicada lojaIndicada : list) {
            if ((companyId != lojaIndicada.getCompanyId()) || (groupId != lojaIndicada.getGroupId())) {
                list = null;

                break;
            }
        }
    }

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

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

        query.append(_SQL_SELECT_LOJAINDICADA_WHERE);

        query.append(_FINDER_COLUMN_CG_COMPANYID_2);

        query.append(_FINDER_COLUMN_CG_GROUPID_2);

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(LojaIndicadaModelImpl.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 (!pagination) {
                list = (List<LojaIndicada>) QueryUtil.list(q, getDialect(), start, end, false);

                Collections.sort(list);

                list = new UnmodifiableList<LojaIndicada>(list);
            } else {
                list = (List<LojaIndicada>) 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.lojaindicada.service.persistence.LojaIndicadaPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the loja indicadas where companyId = &#63; and groupId = &#63; and idLoja LIKE &#63;.
 *
 * <p>//w  ww.j  a  v 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 br.com.prodevelopment.lapidarios.lojaindicada.model.impl.LojaIndicadaModelImpl}. 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 idLoja the id loja
 * @param start the lower bound of the range of loja indicadas
 * @param end the upper bound of the range of loja indicadas (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching loja indicadas
 * @throws SystemException if a system exception occurred
 */
@Override
public List<LojaIndicada> findByCG_IdLoja(long companyId, long groupId, String idLoja, 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_IDLOJA;
    finderArgs = new Object[] { companyId, groupId, idLoja,

            start, end, orderByComparator };

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

    if ((list != null) && !list.isEmpty()) {
        for (LojaIndicada lojaIndicada : list) {
            if ((companyId != lojaIndicada.getCompanyId()) || (groupId != lojaIndicada.getGroupId())
                    || !StringUtil.wildcardMatches(lojaIndicada.getIdLoja(), idLoja, CharPool.UNDERLINE,
                            CharPool.PERCENT, CharPool.BACK_SLASH, true)) {
                list = null;

                break;
            }
        }
    }

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

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

        query.append(_SQL_SELECT_LOJAINDICADA_WHERE);

        query.append(_FINDER_COLUMN_CG_IDLOJA_COMPANYID_2);

        query.append(_FINDER_COLUMN_CG_IDLOJA_GROUPID_2);

        boolean bindIdLoja = false;

        if (idLoja == null) {
            query.append(_FINDER_COLUMN_CG_IDLOJA_IDLOJA_1);
        } else if (idLoja.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_CG_IDLOJA_IDLOJA_3);
        } else {
            bindIdLoja = true;

            query.append(_FINDER_COLUMN_CG_IDLOJA_IDLOJA_2);
        }

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(LojaIndicadaModelImpl.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 (bindIdLoja) {
                qPos.add(idLoja);
            }

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

                Collections.sort(list);

                list = new UnmodifiableList<LojaIndicada>(list);
            } else {
                list = (List<LojaIndicada>) 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.lojaindicada.service.persistence.LojaIndicadaPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the loja indicadas.
 *
 * <p>// w  ww .j  av  a 2s . c om
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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.lojaindicada.model.impl.LojaIndicadaModelImpl}. 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 loja indicadas
 * @param end the upper bound of the range of loja indicadas (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of loja indicadas
 * @throws SystemException if a system exception occurred
 */
@Override
public List<LojaIndicada> 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<LojaIndicada> list = (List<LojaIndicada>) 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_LOJAINDICADA);

            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);

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

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

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

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

                Collections.sort(list);

                list = new UnmodifiableList<LojaIndicada>(list);
            } else {
                list = (List<LojaIndicada>) 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.municipio.service.persistence.MunicipioPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the municipios where uf = &#63;.
 *
 * <p>/*from   w w  w  .  jav  a2  s.co  m*/
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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.municipio.model.impl.MunicipioModelImpl}. 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 uf the uf
 * @param start the lower bound of the range of municipios
 * @param end the upper bound of the range of municipios (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching municipios
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Municipio> findByUF(String uf, 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_UF;
        finderArgs = new Object[] { uf };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UF;
        finderArgs = new Object[] { uf, start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (Municipio municipio : list) {
            if (!Validator.equals(uf, municipio.getUf())) {
                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_MUNICIPIO_WHERE);

        boolean bindUf = false;

        if (uf == null) {
            query.append(_FINDER_COLUMN_UF_UF_1);
        } else if (uf.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_UF_UF_3);
        } else {
            bindUf = true;

            query.append(_FINDER_COLUMN_UF_UF_2);
        }

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindUf) {
                qPos.add(uf);
            }

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

                Collections.sort(list);

                list = new UnmodifiableList<Municipio>(list);
            } else {
                list = (List<Municipio>) 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.municipio.service.persistence.MunicipioPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the municipios where cidade LIKE &#63;.
 *
 * <p>/*w  ww.j  a va 2 s.c  o m*/
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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.municipio.model.impl.MunicipioModelImpl}. 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 cidade the cidade
 * @param start the lower bound of the range of municipios
 * @param end the upper bound of the range of municipios (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching municipios
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Municipio> findByCIDADE(String cidade, int start, int end, OrderByComparator orderByComparator)
        throws SystemException {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CIDADE;
    finderArgs = new Object[] { cidade, start, end, orderByComparator };

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

    if ((list != null) && !list.isEmpty()) {
        for (Municipio municipio : list) {
            if (!StringUtil.wildcardMatches(municipio.getCidade(), cidade, 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_MUNICIPIO_WHERE);

        boolean bindCidade = false;

        if (cidade == null) {
            query.append(_FINDER_COLUMN_CIDADE_CIDADE_1);
        } else if (cidade.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_CIDADE_CIDADE_3);
        } else {
            bindCidade = true;

            query.append(_FINDER_COLUMN_CIDADE_CIDADE_2);
        }

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindCidade) {
                qPos.add(cidade);
            }

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

                Collections.sort(list);

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