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.journal.service.persistence.impl.JournalArticlePersistenceImpl.java

License:Open Source License

/**
 * Returns the number of journal articles where resourcePrimKey = ? and status = any ?.
 *
 * @param resourcePrimKey the resource prim key
 * @param statuses the statuses/*w ww .  ja va 2s .c  o m*/
 * @return the number of matching journal articles
 */
@Override
public int countByR_ST(long resourcePrimKey, int[] statuses) {
    if (statuses == null) {
        statuses = new int[0];
    } else if (statuses.length > 1) {
        statuses = ArrayUtil.unique(statuses);

        Arrays.sort(statuses);
    }

    Object[] finderArgs = new Object[] { resourcePrimKey, StringUtil.merge(statuses) };

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

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

        query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);

        query.append(_FINDER_COLUMN_R_ST_RESOURCEPRIMKEY_2);

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

            query.append(_FINDER_COLUMN_R_ST_STATUS_7);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

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

            qPos.add(resourcePrimKey);

            count = (Long) q.uniqueResult();

            finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_R_ST, finderArgs, count);
        } catch (Exception e) {
            finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_R_ST, 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 = ? and folderId = any ?.
 *
 * <p>/* w  ww  .j a  v a2 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 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 folderIds the folder IDs
 * @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_F(long groupId, long[] folderIds, int start, int end,
        OrderByComparator<JournalArticle> orderByComparator) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return findByG_F(groupId, folderIds, start, end, orderByComparator);
    }

    if (folderIds == null) {
        folderIds = new long[0];
    } else if (folderIds.length > 1) {
        folderIds = ArrayUtil.unique(folderIds);

        Arrays.sort(folderIds);
    }

    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_F_GROUPID_2);

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

        query.append(_FINDER_COLUMN_G_F_FOLDERID_7);

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

        query.append(StringPool.CLOSE_PARENTHESIS);

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

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

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 groupId = &#63; and folderId = &#63;, optionally using the finder cache.
 *
 * <p>//from w ww.jav  a  2  s . co  m
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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 folderId the folder ID
 * @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> findByG_F(long groupId, long[] folderIds, int start, int end,
        OrderByComparator<JournalArticle> orderByComparator, boolean retrieveFromCache) {
    if (folderIds == null) {
        folderIds = new long[0];
    } else if (folderIds.length > 1) {
        folderIds = ArrayUtil.unique(folderIds);

        Arrays.sort(folderIds);
    }

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

                start, end, orderByComparator };
    }

    List<JournalArticle> list = null;

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

        if ((list != null) && !list.isEmpty()) {
            for (JournalArticle journalArticle : list) {
                if ((groupId != journalArticle.getGroupId())
                        || !ArrayUtil.contains(folderIds, journalArticle.getFolderId())) {
                    list = null;

                    break;
                }
            }
        }
    }

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

        query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);

        query.append(_FINDER_COLUMN_G_F_GROUPID_2);

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

            query.append(_FINDER_COLUMN_G_F_FOLDERID_7);

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

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

            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_G_F, finderArgs, list);
        } catch (Exception e) {
            finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F, 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 groupId = &#63; and folderId = any &#63;.
 *
 * @param groupId the group ID//from  w  ww  . j  ava2s  .  c  o  m
 * @param folderIds the folder IDs
 * @return the number of matching journal articles
 */
@Override
public int countByG_F(long groupId, long[] folderIds) {
    if (folderIds == null) {
        folderIds = new long[0];
    } else if (folderIds.length > 1) {
        folderIds = ArrayUtil.unique(folderIds);

        Arrays.sort(folderIds);
    }

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

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

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

        query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);

        query.append(_FINDER_COLUMN_G_F_GROUPID_2);

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

            query.append(_FINDER_COLUMN_G_F_FOLDERID_7);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

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

            qPos.add(groupId);

            count = (Long) q.uniqueResult();

            finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_F, finderArgs, count);
        } catch (Exception e) {
            finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_F, 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 the number of journal articles that the user has permission to view where groupId = &#63; and folderId = any &#63;.
 *
 * @param groupId the group ID//from   w w  w  .j  a  va  2  s. c  om
 * @param folderIds the folder IDs
 * @return the number of matching journal articles that the user has permission to view
 */
@Override
public int filterCountByG_F(long groupId, long[] folderIds) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return countByG_F(groupId, folderIds);
    }

    if (folderIds == null) {
        folderIds = new long[0];
    } else if (folderIds.length > 1) {
        folderIds = ArrayUtil.unique(folderIds);

        Arrays.sort(folderIds);
    }

    StringBundler query = new StringBundler();

    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);

    query.append(_FINDER_COLUMN_G_F_GROUPID_2);

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

        query.append(_FINDER_COLUMN_G_F_FOLDERID_7);

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

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(StringPool.CLOSE_PARENTHESIS);
    }

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

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

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

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

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

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

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>//  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 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);
    }
}

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 groupId = &#63; and layoutUuid &ne; &#63;, optionally using the finder cache.
 *
 * <p>/*w ww .  jav a2s  .  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 layoutUuid the layout uuid
 * @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> findByG_NotL(long groupId, String[] layoutUuids, int start, int end,
        OrderByComparator<JournalArticle> orderByComparator, boolean retrieveFromCache) {
    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);
    }

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

                start, end, orderByComparator };
    }

    List<JournalArticle> list = null;

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

        if ((list != null) && !list.isEmpty()) {
            for (JournalArticle journalArticle : list) {
                if ((groupId != journalArticle.getGroupId())
                        || !ArrayUtil.contains(layoutUuids, journalArticle.getLayoutUuid())) {
                    list = null;

                    break;
                }
            }
        }
    }

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

        query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);

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

            qPos.add(groupId);

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

            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_G_NOTL, finderArgs, list);
        } catch (Exception e) {
            finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTL, 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 groupId = &#63; and layoutUuid &ne; all &#63;.
 *
 * @param groupId the group ID//from   w w w .j a  va 2 s .  c om
 * @param layoutUuids the layout uuids
 * @return the number of matching journal articles
 */
