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.knowledgebase.service.persistence.impl.KBArticlePersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the k b articles that the user has permission to view where groupId = ? and parentResourcePrimKey = any ? and main = ?.
 *
 * <p>// ww  w.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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.knowledgebase.model.impl.KBArticleModelImpl}. 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 parentResourcePrimKeies the parent resource prim keies
 * @param main the main
 * @param start the lower bound of the range of k b articles
 * @param end the upper bound of the range of k b articles (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching k b articles that the user has permission to view
 */
@Override
public List<KBArticle> filterFindByG_P_M(long groupId, long[] parentResourcePrimKeies, boolean main, int start,
        int end, OrderByComparator<KBArticle> orderByComparator) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return findByG_P_M(groupId, parentResourcePrimKeies, main, start, end, orderByComparator);
    }

    if (parentResourcePrimKeies == null) {
        parentResourcePrimKeies = new long[0];
    } else {
        parentResourcePrimKeies = ArrayUtil.unique(parentResourcePrimKeies);
    }

    StringBundler query = new StringBundler();

    if (getDB().isSupportsInlineDistinct()) {
        query.append(_FILTER_SQL_SELECT_KBARTICLE_WHERE);
    } else {
        query.append(_FILTER_SQL_SELECT_KBARTICLE_NO_INLINE_DISTINCT_WHERE_1);
    }

    query.append(_FINDER_COLUMN_G_P_M_GROUPID_2);

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

        query.append(_FINDER_COLUMN_G_P_M_PARENTRESOURCEPRIMKEY_7);

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

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(WHERE_AND);
    }

    query.append(_FINDER_COLUMN_G_P_M_MAIN_2);

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

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

    if (orderByComparator != null) {
        if (getDB().isSupportsInlineDistinct()) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator, true);
        } else {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE, orderByComparator, true);
        }
    } else {
        if (getDB().isSupportsInlineDistinct()) {
            query.append(KBArticleModelImpl.ORDER_BY_JPQL);
        } else {
            query.append(KBArticleModelImpl.ORDER_BY_SQL);
        }
    }

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

    Session session = null;

    try {
        session = openSession();

        SQLQuery q = session.createSynchronizedSQLQuery(sql);

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

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        qPos.add(main);

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

From source file:com.liferay.knowledgebase.service.persistence.impl.KBArticlePersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the k b articles where groupId = &#63; and parentResourcePrimKey = any &#63; and main = &#63;.
 *
 * <p>//from www .j av  a2  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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.knowledgebase.model.impl.KBArticleModelImpl}. 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 parentResourcePrimKeies the parent resource prim keies
 * @param main the main
 * @param start the lower bound of the range of k b articles
 * @param end the upper bound of the range of k b articles (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching k b articles
 */
@Override
public List<KBArticle> findByG_P_M(long groupId, long[] parentResourcePrimKeies, boolean main, int start,
        int end, OrderByComparator<KBArticle> orderByComparator) {
    if (parentResourcePrimKeies == null) {
        parentResourcePrimKeies = new long[0];
    } else {
        parentResourcePrimKeies = ArrayUtil.unique(parentResourcePrimKeies);
    }

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

                start, end, orderByComparator };
    }

    List<KBArticle> list = (List<KBArticle>) FinderCacheUtil
            .getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_M, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (KBArticle kbArticle : list) {
            if ((groupId != kbArticle.getGroupId())
                    || !ArrayUtil.contains(parentResourcePrimKeies, kbArticle.getParentResourcePrimKey())
                    || (main != kbArticle.getMain())) {
                list = null;

                break;
            }
        }
    }

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

        query.append(_SQL_SELECT_KBARTICLE_WHERE);

        query.append(_FINDER_COLUMN_G_P_M_GROUPID_2);

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

            query.append(_FINDER_COLUMN_G_P_M_PARENTRESOURCEPRIMKEY_7);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_G_P_M_MAIN_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(KBArticleModelImpl.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(main);

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

                Collections.sort(list);

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

            cacheResult(list);

            FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_M, finderArgs, list);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_M, finderArgs);

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

    return list;
}

From source file:com.liferay.knowledgebase.service.persistence.impl.KBArticlePersistenceImpl.java

License:Open Source License

/**
 * Returns the number of k b articles where groupId = &#63; and parentResourcePrimKey = any &#63; and main = &#63;.
 *
 * @param groupId the group ID//from   w ww . j  ava 2  s  . co  m
 * @param parentResourcePrimKeies the parent resource prim keies
 * @param main the main
 * @return the number of matching k b articles
 */
