Example usage for com.liferay.portal.kernel.util StringPool OPEN_PARENTHESIS

List of usage examples for com.liferay.portal.kernel.util StringPool OPEN_PARENTHESIS

Introduction

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

Prototype

String OPEN_PARENTHESIS

To view the source code for com.liferay.portal.kernel.util StringPool OPEN_PARENTHESIS.

Click Source Link

Usage

From source file:org.gfbio.service.persistence.SearchFeedbackPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of search feedbacks where searchFeedbackID = any ?.
 *
 * @param searchFeedbackIDs the search feedback i ds
 * @return the number of matching search feedbacks
 * @throws SystemException if a system exception occurred
 *//*from   w  ww.  j av  a  2  s . c o m*/
@Override
public int countBySearchFeedbackIDs(long[] searchFeedbackIDs) throws SystemException {
    Object[] finderArgs = new Object[] { StringUtil.merge(searchFeedbackIDs) };

    Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_SEARCHFEEDBACKIDS,
            finderArgs, this);

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

        query.append(_SQL_COUNT_SEARCHFEEDBACK_WHERE);

        boolean conjunctionable = false;

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

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < searchFeedbackIDs.length; i++) {
                query.append(_FINDER_COLUMN_SEARCHFEEDBACKIDS_SEARCHFEEDBACKID_5);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

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

            count = (Long) q.uniqueResult();

            FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_SEARCHFEEDBACKIDS, finderArgs,
                    count);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_SEARCHFEEDBACKIDS, finderArgs);

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

    return count.intValue();
}

From source file:org.gfbio.service.persistence.SearchFeedbackPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the search feedbacks where rating = any &#63;.
 *
 * <p>//  w w  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 org.gfbio.model.impl.SearchFeedbackModelImpl}. 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 ratings the ratings
 * @param start the lower bound of the range of search feedbacks
 * @param end the upper bound of the range of search feedbacks (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching search feedbacks
 * @throws SystemException if a system exception occurred
 */
@Override
public List<SearchFeedback> findByRating(int[] ratings, int start, int end, OrderByComparator orderByComparator)
        throws SystemException {
    if ((ratings != null) && (ratings.length == 1)) {
        return findByRating(ratings[0], start, end, orderByComparator);
    }

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

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

                start, end, orderByComparator };
    }

    List<SearchFeedback> list = (List<SearchFeedback>) FinderCacheUtil
            .getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_RATING, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (SearchFeedback searchFeedback : list) {
            if (!ArrayUtil.contains(ratings, searchFeedback.getRating())) {
                list = null;

                break;
            }
        }
    }

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

        query.append(_SQL_SELECT_SEARCHFEEDBACK_WHERE);

        boolean conjunctionable = false;

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

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < ratings.length; i++) {
                query.append(_FINDER_COLUMN_RATING_RATING_5);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

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

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

                Collections.sort(list);

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

            cacheResult(list);

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

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

    return list;
}

From source file:org.gfbio.service.persistence.SearchFeedbackPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of search feedbacks where rating = any &#63;.
 *
 * @param ratings the ratings//from   w w  w  . j  a va  2  s .c o m
 * @return the number of matching search feedbacks
 * @throws SystemException if a system exception occurred
 */
@Override
public int countByRating(int[] ratings) throws SystemException {
    Object[] finderArgs = new Object[] { StringUtil.merge(ratings) };

    Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_RATING, finderArgs,
            this);

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

        query.append(_SQL_COUNT_SEARCHFEEDBACK_WHERE);

        boolean conjunctionable = false;

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

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < ratings.length; i++) {
                query.append(_FINDER_COLUMN_RATING_RATING_5);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

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

            count = (Long) q.uniqueResult();

            FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_RATING, finderArgs, count);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_RATING, finderArgs);

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

    return count.intValue();
}

From source file:org.gfbio.service.persistence.SearchFeedbackPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the search feedbacks where rating = any &#63; and lastModifiedDate &gt; &#63;.
 *
 * <p>/*from ww  w.ja 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 org.gfbio.model.impl.SearchFeedbackModelImpl}. 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 ratings the ratings
 * @param lastModifiedDate the last modified date
 * @param start the lower bound of the range of search feedbacks
 * @param end the upper bound of the range of search feedbacks (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching search feedbacks
 * @throws SystemException if a system exception occurred
 */
