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.portlet.asset.service.persistence.AssetEntryFinderImpl.java

License:Open Source License

protected String getNotTagIds(long[] notTagIds) {
    if (notTagIds.length == 0) {
        return StringPool.BLANK;
    }/*from  w  w w  .  j  a v a2s  .com*/

    StringBundler sb = new StringBundler(notTagIds.length * 4 - 1);

    for (int i = 0; i < notTagIds.length; i++) {
        sb.append("AssetEntry.entryId NOT IN (");
        sb.append(CustomSQLUtil.get(FIND_BY_AND_TAG_IDS));
        sb.append(StringPool.CLOSE_PARENTHESIS);

        if ((i + 1) < notTagIds.length) {
            sb.append(" AND ");
        }
    }

    return sb.toString();
}

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

License:Open Source License

/**
 * Returns an ordered range of all the bookmarks entries where groupId = &#63; and folderId = any &#63;.
 *
 * <p>//  w w  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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
 * </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
 * @throws SystemException if a system exception occurred
 */
public List<BookmarksEntry> findByG_F(long groupId, long[] folderIds, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F;
        finderArgs = new Object[] { groupId, StringUtil.merge(folderIds) };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F;
        finderArgs = new Object[] { groupId, StringUtil.merge(folderIds),

                start, end, orderByComparator };
    }

    List<BookmarksEntry> list = (List<BookmarksEntry>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

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

        query.append(_SQL_SELECT_BOOKMARKSENTRY_WHERE);

        boolean conjunctionable = false;

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

        query.append(_FINDER_COLUMN_G_F_GROUPID_5);

        conjunctionable = true;

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

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < folderIds.length; i++) {
                query.append(_FINDER_COLUMN_G_F_FOLDERID_5);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        }

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

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

            list = (List<BookmarksEntry>) QueryUtil.list(q, getDialect(), start, end);
        } catch (Exception e) {
            throw processException(e);
        } finally {
            if (list == null) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);
            } else {
                cacheResult(list);

                FinderCacheUtil.putResult(finderPath, finderArgs, list);
            }

            closeSession(session);
        }
    }

    return list;
}

From source file:com.liferay.portlet.bookmarks.service.persistence.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 ww  w.j a v a  2s .  co  m
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
 * </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
 * @throws SystemException if a system exception occurred
 */
public List<BookmarksEntry> filterFindByG_F(long groupId, long[] folderIds, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return findByG_F(groupId, folderIds, start, end, orderByComparator);
    }

    StringBundler query = new StringBundler();

    query.append(_SQL_SELECT_BOOKMARKSENTRY_WHERE);

    boolean conjunctionable = false;

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

    query.append(_FINDER_COLUMN_G_F_GROUPID_5);

    conjunctionable = true;

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

        query.append(StringPool.OPEN_PARENTHESIS);

        for (int i = 0; i < folderIds.length; i++) {
            query.append(_FINDER_COLUMN_G_F_FOLDERID_5);

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

        query.append(StringPool.CLOSE_PARENTHESIS);

        conjunctionable = true;
    }

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

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

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

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

License:Open Source License

/**
 * Returns the number of bookmarks entries where groupId = &#63; and folderId = any &#63;.
 *
 * @param groupId the group ID//from  ww  w  .j  a  v  a 2s .  c  o m
 * @param folderIds the folder IDs
 * @return the number of matching bookmarks entries
 * @throws SystemException if a system exception occurred
 */
public int countByG_F(long groupId, long[] folderIds) throws SystemException {
    Object[] finderArgs = new Object[] { groupId, StringUtil.merge(folderIds) };

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

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

        query.append(_SQL_COUNT_BOOKMARKSENTRY_WHERE);

        boolean conjunctionable = false;

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

        query.append(_FINDER_COLUMN_G_F_GROUPID_5);

        conjunctionable = true;

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

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < folderIds.length; i++) {
                query.append(_FINDER_COLUMN_G_F_FOLDERID_5);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(groupId);

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

            count = (Long) q.uniqueResult();
        } catch (Exception e) {
            throw processException(e);
        } finally {
            if (count == null) {
                count = Long.valueOf(0);
            }

            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F, finderArgs, count);

            closeSession(session);
        }
    }

    return count.intValue();
}

From source file:com.liferay.portlet.bookmarks.service.persistence.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/*ww w.  java  2 s  . c om*/
 * @param folderIds the folder IDs
 * @return the number of matching bookmarks entries that the user has permission to view
 * @throws SystemException if a system exception occurred
 */
public int filterCountByG_F(long groupId, long[] folderIds) throws SystemException {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return countByG_F(groupId, folderIds);
    }

    StringBundler query = new StringBundler();

    query.append(_SQL_COUNT_BOOKMARKSENTRY_WHERE);

    boolean conjunctionable = false;

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

    query.append(_FINDER_COLUMN_G_F_GROUPID_5);

    conjunctionable = true;

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

        query.append(StringPool.OPEN_PARENTHESIS);

        for (int i = 0; i < folderIds.length; i++) {
            query.append(_FINDER_COLUMN_G_F_FOLDERID_5);

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

        query.append(StringPool.CLOSE_PARENTHESIS);

        conjunctionable = true;
    }

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

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

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

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