@Override
public int countByG_P_M(long groupId, long[] parentResourcePrimKeies, boolean main) {
    if (parentResourcePrimKeies == null) {
        parentResourcePrimKeies = new long[0];
    } else {
        parentResourcePrimKeies = ArrayUtil.unique(parentResourcePrimKeies);
    }

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

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

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

        query.append(_SQL_COUNT_KBARTICLE_WHERE);

        query.append(_FINDER_COLUMN_G_P_M_GROUPID_2);

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

            query.append(_FINDER_COLUMN_G_P_M_PARENTRESOURCEPRIMKEY_7);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(WHERE_AND);
        }

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

            count = (Long) q.uniqueResult();

            FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_M, finderArgs, count);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_M, finderArgs);

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

    return count.intValue();
}

From source file:com.liferay.knowledgebase.service.persistence.impl.KBArticlePersistenceImpl.java

License:Open Source License

/**
 * Returns the number of k b articles that the user has permission to view where groupId = &#63; and parentResourcePrimKey = any &#63; and main = &#63;.
 *
 * @param groupId the group ID// w  w  w.  jav  a  2  s .c om
 * @param parentResourcePrimKeies the parent resource prim keies
 * @param main the main
 * @return the number of matching k b articles that the user has permission to view
 */
@Override
public int filterCountByG_P_M(long groupId, long[] parentResourcePrimKeies, boolean main) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return countByG_P_M(groupId, parentResourcePrimKeies, main);
    }

    if (parentResourcePrimKeies == null) {
        parentResourcePrimKeies = new long[0];
    } else {
        parentResourcePrimKeies = ArrayUtil.unique(parentResourcePrimKeies);
    }

    StringBundler query = new StringBundler();

    query.append(_FILTER_SQL_COUNT_KBARTICLE_WHERE);

    query.append(_FINDER_COLUMN_G_P_M_GROUPID_2);

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

        query.append(_FINDER_COLUMN_G_P_M_PARENTRESOURCEPRIMKEY_7);

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

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(WHERE_AND);
    }

    query.append(_FINDER_COLUMN_G_P_M_MAIN_2);

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

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

    Session session = null;

    try {
        session = openSession();

        SQLQuery q = session.createSynchronizedSQLQuery(sql);

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

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        qPos.add(main);

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

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

From source file:com.liferay.knowledgebase.service.persistence.impl.KBArticlePersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the k b articles that the user has permission to view where groupId = &#63; and parentResourcePrimKey = any &#63; and status = &#63;.
 *
 * <p>//from w  ww .  j a  va2 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. 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.knowledgebase.model.impl.KBArticleModelImpl}. 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 parentResourcePrimKeies the parent resource prim keies
 * @param status the status
 * @param start the lower bound of the range of k b articles
 * @param end the upper bound of the range of k b articles (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching k b articles that the user has permission to view
 */
@Override
public List<KBArticle> filterFindByG_P_S(long groupId, long[] parentResourcePrimKeies, int status, int start,
        int end, OrderByComparator<KBArticle> orderByComparator) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return findByG_P_S(groupId, parentResourcePrimKeies, status, start, end, orderByComparator);
    }

    if (parentResourcePrimKeies == null) {
        parentResourcePrimKeies = new long[0];
    } else {
        parentResourcePrimKeies = ArrayUtil.unique(parentResourcePrimKeies);
    }

    StringBundler query = new StringBundler();

    if (getDB().isSupportsInlineDistinct()) {
        query.append(_FILTER_SQL_SELECT_KBARTICLE_WHERE);
    } else {
        query.append(_FILTER_SQL_SELECT_KBARTICLE_NO_INLINE_DISTINCT_WHERE_1);
    }

    query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);

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

        query.append(_FINDER_COLUMN_G_P_S_PARENTRESOURCEPRIMKEY_7);

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

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(WHERE_AND);
    }

    query.append(_FINDER_COLUMN_G_P_S_STATUS_2);

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

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

    if (orderByComparator != null) {
        if (getDB().isSupportsInlineDistinct()) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator, true);
        } else {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE, orderByComparator, true);
        }
    } else {
        if (getDB().isSupportsInlineDistinct()) {
            query.append(KBArticleModelImpl.ORDER_BY_JPQL);
        } else {
            query.append(KBArticleModelImpl.ORDER_BY_SQL);
        }
    }

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

    Session session = null;

    try {
        session = openSession();

        SQLQuery q = session.createSynchronizedSQLQuery(sql);

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

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        qPos.add(status);

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

From source file:com.liferay.knowledgebase.service.persistence.impl.KBArticlePersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the k b articles where groupId = &#63; and parentResourcePrimKey = any &#63; and status = &#63;.
 *
 * <p>// w ww  .  ja v a2 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.knowledgebase.model.impl.KBArticleModelImpl}. 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 parentResourcePrimKeies the parent resource prim keies
 * @param status the status
 * @param start the lower bound of the range of k b articles
 * @param end the upper bound of the range of k b articles (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching k b articles
 */
@Override
public List<KBArticle> findByG_P_S(long groupId, long[] parentResourcePrimKeies, int status, int start, int end,
        OrderByComparator<KBArticle> orderByComparator) {
    if (parentResourcePrimKeies == null) {
        parentResourcePrimKeies = new long[0];
    } else {
        parentResourcePrimKeies = ArrayUtil.unique(parentResourcePrimKeies);
    }

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

                start, end, orderByComparator };
    }

    List<KBArticle> list = (List<KBArticle>) FinderCacheUtil
            .getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (KBArticle kbArticle : list) {
            if ((groupId != kbArticle.getGroupId())
                    || !ArrayUtil.contains(parentResourcePrimKeies, kbArticle.getParentResourcePrimKey())
                    || (status != kbArticle.getStatus())) {
                list = null;

                break;
            }
        }
    }

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

        query.append(_SQL_SELECT_KBARTICLE_WHERE);

        query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);

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

            query.append(_FINDER_COLUMN_G_P_S_PARENTRESOURCEPRIMKEY_7);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_G_P_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(KBArticleModelImpl.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<KBArticle>) QueryUtil.list(q, getDialect(), start, end, false);

                Collections.sort(list);

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

            cacheResult(list);

            FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S, finderArgs, list);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S, finderArgs);

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

    return list;
}