@Override
public List<SearchFeedback> findByRatingSince(int[] ratings, Date lastModifiedDate, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    if ((ratings != null) && (ratings.length == 1)) {
        return findByRatingSince(ratings[0], lastModifiedDate, start, end, orderByComparator);
    }

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

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

                start, end, orderByComparator };
    }

    List<SearchFeedback> list = (List<SearchFeedback>) FinderCacheUtil
            .getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_RATINGSINCE, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (SearchFeedback searchFeedback : list) {
            if (!ArrayUtil.contains(ratings, searchFeedback.getRating())
                    || !Validator.equals(lastModifiedDate, searchFeedback.getLastModifiedDate())) {
                list = null;

                break;
            }
        }
    }

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

        query.append(_SQL_SELECT_SEARCHFEEDBACK_WHERE);

        boolean conjunctionable = false;

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

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < ratings.length; i++) {
                query.append(_FINDER_COLUMN_RATINGSINCE_RATING_5);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

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

        boolean bindLastModifiedDate = false;

        if (lastModifiedDate == null) {
            query.append(_FINDER_COLUMN_RATINGSINCE_LASTMODIFIEDDATE_4);
        } else {
            bindLastModifiedDate = true;

            query.append(_FINDER_COLUMN_RATINGSINCE_LASTMODIFIEDDATE_5);
        }

        conjunctionable = true;

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

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

            if (bindLastModifiedDate) {
                qPos.add(CalendarUtil.getTimestamp(lastModifiedDate));
            }

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

                Collections.sort(list);

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

            cacheResult(list);

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

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

    return list;
}

From source file:org.gfbio.service.persistence.SearchFeedbackPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of search feedbacks where rating = any &#63; and lastModifiedDate &gt; &#63;.
 *
 * @param ratings the ratings//from   www  .java2  s. co m
 * @param lastModifiedDate the last modified date
 * @return the number of matching search feedbacks
 * @throws SystemException if a system exception occurred
 */
@Override
public int countByRatingSince(int[] ratings, Date lastModifiedDate) throws SystemException {
    Object[] finderArgs = new Object[] { StringUtil.merge(ratings), lastModifiedDate };

    Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_RATINGSINCE, finderArgs,
            this);

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

        query.append(_SQL_COUNT_SEARCHFEEDBACK_WHERE);

        boolean conjunctionable = false;

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

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < ratings.length; i++) {
                query.append(_FINDER_COLUMN_RATINGSINCE_RATING_5);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

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

        boolean bindLastModifiedDate = false;

        if (lastModifiedDate == null) {
            query.append(_FINDER_COLUMN_RATINGSINCE_LASTMODIFIEDDATE_4);
        } else {
            bindLastModifiedDate = true;

            query.append(_FINDER_COLUMN_RATINGSINCE_LASTMODIFIEDDATE_5);
        }

        conjunctionable = true;

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

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

            if (bindLastModifiedDate) {
                qPos.add(CalendarUtil.getTimestamp(lastModifiedDate));
            }

            count = (Long) q.uniqueResult();

            FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_RATINGSINCE, finderArgs, count);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_RATINGSINCE, finderArgs);

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

    return count.intValue();
}

From source file:org.gfbio.service.persistence.SearchHistoryPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the search histories where searchHistoryID = any &#63;.
 *
 * <p>//from  www. j  a v a2 s .  c  om
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link org.gfbio.model.impl.SearchHistoryModelImpl}. 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 searchHistoryIDs the search history i ds
 * @param start the lower bound of the range of search histories
 * @param end the upper bound of the range of search histories (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching search histories
 * @throws SystemException if a system exception occurred
 */
@Override
public List<SearchHistory> findBySearchHistoryIDs(long[] searchHistoryIDs, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    if ((searchHistoryIDs != null) && (searchHistoryIDs.length == 1)) {
        return findBySearchHistoryIDs(searchHistoryIDs[0], start, end, orderByComparator);
    }

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

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

                start, end, orderByComparator };
    }

    List<SearchHistory> list = (List<SearchHistory>) FinderCacheUtil
            .getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_SEARCHHISTORYIDS, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (SearchHistory searchHistory : list) {
            if (!ArrayUtil.contains(searchHistoryIDs, searchHistory.getSearchHistoryID())) {
                list = null;

                break;
            }
        }
    }

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

        query.append(_SQL_SELECT_SEARCHHISTORY_WHERE);

        boolean conjunctionable = false;

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

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < searchHistoryIDs.length; i++) {
                query.append(_FINDER_COLUMN_SEARCHHISTORYIDS_SEARCHHISTORYID_5);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

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

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

                Collections.sort(list);

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

            cacheResult(list);

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

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

    return list;
}

