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

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

Introduction

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

Prototype

String CLOSE_PARENTHESIS

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

Click Source Link

Usage

From source file:com.liferay.chat.service.persistence.impl.StatusPersistenceImpl.java

License:Open Source License

@Override
public Map<Serializable, Status> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }/*  w  w  w  . ja  v  a 2 s .  com*/

    Map<Serializable, Status> map = new HashMap<Serializable, Status>();

    if (primaryKeys.size() == 1) {
        Iterator<Serializable> iterator = primaryKeys.iterator();

        Serializable primaryKey = iterator.next();

        Status status = fetchByPrimaryKey(primaryKey);

        if (status != null) {
            map.put(primaryKey, status);
        }

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        Status status = (Status) EntityCacheUtil.getResult(StatusModelImpl.ENTITY_CACHE_ENABLED,
                StatusImpl.class, primaryKey);

        if (status == null) {
            if (uncachedPrimaryKeys == null) {
                uncachedPrimaryKeys = new HashSet<Serializable>();
            }

            uncachedPrimaryKeys.add(primaryKey);
        } else {
            map.put(primaryKey, status);
        }
    }

    if (uncachedPrimaryKeys == null) {
        return map;
    }

    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1);

    query.append(_SQL_SELECT_STATUS_WHERE_PKS_IN);

    for (Serializable primaryKey : uncachedPrimaryKeys) {
        query.append(String.valueOf(primaryKey));

        query.append(StringPool.COMMA);
    }

    query.setIndex(query.index() - 1);

    query.append(StringPool.CLOSE_PARENTHESIS);

    String sql = query.toString();

    Session session = null;

    try {
        session = openSession();

        Query q = session.createQuery(sql);

        for (Status status : (List<Status>) q.list()) {
            map.put(status.getPrimaryKeyObj(), status);

            cacheResult(status);

            uncachedPrimaryKeys.remove(status.getPrimaryKeyObj());
        }

        for (Serializable primaryKey : uncachedPrimaryKeys) {
            EntityCacheUtil.putResult(StatusModelImpl.ENTITY_CACHE_ENABLED, StatusImpl.class, primaryKey,
                    _nullStatus);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    return map;
}

From source file:com.liferay.content.targeting.analytics.service.persistence.AnalyticsReferrerPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the analytics referrers where analyticsEventId = any &#63; and referrerClassName = &#63; and referrerClassPK = &#63;.
 *
 * <p>/*from   w w w. ja  va  2  s  .c om*/
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.content.targeting.analytics.model.impl.AnalyticsReferrerModelImpl}. 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 analyticsEventIds the analytics event IDs
 * @param referrerClassName the referrer class name
 * @param referrerClassPK the referrer class p k
 * @param start the lower bound of the range of analytics referrers
 * @param end the upper bound of the range of analytics referrers (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching analytics referrers
 * @throws SystemException if a system exception occurred
 */
@Override
public List<AnalyticsReferrer> findByA_R_R(long[] analyticsEventIds, String referrerClassName,
        long referrerClassPK, int start, int end, OrderByComparator orderByComparator) throws SystemException {
    if ((analyticsEventIds != null) && (analyticsEventIds.length == 1)) {
        return findByA_R_R(analyticsEventIds[0], referrerClassName, referrerClassPK, 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(analyticsEventIds), referrerClassName, referrerClassPK };
    } else {
        finderArgs = new Object[] { StringUtil.merge(analyticsEventIds), referrerClassName, referrerClassPK,

                start, end, orderByComparator };
    }

    List<AnalyticsReferrer> list = (List<AnalyticsReferrer>) FinderCacheUtil
            .getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_A_R_R, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (AnalyticsReferrer analyticsReferrer : list) {
            if (!ArrayUtil.contains(analyticsEventIds, analyticsReferrer.getAnalyticsEventId())
                    || !Validator.equals(referrerClassName, analyticsReferrer.getReferrerClassName())
                    || (referrerClassPK != analyticsReferrer.getReferrerClassPK())) {
                list = null;

                break;
            }
        }
    }

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

        query.append(_SQL_SELECT_ANALYTICSREFERRER_WHERE);

        boolean conjunctionable = false;

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

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < analyticsEventIds.length; i++) {
                query.append(_FINDER_COLUMN_A_R_R_ANALYTICSEVENTID_5);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

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

        boolean bindReferrerClassName = false;

        if (referrerClassName == null) {
            query.append(_FINDER_COLUMN_A_R_R_REFERRERCLASSNAME_4);
        } else if (referrerClassName.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_A_R_R_REFERRERCLASSNAME_6);
        } else {
            bindReferrerClassName = true;

            query.append(_FINDER_COLUMN_A_R_R_REFERRERCLASSNAME_5);
        }

        conjunctionable = true;

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

        query.append(_FINDER_COLUMN_A_R_R_REFERRERCLASSPK_5);

        conjunctionable = true;

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

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

            if (bindReferrerClassName) {
                qPos.add(referrerClassName);
            }

            qPos.add(referrerClassPK);

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

                Collections.sort(list);

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

            cacheResult(list);

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

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

    return list;
}

