Example usage for com.liferay.portal.kernel.util ArrayUtil distinct

List of usage examples for com.liferay.portal.kernel.util ArrayUtil distinct

Introduction

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

Prototype

public static String[] distinct(String[] array, Comparator<String> comparator) 

Source Link

Usage

From source file:com.bemis.portal.report.service.persistence.impl.ReportDefinitionPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the report definitions that the user has permission to view where category = any &#63; and companyId = &#63; and groupId = &#63;.
 *
 * <p>//from w  w w.  j av  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 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 ReportDefinitionModelImpl}. 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 categories the categories
 * @param companyId the company ID
 * @param groupId the group ID
 * @param start the lower bound of the range of report definitions
 * @param end the upper bound of the range of report definitions (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching report definitions that the user has permission to view
 */
@Override
public List<ReportDefinition> filterFindByC_C_G(String[] categories, long companyId, long groupId, int start,
        int end, OrderByComparator<ReportDefinition> orderByComparator) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return findByC_C_G(categories, companyId, groupId, start, end, orderByComparator);
    }

    if (categories == null) {
        categories = new String[0];
    } else if (categories.length > 1) {
        categories = ArrayUtil.distinct(categories, NULL_SAFE_STRING_COMPARATOR);

        Arrays.sort(categories, NULL_SAFE_STRING_COMPARATOR);
    }

    StringBundler query = new StringBundler();

    if (getDB().isSupportsInlineDistinct()) {
        query.append(_FILTER_SQL_SELECT_REPORTDEFINITION_WHERE);
    } else {
        query.append(_FILTER_SQL_SELECT_REPORTDEFINITION_NO_INLINE_DISTINCT_WHERE_1);
    }

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

        for (int i = 0; i < categories.length; i++) {
            String category = categories[i];

            if (category == null) {
                query.append(_FINDER_COLUMN_C_C_G_CATEGORY_4);
            } else if (category.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_C_C_G_CATEGORY_6);
            } else {
                query.append(_FINDER_COLUMN_C_C_G_CATEGORY_5);
            }

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

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(WHERE_AND);
    }

    query.append(_FINDER_COLUMN_C_C_G_COMPANYID_2);

    query.append(_FINDER_COLUMN_C_C_G_GROUPID_2);

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

    if (!getDB().isSupportsInlineDistinct()) {
        query.append(_FILTER_SQL_SELECT_REPORTDEFINITION_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(ReportDefinitionModelImpl.ORDER_BY_JPQL);
        } else {
            query.append(ReportDefinitionModelImpl.ORDER_BY_SQL);
        }
    }

    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), ReportDefinition.class.getName(),
            _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);

    Session session = null;

    try {
        session = openSession();

        SQLQuery q = session.createSynchronizedSQLQuery(sql);

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

        QueryPos qPos = QueryPos.getInstance(q);

        for (String category : categories) {
            if ((category != null) && !category.isEmpty()) {
                qPos.add(category);
            }
        }

        qPos.add(companyId);

        qPos.add(groupId);

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

From source file:com.bemis.portal.report.service.persistence.impl.ReportDefinitionPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the report definitions where category = &#63; and companyId = &#63; and groupId = &#63;, optionally using the finder cache.
 *
 * <p>/*from  w w w.  j a 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 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 ReportDefinitionModelImpl}. 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 category the category
 * @param companyId the company ID
 * @param groupId the group ID
 * @param start the lower bound of the range of report definitions
 * @param end the upper bound of the range of report definitions (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 report definitions
 */
@Override
public List<ReportDefinition> findByC_C_G(String[] categories, long companyId, long groupId, int start, int end,
        OrderByComparator<ReportDefinition> orderByComparator, boolean retrieveFromCache) {
    if (categories == null) {
        categories = new String[0];
    } else if (categories.length > 1) {
        categories = ArrayUtil.distinct(categories, NULL_SAFE_STRING_COMPARATOR);

        Arrays.sort(categories, NULL_SAFE_STRING_COMPARATOR);
    }

    if (categories.length == 1) {
        return findByC_C_G(categories[0], companyId, groupId, 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(categories), companyId, groupId };
    } else {
        finderArgs = new Object[] { StringUtil.merge(categories), companyId, groupId,

                start, end, orderByComparator };
    }

    List<ReportDefinition> list = null;

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

        if ((list != null) && !list.isEmpty()) {
            for (ReportDefinition reportDefinition : list) {
                if (!ArrayUtil.contains(categories, reportDefinition.getCategory())
                        || (companyId != reportDefinition.getCompanyId())
                        || (groupId != reportDefinition.getGroupId())) {
                    list = null;

                    break;
                }
            }
        }
    }

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

        query.append(_SQL_SELECT_REPORTDEFINITION_WHERE);

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

            for (int i = 0; i < categories.length; i++) {
                String category = categories[i];

                if (category == null) {
                    query.append(_FINDER_COLUMN_C_C_G_CATEGORY_4);
                } else if (category.equals(StringPool.BLANK)) {
                    query.append(_FINDER_COLUMN_C_C_G_CATEGORY_6);
                } else {
                    query.append(_FINDER_COLUMN_C_C_G_CATEGORY_5);
                }

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_C_C_G_COMPANYID_2);

        query.append(_FINDER_COLUMN_C_C_G_GROUPID_2);

        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(ReportDefinitionModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            for (String category : categories) {
                if ((category != null) && !category.isEmpty()) {
                    qPos.add(category);
                }
            }

            qPos.add(companyId);

            qPos.add(groupId);

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

                Collections.sort(list);

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

            cacheResult(list);

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

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

    return list;
}

From source file:com.bemis.portal.report.service.persistence.impl.ReportDefinitionPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of report definitions where category = any &#63; and companyId = &#63; and groupId = &#63;.
 *
 * @param categories the categories//w w w  .ja  v  a 2 s  . c  o m
 * @param companyId the company ID
 * @param groupId the group ID
 * @return the number of matching report definitions
 */
@Override
public int countByC_C_G(String[] categories, long companyId, long groupId) {
    if (categories == null) {
        categories = new String[0];
    } else if (categories.length > 1) {
        categories = ArrayUtil.distinct(categories, NULL_SAFE_STRING_COMPARATOR);

        Arrays.sort(categories, NULL_SAFE_STRING_COMPARATOR);
    }

    Object[] finderArgs = new Object[] { StringUtil.merge(categories), companyId, groupId };

    Long count = (Long) finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_C_G, finderArgs, this);

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

        query.append(_SQL_COUNT_REPORTDEFINITION_WHERE);

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

            for (int i = 0; i < categories.length; i++) {
                String category = categories[i];

                if (category == null) {
                    query.append(_FINDER_COLUMN_C_C_G_CATEGORY_4);
                } else if (category.equals(StringPool.BLANK)) {
                    query.append(_FINDER_COLUMN_C_C_G_CATEGORY_6);
                } else {
                    query.append(_FINDER_COLUMN_C_C_G_CATEGORY_5);
                }

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_C_C_G_COMPANYID_2);

        query.append(_FINDER_COLUMN_C_C_G_GROUPID_2);

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            for (String category : categories) {
                if ((category != null) && !category.isEmpty()) {
                    qPos.add(category);
                }
            }

            qPos.add(companyId);

            qPos.add(groupId);

            count = (Long) q.uniqueResult();

            finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_C_G, finderArgs, count);
        } catch (Exception e) {
            finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_C_G, finderArgs);

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

    return count.intValue();
}