From source file:com.liferay.portlet.calendar.service.persistence.CalEventPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the cal events where groupId = &#63; and type = any &#63;.
 *
 * <p>/*from   www .j av  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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
 * </p>
 *
 * @param groupId the group ID
 * @param types the types
 * @param start the lower bound of the range of cal events
 * @param end the upper bound of the range of cal events (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching cal events
 * @throws SystemException if a system exception occurred
 */
public List<CalEvent> findByG_T(long groupId, String[] types, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T;
        finderArgs = new Object[] { groupId, StringUtil.merge(types) };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T;
        finderArgs = new Object[] { groupId, StringUtil.merge(types),

                start, end, orderByComparator };
    }

    List<CalEvent> list = (List<CalEvent>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

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

        query.append(_SQL_SELECT_CALEVENT_WHERE);

        boolean conjunctionable = false;

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

        query.append(_FINDER_COLUMN_G_T_GROUPID_5);

        conjunctionable = true;

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

            query.append(StringPool.OPEN_PARENTHESIS);

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

                if (type == null) {
                    query.append(_FINDER_COLUMN_G_T_TYPE_4);
                } else {
                    if (type.equals(StringPool.BLANK)) {
                        query.append(_FINDER_COLUMN_G_T_TYPE_6);
                    } else {
                        query.append(_FINDER_COLUMN_G_T_TYPE_5);
                    }
                }

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        }

        else {
            query.append(CalEventModelImpl.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 (types != null) {
                qPos.add(types);
            }

            list = (List<CalEvent>) QueryUtil.list(q, getDialect(), start, end);
        } catch (Exception e) {
            throw processException(e);
        } finally {
            if (list == null) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);
            } else {
                cacheResult(list);

                FinderCacheUtil.putResult(finderPath, finderArgs, list);
            }

            closeSession(session);
        }
    }

    return list;
}

From source file:com.liferay.portlet.calendar.service.persistence.CalEventPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the cal events that the user has permission to view where groupId = &#63; and type = any &#63;.
 *
 * <p>//from  w w w. j  av  a  2  s.  co  m
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
 * </p>
 *
 * @param groupId the group ID
 * @param types the types
 * @param start the lower bound of the range of cal events
 * @param end the upper bound of the range of cal events (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching cal events that the user has permission to view
 * @throws SystemException if a system exception occurred
 */
public List<CalEvent> filterFindByG_T(long groupId, String[] types, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return findByG_T(groupId, types, start, end, orderByComparator);
    }

    StringBundler query = new StringBundler();

    if (getDB().isSupportsInlineDistinct()) {
        query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
    } else {
        query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_1);
    }

    boolean conjunctionable = false;

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

    query.append(_FINDER_COLUMN_G_T_GROUPID_5);

    conjunctionable = true;

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

        query.append(StringPool.OPEN_PARENTHESIS);

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

            if (type == null) {
                query.append(_FINDER_COLUMN_G_T_TYPE_4);
            } else {
                if (type.equals(StringPool.BLANK)) {
                    query.append(_FINDER_COLUMN_G_T_TYPE_6);
                } else {
                    query.append(_FINDER_COLUMN_G_T_TYPE_5);
                }
            }

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

        query.append(StringPool.CLOSE_PARENTHESIS);

        conjunctionable = true;
    }

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

    if (orderByComparator != null) {
        if (getDB().isSupportsInlineDistinct()) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE, orderByComparator);
        }
    }

    else {
        if (getDB().isSupportsInlineDistinct()) {
            query.append(CalEventModelImpl.ORDER_BY_JPQL);
        } else {
            query.append(CalEventModelImpl.ORDER_BY_SQL);
        }
    }

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

    Session session = null;

    try {
        session = openSession();

        SQLQuery q = session.createSQLQuery(sql);

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

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

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

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

From source file:com.liferay.portlet.calendar.service.persistence.CalEventPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the cal events where groupId = &#63; and type = any &#63; and repeating = &#63;.
 *
 * <p>/*from   www.jav a 2s  .  c om*/
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
 * </p>
 *
 * @param groupId the group ID
 * @param types the types
 * @param repeating the repeating
 * @param start the lower bound of the range of cal events
 * @param end the upper bound of the range of cal events (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching cal events
 * @throws SystemException if a system exception occurred
 */
public List<CalEvent> findByG_T_R(long groupId, String[] types, boolean repeating, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T_R;
        finderArgs = new Object[] { groupId, StringUtil.merge(types), repeating };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T_R;
        finderArgs = new Object[] { groupId, StringUtil.merge(types), repeating,

                start, end, orderByComparator };
    }

    List<CalEvent> list = (List<CalEvent>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

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

        query.append(_SQL_SELECT_CALEVENT_WHERE);

        boolean conjunctionable = false;

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

        query.append(_FINDER_COLUMN_G_T_R_GROUPID_5);

        conjunctionable = true;

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

            query.append(StringPool.OPEN_PARENTHESIS);

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

                if (type == null) {
                    query.append(_FINDER_COLUMN_G_T_R_TYPE_4);
                } else {
                    if (type.equals(StringPool.BLANK)) {
                        query.append(_FINDER_COLUMN_G_T_R_TYPE_6);
                    } else {
                        query.append(_FINDER_COLUMN_G_T_R_TYPE_5);
                    }
                }

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

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

        query.append(_FINDER_COLUMN_G_T_R_REPEATING_5);

        conjunctionable = true;

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        }

        else {
            query.append(CalEventModelImpl.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 (types != null) {
                qPos.add(types);
            }

            qPos.add(repeating);

            list = (List<CalEvent>) QueryUtil.list(q, getDialect(), start, end);
        } catch (Exception e) {
            throw processException(e);
        } finally {
            if (list == null) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);
            } else {
                cacheResult(list);

                FinderCacheUtil.putResult(finderPath, finderArgs, list);
            }

            closeSession(session);
        }
    }

    return list;
}