From source file:com.liferay.content.targeting.analytics.service.persistence.AnalyticsReferrerPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of analytics referrers where analyticsEventId = any &#63; and referrerClassName = &#63; and referrerClassPK = &#63;.
 *
 * @param analyticsEventIds the analytics event IDs
 * @param referrerClassName the referrer class name
 * @param referrerClassPK the referrer class p k
 * @return the number of matching analytics referrers
 * @throws SystemException if a system exception occurred
 *//*ww  w .  j  ava 2 s.c o  m*/
@Override
public int countByA_R_R(long[] analyticsEventIds, String referrerClassName, long referrerClassPK)
        throws SystemException {
    Object[] finderArgs = new Object[] { StringUtil.merge(analyticsEventIds), referrerClassName,
            referrerClassPK };

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

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

        query.append(_SQL_COUNT_ANALYTICSREFERRER_WHERE);

        boolean conjunctionable = false;

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

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < analyticsEventIds.length; i++) {
                query.append(_FINDER_COLUMN_A_R_R_ANALYTICSEVENTID_5);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

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

        boolean bindReferrerClassName = false;

        if (referrerClassName == null) {
            query.append(_FINDER_COLUMN_A_R_R_REFERRERCLASSNAME_4);
        } else if (referrerClassName.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_A_R_R_REFERRERCLASSNAME_6);
        } else {
            bindReferrerClassName = true;

            query.append(_FINDER_COLUMN_A_R_R_REFERRERCLASSNAME_5);
        }

        conjunctionable = true;

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

        query.append(_FINDER_COLUMN_A_R_R_REFERRERCLASSPK_5);

        conjunctionable = true;

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

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

            if (bindReferrerClassName) {
                qPos.add(referrerClassName);
            }

            qPos.add(referrerClassPK);

            count = (Long) q.uniqueResult();

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

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

    return count.intValue();
}

From source file:com.liferay.content.targeting.hook.CTAssetVocabularyServiceImpl.java

License:Open Source License

@Override
public List<AssetVocabulary> getVocabularies(long[] vocabularyIds) throws PortalException, SystemException {

    List<AssetVocabulary> vocabularies = super.getVocabularies(vocabularyIds);

    if (vocabularies.size() <= 1) {
        return vocabularies;
    }//from w w  w  . j  a v  a2s.  c o m

    List<AssetVocabulary> unambiguousVocabularies = new ArrayList<AssetVocabulary>();

    Locale locale = LocaleThreadLocal.getThemeDisplayLocale();

    for (AssetVocabulary vocabulary : vocabularies) {
        String vocabularyTitle = vocabulary.getTitle(locale);

        if (vocabularyTitle.equals(UserSegmentUtil.getAssetVocabularyName())) {

            Group vocabularyGroup = GroupLocalServiceUtil.getGroup(vocabulary.getGroupId());

            if (!vocabularyGroup.isCompany()) {
                StringBundler sb = new StringBundler(5);

                sb.append(vocabularyTitle);
                sb.append(StringPool.SPACE);
                sb.append(StringPool.OPEN_PARENTHESIS);
                sb.append(vocabularyGroup.getDescriptiveName(locale));
                sb.append(StringPool.CLOSE_PARENTHESIS);

                vocabulary.setTitle(sb.toString(), locale);
            }
        }

        unambiguousVocabularies.add(vocabulary);
    }

    return unambiguousVocabularies;
}