From source file:com.bemis.portal.report.service.persistence.impl.ReportDefinitionPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of report definitions that the user has permission to view where category = any &#63; and companyId = &#63; and groupId = &#63;.
 *
 * @param categories the categories/*from   www. jav  a 2s. c o  m*/
 * @param companyId the company ID
 * @param groupId the group ID
 * @return the number of matching report definitions that the user has permission to view
 */
@Override
public int filterCountByC_C_G(String[] categories, long companyId, long groupId) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return countByC_C_G(categories, companyId, groupId);
    }

    if (categories == null) {
        categories = new String[0];
    } else if (categories.length > 1) {
        categories = ArrayUtil.distinct(categories, NULL_SAFE_STRING_COMPARATOR);

        Arrays.sort(categories, NULL_SAFE_STRING_COMPARATOR);
    }

    StringBundler query = new StringBundler();

    query.append(_FILTER_SQL_COUNT_REPORTDEFINITION_WHERE);

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

        for (int i = 0; i < categories.length; i++) {
            String category = categories[i];

            if (category == null) {
                query.append(_FINDER_COLUMN_C_C_G_CATEGORY_4);
            } else if (category.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_C_C_G_CATEGORY_6);
            } else {
                query.append(_FINDER_COLUMN_C_C_G_CATEGORY_5);
            }

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

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(WHERE_AND);
    }

    query.append(_FINDER_COLUMN_C_C_G_COMPANYID_2);

    query.append(_FINDER_COLUMN_C_C_G_GROUPID_2);

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

    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), ReportDefinition.class.getName(),
            _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);

    Session session = null;

    try {
        session = openSession();

        SQLQuery q = session.createSynchronizedSQLQuery(sql);

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

        QueryPos qPos = QueryPos.getInstance(q);

        for (String category : categories) {
            if ((category != null) && !category.isEmpty()) {
                qPos.add(category);
            }
        }

        qPos.add(companyId);

        qPos.add(groupId);

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

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

From source file:com.bemis.portal.report.service.persistence.impl.ReportRequestPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the report requests where reportDefinitionCategory = &#63; and userId = &#63;, optionally using the finder cache.
 *
 * <p>//www  .j a  va  2 s .c  o  m
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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 ReportRequestModelImpl}. 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 reportDefinitionCategory the report definition category
 * @param userId the user ID
 * @param start the lower bound of the range of report requests
 * @param end the upper bound of the range of report requests (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 report requests
 */
@Override
public List<ReportRequest> findByRDC_U(String[] reportDefinitionCategories, long userId, int start, int end,
        OrderByComparator<ReportRequest> orderByComparator, boolean retrieveFromCache) {
    if (reportDefinitionCategories == null) {
        reportDefinitionCategories = new String[0];
    } else if (reportDefinitionCategories.length > 1) {
        reportDefinitionCategories = ArrayUtil.distinct(reportDefinitionCategories,
                NULL_SAFE_STRING_COMPARATOR);

        Arrays.sort(reportDefinitionCategories, NULL_SAFE_STRING_COMPARATOR);
    }

    if (reportDefinitionCategories.length == 1) {
        return findByRDC_U(reportDefinitionCategories[0], userId, 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(reportDefinitionCategories), userId };
    } else {
        finderArgs = new Object[] { StringUtil.merge(reportDefinitionCategories), userId,

                start, end, orderByComparator };
    }

    List<ReportRequest> list = null;

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

        if ((list != null) && !list.isEmpty()) {
            for (ReportRequest reportRequest : list) {
                if (!ArrayUtil.contains(reportDefinitionCategories, reportRequest.getReportDefinitionCategory())
                        || (userId != reportRequest.getUserId())) {
                    list = null;

                    break;
                }
            }
        }
    }

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

        query.append(_SQL_SELECT_REPORTREQUEST_WHERE);

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

            for (int i = 0; i < reportDefinitionCategories.length; i++) {
                String reportDefinitionCategory = reportDefinitionCategories[i];

                if (reportDefinitionCategory == null) {
                    query.append(_FINDER_COLUMN_RDC_U_REPORTDEFINITIONCATEGORY_4);
                } else if (reportDefinitionCategory.equals(StringPool.BLANK)) {
                    query.append(_FINDER_COLUMN_RDC_U_REPORTDEFINITIONCATEGORY_6);
                } else {
                    query.append(_FINDER_COLUMN_RDC_U_REPORTDEFINITIONCATEGORY_5);
                }

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_RDC_U_USERID_2);

        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(ReportRequestModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            for (String reportDefinitionCategory : reportDefinitionCategories) {
                if ((reportDefinitionCategory != null) && !reportDefinitionCategory.isEmpty()) {
                    qPos.add(reportDefinitionCategory);
                }
            }

            qPos.add(userId);

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

                Collections.sort(list);

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

            cacheResult(list);

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

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

    return list;
}

From source file:com.bemis.portal.report.service.persistence.impl.ReportRequestPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of report requests where reportDefinitionCategory = any &#63; and userId = &#63;.
 *
 * @param reportDefinitionCategories the report definition categories
 * @param userId the user ID//  ww  w  .  ja v  a 2 s.  com
 * @return the number of matching report requests
 */
@Override
public int countByRDC_U(String[] reportDefinitionCategories, long userId) {
    if (reportDefinitionCategories == null) {
        reportDefinitionCategories = new String[0];
    } else if (reportDefinitionCategories.length > 1) {
        reportDefinitionCategories = ArrayUtil.distinct(reportDefinitionCategories,
                NULL_SAFE_STRING_COMPARATOR);

        Arrays.sort(reportDefinitionCategories, NULL_SAFE_STRING_COMPARATOR);
    }

    Object[] finderArgs = new Object[] { StringUtil.merge(reportDefinitionCategories), userId };

    Long count = (Long) finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_RDC_U, finderArgs, this);

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

        query.append(_SQL_COUNT_REPORTREQUEST_WHERE);

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

            for (int i = 0; i < reportDefinitionCategories.length; i++) {
                String reportDefinitionCategory = reportDefinitionCategories[i];

                if (reportDefinitionCategory == null) {
                    query.append(_FINDER_COLUMN_RDC_U_REPORTDEFINITIONCATEGORY_4);
                } else if (reportDefinitionCategory.equals(StringPool.BLANK)) {
                    query.append(_FINDER_COLUMN_RDC_U_REPORTDEFINITIONCATEGORY_6);
                } else {
                    query.append(_FINDER_COLUMN_RDC_U_REPORTDEFINITIONCATEGORY_5);
                }

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_RDC_U_USERID_2);

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            for (String reportDefinitionCategory : reportDefinitionCategories) {
                if ((reportDefinitionCategory != null) && !reportDefinitionCategory.isEmpty()) {
                    qPos.add(reportDefinitionCategory);
                }
            }

            qPos.add(userId);

            count = (Long) q.uniqueResult();

            finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_RDC_U, finderArgs, count);
        } catch (Exception e) {
            finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_RDC_U, finderArgs);

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

    return count.intValue();
}

