Example usage for com.liferay.portal.kernel.security.permission InlineSQLHelperUtil replacePermissionCheck

List of usage examples for com.liferay.portal.kernel.security.permission InlineSQLHelperUtil replacePermissionCheck

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.security.permission InlineSQLHelperUtil replacePermissionCheck.

Prototype

public static String replacePermissionCheck(String sql, String className, String classPKField,
            String userIdField, String bridgeJoin) 

Source Link

Usage

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 permissions to view where groupId = ? and folderId = ?.
 *
 * <p>//from ww  w. ja 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 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 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(long groupId, long folderId, int start, int end,
        OrderByComparator<BookmarksEntry> orderByComparator) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return findByG_F(groupId, folderId, start, end, orderByComparator);
    }

    StringBundler query = null;

    if (orderByComparator != null) {
        query = new StringBundler(4 + (orderByComparator.getOrderByFields().length * 2));
    } else {
        query = new StringBundler(4);
    }

    query.append(_SQL_SELECT_BOOKMARKSENTRY_WHERE);

    query.append(_FINDER_COLUMN_G_F_GROUPID_2);

    query.append(_FINDER_COLUMN_G_F_FOLDERID_2);

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

        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

protected BookmarksEntry filterGetByG_F_PrevAndNext(Session session, BookmarksEntry bookmarksEntry,
        long groupId, long folderId, OrderByComparator<BookmarksEntry> orderByComparator, boolean previous) {
    StringBundler query = null;//from  w  w w.  ja  v  a 2 s. c  o m

    if (orderByComparator != null) {
        query = new StringBundler(5 + (orderByComparator.getOrderByConditionFields().length * 3)
                + (orderByComparator.getOrderByFields().length * 3));
    } else {
        query = new StringBundler(4);
    }

    query.append(_SQL_SELECT_BOOKMARKSENTRY_WHERE);

    query.append(_FINDER_COLUMN_G_F_GROUPID_2);

    query.append(_FINDER_COLUMN_G_F_FOLDERID_2);

    if (orderByComparator != null) {
        String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

        if (orderByConditionFields.length > 0) {
            query.append(WHERE_AND);
        }

        for (int i = 0; i < orderByConditionFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByConditionFields[i]);

            if ((i + 1) < orderByConditionFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
                } else {
                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN);
                } else {
                    query.append(WHERE_LESSER_THAN);
                }
            }
        }

        query.append(ORDER_BY_CLAUSE);

        String[] orderByFields = orderByComparator.getOrderByFields();

        for (int i = 0; i < orderByFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByFields[i]);

            if ((i + 1) < orderByFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC_HAS_NEXT);
                } else {
                    query.append(ORDER_BY_DESC_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC);
                } else {
                    query.append(ORDER_BY_DESC);
                }
            }
        }
    } 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);

    Query q = session.createQuery(sql);

    q.setFirstResult(0);
    q.setMaxResults(2);

    QueryPos qPos = QueryPos.getInstance(q);

    qPos.add(groupId);

    qPos.add(folderId);

    if (orderByComparator != null) {
        Object[] values = orderByComparator.getOrderByConditionValues(bookmarksEntry);

        for (Object value : values) {
            qPos.add(value);
        }
    }

    List<BookmarksEntry> list = q.list();

    if (list.size() == 2) {
        return list.get(1);
    } else {
        return null;
    }
}

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 folderId = any &#63;.
 *
 * <p>//from   w w w . j a v  a2s  .  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 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 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(long groupId, long[] folderIds, int start, int end,
        OrderByComparator<BookmarksEntry> 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();

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

        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 the number of bookmarks entries that the user has permission to view where groupId = &#63; and folderId = &#63;.
 *
 * @param groupId the group ID/*from  w w  w  . j av a 2  s.com*/
 * @param folderId the folder ID
 * @return the number of matching bookmarks entries that the user has permission to view
 */
@Override
public int filterCountByG_F(long groupId, long folderId) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return countByG_F(groupId, folderId);
    }

    StringBundler query = new StringBundler(3);

    query.append(_SQL_COUNT_BOOKMARKSENTRY_WHERE);

    query.append(_FINDER_COLUMN_G_F_GROUPID_2);

    query.append(_FINDER_COLUMN_G_F_FOLDERID_2);

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

        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 the number of bookmarks entries that the user has permission to view where groupId = &#63; and folderId = any &#63;.
 *
 * @param groupId the group ID/*from w w w  .j av a  2s. co  m*/
 * @param folderIds the folder IDs
 * @return the number of matching bookmarks entries 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(_SQL_COUNT_BOOKMARKSENTRY_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(), 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);

        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 permissions to view where groupId = &#63; and status = &#63;.
 *
 * <p>/*from w ww .  ja va  2 s .  c  om*/
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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 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_S(long groupId, int status, int start, int end,
        OrderByComparator<BookmarksEntry> orderByComparator) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return findByG_S(groupId, status, start, end, orderByComparator);
    }

    StringBundler query = null;

    if (orderByComparator != null) {
        query = new StringBundler(4 + (orderByComparator.getOrderByFields().length * 2));
    } else {
        query = new StringBundler(4);
    }

    query.append(_SQL_SELECT_BOOKMARKSENTRY_WHERE);

    query.append(_FINDER_COLUMN_G_S_GROUPID_2);

    query.append(_FINDER_COLUMN_G_S_STATUS_2);

    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