From source file:com.liferay.content.targeting.model.impl.CampaignImpl.java

License:Open Source License

public String getNameWithGroupName(Locale locale, long groupId) {
    String name = getName(locale);

    if (groupId != getGroupId()) {
        try {/*from   ww  w.ja v  a 2s  . com*/
            Group group = GroupLocalServiceUtil.getGroup(getGroupId());

            StringBundler sb = new StringBundler(5);

            sb.append(name);
            sb.append(StringPool.SPACE);
            sb.append(StringPool.OPEN_PARENTHESIS);
            sb.append(group.getDescriptiveName(locale));
            sb.append(StringPool.CLOSE_PARENTHESIS);

            name = sb.toString();
        } catch (Exception e) {
            if (_log.isDebugEnabled()) {
                _log.debug("Group can not be found for groupId " + getGroupId());
            }
        }
    }

    return name;
}

From source file:com.liferay.content.targeting.model.impl.UserSegmentImpl.java

License:Open Source License

public String getNameWithGroupName(Locale locale, long groupId) {
    String name = getName(locale);

    try {/*from  w  ww .j ava  2 s . com*/
        Group group = GroupLocalServiceUtil.getGroup(getGroupId());

        if ((groupId != getGroupId())
                && (!group.hasStagingGroup() || (group.getStagingGroup().getGroupId() != groupId))) {

            StringBundler sb = new StringBundler(5);

            sb.append(name);
            sb.append(StringPool.SPACE);
            sb.append(StringPool.OPEN_PARENTHESIS);
            sb.append(group.getDescriptiveName(locale));
            sb.append(StringPool.CLOSE_PARENTHESIS);

            name = sb.toString();
        }
    } catch (Exception e) {
        if (_log.isDebugEnabled()) {
            _log.debug("Group can not be found for groupId " + getGroupId());
        }
    }

    return name;
}

From source file:com.liferay.content.targeting.service.persistence.CampaignPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the campaigns that the user has permission to view where groupId = any &#63;.
 *
 * <p>/*  w ww. j a  va2s  .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 com.liferay.content.targeting.model.impl.CampaignModelImpl}. 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 groupIds the group IDs
 * @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 that the user has permission to view
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Campaign> filterFindByGroupId(long[] groupIds, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    if (!InlineSQLHelperUtil.isEnabled(groupIds)) {
        return findByGroupId(groupIds, start, end, orderByComparator);
    }

    StringBundler query = new StringBundler();

    if (getDB().isSupportsInlineDistinct()) {
        query.append(_FILTER_SQL_SELECT_CAMPAIGN_WHERE);
    } else {
        query.append(_FILTER_SQL_SELECT_CAMPAIGN_NO_INLINE_DISTINCT_WHERE_1);
    }

    boolean conjunctionable = false;

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

        query.append(StringPool.OPEN_PARENTHESIS);

        for (int i = 0; i < groupIds.length; i++) {
            query.append(_FINDER_COLUMN_GROUPID_GROUPID_5);

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

        query.append(StringPool.CLOSE_PARENTHESIS);

        conjunctionable = true;
    }

    if (!getDB().isSupportsInlineDistinct()) {
        query.append(_FILTER_SQL_SELECT_CAMPAIGN_NO_INLINE_DISTINCT_WHERE_2);
    }

    if (orderByComparator != null) {
        if (getDB().isSupportsInlineDistinct()) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator, true);
        } else {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE, orderByComparator, true);
        }
    } else {
        if (getDB().isSupportsInlineDistinct()) {
            query.append(CampaignModelImpl.ORDER_BY_JPQL);
        } else {
            query.append(CampaignModelImpl.ORDER_BY_SQL);
        }
    }

    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Campaign.class.getName(),
            _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupIds);

    Session session = null;

    try {
        session = openSession();

        SQLQuery q = session.createSQLQuery(sql);

        if (getDB().isSupportsInlineDistinct()) {
            q.addEntity(_FILTER_ENTITY_ALIAS, CampaignImpl.class);
        } else {
            q.addEntity(_FILTER_ENTITY_TABLE, CampaignImpl.class);
        }

        QueryPos qPos = QueryPos.getInstance(q);

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

        return (List<Campaign>) QueryUtil.list(q, getDialect(), start, end);
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}

From source file:com.liferay.content.targeting.service.persistence.CampaignPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the campaigns where groupId = any &#63;.
 *
 * <p>//  w  w w  . java 2 s. c  o  m
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.content.targeting.model.impl.CampaignModelImpl}. 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 groupIds the group IDs
 * @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
 */