From source file:org.gfbio.service.persistence.SearchHistoryPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of search histories where searchHistoryID = any &#63;.
 *
 * @param searchHistoryIDs the search history i ds
 * @return the number of matching search histories
 * @throws SystemException if a system exception occurred
 *///from w ww  .ja va  2 s. c o m
@Override
public int countBySearchHistoryIDs(long[] searchHistoryIDs) throws SystemException {
    Object[] finderArgs = new Object[] { StringUtil.merge(searchHistoryIDs) };

    Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_SEARCHHISTORYIDS,
            finderArgs, this);

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

        query.append(_SQL_COUNT_SEARCHHISTORY_WHERE);

        boolean conjunctionable = false;

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

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < searchHistoryIDs.length; i++) {
                query.append(_FINDER_COLUMN_SEARCHHISTORYIDS_SEARCHHISTORYID_5);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

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

            count = (Long) q.uniqueResult();

            FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_SEARCHHISTORYIDS, finderArgs, count);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_SEARCHHISTORYIDS, finderArgs);

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

    return count.intValue();
}

From source file:org.lsp.liferay.portlet.advertising.service.persistence.CampaignPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the campaigns where companyId = &#63; and campaignStatus = &#63; and beginDate &le; &#63; and endDate &ge; all &#63;.
 *
 * <p>/*ww  w. j av  a 2s. c  o m*/
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
 * </p>
 *
 * @param companyId the company ID
 * @param campaignStatus the campaign status
 * @param beginDate the begin date
 * @param endDates the end dates
 * @param start the lower bound of the range of campaigns
 * @param end the upper bound of the range of campaigns (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching campaigns
 * @throws SystemException if a system exception occurred
 */
public List<Campaign> findByActiveCampaignsByDate(long companyId, int campaignStatus, Date beginDate,
        Date[] endDates, int start, int end, OrderByComparator orderByComparator) throws SystemException {
    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVECAMPAIGNSBYDATE;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        finderArgs = new Object[] { companyId, campaignStatus, beginDate, StringUtil.merge(endDates) };
    } else {
        finderArgs = new Object[] { companyId, campaignStatus, beginDate, StringUtil.merge(endDates),

                start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (Campaign campaign : list) {
            if ((companyId != campaign.getCompanyId()) || (campaignStatus != campaign.getCampaignStatus())
                    || !Validator.equals(beginDate, campaign.getBeginDate())
                    || !ArrayUtil.contains(endDates, campaign.getEndDate())) {
                list = null;

                break;
            }
        }
    }

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

        query.append(_SQL_SELECT_CAMPAIGN_WHERE);

        boolean conjunctionable = false;

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

        query.append(_FINDER_COLUMN_ACTIVECAMPAIGNSBYDATE_COMPANYID_5);

        conjunctionable = true;

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

        query.append(_FINDER_COLUMN_ACTIVECAMPAIGNSBYDATE_CAMPAIGNSTATUS_5);

        conjunctionable = true;

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

        if (beginDate == null) {
            query.append(_FINDER_COLUMN_ACTIVECAMPAIGNSBYDATE_BEGINDATE_4);
        } else {
            query.append(_FINDER_COLUMN_ACTIVECAMPAIGNSBYDATE_BEGINDATE_5);
        }

        conjunctionable = true;

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

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < endDates.length; i++) {
                Date endDate = endDates[i];

                if (endDate == null) {
                    query.append(_FINDER_COLUMN_ACTIVECAMPAIGNSBYDATE_ENDDATE_4);
                } else {
                    query.append(_FINDER_COLUMN_ACTIVECAMPAIGNSBYDATE_ENDDATE_5);
                }

                if ((i + 1) < endDates.length) {
                    query.append(WHERE_AND);
                }
            }

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        }

        else {
            query.append(CampaignModelImpl.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(campaignStatus);

            if (beginDate != null) {
                qPos.add(CalendarUtil.getTimestamp(beginDate));
            }

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

            list = (List<Campaign>) QueryUtil.list(q, getDialect(), start, end);
        } catch (Exception e) {
            throw processException(e);
        } finally {
            if (list == null) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);
            } else {
                cacheResult(list);

                FinderCacheUtil.putResult(finderPath, finderArgs, list);
            }

            closeSession(session);
        }
    }

    return list;
}