From source file:com.liferay.asset.publisher.web.display.context.AssetPublisherDisplayContext.java

License:Open Source License

public String[] getAllAssetTagNames() throws Exception {
    if (_allAssetTagNames != null) {
        return _allAssetTagNames;
    }/*from w w w .jav  a  2s .c o m*/

    _allAssetTagNames = new String[0];

    String assetTagName = ParamUtil.getString(_request, "tag");

    String selectionStyle = getSelectionStyle();

    if (selectionStyle.equals("dynamic")) {
        _allAssetTagNames = AssetPublisherUtil.getAssetTagNames(_portletPreferences);
    }

    if (Validator.isNotNull(assetTagName) && !ArrayUtil.contains(_allAssetTagNames, assetTagName)) {

        _allAssetTagNames = ArrayUtil.append(_allAssetTagNames, assetTagName);
    }

    if (isMergeURLTags()) {
        _allAssetTagNames = ArrayUtil.append(_allAssetTagNames, getCompilerTagNames());
    }

    _allAssetTagNames = ArrayUtil.distinct(_allAssetTagNames, new StringComparator());

    return _allAssetTagNames;
}

From source file:com.liferay.journal.service.persistence.impl.JournalArticlePersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the journal articles where DDMStructureKey = &#63;, optionally using the finder cache.
 *
 * <p>/*w w w  .j  a  v  a  2s . c  o m*/
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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 JournalArticleModelImpl}. 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 DDMStructureKey the ddm structure key
 * @param start the lower bound of the range of journal articles
 * @param end the upper bound of the range of journal articles (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 journal articles
 */
@Override
public List<JournalArticle> findByDDMStructureKey(String[] DDMStructureKeies, int start, int end,
        OrderByComparator<JournalArticle> orderByComparator, boolean retrieveFromCache) {
    if (DDMStructureKeies == null) {
        DDMStructureKeies = new String[0];
    } else if (DDMStructureKeies.length > 1) {
        DDMStructureKeies = ArrayUtil.distinct(DDMStructureKeies, NULL_SAFE_STRING_COMPARATOR);

        Arrays.sort(DDMStructureKeies, NULL_SAFE_STRING_COMPARATOR);
    }

    if (DDMStructureKeies.length == 1) {
        return findByDDMStructureKey(DDMStructureKeies[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(DDMStructureKeies) };
    } else {
        finderArgs = new Object[] { StringUtil.merge(DDMStructureKeies),

                start, end, orderByComparator };
    }

    List<JournalArticle> list = null;

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

        if ((list != null) && !list.isEmpty()) {
            for (JournalArticle journalArticle : list) {
                if (!ArrayUtil.contains(DDMStructureKeies, journalArticle.getDDMStructureKey())) {
                    list = null;

                    break;
                }
            }
        }
    }

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

        query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);

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

            for (int i = 0; i < DDMStructureKeies.length; i++) {
                String DDMStructureKey = DDMStructureKeies[i];

                if (DDMStructureKey == null) {
                    query.append(_FINDER_COLUMN_DDMSTRUCTUREKEY_DDMSTRUCTUREKEY_1);
                } else if (DDMStructureKey.equals(StringPool.BLANK)) {
                    query.append(_FINDER_COLUMN_DDMSTRUCTUREKEY_DDMSTRUCTUREKEY_3);
                } else {
                    query.append(_FINDER_COLUMN_DDMSTRUCTUREKEY_DDMSTRUCTUREKEY_2);
                }

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

            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(JournalArticleModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            for (String DDMStructureKey : DDMStructureKeies) {
                if ((DDMStructureKey != null) && !DDMStructureKey.isEmpty()) {
                    qPos.add(DDMStructureKey);
                }
            }

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

                Collections.sort(list);

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

            cacheResult(list);

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

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

    return list;
}

From source file:com.liferay.journal.service.persistence.impl.JournalArticlePersistenceImpl.java

License:Open Source License

/**
 * Returns the number of journal articles where DDMStructureKey = any &#63;.
 *
 * @param DDMStructureKeies the ddm structure keies
 * @return the number of matching journal articles
 *///ww w  . ja v a  2s  . com
@Override
public int countByDDMStructureKey(String[] DDMStructureKeies) {
    if (DDMStructureKeies == null) {
        DDMStructureKeies = new String[0];
    } else if (DDMStructureKeies.length > 1) {
        DDMStructureKeies = ArrayUtil.distinct(DDMStructureKeies, NULL_SAFE_STRING_COMPARATOR);

        Arrays.sort(DDMStructureKeies, NULL_SAFE_STRING_COMPARATOR);
    }

    Object[] finderArgs = new Object[] { StringUtil.merge(DDMStructureKeies) };

    Long count = (Long) finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_DDMSTRUCTUREKEY, finderArgs,
            this);

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

        query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);

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

            for (int i = 0; i < DDMStructureKeies.length; i++) {
                String DDMStructureKey = DDMStructureKeies[i];

                if (DDMStructureKey == null) {
                    query.append(_FINDER_COLUMN_DDMSTRUCTUREKEY_DDMSTRUCTUREKEY_1);
                } else if (DDMStructureKey.equals(StringPool.BLANK)) {
                    query.append(_FINDER_COLUMN_DDMSTRUCTUREKEY_DDMSTRUCTUREKEY_3);
                } else {
                    query.append(_FINDER_COLUMN_DDMSTRUCTUREKEY_DDMSTRUCTUREKEY_2);
                }

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

            query.append(StringPool.CLOSE_PARENTHESIS);
        }

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            for (String DDMStructureKey : DDMStructureKeies) {
                if ((DDMStructureKey != null) && !DDMStructureKey.isEmpty()) {
                    qPos.add(DDMStructureKey);
                }
            }

            count = (Long) q.uniqueResult();

            finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_DDMSTRUCTUREKEY, finderArgs, count);
        } catch (Exception e) {
            finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_DDMSTRUCTUREKEY, finderArgs);

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

    return count.intValue();
}