@Override
public int countByG_NotL(long groupId, String[] layoutUuids) {
    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);
    }

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

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

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

        query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(groupId);

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

            count = (Long) q.uniqueResult();

            finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTL, finderArgs, count);
        } catch (Exception e) {
            finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTL, 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 the number of journal articles that the user has permission to view where groupId = &#63; and layoutUuid &ne; all &#63;.
 *
 * @param groupId the group ID/* www .  j  a v a 2s. c om*/
 * @param layoutUuids the layout uuids
 * @return the number of matching journal articles that the user has permission to view
 */
@Override
public int filterCountByG_NotL(long groupId, String[] layoutUuids) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return countByG_NotL(groupId, layoutUuids);
    }

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

    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);

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

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

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

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

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

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

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

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 resourcePrimKey = &#63; and indexable = &#63; and status = &#63;, optionally using the finder cache.
 *
 * <p>/*from  w ww. 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 resourcePrimKey the resource prim key
 * @param indexable the indexable
 * @param status the status
 * @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> findByR_I_S(long resourcePrimKey, boolean indexable, int[] statuses, int start,
        int end, OrderByComparator<JournalArticle> orderByComparator, boolean retrieveFromCache) {
    if (statuses == null) {
        statuses = new int[0];
    } else if (statuses.length > 1) {
        statuses = ArrayUtil.unique(statuses);

        Arrays.sort(statuses);
    }

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

                start, end, orderByComparator };
    }

    List<JournalArticle> list = null;

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

        if ((list != null) && !list.isEmpty()) {
            for (JournalArticle journalArticle : list) {
                if ((resourcePrimKey != journalArticle.getResourcePrimKey())
                        || (indexable != journalArticle.getIndexable())
                        || !ArrayUtil.contains(statuses, journalArticle.getStatus())) {
                    list = null;

                    break;
                }
            }
        }
    }

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

        query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);

        query.append(_FINDER_COLUMN_R_I_S_RESOURCEPRIMKEY_2);

        query.append(_FINDER_COLUMN_R_I_S_INDEXABLE_2);

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

            query.append(_FINDER_COLUMN_R_I_S_STATUS_7);

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

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

            qPos.add(indexable);

            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_R_I_S, finderArgs, list);
        } catch (Exception e) {
            finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_R_I_S, finderArgs);

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

    return list;
}