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

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

Introduction

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

Prototype

String OPEN_PARENTHESIS

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

Click Source Link

Usage

From source file:com.liferay.bookmarks.service.persistence.impl.BookmarksEntryPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of bookmarks entries where groupId = ? and folderId = any ? and status = ?.
 *
 * @param groupId the group ID/*from   www.  j  a  va  2s.  c  o  m*/
 * @param folderIds the folder IDs
 * @param status the status
 * @return the number of matching bookmarks entries
 */
@Override
public int countByG_F_S(long groupId, long[] folderIds, int status) {
    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), status };

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

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

        query.append(_SQL_COUNT_BOOKMARKSENTRY_WHERE);

        query.append(_FINDER_COLUMN_G_F_S_GROUPID_2);

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

            query.append(_FINDER_COLUMN_G_F_S_FOLDERID_7);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_G_F_S_STATUS_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);

            qPos.add(groupId);

            qPos.add(status);

            count = (Long) q.uniqueResult();

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

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

    return count.intValue();
}

From source file:com.liferay.bookmarks.service.persistence.impl.BookmarksEntryPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of bookmarks entries that the user has permission to view where groupId = ? and folderId = any ? and status = ?.
 *
 * @param groupId the group ID/*from   w  w  w .j a v  a 2s.c om*/
 * @param folderIds the folder IDs
 * @param status the status
 * @return the number of matching bookmarks entries that the user has permission to view
 */
@Override
public int filterCountByG_F_S(long groupId, long[] folderIds, int status) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return countByG_F_S(groupId, folderIds, status);
    }

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

    query.append(_FINDER_COLUMN_G_F_S_GROUPID_2);

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

        query.append(_FINDER_COLUMN_G_F_S_FOLDERID_7);

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

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(WHERE_AND);
    }

    query.append(_FINDER_COLUMN_G_F_S_STATUS_2);

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

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

    Session session = null;

    try {
        session = openSession();

        Query q = session.createQuery(sql);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        qPos.add(status);

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

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

From source file:com.liferay.bookmarks.service.persistence.impl.BookmarksEntryPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the bookmarks entries that the user has permission to view where groupId = ? and folderId = any ? and status ≠ ?.
 *
 * <p>//  ww w .  j  a  v a  2 s . c o  m
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link BookmarksEntryModelImpl}. 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 status the status
 * @param start the lower bound of the range of bookmarks entries
 * @param end the upper bound of the range of bookmarks entries (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching bookmarks entries that the user has permission to view
 */
@Override
public List<BookmarksEntry> filterFindByG_F_NotS(long groupId, long[] folderIds, int status, int start, int end,
        OrderByComparator<BookmarksEntry> orderByComparator) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return findByG_F_NotS(groupId, folderIds, status, 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();

    query.append(_SQL_SELECT_BOOKMARKSENTRY_WHERE);

    query.append(_FINDER_COLUMN_G_F_NOTS_GROUPID_2);

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

        query.append(_FINDER_COLUMN_G_F_NOTS_FOLDERID_7);

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

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(WHERE_AND);
    }

    query.append(_FINDER_COLUMN_G_F_NOTS_STATUS_2);

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

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

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

    Session session = null;

    try {
        session = openSession();

        Query q = session.createQuery(sql);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        qPos.add(status);

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

From source file:com.liferay.bookmarks.service.persistence.impl.BookmarksEntryPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the bookmarks entries where groupId = &#63; and folderId = &#63; and status &ne; &#63;, optionally using the finder cache.
 *
 * <p>//w  ww. jav  a2  s.c o m
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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 BookmarksEntryModelImpl}. 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 status the status
 * @param start the lower bound of the range of bookmarks entries
 * @param end the upper bound of the range of bookmarks entries (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 bookmarks entries
 */
@Override
public List<BookmarksEntry> findByG_F_NotS(long groupId, long[] folderIds, int status, int start, int end,
        OrderByComparator<BookmarksEntry> 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_NotS(groupId, folderIds[0], status, 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), status };
    } else {
        finderArgs = new Object[] { groupId, StringUtil.merge(folderIds), status,

                start, end, orderByComparator };
    }

    List<BookmarksEntry> list = null;

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

        if ((list != null) && !list.isEmpty()) {
            for (BookmarksEntry bookmarksEntry : list) {
                if ((groupId != bookmarksEntry.getGroupId())
                        || !ArrayUtil.contains(folderIds, bookmarksEntry.getFolderId())
                        || (status == bookmarksEntry.getStatus())) {
                    list = null;

                    break;
                }
            }
        }
    }

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

        query.append(_SQL_SELECT_BOOKMARKSENTRY_WHERE);

        query.append(_FINDER_COLUMN_G_F_NOTS_GROUPID_2);

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

            query.append(_FINDER_COLUMN_G_F_NOTS_FOLDERID_7);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_G_F_NOTS_STATUS_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(BookmarksEntryModelImpl.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);

            qPos.add(status);

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

                Collections.sort(list);

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

            cacheResult(list);

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

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

    return list;
}