From source file:com.liferay.knowledgebase.service.persistence.impl.KBArticlePersistenceImpl.java

License:Open Source License

/**
 * Returns the number of k b articles where groupId = &#63; and parentResourcePrimKey = any &#63; and status = &#63;.
 *
 * @param groupId the group ID//from  w ww . jav  a 2s.  c  o  m
 * @param parentResourcePrimKeies the parent resource prim keies
 * @param status the status
 * @return the number of matching k b articles
 */
@Override
public int countByG_P_S(long groupId, long[] parentResourcePrimKeies, int status) {
    if (parentResourcePrimKeies == null) {
        parentResourcePrimKeies = new long[0];
    } else {
        parentResourcePrimKeies = ArrayUtil.unique(parentResourcePrimKeies);
    }

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

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

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

        query.append(_SQL_COUNT_KBARTICLE_WHERE);

        query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);

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

            query.append(_FINDER_COLUMN_G_P_S_PARENTRESOURCEPRIMKEY_7);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(WHERE_AND);
        }

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

            FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_S, finderArgs, count);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_S, finderArgs);

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

    return count.intValue();
}

From source file:com.liferay.knowledgebase.service.persistence.impl.KBArticlePersistenceImpl.java

License:Open Source License

/**
 * Returns the number of k b articles that the user has permission to view where groupId = &#63; and parentResourcePrimKey = any &#63; and status = &#63;.
 *
 * @param groupId the group ID/*from  ww w  .j  a  v  a 2s  .  c  om*/
 * @param parentResourcePrimKeies the parent resource prim keies
 * @param status the status
 * @return the number of matching k b articles that the user has permission to view
 */
