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.ContatoPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the contatos where companyId = &#63; and groupId = &#63; and dataNascimento = &#63;.
 *
 * <p>/*w w w . j  a  va 2  s  .c  o  m*/
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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.ContatoModelImpl}. 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 dataNascimento the data nascimento
 * @param start the lower bound of the range of contatos
 * @param end the upper bound of the range of contatos (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching contatos
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Contato> findByC_G_DTN(long companyId, long groupId, Date dataNascimento, 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_DTN;
        finderArgs = new Object[] { companyId, groupId, dataNascimento };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_G_DTN;
        finderArgs = new Object[] { companyId, groupId, dataNascimento,

                start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (Contato contato : list) {
            if ((companyId != contato.getCompanyId()) || (groupId != contato.getGroupId())
                    || !Validator.equals(dataNascimento, contato.getDataNascimento())) {
                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_CONTATO_WHERE);

        query.append(_FINDER_COLUMN_C_G_DTN_COMPANYID_2);

        query.append(_FINDER_COLUMN_C_G_DTN_GROUPID_2);

        boolean bindDataNascimento = false;

        if (dataNascimento == null) {
            query.append(_FINDER_COLUMN_C_G_DTN_DATANASCIMENTO_1);
        } else {
            bindDataNascimento = true;

            query.append(_FINDER_COLUMN_C_G_DTN_DATANASCIMENTO_2);
        }

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(ContatoModelImpl.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 (bindDataNascimento) {
                qPos.add(CalendarUtil.getTimestamp(dataNascimento));
            }

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

                Collections.sort(list);

                list = new UnmodifiableList<Contato>(list);
            } else {
                list = (List<Contato>) 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.ContatoPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the contatos where dataNascimento = &#63;.
 *
 * <p>/*from  w  w w.j  ava  2  s  . c  o  m*/
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link br.com.prodevelopment.lapidarios.contato.model.impl.ContatoModelImpl}. 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 dataNascimento the data nascimento
 * @param start the lower bound of the range of contatos
 * @param end the upper bound of the range of contatos (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching contatos
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Contato> findByDTN(Date dataNascimento, 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_DTN;
        finderArgs = new Object[] { dataNascimento };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_DTN;
        finderArgs = new Object[] { dataNascimento,

                start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (Contato contato : list) {
            if (!Validator.equals(dataNascimento, contato.getDataNascimento())) {
                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_CONTATO_WHERE);

        boolean bindDataNascimento = false;

        if (dataNascimento == null) {
            query.append(_FINDER_COLUMN_DTN_DATANASCIMENTO_1);
        } else {
            bindDataNascimento = true;

            query.append(_FINDER_COLUMN_DTN_DATANASCIMENTO_2);
        }

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindDataNascimento) {
                qPos.add(CalendarUtil.getTimestamp(dataNascimento));
            }

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

                Collections.sort(list);

                list = new UnmodifiableList<Contato>(list);
            } else {
                list = (List<Contato>) 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.ContatoPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the contatos where companyId = &#63; and endEmail = &#63;.
 *
 * <p>/*w  w w .  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.ContatoModelImpl}. 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 endEmail the end email
 * @param start the lower bound of the range of contatos
 * @param end the upper bound of the range of contatos (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching contatos
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Contato> findByC_EMAIL(long companyId, String endEmail, 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_EMAIL;
        finderArgs = new Object[] { companyId, endEmail };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_EMAIL;
        finderArgs = new Object[] { companyId, endEmail,

                start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (Contato contato : list) {
            if ((companyId != contato.getCompanyId()) || !Validator.equals(endEmail, contato.getEndEmail())) {
                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_CONTATO_WHERE);

        query.append(_FINDER_COLUMN_C_EMAIL_COMPANYID_2);

        boolean bindEndEmail = false;

        if (endEmail == null) {
            query.append(_FINDER_COLUMN_C_EMAIL_ENDEMAIL_1);
        } else if (endEmail.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_C_EMAIL_ENDEMAIL_3);
        } else {
            bindEndEmail = true;

            query.append(_FINDER_COLUMN_C_EMAIL_ENDEMAIL_2);
        }

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

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

                Collections.sort(list);

                list = new UnmodifiableList<Contato>(list);
            } else {
                list = (List<Contato>) 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.ContatoPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the contatos where companyId = &#63; and groupId = &#63; and endEmail = &#63;.
 *
 * <p>// w  ww .  j a  v a 2  s . c  om
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link br.com.prodevelopment.lapidarios.contato.model.impl.ContatoModelImpl}. 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 endEmail the end email
 * @param start the lower bound of the range of contatos
 * @param end the upper bound of the range of contatos (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching contatos
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Contato> findByC_G_EMAIL(long companyId, long groupId, String endEmail, 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_EMAIL;
        finderArgs = new Object[] { companyId, groupId, endEmail };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_G_EMAIL;
        finderArgs = new Object[] { companyId, groupId, endEmail,

                start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (Contato contato : list) {
            if ((companyId != contato.getCompanyId()) || (groupId != contato.getGroupId())
                    || !Validator.equals(endEmail, contato.getEndEmail())) {
                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_CONTATO_WHERE);

        query.append(_FINDER_COLUMN_C_G_EMAIL_COMPANYID_2);

        query.append(_FINDER_COLUMN_C_G_EMAIL_GROUPID_2);

        boolean bindEndEmail = false;

        if (endEmail == null) {
            query.append(_FINDER_COLUMN_C_G_EMAIL_ENDEMAIL_1);
        } else if (endEmail.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_C_G_EMAIL_ENDEMAIL_3);
        } else {
            bindEndEmail = true;

            query.append(_FINDER_COLUMN_C_G_EMAIL_ENDEMAIL_2);
        }

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

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

                Collections.sort(list);

                list = new UnmodifiableList<Contato>(list);
            } else {
                list = (List<Contato>) 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.ContatoPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the contatos where endEmail = &#63;.
 *
 * <p>/*from   w  w w.  j ava 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.ContatoModelImpl}. 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 endEmail the end email
 * @param start the lower bound of the range of contatos
 * @param end the upper bound of the range of contatos (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching contatos
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Contato> findByEMAIL(String endEmail, 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_EMAIL;
        finderArgs = new Object[] { endEmail };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_EMAIL;
        finderArgs = new Object[] { endEmail, start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (Contato contato : list) {
            if (!Validator.equals(endEmail, contato.getEndEmail())) {
                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_CONTATO_WHERE);

        boolean bindEndEmail = false;

        if (endEmail == null) {
            query.append(_FINDER_COLUMN_EMAIL_ENDEMAIL_1);
        } else if (endEmail.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_EMAIL_ENDEMAIL_3);
        } else {
            bindEndEmail = true;

            query.append(_FINDER_COLUMN_EMAIL_ENDEMAIL_2);
        }

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindEndEmail) {
                qPos.add(endEmail);
            }

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

                Collections.sort(list);

                list = new UnmodifiableList<Contato>(list);
            } else {
                list = (List<Contato>) 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.ContatoPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the contatos where companyId = &#63; and dataNascimento = &#63;.
 *
 * <p>//  w  w w .j  a v  a 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.contato.model.impl.ContatoModelImpl}. 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 dataNascimento the data nascimento
 * @param start the lower bound of the range of contatos
 * @param end the upper bound of the range of contatos (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching contatos
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Contato> findByC_SEXO(long companyId, Date dataNascimento, 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_SEXO;
        finderArgs = new Object[] { companyId, dataNascimento };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_SEXO;
        finderArgs = new Object[] { companyId, dataNascimento,

                start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (Contato contato : list) {
            if ((companyId != contato.getCompanyId())
                    || !Validator.equals(dataNascimento, contato.getDataNascimento())) {
                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_CONTATO_WHERE);

        query.append(_FINDER_COLUMN_C_SEXO_COMPANYID_2);

        boolean bindDataNascimento = false;

        if (dataNascimento == null) {
            query.append(_FINDER_COLUMN_C_SEXO_DATANASCIMENTO_1);
        } else {
            bindDataNascimento = true;

            query.append(_FINDER_COLUMN_C_SEXO_DATANASCIMENTO_2);
        }

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(ContatoModelImpl.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 (bindDataNascimento) {
                qPos.add(CalendarUtil.getTimestamp(dataNascimento));
            }

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

                Collections.sort(list);

                list = new UnmodifiableList<Contato>(list);
            } else {
                list = (List<Contato>) 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.ContatoPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the contatos where companyId = &#63; and groupId = &#63; and dataNascimento = &#63;.
 *
 * <p>//from 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.contato.model.impl.ContatoModelImpl}. 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 dataNascimento the data nascimento
 * @param start the lower bound of the range of contatos
 * @param end the upper bound of the range of contatos (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching contatos
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Contato> findByC_G_SEXO(long companyId, long groupId, Date dataNascimento, 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_SEXO;
        finderArgs = new Object[] { companyId, groupId, dataNascimento };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_G_SEXO;
        finderArgs = new Object[] { companyId, groupId, dataNascimento,

                start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (Contato contato : list) {
            if ((companyId != contato.getCompanyId()) || (groupId != contato.getGroupId())
                    || !Validator.equals(dataNascimento, contato.getDataNascimento())) {
                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_CONTATO_WHERE);

        query.append(_FINDER_COLUMN_C_G_SEXO_COMPANYID_2);

        query.append(_FINDER_COLUMN_C_G_SEXO_GROUPID_2);

        boolean bindDataNascimento = false;

        if (dataNascimento == null) {
            query.append(_FINDER_COLUMN_C_G_SEXO_DATANASCIMENTO_1);
        } else {
            bindDataNascimento = true;

            query.append(_FINDER_COLUMN_C_G_SEXO_DATANASCIMENTO_2);
        }

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(ContatoModelImpl.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 (bindDataNascimento) {
                qPos.add(CalendarUtil.getTimestamp(dataNascimento));
            }

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

                Collections.sort(list);

                list = new UnmodifiableList<Contato>(list);
            } else {
                list = (List<Contato>) 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.ContatoPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the contatos where dataNascimento = &#63;.
 *
 * <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.contato.model.impl.ContatoModelImpl}. 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 dataNascimento the data nascimento
 * @param start the lower bound of the range of contatos
 * @param end the upper bound of the range of contatos (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching contatos
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Contato> findBySEXO(Date dataNascimento, 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_SEXO;
        finderArgs = new Object[] { dataNascimento };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SEXO;
        finderArgs = new Object[] { dataNascimento,

                start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (Contato contato : list) {
            if (!Validator.equals(dataNascimento, contato.getDataNascimento())) {
                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_CONTATO_WHERE);

        boolean bindDataNascimento = false;

        if (dataNascimento == null) {
            query.append(_FINDER_COLUMN_SEXO_DATANASCIMENTO_1);
        } else {
            bindDataNascimento = true;

            query.append(_FINDER_COLUMN_SEXO_DATANASCIMENTO_2);
        }

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindDataNascimento) {
                qPos.add(CalendarUtil.getTimestamp(dataNascimento));
            }

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

                Collections.sort(list);

                list = new UnmodifiableList<Contato>(list);
            } else {
                list = (List<Contato>) 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.ContatoPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the contatos.
 *
 * <p>/*from ww w. j  a  va  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.ContatoModelImpl}. 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 contatos
 * @param end the upper bound of the range of contatos (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of contatos
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Contato> 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<Contato> list = (List<Contato>) 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_CONTATO);

            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);

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

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

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

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

                Collections.sort(list);

                list = new UnmodifiableList<Contato>(list);
            } else {
                list = (List<Contato>) 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.EnderecoEmailPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the endereco emails where uuid = &#63;.
 *
 * <p>/*w ww .  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.EnderecoEmailModelImpl}. 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 endereco emails
 * @param end the upper bound of the range of endereco emails (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching endereco emails
 * @throws SystemException if a system exception occurred
 */
@Override
public List<EnderecoEmail> 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<EnderecoEmail> list = (List<EnderecoEmail>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (EnderecoEmail enderecoEmail : list) {
            if (!Validator.equals(uuid, enderecoEmail.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_ENDERECOEMAIL_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(EnderecoEmailModelImpl.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<EnderecoEmail>) QueryUtil.list(q, getDialect(), start, end, false);

                Collections.sort(list);

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