From source file:com.liferay.journal.service.persistence.impl.JournalArticlePersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the journal articles that the user has permission to view where groupId = &#63; and layoutUuid &ne; all &#63;.
 *
 * <p>/*from  ww  w  . j  a 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 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 JournalArticleModelImpl}. 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 groupId the group ID
 * @param layoutUuids the layout uuids
 * @param start the lower bound of the range of journal articles
 * @param end the upper bound of the range of journal articles (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching journal articles that the user has permission to view
 */
@Override
public List<JournalArticle> filterFindByG_NotL(long groupId, String[] layoutUuids, int start, int end,
        OrderByComparator<JournalArticle> orderByComparator) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return findByG_NotL(groupId, layoutUuids, start, end, orderByComparator);
    }

    if (layoutUuids == null) {
        layoutUuids = new String[0];
    } else if (layoutUuids.length > 1) {
        layoutUuids = ArrayUtil.distinct(layoutUuids, NULL_SAFE_STRING_COMPARATOR);

        Arrays.sort(layoutUuids, NULL_SAFE_STRING_COMPARATOR);
    }

    StringBundler query = new StringBundler();

    if (getDB().isSupportsInlineDistinct()) {
        query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
    } else {
        query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
    }

    query.append(_FINDER_COLUMN_G_NOTL_GROUPID_2);

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

        for (int i = 0; i < layoutUuids.length; i++) {
            String layoutUuid = layoutUuids[i];

            if (layoutUuid == null) {
                query.append(_FINDER_COLUMN_G_NOTL_LAYOUTUUID_1);
            } else if (layoutUuid.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_G_NOTL_LAYOUTUUID_3);
            } else {
                query.append(_FINDER_COLUMN_G_NOTL_LAYOUTUUID_2);
            }

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

        query.append(StringPool.CLOSE_PARENTHESIS);
    }

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

    if (!getDB().isSupportsInlineDistinct()) {
        query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_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(JournalArticleModelImpl.ORDER_BY_JPQL);
        } else {
            query.append(JournalArticleModelImpl.ORDER_BY_SQL);
        }
    }

    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), JournalArticle.class.getName(),
            _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);

    Session session = null;

    try {
        session = openSession();

        SQLQuery q = session.createSynchronizedSQLQuery(sql);

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

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        for (String layoutUuid : layoutUuids) {
            if ((layoutUuid != null) && !layoutUuid.isEmpty()) {
                qPos.add(layoutUuid);
            }
        }

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