From source file:com.liferay.portlet.calendar.service.persistence.CalEventPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the cal events that the user has permission to view where groupId = &#63; and type = any &#63; and repeating = &#63;.
 *
 * <p>//from   www. ja 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
 * </p>
 *
 * @param groupId the group ID
 * @param types the types
 * @param repeating the repeating
 * @param start the lower bound of the range of cal events
 * @param end the upper bound of the range of cal events (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching cal events that the user has permission to view
 * @throws SystemException if a system exception occurred
 */
public List<CalEvent> filterFindByG_T_R(long groupId, String[] types, boolean repeating, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return findByG_T_R(groupId, types, repeating, start, end, orderByComparator);
    }

    StringBundler query = new StringBundler();

    if (getDB().isSupportsInlineDistinct()) {
        query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
    } else {
        query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_1);
    }

    boolean conjunctionable = false;

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

    query.append(_FINDER_COLUMN_G_T_R_GROUPID_5);

    conjunctionable = true;

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

        query.append(StringPool.OPEN_PARENTHESIS);

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

            if (type == null) {
                query.append(_FINDER_COLUMN_G_T_R_TYPE_4);
            } else {
                if (type.equals(StringPool.BLANK)) {
                    query.append(_FINDER_COLUMN_G_T_R_TYPE_6);
                } else {
                    query.append(_FINDER_COLUMN_G_T_R_TYPE_5);
                }
            }

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

        query.append(StringPool.CLOSE_PARENTHESIS);

        conjunctionable = true;
    }

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

    query.append(_FINDER_COLUMN_G_T_R_REPEATING_5);

    conjunctionable = true;

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

    if (orderByComparator != null) {
        if (getDB().isSupportsInlineDistinct()) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE, orderByComparator);
        }
    }

    else {
        if (getDB().isSupportsInlineDistinct()) {
            query.append(CalEventModelImpl.ORDER_BY_JPQL);
        } else {
            query.append(CalEventModelImpl.ORDER_BY_SQL);
        }
    }

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

    Session session = null;

    try {
        session = openSession();

        SQLQuery q = session.createSQLQuery(sql);

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

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

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

        qPos.add(repeating);

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

From source file:com.liferay.portlet.calendar.service.persistence.CalEventPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of cal events where groupId = &#63; and type = any &#63;.
 *
 * @param groupId the group ID// w w w .  ja v  a2 s  . c  o m
 * @param types the types
 * @return the number of matching cal events
 * @throws SystemException if a system exception occurred
 */
public int countByG_T(long groupId, String[] types) throws SystemException {
    Object[] finderArgs = new Object[] { groupId, StringUtil.merge(types) };

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

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

        query.append(_SQL_COUNT_CALEVENT_WHERE);

        boolean conjunctionable = false;

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

        query.append(_FINDER_COLUMN_G_T_GROUPID_5);

        conjunctionable = true;

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

            query.append(StringPool.OPEN_PARENTHESIS);

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

                if (type == null) {
                    query.append(_FINDER_COLUMN_G_T_TYPE_4);
                } else {
                    if (type.equals(StringPool.BLANK)) {
                        query.append(_FINDER_COLUMN_G_T_TYPE_6);
                    } else {
                        query.append(_FINDER_COLUMN_G_T_TYPE_5);
                    }
                }

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(groupId);

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

            count = (Long) q.uniqueResult();
        } catch (Exception e) {
            throw processException(e);
        } finally {
            if (count == null) {
                count = Long.valueOf(0);
            }

            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_T, finderArgs, count);

            closeSession(session);
        }
    }

    return count.intValue();
}