protected BookmarksEntry filterGetByG_S_PrevAndNext(Session session, BookmarksEntry bookmarksEntry,
        long groupId, int status, OrderByComparator<BookmarksEntry> orderByComparator, boolean previous) {
    StringBundler query = null;/*ww w.j  av  a 2  s.  c  o m*/

    if (orderByComparator != null) {
        query = new StringBundler(5 + (orderByComparator.getOrderByConditionFields().length * 3)
                + (orderByComparator.getOrderByFields().length * 3));
    } else {
        query = new StringBundler(4);
    }

    query.append(_SQL_SELECT_BOOKMARKSENTRY_WHERE);

    query.append(_FINDER_COLUMN_G_S_GROUPID_2);

    query.append(_FINDER_COLUMN_G_S_STATUS_2);

    if (orderByComparator != null) {
        String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

        if (orderByConditionFields.length > 0) {
            query.append(WHERE_AND);
        }

        for (int i = 0; i < orderByConditionFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByConditionFields[i]);

            if ((i + 1) < orderByConditionFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
                } else {
                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN);
                } else {
                    query.append(WHERE_LESSER_THAN);
                }
            }
        }

        query.append(ORDER_BY_CLAUSE);

        String[] orderByFields = orderByComparator.getOrderByFields();

        for (int i = 0; i < orderByFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByFields[i]);

            if ((i + 1) < orderByFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC_HAS_NEXT);
                } else {
                    query.append(ORDER_BY_DESC_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC);
                } else {
                    query.append(ORDER_BY_DESC);
                }
            }
        }
    } 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);

    Query q = session.createQuery(sql);

    q.setFirstResult(0);
    q.setMaxResults(2);

    QueryPos qPos = QueryPos.getInstance(q);

    qPos.add(groupId);

    qPos.add(status);

    if (orderByComparator != null) {
        Object[] values = orderByComparator.getOrderByConditionValues(bookmarksEntry);

        for (Object value : values) {
            qPos.add(value);
        }
    }

    List<BookmarksEntry> list = q.list();

    if (list.size() == 2) {
        return list.get(1);
    } else {
        return null;
    }
}

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 status = &#63;.
 *
 * @param groupId the group ID//from  w  w  w.  j  a v a 2s .  com
 * @param status the status
 * @return the number of matching bookmarks entries that the user has permission to view
 */
@Override
public int filterCountByG_S(long groupId, int status) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return countByG_S(groupId, status);
    }

    StringBundler query = new StringBundler(3);

    query.append(_SQL_COUNT_BOOKMARKSENTRY_WHERE);

    query.append(_FINDER_COLUMN_G_S_GROUPID_2);

    query.append(_FINDER_COLUMN_G_S_STATUS_2);

    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 permissions to view where groupId = &#63; and status &ne; &#63;.
 *
 * <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 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 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_NotS(long groupId, int status, int start, int end,
        OrderByComparator<BookmarksEntry> orderByComparator) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return findByG_NotS(groupId, status, start, end, orderByComparator);
    }

    StringBundler query = null;

    if (orderByComparator != null) {
        query = new StringBundler(4 + (orderByComparator.getOrderByFields().length * 2));
    } else {
        query = new StringBundler(4);
    }

    query.append(_SQL_SELECT_BOOKMARKSENTRY_WHERE);

    query.append(_FINDER_COLUMN_G_NOTS_GROUPID_2);

    query.append(_FINDER_COLUMN_G_NOTS_STATUS_2);

    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

protected BookmarksEntry filterGetByG_NotS_PrevAndNext(Session session, BookmarksEntry bookmarksEntry,
        long groupId, int status, OrderByComparator<BookmarksEntry> orderByComparator, boolean previous) {
    StringBundler query = null;/*from  w ww. j  av  a  2s. c o m*/

    if (orderByComparator != null) {
        query = new StringBundler(5 + (orderByComparator.getOrderByConditionFields().length * 3)
                + (orderByComparator.getOrderByFields().length * 3));
    } else {
        query = new StringBundler(4);
    }

    query.append(_SQL_SELECT_BOOKMARKSENTRY_WHERE);

    query.append(_FINDER_COLUMN_G_NOTS_GROUPID_2);

    query.append(_FINDER_COLUMN_G_NOTS_STATUS_2);

    if (orderByComparator != null) {
        String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

        if (orderByConditionFields.length > 0) {
            query.append(WHERE_AND);
        }

        for (int i = 0; i < orderByConditionFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByConditionFields[i]);

            if ((i + 1) < orderByConditionFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
                } else {
                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN);
                } else {
                    query.append(WHERE_LESSER_THAN);
                }
            }
        }

        query.append(ORDER_BY_CLAUSE);

        String[] orderByFields = orderByComparator.getOrderByFields();

        for (int i = 0; i < orderByFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByFields[i]);

            if ((i + 1) < orderByFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC_HAS_NEXT);
                } else {
                    query.append(ORDER_BY_DESC_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC);
                } else {
                    query.append(ORDER_BY_DESC);
                }
            }
        }
    } 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);

    Query q = session.createQuery(sql);

    q.setFirstResult(0);
    q.setMaxResults(2);

    QueryPos qPos = QueryPos.getInstance(q);

    qPos.add(groupId);

    qPos.add(status);

    if (orderByComparator != null) {
        Object[] values = orderByComparator.getOrderByConditionValues(bookmarksEntry);

        for (Object value : values) {
            qPos.add(value);
        }
    }

    List<BookmarksEntry> list = q.list();

    if (list.size() == 2) {
        return list.get(1);
    } else {
        return null;
    }
}