From source file:com.liferay.bookmarks.service.persistence.impl.BookmarksEntryPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of bookmarks entries where groupId = &#63; and folderId = any &#63; and status &ne; &#63;.
 *
 * @param groupId the group ID//from  w  ww.  j a  v  a 2 s . co  m
 * @param folderIds the folder IDs
 * @param status the status
 * @return the number of matching bookmarks entries
 */
@Override
public int countByG_F_NotS(long groupId, long[] folderIds, int status) {
    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), status };

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

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

        query.append(_SQL_COUNT_BOOKMARKSENTRY_WHERE);

        query.append(_FINDER_COLUMN_G_F_NOTS_GROUPID_2);

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

            query.append(_FINDER_COLUMN_G_F_NOTS_FOLDERID_7);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_G_F_NOTS_STATUS_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);

            qPos.add(groupId);

            qPos.add(status);

            count = (Long) q.uniqueResult();

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

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

    return count.intValue();
}

From source file:com.liferay.bookmarks.service.persistence.impl.BookmarksEntryPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of bookmarks entries that the user has permission to view where groupId = &#63; and folderId = any &#63; and status &ne; &#63;.
 *
 * @param groupId the group ID//from  w  w  w .  ja  v a  2  s  .c  o m
 * @param folderIds the folder IDs
 * @param status the status
 * @return the number of matching bookmarks entries that the user has permission to view
 */