From source file:org.lsp.liferay.portlet.advertising.service.persistence.CampaignPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of campaigns where companyId = &#63; and campaignStatus = &#63; and beginDate &le; &#63; and endDate &ge; all &#63;.
 *
 * @param companyId the company ID/*from w  w  w .ja v a2 s  . co m*/
 * @param campaignStatus the campaign status
 * @param beginDate the begin date
 * @param endDates the end dates
 * @return the number of matching campaigns
 * @throws SystemException if a system exception occurred
 */
public int countByActiveCampaignsByDate(long companyId, int campaignStatus, Date beginDate, Date[] endDates)
        throws SystemException {
    Object[] finderArgs = new Object[] { companyId, campaignStatus, beginDate, StringUtil.merge(endDates) };

    Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_ACTIVECAMPAIGNSBYDATE,
            finderArgs, this);

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

        query.append(_SQL_COUNT_CAMPAIGN_WHERE);

        boolean conjunctionable = false;

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

        query.append(_FINDER_COLUMN_ACTIVECAMPAIGNSBYDATE_COMPANYID_5);

        conjunctionable = true;

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

        query.append(_FINDER_COLUMN_ACTIVECAMPAIGNSBYDATE_CAMPAIGNSTATUS_5);

        conjunctionable = true;

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

        if (beginDate == null) {
            query.append(_FINDER_COLUMN_ACTIVECAMPAIGNSBYDATE_BEGINDATE_4);
        } else {
            query.append(_FINDER_COLUMN_ACTIVECAMPAIGNSBYDATE_BEGINDATE_5);
        }

        conjunctionable = true;

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

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < endDates.length; i++) {
                Date endDate = endDates[i];

                if (endDate == null) {
                    query.append(_FINDER_COLUMN_ACTIVECAMPAIGNSBYDATE_ENDDATE_4);
                } else {
                    query.append(_FINDER_COLUMN_ACTIVECAMPAIGNSBYDATE_ENDDATE_5);
                }

                if ((i + 1) < endDates.length) {
                    query.append(WHERE_AND);
                }
            }

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

        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(campaignStatus);

            if (beginDate != null) {
                qPos.add(CalendarUtil.getTimestamp(beginDate));
            }

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

            count = (Long) q.uniqueResult();
        } catch (Exception e) {
            throw processException(e);
        } finally {
            if (count == null) {
                count = Long.valueOf(0);
            }

            FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_ACTIVECAMPAIGNSBYDATE, finderArgs,
                    count);

            closeSession(session);
        }
    }

    return count.intValue();
}

From source file:org.lsug.quota.service.persistence.impl.QuotaPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the quotas where classNameId = &#63;, optionally using the finder cache.
 *
 * <p>//from  w  w w.  j av  a 2 s. c  o m
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link QuotaModelImpl}. 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 classNameId the class name ID
 * @param start the lower bound of the range of quotas
 * @param end the upper bound of the range of quotas (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @param retrieveFromCache whether to retrieve from the finder cache
 * @return the ordered range of matching quotas
 */
@Override
public List<Quota> findByCN(long[] classNameIds, int start, int end, OrderByComparator<Quota> orderByComparator,
        boolean retrieveFromCache) {
    if (classNameIds == null) {
        classNameIds = new long[0];
    } else if (classNameIds.length > 1) {
        classNameIds = ArrayUtil.unique(classNameIds);

        Arrays.sort(classNameIds);
    }

    if (classNameIds.length == 1) {
        return findByCN(classNameIds[0], start, end, orderByComparator);
    }

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

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

                start, end, orderByComparator };
    }

    List<Quota> list = null;

    if (retrieveFromCache) {
        list = (List<Quota>) finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_CN, finderArgs, this);

        if ((list != null) && !list.isEmpty()) {
            for (Quota quota : list) {
                if (!ArrayUtil.contains(classNameIds, quota.getClassNameId())) {
                    list = null;

                    break;
                }
            }
        }
    }

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

        query.append(_SQL_SELECT_QUOTA_WHERE);

        if (classNameIds.length > 0) {
            query.append(StringPool.OPEN_PARENTHESIS);

            query.append(_FINDER_COLUMN_CN_CLASSNAMEID_7);

            query.append(StringUtil.merge(classNameIds));

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(StringPool.CLOSE_PARENTHESIS);
        }

        query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)), query.index() - 1);

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

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

                Collections.sort(list);

                list = Collections.unmodifiableList(list);
            } else {
                list = (List<Quota>) QueryUtil.list(q, getDialect(), start, end);
            }

            cacheResult(list);

            finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_CN, finderArgs, list);
        } catch (Exception e) {
            finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_CN, finderArgs);

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

    return list;
}