@Override
public List<Campaign> findByGroupId(long[] groupIds, int start, int end, OrderByComparator orderByComparator)
        throws SystemException {
    if ((groupIds != null) && (groupIds.length == 1)) {
        return findByGroupId(groupIds[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(groupIds) };
    } else {
        finderArgs = new Object[] { StringUtil.merge(groupIds),

                start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (Campaign campaign : list) {
            if (!ArrayUtil.contains(groupIds, campaign.getGroupId())) {
                list = null;

                break;
            }
        }
    }

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

        query.append(_SQL_SELECT_CAMPAIGN_WHERE);

        boolean conjunctionable = false;

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

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < groupIds.length; i++) {
                query.append(_FINDER_COLUMN_GROUPID_GROUPID_5);

                if ((i + 1) < groupIds.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(CampaignModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

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

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

                Collections.sort(list);

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

            cacheResult(list);

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

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

    return list;
}

From source file:com.liferay.content.targeting.service.persistence.CampaignPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of campaigns where groupId = any &#63;.
 *
 * @param groupIds the group IDs/*w  w w  .  jav  a 2 s  . c  om*/
 * @return the number of matching campaigns
 * @throws SystemException if a system exception occurred
 */
@Override
public int countByGroupId(long[] groupIds) throws SystemException {
    Object[] finderArgs = new Object[] { StringUtil.merge(groupIds) };

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

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

        query.append(_SQL_COUNT_CAMPAIGN_WHERE);

        boolean conjunctionable = false;

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

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < groupIds.length; i++) {
                query.append(_FINDER_COLUMN_GROUPID_GROUPID_5);

                if ((i + 1) < groupIds.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 (groupIds != null) {
                qPos.add(groupIds);
            }

            count = (Long) q.uniqueResult();

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

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

    return count.intValue();
}

From source file:com.liferay.content.targeting.service.persistence.CampaignPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of campaigns that the user has permission to view where groupId = any &#63;.
 *
 * @param groupIds the group IDs//from   w w  w .j  a  v  a 2s. c om
 * @return the number of matching campaigns that the user has permission to view
 * @throws SystemException if a system exception occurred
 */
@Override
public int filterCountByGroupId(long[] groupIds) throws SystemException {
    if (!InlineSQLHelperUtil.isEnabled(groupIds)) {
        return countByGroupId(groupIds);
    }

    StringBundler query = new StringBundler();

    query.append(_FILTER_SQL_COUNT_CAMPAIGN_WHERE);

    boolean conjunctionable = false;

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

        query.append(StringPool.OPEN_PARENTHESIS);

        for (int i = 0; i < groupIds.length; i++) {
            query.append(_FINDER_COLUMN_GROUPID_GROUPID_5);

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

        query.append(StringPool.CLOSE_PARENTHESIS);

        conjunctionable = true;
    }

    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Campaign.class.getName(),
            _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupIds);

    Session session = null;

    try {
        session = openSession();

        SQLQuery q = session.createSQLQuery(sql);

        q.addScalar(COUNT_COLUMN_NAME, com.liferay.portal.kernel.dao.orm.Type.LONG);

        QueryPos qPos = QueryPos.getInstance(q);

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

        Long count = (Long) q.uniqueResult();

        return count.intValue();
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}