@Override
public int filterCountByG_F_NotS(long groupId, long[] folderIds, int status) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return countByG_F_NotS(groupId, folderIds, status);
    }

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

    query.append(_FINDER_COLUMN_G_F_NOTS_GROUPID_2);

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

        query.append(_FINDER_COLUMN_G_F_NOTS_FOLDERID_7);

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

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(WHERE_AND);
    }

    query.append(_FINDER_COLUMN_G_F_NOTS_STATUS_2);

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

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

    Session session = null;

    try {
        session = openSession();

        Query q = session.createQuery(sql);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        qPos.add(status);

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

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

From source file:com.liferay.bookmarks.service.persistence.impl.BookmarksEntryPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the bookmarks entries that the user has permission to view where groupId = &#63; and userId = &#63; and folderId = any &#63; and status = &#63;.
 *
 * <p>/*w ww .j a va  2  s. com*/
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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 BookmarksEntryModelImpl}. 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 userId the user ID
 * @param folderIds the folder IDs
 * @param status the status
 * @param start the lower bound of the range of bookmarks entries
 * @param end the upper bound of the range of bookmarks entries (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching bookmarks entries that the user has permission to view
 */
@Override
public List<BookmarksEntry> filterFindByG_U_F_S(long groupId, long userId, long[] folderIds, int status,
        int start, int end, OrderByComparator<BookmarksEntry> orderByComparator) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return findByG_U_F_S(groupId, userId, folderIds, status, 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();

    query.append(_SQL_SELECT_BOOKMARKSENTRY_WHERE);

    query.append(_FINDER_COLUMN_G_U_F_S_GROUPID_2);

    query.append(_FINDER_COLUMN_G_U_F_S_USERID_2);

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

        query.append(_FINDER_COLUMN_G_U_F_S_FOLDERID_7);

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

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(WHERE_AND);
    }

    query.append(_FINDER_COLUMN_G_U_F_S_STATUS_2);

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

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

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

    Session session = null;

    try {
        session = openSession();

        Query q = session.createQuery(sql);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        qPos.add(userId);

        qPos.add(status);

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

From source file:com.liferay.bookmarks.service.persistence.impl.BookmarksEntryPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the bookmarks entries where groupId = &#63; and userId = &#63; and folderId = &#63; and status = &#63;, optionally using the finder cache.
 *
 * <p>//ww  w .jav  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 BookmarksEntryModelImpl}. 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 userId the user ID
 * @param folderId the folder ID
 * @param status the status
 * @param start the lower bound of the range of bookmarks entries
 * @param end the upper bound of the range of bookmarks entries (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 bookmarks entries
 */
@Override
public List<BookmarksEntry> findByG_U_F_S(long groupId, long userId, long[] folderIds, int status, int start,
        int end, OrderByComparator<BookmarksEntry> 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_U_F_S(groupId, userId, folderIds[0], status, 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, userId, StringUtil.merge(folderIds), status };
    } else {
        finderArgs = new Object[] { groupId, userId, StringUtil.merge(folderIds), status,

                start, end, orderByComparator };
    }

    List<BookmarksEntry> list = null;

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

        if ((list != null) && !list.isEmpty()) {
            for (BookmarksEntry bookmarksEntry : list) {
                if ((groupId != bookmarksEntry.getGroupId()) || (userId != bookmarksEntry.getUserId())
                        || !ArrayUtil.contains(folderIds, bookmarksEntry.getFolderId())
                        || (status != bookmarksEntry.getStatus())) {
                    list = null;

                    break;
                }
            }
        }
    }

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

        query.append(_SQL_SELECT_BOOKMARKSENTRY_WHERE);

        query.append(_FINDER_COLUMN_G_U_F_S_GROUPID_2);

        query.append(_FINDER_COLUMN_G_U_F_S_USERID_2);

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

            query.append(_FINDER_COLUMN_G_U_F_S_FOLDERID_7);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_G_U_F_S_STATUS_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(BookmarksEntryModelImpl.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);

            qPos.add(userId);

            qPos.add(status);

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

                Collections.sort(list);

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

            cacheResult(list);

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

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

    return list;
}

From source file:com.liferay.bookmarks.service.persistence.impl.BookmarksEntryPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of bookmarks entries where groupId = &#63; and userId = &#63; and folderId = any &#63; and status = &#63;.
 *
 * @param groupId the group ID/* ww  w.j a  v a  2 s. c  om*/
 * @param userId the user ID
 * @param folderIds the folder IDs
 * @param status the status
 * @return the number of matching bookmarks entries
 */
@Override
public int countByG_U_F_S(long groupId, long userId, long[] folderIds, int status) {
    if (folderIds == null) {
        folderIds = new long[0];
    } else if (folderIds.length > 1) {
        folderIds = ArrayUtil.unique(folderIds);

        Arrays.sort(folderIds);
    }

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

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

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

        query.append(_SQL_COUNT_BOOKMARKSENTRY_WHERE);

        query.append(_FINDER_COLUMN_G_U_F_S_GROUPID_2);

        query.append(_FINDER_COLUMN_G_U_F_S_USERID_2);

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

            query.append(_FINDER_COLUMN_G_U_F_S_FOLDERID_7);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_G_U_F_S_STATUS_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);

            qPos.add(groupId);

            qPos.add(userId);

            qPos.add(status);

            count = (Long) q.uniqueResult();

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

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

    return count.intValue();
}

From source file:com.liferay.bookmarks.service.persistence.impl.BookmarksEntryPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of bookmarks entries that the user has permission to view where groupId = &#63; and userId = &#63; and folderId = any &#63; and status = &#63;.
 *
 * @param groupId the group ID/*ww w .  j  a va 2  s  .  c  om*/
 * @param userId the user ID
 * @param folderIds the folder IDs
 * @param status the status
 * @return the number of matching bookmarks entries that the user has permission to view
 */
@Override
public int filterCountByG_U_F_S(long groupId, long userId, long[] folderIds, int status) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return countByG_U_F_S(groupId, userId, folderIds, status);
    }

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

    query.append(_FINDER_COLUMN_G_U_F_S_GROUPID_2);

    query.append(_FINDER_COLUMN_G_U_F_S_USERID_2);

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

        query.append(_FINDER_COLUMN_G_U_F_S_FOLDERID_7);

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

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(WHERE_AND);
    }

    query.append(_FINDER_COLUMN_G_U_F_S_STATUS_2);

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

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

    Session session = null;

    try {
        session = openSession();

        Query q = session.createQuery(sql);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        qPos.add(userId);

        qPos.add(status);

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

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