Example usage for com.liferay.portal.kernel.util StringUtil wildcardMatches

List of usage examples for com.liferay.portal.kernel.util StringUtil wildcardMatches

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util StringUtil wildcardMatches.

Prototype

public static boolean wildcardMatches(String s, String wildcard, char singleWildcardCharacter,
        char multipleWildcardCharacter, char escapeWildcardCharacter, boolean caseSensitive) 

Source Link

Document

Returns true if the string matches the wildcard pattern.

Usage

From source file:at.meduni.liferay.portlet.rdconnect.service.persistence.CandidatePersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the candidates where country LIKE ? and name LIKE ? and source LIKE ? and candidatetype LIKE ? and subunitof = ?.
 *
 * <p>//from  w ww .j ava  2 s  .c o m
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link at.meduni.liferay.portlet.rdconnect.model.impl.CandidateModelImpl}. 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 country the country
 * @param name the name
 * @param source the source
 * @param candidatetype the candidatetype
 * @param subunitof the subunitof
 * @param start the lower bound of the range of candidates
 * @param end the upper bound of the range of candidates (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching candidates
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Candidate> findByCNST(String country, String name, String source, String candidatetype,
        String subunitof, int start, int end, OrderByComparator orderByComparator) throws SystemException {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CNST;
    finderArgs = new Object[] { country, name, source, candidatetype, subunitof,

            start, end, orderByComparator };

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

    if ((list != null) && !list.isEmpty()) {
        for (Candidate candidate : list) {
            if (!StringUtil.wildcardMatches(candidate.getCountry(), country, CharPool.UNDERLINE,
                    CharPool.PERCENT, CharPool.BACK_SLASH, false)
                    || !StringUtil.wildcardMatches(candidate.getName(), name, CharPool.UNDERLINE,
                            CharPool.PERCENT, CharPool.BACK_SLASH, false)
                    || !StringUtil.wildcardMatches(candidate.getSource(), source, CharPool.UNDERLINE,
                            CharPool.PERCENT, CharPool.BACK_SLASH, false)
                    || !StringUtil.wildcardMatches(candidate.getCandidatetype(), candidatetype,
                            CharPool.UNDERLINE, CharPool.PERCENT, CharPool.BACK_SLASH, false)
                    || !Validator.equals(subunitof, candidate.getSubunitof())) {
                list = null;

                break;
            }
        }
    }

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

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

        query.append(_SQL_SELECT_CANDIDATE_WHERE);

        boolean bindCountry = false;

        if (country == null) {
            query.append(_FINDER_COLUMN_CNST_COUNTRY_1);
        } else if (country.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_CNST_COUNTRY_3);
        } else {
            bindCountry = true;

            query.append(_FINDER_COLUMN_CNST_COUNTRY_2);
        }

        boolean bindName = false;

        if (name == null) {
            query.append(_FINDER_COLUMN_CNST_NAME_1);
        } else if (name.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_CNST_NAME_3);
        } else {
            bindName = true;

            query.append(_FINDER_COLUMN_CNST_NAME_2);
        }

        boolean bindSource = false;

        if (source == null) {
            query.append(_FINDER_COLUMN_CNST_SOURCE_1);
        } else if (source.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_CNST_SOURCE_3);
        } else {
            bindSource = true;

            query.append(_FINDER_COLUMN_CNST_SOURCE_2);
        }

        boolean bindCandidatetype = false;

        if (candidatetype == null) {
            query.append(_FINDER_COLUMN_CNST_CANDIDATETYPE_1);
        } else if (candidatetype.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_CNST_CANDIDATETYPE_3);
        } else {
            bindCandidatetype = true;

            query.append(_FINDER_COLUMN_CNST_CANDIDATETYPE_2);
        }

        boolean bindSubunitof = false;

        if (subunitof == null) {
            query.append(_FINDER_COLUMN_CNST_SUBUNITOF_1);
        } else if (subunitof.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_CNST_SUBUNITOF_3);
        } else {
            bindSubunitof = true;

            query.append(_FINDER_COLUMN_CNST_SUBUNITOF_2);
        }

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindCountry) {
                qPos.add(country.toLowerCase());
            }

            if (bindName) {
                qPos.add(name.toLowerCase());
            }

            if (bindSource) {
                qPos.add(source.toLowerCase());
            }

            if (bindCandidatetype) {
                qPos.add(candidatetype.toLowerCase());
            }

            if (bindSubunitof) {
                qPos.add(subunitof);
            }

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

                Collections.sort(list);

                list = new UnmodifiableList<Candidate>(list);
            } else {
                list = (List<Candidate>) 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:at.meduni.liferay.portlet.rdconnect.service.persistence.CandidatePersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the candidates where country LIKE &#63; and name LIKE &#63; and source LIKE &#63; and candidatetype LIKE &#63; and diseasesfreetext LIKE &#63; and diseasescodes LIKE &#63; and subunitof = &#63;.
 *
 * <p>// w  ww  . ja  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 at.meduni.liferay.portlet.rdconnect.model.impl.CandidateModelImpl}. 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 country the country
 * @param name the name
 * @param source the source
 * @param candidatetype the candidatetype
 * @param diseasesfreetext the diseasesfreetext
 * @param diseasescodes the diseasescodes
 * @param subunitof the subunitof
 * @param start the lower bound of the range of candidates
 * @param end the upper bound of the range of candidates (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching candidates
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Candidate> findByCNSTDD(String country, String name, String source, String candidatetype,
        String diseasesfreetext, String diseasescodes, String subunitof, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CNSTDD;
    finderArgs = new Object[] { country, name, source, candidatetype, diseasesfreetext, diseasescodes,
            subunitof,

            start, end, orderByComparator };

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

    if ((list != null) && !list.isEmpty()) {
        for (Candidate candidate : list) {
            if (!StringUtil.wildcardMatches(candidate.getCountry(), country, CharPool.UNDERLINE,
                    CharPool.PERCENT, CharPool.BACK_SLASH, false)
                    || !StringUtil.wildcardMatches(candidate.getName(), name, CharPool.UNDERLINE,
                            CharPool.PERCENT, CharPool.BACK_SLASH, false)
                    || !StringUtil.wildcardMatches(candidate.getSource(), source, CharPool.UNDERLINE,
                            CharPool.PERCENT, CharPool.BACK_SLASH, false)
                    || !StringUtil.wildcardMatches(candidate.getCandidatetype(), candidatetype,
                            CharPool.UNDERLINE, CharPool.PERCENT, CharPool.BACK_SLASH, false)
                    || !StringUtil.wildcardMatches(candidate.getDiseasesfreetext(), diseasesfreetext,
                            CharPool.UNDERLINE, CharPool.PERCENT, CharPool.BACK_SLASH, false)
                    || !StringUtil.wildcardMatches(candidate.getDiseasescodes(), diseasescodes,
                            CharPool.UNDERLINE, CharPool.PERCENT, CharPool.BACK_SLASH, false)
                    || !Validator.equals(subunitof, candidate.getSubunitof())) {
                list = null;

                break;
            }
        }
    }

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

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

        query.append(_SQL_SELECT_CANDIDATE_WHERE);

        boolean bindCountry = false;

        if (country == null) {
            query.append(_FINDER_COLUMN_CNSTDD_COUNTRY_1);
        } else if (country.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_CNSTDD_COUNTRY_3);
        } else {
            bindCountry = true;

            query.append(_FINDER_COLUMN_CNSTDD_COUNTRY_2);
        }

        boolean bindName = false;

        if (name == null) {
            query.append(_FINDER_COLUMN_CNSTDD_NAME_1);
        } else if (name.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_CNSTDD_NAME_3);
        } else {
            bindName = true;

            query.append(_FINDER_COLUMN_CNSTDD_NAME_2);
        }

        boolean bindSource = false;

        if (source == null) {
            query.append(_FINDER_COLUMN_CNSTDD_SOURCE_1);
        } else if (source.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_CNSTDD_SOURCE_3);
        } else {
            bindSource = true;

            query.append(_FINDER_COLUMN_CNSTDD_SOURCE_2);
        }

        boolean bindCandidatetype = false;

        if (candidatetype == null) {
            query.append(_FINDER_COLUMN_CNSTDD_CANDIDATETYPE_1);
        } else if (candidatetype.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_CNSTDD_CANDIDATETYPE_3);
        } else {
            bindCandidatetype = true;

            query.append(_FINDER_COLUMN_CNSTDD_CANDIDATETYPE_2);
        }

        boolean bindDiseasesfreetext = false;

        if (diseasesfreetext == null) {
            query.append(_FINDER_COLUMN_CNSTDD_DISEASESFREETEXT_1);
        } else if (diseasesfreetext.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_CNSTDD_DISEASESFREETEXT_3);
        } else {
            bindDiseasesfreetext = true;

            query.append(_FINDER_COLUMN_CNSTDD_DISEASESFREETEXT_2);
        }

        boolean bindDiseasescodes = false;

        if (diseasescodes == null) {
            query.append(_FINDER_COLUMN_CNSTDD_DISEASESCODES_1);
        } else if (diseasescodes.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_CNSTDD_DISEASESCODES_3);
        } else {
            bindDiseasescodes = true;

            query.append(_FINDER_COLUMN_CNSTDD_DISEASESCODES_2);
        }

        boolean bindSubunitof = false;

        if (subunitof == null) {
            query.append(_FINDER_COLUMN_CNSTDD_SUBUNITOF_1);
        } else if (subunitof.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_CNSTDD_SUBUNITOF_3);
        } else {
            bindSubunitof = true;

            query.append(_FINDER_COLUMN_CNSTDD_SUBUNITOF_2);
        }

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindCountry) {
                qPos.add(country.toLowerCase());
            }

            if (bindName) {
                qPos.add(name.toLowerCase());
            }

            if (bindSource) {
                qPos.add(source.toLowerCase());
            }

            if (bindCandidatetype) {
                qPos.add(candidatetype.toLowerCase());
            }

            if (bindDiseasesfreetext) {
                qPos.add(diseasesfreetext.toLowerCase());
            }

            if (bindDiseasescodes) {
                qPos.add(diseasescodes.toLowerCase());
            }

            if (bindSubunitof) {
                qPos.add(subunitof);
            }

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

                Collections.sort(list);

                list = new UnmodifiableList<Candidate>(list);
            } else {
                list = (List<Candidate>) 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:at.meduni.liferay.portlet.rdconnect.service.persistence.MasterCandidatePersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the master candidates where country LIKE &#63; and name LIKE &#63; and candidatetype LIKE &#63;.
 *
 * <p>/*from w  w w.  j  ava 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 at.meduni.liferay.portlet.rdconnect.model.impl.MasterCandidateModelImpl}. 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 country the country
 * @param name the name
 * @param candidatetype the candidatetype
 * @param start the lower bound of the range of master candidates
 * @param end the upper bound of the range of master candidates (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching master candidates
 * @throws SystemException if a system exception occurred
 */
@Override
public List<MasterCandidate> findByCNST(String country, String name, String candidatetype, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CNST;
    finderArgs = new Object[] { country, name, candidatetype,

            start, end, orderByComparator };

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

    if ((list != null) && !list.isEmpty()) {
        for (MasterCandidate masterCandidate : list) {
            if (!StringUtil.wildcardMatches(masterCandidate.getCountry(), country, CharPool.UNDERLINE,
                    CharPool.PERCENT, CharPool.BACK_SLASH, false)
                    || !StringUtil.wildcardMatches(masterCandidate.getName(), name, CharPool.UNDERLINE,
                            CharPool.PERCENT, CharPool.BACK_SLASH, false)
                    || !StringUtil.wildcardMatches(masterCandidate.getCandidatetype(), candidatetype,
                            CharPool.UNDERLINE, CharPool.PERCENT, CharPool.BACK_SLASH, false)) {
                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_MASTERCANDIDATE_WHERE);

        boolean bindCountry = false;

        if (country == null) {
            query.append(_FINDER_COLUMN_CNST_COUNTRY_1);
        } else if (country.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_CNST_COUNTRY_3);
        } else {
            bindCountry = true;

            query.append(_FINDER_COLUMN_CNST_COUNTRY_2);
        }

        boolean bindName = false;

        if (name == null) {
            query.append(_FINDER_COLUMN_CNST_NAME_1);
        } else if (name.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_CNST_NAME_3);
        } else {
            bindName = true;

            query.append(_FINDER_COLUMN_CNST_NAME_2);
        }

        boolean bindCandidatetype = false;

        if (candidatetype == null) {
            query.append(_FINDER_COLUMN_CNST_CANDIDATETYPE_1);
        } else if (candidatetype.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_CNST_CANDIDATETYPE_3);
        } else {
            bindCandidatetype = true;

            query.append(_FINDER_COLUMN_CNST_CANDIDATETYPE_2);
        }

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindCountry) {
                qPos.add(country.toLowerCase());
            }

            if (bindName) {
                qPos.add(name.toLowerCase());
            }

            if (bindCandidatetype) {
                qPos.add(candidatetype.toLowerCase());
            }

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

                Collections.sort(list);

                list = new UnmodifiableList<MasterCandidate>(list);
            } else {
                list = (List<MasterCandidate>) 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.cnf.curso.inscricao.service.persistence.CursoInscricaoPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the curso inscricaos where statusMoedaDigital LIKE &#63;.
 *
 * <p>//from   w w  w  .j  a v a2 s .c  o  m
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link br.com.cnf.curso.inscricao.model.impl.CursoInscricaoModelImpl}. 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 statusMoedaDigital the status moeda digital
 * @param start the lower bound of the range of curso inscricaos
 * @param end the upper bound of the range of curso inscricaos (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching curso inscricaos
 * @throws SystemException if a system exception occurred
 */
@Override
public List<CursoInscricao> findByLikeStatusMoedaDigital(String statusMoedaDigital, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LIKESTATUSMOEDADIGITAL;
    finderArgs = new Object[] { statusMoedaDigital,

            start, end, orderByComparator };

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

    if ((list != null) && !list.isEmpty()) {
        for (CursoInscricao cursoInscricao : list) {
            if (!StringUtil.wildcardMatches(cursoInscricao.getStatusMoedaDigital(), statusMoedaDigital,
                    CharPool.UNDERLINE, CharPool.PERCENT, CharPool.BACK_SLASH, true)) {
                list = null;

                break;
            }
        }
    }

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

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

        query.append(_SQL_SELECT_CURSOINSCRICAO_WHERE);

        boolean bindStatusMoedaDigital = false;

        if (statusMoedaDigital == null) {
            query.append(_FINDER_COLUMN_LIKESTATUSMOEDADIGITAL_STATUSMOEDADIGITAL_1);
        } else if (statusMoedaDigital.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_LIKESTATUSMOEDADIGITAL_STATUSMOEDADIGITAL_3);
        } else {
            bindStatusMoedaDigital = true;

            query.append(_FINDER_COLUMN_LIKESTATUSMOEDADIGITAL_STATUSMOEDADIGITAL_2);
        }

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindStatusMoedaDigital) {
                qPos.add(statusMoedaDigital);
            }

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

                Collections.sort(list);

                list = new UnmodifiableList<CursoInscricao>(list);
            } else {
                list = (List<CursoInscricao>) 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.associado.service.persistence.AssociadoPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the associados where companyId = &#63; and nome LIKE &#63;.
 *
 * <p>/*from  www .  jav  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.associado.model.impl.AssociadoModelImpl}. 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 nome the nome
 * @param start the lower bound of the range of associados
 * @param end the upper bound of the range of associados (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching associados
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Associado> findByC_NOME(long companyId, String nome, 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_NOME;
    finderArgs = new Object[] { companyId, nome, start, end, orderByComparator };

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

    if ((list != null) && !list.isEmpty()) {
        for (Associado associado : list) {
            if ((companyId != associado.getCompanyId()) || !StringUtil.wildcardMatches(associado.getNome(),
                    nome, 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_ASSOCIADO_WHERE);

        query.append(_FINDER_COLUMN_C_NOME_COMPANYID_2);

        boolean bindNome = false;

        if (nome == null) {
            query.append(_FINDER_COLUMN_C_NOME_NOME_1);
        } else if (nome.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_C_NOME_NOME_3);
        } else {
            bindNome = true;

            query.append(_FINDER_COLUMN_C_NOME_NOME_2);
        }

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

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

                Collections.sort(list);

                list = new UnmodifiableList<Associado>(list);
            } else {
                list = (List<Associado>) 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.associado.service.persistence.AssociadoPersistenceImpl.java

License:Open Source License

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

            start, end, orderByComparator };

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

    if ((list != null) && !list.isEmpty()) {
        for (Associado associado : list) {
            if ((companyId != associado.getCompanyId()) || (groupId != associado.getGroupId())
                    || !StringUtil.wildcardMatches(associado.getNome(), nome, 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_ASSOCIADO_WHERE);

        query.append(_FINDER_COLUMN_C_G_NOME_COMPANYID_2);

        query.append(_FINDER_COLUMN_C_G_NOME_GROUPID_2);

        boolean bindNome = false;

        if (nome == null) {
            query.append(_FINDER_COLUMN_C_G_NOME_NOME_1);
        } else if (nome.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_C_G_NOME_NOME_3);
        } else {
            bindNome = true;

            query.append(_FINDER_COLUMN_C_G_NOME_NOME_2);
        }

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

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

                Collections.sort(list);

                list = new UnmodifiableList<Associado>(list);
            } else {
                list = (List<Associado>) 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 nome LIKE &#63;.
 *
 * <p>/*from ww  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 nome the nome
 * @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_NOME(long companyId, String nome, 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_NOME;
    finderArgs = new Object[] { companyId, nome, 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()) || !StringUtil.wildcardMatches(contato.getNome(), nome,
                    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_CONTATO_WHERE);

        query.append(_FINDER_COLUMN_C_NOME_COMPANYID_2);

        boolean bindNome = false;

        if (nome == null) {
            query.append(_FINDER_COLUMN_C_NOME_NOME_1);
        } else if (nome.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_C_NOME_NOME_3);
        } else {
            bindNome = true;

            query.append(_FINDER_COLUMN_C_NOME_NOME_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 (bindNome) {
                qPos.add(nome);
            }

            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 nome LIKE &#63;.
 *
 * <p>//from www . j  a  v a2 s. c  o m
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link br.com.prodevelopment.lapidarios.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 nome the nome
 * @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_NOME(long companyId, long groupId, String nome, 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_NOME;
    finderArgs = new Object[] { companyId, groupId, nome,

            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())
                    || !StringUtil.wildcardMatches(contato.getNome(), nome, 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_CONTATO_WHERE);

        query.append(_FINDER_COLUMN_C_G_NOME_COMPANYID_2);

        query.append(_FINDER_COLUMN_C_G_NOME_GROUPID_2);

        boolean bindNome = false;

        if (nome == null) {
            query.append(_FINDER_COLUMN_C_G_NOME_NOME_1);
        } else if (nome.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_C_G_NOME_NOME_3);
        } else {
            bindNome = true;

            query.append(_FINDER_COLUMN_C_G_NOME_NOME_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 (bindNome) {
                qPos.add(nome);
            }

            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 nome LIKE &#63;.
 *
 * <p>//from  www  . 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 nome the nome
 * @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> findByNOME(String nome, int start, int end, OrderByComparator orderByComparator)
        throws SystemException {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NOME;
    finderArgs = new Object[] { nome, start, end, orderByComparator };

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

    if ((list != null) && !list.isEmpty()) {
        for (Contato contato : list) {
            if (!StringUtil.wildcardMatches(contato.getNome(), nome, CharPool.UNDERLINE, CharPool.PERCENT,
                    CharPool.BACK_SLASH, true)) {
                list = null;

                break;
            }
        }
    }

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

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

        query.append(_SQL_SELECT_CONTATO_WHERE);

        boolean bindNome = false;

        if (nome == null) {
            query.append(_FINDER_COLUMN_NOME_NOME_1);
        } else if (nome.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_NOME_NOME_3);
        } else {
            bindNome = true;

            query.append(_FINDER_COLUMN_NOME_NOME_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 (bindNome) {
                qPos.add(nome);
            }

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

License:Open Source License

/**
 * Returns an ordered range of all the enderecos where companyId = &#63; and bairro LIKE &#63;.
 *
 * <p>/*  w ww. jav 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 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;
}