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.contato.service.persistence.EnderecoPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the enderecos where companyId = &#63; and groupId = &#63; and classNameId = &#63;.
 *
 * <p>//  w w  w  .  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.contato.model.impl.EnderecoModelImpl}. 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 start the lower bound of the range of enderecos
 * @param end the upper bound of the range of enderecos (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching enderecos
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Endereco> findByC_G_U(long companyId, long groupId, long classNameId, 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_C_G_U;
        finderArgs = new Object[] { companyId, groupId, classNameId };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_G_U;
        finderArgs = new Object[] { companyId, groupId, classNameId,

                start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (Endereco endereco : list) {
            if ((companyId != endereco.getCompanyId()) || (groupId != endereco.getGroupId())
                    || (classNameId != endereco.getClassNameId())) {
                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_ENDERECO_WHERE);

        query.append(_FINDER_COLUMN_C_G_U_COMPANYID_2);

        query.append(_FINDER_COLUMN_C_G_U_GROUPID_2);

        query.append(_FINDER_COLUMN_C_G_U_CLASSNAMEID_2);

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

                Collections.sort(list);

                list = new UnmodifiableList<Endereco>(list);
            } else {
                list = (List<Endereco>) 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.contato.service.persistence.EnderecoPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the enderecos where companyId = &#63; and classNameId = &#63;.
 *
 * <p>//from   w ww  .j  a v 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.contato.model.impl.EnderecoModelImpl}. 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 classNameId the class name ID
 * @param start the lower bound of the range of enderecos
 * @param end the upper bound of the range of enderecos (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching enderecos
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Endereco> findByC_C(long companyId, long classNameId, 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_C_C;
        finderArgs = new Object[] { companyId, classNameId };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
        finderArgs = new Object[] { companyId, classNameId,

                start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (Endereco endereco : list) {
            if ((companyId != endereco.getCompanyId()) || (classNameId != endereco.getClassNameId())) {
                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_ENDERECO_WHERE);

        query.append(_FINDER_COLUMN_C_C_COMPANYID_2);

        query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);

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

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

                Collections.sort(list);

                list = new UnmodifiableList<Endereco>(list);
            } else {
                list = (List<Endereco>) 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.contato.service.persistence.EnderecoPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the enderecos where companyId = &#63; and groupId = &#63; and classNameId = &#63;.
 *
 * <p>/*from  w w w  .j  ava2s .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.contato.model.impl.EnderecoModelImpl}. 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 start the lower bound of the range of enderecos
 * @param end the upper bound of the range of enderecos (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching enderecos
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Endereco> findByC_C_G(long companyId, long groupId, long classNameId, 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_C_C_G;
        finderArgs = new Object[] { companyId, groupId, classNameId };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_G;
        finderArgs = new Object[] { companyId, groupId, classNameId,

                start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (Endereco endereco : list) {
            if ((companyId != endereco.getCompanyId()) || (groupId != endereco.getGroupId())
                    || (classNameId != endereco.getClassNameId())) {
                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_ENDERECO_WHERE);

        query.append(_FINDER_COLUMN_C_C_G_COMPANYID_2);

        query.append(_FINDER_COLUMN_C_C_G_GROUPID_2);

        query.append(_FINDER_COLUMN_C_C_G_CLASSNAMEID_2);

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

                Collections.sort(list);

                list = new UnmodifiableList<Endereco>(list);
            } else {
                list = (List<Endereco>) 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.contato.service.persistence.EnderecoPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the enderecos where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
 *
 * <p>/*from  w  w  w.  j av  a2 s.co m*/
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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.contato.model.impl.EnderecoModelImpl}. 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 classNameId the class name ID
 * @param classPK the class p k
 * @param start the lower bound of the range of enderecos
 * @param end the upper bound of the range of enderecos (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching enderecos
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Endereco> findByC_C_C(long companyId, long classNameId, long classPK, 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_C_C_C;
        finderArgs = new Object[] { companyId, classNameId, classPK };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C;
        finderArgs = new Object[] { companyId, classNameId, classPK,

                start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (Endereco endereco : list) {
            if ((companyId != endereco.getCompanyId()) || (classNameId != endereco.getClassNameId())
                    || (classPK != endereco.getClassPK())) {
                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_ENDERECO_WHERE);

        query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);

        query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);

        query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);

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

            qPos.add(classPK);

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

                Collections.sort(list);

                list = new UnmodifiableList<Endereco>(list);
            } else {
                list = (List<Endereco>) 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.contato.service.persistence.EnderecoPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the enderecos where companyId = &#63; and classNameId = &#63; and classPK = &#63; and principal = &#63;.
 *
 * <p>/*from   www  .  ja  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.contato.model.impl.EnderecoModelImpl}. 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 classNameId the class name ID
 * @param classPK the class p k
 * @param principal the principal
 * @param start the lower bound of the range of enderecos
 * @param end the upper bound of the range of enderecos (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching enderecos
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Endereco> findByC_C_C_P(long companyId, long classNameId, long classPK, boolean principal,
        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_C_C_C_P;
        finderArgs = new Object[] { companyId, classNameId, classPK, principal };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C_P;
        finderArgs = new Object[] { companyId, classNameId, classPK, principal,

                start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (Endereco endereco : list) {
            if ((companyId != endereco.getCompanyId()) || (classNameId != endereco.getClassNameId())
                    || (classPK != endereco.getClassPK()) || (principal != endereco.getPrincipal())) {
                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_ENDERECO_WHERE);

        query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);

        query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);

        query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);

        query.append(_FINDER_COLUMN_C_C_C_P_PRINCIPAL_2);

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

            qPos.add(classPK);

            qPos.add(principal);

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

                Collections.sort(list);

                list = new UnmodifiableList<Endereco>(list);
            } else {
                list = (List<Endereco>) 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.contato.service.persistence.EnderecoPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the enderecos where companyId = &#63; and cep = &#63;.
 *
 * <p>/*ww w.  j  ava2s.  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.contato.model.impl.EnderecoModelImpl}. 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 cep the cep
 * @param start the lower bound of the range of enderecos
 * @param end the upper bound of the range of enderecos (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching enderecos
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Endereco> findByC_CEP(long companyId, String cep, 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_C_CEP;
        finderArgs = new Object[] { companyId, cep };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_CEP;
        finderArgs = new Object[] { companyId, cep,

                start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (Endereco endereco : list) {
            if ((companyId != endereco.getCompanyId()) || !Validator.equals(cep, endereco.getCep())) {
                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_ENDERECO_WHERE);

        query.append(_FINDER_COLUMN_C_CEP_COMPANYID_2);

        boolean bindCep = false;

        if (cep == null) {
            query.append(_FINDER_COLUMN_C_CEP_CEP_1);
        } else if (cep.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_C_CEP_CEP_3);
        } else {
            bindCep = true;

            query.append(_FINDER_COLUMN_C_CEP_CEP_2);
        }

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

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

                Collections.sort(list);

                list = new UnmodifiableList<Endereco>(list);
            } else {
                list = (List<Endereco>) 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.contato.service.persistence.EnderecoPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the enderecos where companyId = &#63; and groupId = &#63; and cep = &#63;.
 *
 * <p>/*from   w w w.ja va2s.c o m*/
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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.contato.model.impl.EnderecoModelImpl}. 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 cep the cep
 * @param start the lower bound of the range of enderecos
 * @param end the upper bound of the range of enderecos (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching enderecos
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Endereco> findByC_G_CEP(long companyId, long groupId, String cep, 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_C_G_CEP;
        finderArgs = new Object[] { companyId, groupId, cep };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_G_CEP;
        finderArgs = new Object[] { companyId, groupId, cep,

                start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (Endereco endereco : list) {
            if ((companyId != endereco.getCompanyId()) || (groupId != endereco.getGroupId())
                    || !Validator.equals(cep, endereco.getCep())) {
                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_ENDERECO_WHERE);

        query.append(_FINDER_COLUMN_C_G_CEP_COMPANYID_2);

        query.append(_FINDER_COLUMN_C_G_CEP_GROUPID_2);

        boolean bindCep = false;

        if (cep == null) {
            query.append(_FINDER_COLUMN_C_G_CEP_CEP_1);
        } else if (cep.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_C_G_CEP_CEP_3);
        } else {
            bindCep = true;

            query.append(_FINDER_COLUMN_C_G_CEP_CEP_2);
        }

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

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

                Collections.sort(list);

                list = new UnmodifiableList<Endereco>(list);
            } else {
                list = (List<Endereco>) 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.contato.service.persistence.EnderecoPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the enderecos where cep = &#63;.
 *
 * <p>/*from ww  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.contato.model.impl.EnderecoModelImpl}. 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 cep the cep
 * @param start the lower bound of the range of enderecos
 * @param end the upper bound of the range of enderecos (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching enderecos
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Endereco> findByCEP(String cep, 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_CEP;
        finderArgs = new Object[] { cep };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CEP;
        finderArgs = new Object[] { cep, start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (Endereco endereco : list) {
            if (!Validator.equals(cep, endereco.getCep())) {
                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_ENDERECO_WHERE);

        boolean bindCep = false;

        if (cep == null) {
            query.append(_FINDER_COLUMN_CEP_CEP_1);
        } else if (cep.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_CEP_CEP_3);
        } else {
            bindCep = true;

            query.append(_FINDER_COLUMN_CEP_CEP_2);
        }

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindCep) {
                qPos.add(cep);
            }

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

                Collections.sort(list);

                list = new UnmodifiableList<Endereco>(list);
            } else {
                list = (List<Endereco>) 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.contato.service.persistence.EnderecoPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the enderecos where companyId = &#63; and bairro LIKE &#63;.
 *
 * <p>/*from   w  w  w  . 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.contato.model.impl.EnderecoModelImpl}. 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 bairro the bairro
 * @param start the lower bound of the range of enderecos
 * @param end the upper bound of the range of enderecos (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching enderecos
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Endereco> findByC_BAIRRO(long companyId, String bairro, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_BAIRRO;
    finderArgs = new Object[] { companyId, bairro,

            start, end, orderByComparator };

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

    if ((list != null) && !list.isEmpty()) {
        for (Endereco endereco : list) {
            if ((companyId != endereco.getCompanyId()) || !StringUtil.wildcardMatches(endereco.getBairro(),
                    bairro, CharPool.UNDERLINE, CharPool.PERCENT, CharPool.BACK_SLASH, true)) {
                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_ENDERECO_WHERE);

        query.append(_FINDER_COLUMN_C_BAIRRO_COMPANYID_2);

        boolean bindBairro = false;

        if (bairro == null) {
            query.append(_FINDER_COLUMN_C_BAIRRO_BAIRRO_1);
        } else if (bairro.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_C_BAIRRO_BAIRRO_3);
        } else {
            bindBairro = true;

            query.append(_FINDER_COLUMN_C_BAIRRO_BAIRRO_2);
        }

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

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

                Collections.sort(list);

                list = new UnmodifiableList<Endereco>(list);
            } else {
                list = (List<Endereco>) 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.contato.service.persistence.EnderecoPersistenceImpl.java

License:Open Source License

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

    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_G_BAIRRO;
    finderArgs = new Object[] { companyId, groupId, bairro,

            start, end, orderByComparator };

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

    if ((list != null) && !list.isEmpty()) {
        for (Endereco endereco : list) {
            if ((companyId != endereco.getCompanyId()) || (groupId != endereco.getGroupId())
                    || !StringUtil.wildcardMatches(endereco.getBairro(), bairro, 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_ENDERECO_WHERE);

        query.append(_FINDER_COLUMN_C_G_BAIRRO_COMPANYID_2);

        query.append(_FINDER_COLUMN_C_G_BAIRRO_GROUPID_2);

        boolean bindBairro = false;

        if (bairro == null) {
            query.append(_FINDER_COLUMN_C_G_BAIRRO_BAIRRO_1);
        } else if (bairro.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_C_G_BAIRRO_BAIRRO_3);
        } else {
            bindBairro = true;

            query.append(_FINDER_COLUMN_C_G_BAIRRO_BAIRRO_2);
        }

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

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

                Collections.sort(list);

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