@Override
public int filterCountByG_P_S(long groupId, long[] parentResourcePrimKeies, int status) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return countByG_P_S(groupId, parentResourcePrimKeies, status);
    }

    if (parentResourcePrimKeies == null) {
        parentResourcePrimKeies = new long[0];
    } else {
        parentResourcePrimKeies = ArrayUtil.unique(parentResourcePrimKeies);
    }

    StringBundler query = new StringBundler();

    query.append(_FILTER_SQL_COUNT_KBARTICLE_WHERE);

    query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);

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

        query.append(_FINDER_COLUMN_G_P_S_PARENTRESOURCEPRIMKEY_7);

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

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(WHERE_AND);
    }

    query.append(_FINDER_COLUMN_G_P_S_STATUS_2);

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

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

    Session session = null;

    try {
        session = openSession();

        SQLQuery q = session.createSynchronizedSQLQuery(sql);

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

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        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.knowledgebase.service.persistence.impl.KBArticlePersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the k b articles that the user has permission to view where groupId = &#63; and parentResourcePrimKey = &#63; and sections LIKE any &#63; and latest = &#63;.
 *
 * <p>//w w  w  .  ja va  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. 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.knowledgebase.model.impl.KBArticleModelImpl}. 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 parentResourcePrimKey the parent resource prim key
 * @param sectionses the sectionses
 * @param latest the latest
 * @param start the lower bound of the range of k b articles
 * @param end the upper bound of the range of k b articles (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching k b articles that the user has permission to view
 */
@Override
public List<KBArticle> filterFindByG_P_S_L(long groupId, long parentResourcePrimKey, String[] sectionses,
        boolean latest, int start, int end, OrderByComparator<KBArticle> orderByComparator) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return findByG_P_S_L(groupId, parentResourcePrimKey, sectionses, latest, start, end, orderByComparator);
    }

    if (sectionses == null) {
        sectionses = new String[0];
    } else {
        sectionses = ArrayUtil.distinct(sectionses, NULL_SAFE_STRING_COMPARATOR);
    }

    StringBundler query = new StringBundler();

    if (getDB().isSupportsInlineDistinct()) {
        query.append(_FILTER_SQL_SELECT_KBARTICLE_WHERE);
    } else {
        query.append(_FILTER_SQL_SELECT_KBARTICLE_NO_INLINE_DISTINCT_WHERE_1);
    }

    query.append(_FINDER_COLUMN_G_P_S_L_GROUPID_2);

    query.append(_FINDER_COLUMN_G_P_S_L_PARENTRESOURCEPRIMKEY_2);

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

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

            if (sections == null) {
                query.append(_FINDER_COLUMN_G_P_S_L_SECTIONS_4);
            } else if (sections.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_G_P_S_L_SECTIONS_6);
            } else {
                query.append(_FINDER_COLUMN_G_P_S_L_SECTIONS_5);
            }

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

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(WHERE_AND);
    }

    query.append(_FINDER_COLUMN_G_P_S_L_LATEST_2);

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

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

    if (orderByComparator != null) {
        if (getDB().isSupportsInlineDistinct()) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator, true);
        } else {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE, orderByComparator, true);
        }
    } else {
        if (getDB().isSupportsInlineDistinct()) {
            query.append(KBArticleModelImpl.ORDER_BY_JPQL);
        } else {
            query.append(KBArticleModelImpl.ORDER_BY_SQL);
        }
    }

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

    Session session = null;

    try {
        session = openSession();

        SQLQuery q = session.createSynchronizedSQLQuery(sql);

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

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        qPos.add(parentResourcePrimKey);

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

        qPos.add(latest);

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

From source file:com.liferay.knowledgebase.service.persistence.impl.KBArticlePersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the k b articles where groupId = &#63; and parentResourcePrimKey = &#63; and sections LIKE any &#63; and latest = &#63;.
 *
 * <p>/*w  ww  .  j  av a2 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.knowledgebase.model.impl.KBArticleModelImpl}. 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 parentResourcePrimKey the parent resource prim key
 * @param sectionses the sectionses
 * @param latest the latest
 * @param start the lower bound of the range of k b articles
 * @param end the upper bound of the range of k b articles (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching k b articles
 */
@Override
public List<KBArticle> findByG_P_S_L(long groupId, long parentResourcePrimKey, String[] sectionses,
        boolean latest, int start, int end, OrderByComparator<KBArticle> orderByComparator) {
    if (sectionses == null) {
        sectionses = new String[0];
    } else {
        sectionses = ArrayUtil.distinct(sectionses, NULL_SAFE_STRING_COMPARATOR);
    }

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

                start, end, orderByComparator };
    }

    List<KBArticle> list = (List<KBArticle>) FinderCacheUtil
            .getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S_L, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (KBArticle kbArticle : list) {
            if ((groupId != kbArticle.getGroupId())
                    || (parentResourcePrimKey != kbArticle.getParentResourcePrimKey())
                    || !ArrayUtil.contains(sectionses, kbArticle.getSections())
                    || (latest != kbArticle.getLatest())) {
                list = null;

                break;
            }
        }
    }

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

        query.append(_SQL_SELECT_KBARTICLE_WHERE);

        query.append(_FINDER_COLUMN_G_P_S_L_GROUPID_2);

        query.append(_FINDER_COLUMN_G_P_S_L_PARENTRESOURCEPRIMKEY_2);

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

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

                if (sections == null) {
                    query.append(_FINDER_COLUMN_G_P_S_L_SECTIONS_4);
                } else if (sections.equals(StringPool.BLANK)) {
                    query.append(_FINDER_COLUMN_G_P_S_L_SECTIONS_6);
                } else {
                    query.append(_FINDER_COLUMN_G_P_S_L_SECTIONS_5);
                }

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_G_P_S_L_LATEST_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(KBArticleModelImpl.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(parentResourcePrimKey);

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

            qPos.add(latest);

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

                Collections.sort(list);

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

            cacheResult(list);

            FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S_L, finderArgs, list);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S_L, finderArgs);

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

    return list;
}