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

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

Introduction

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

Prototype

String CLOSE_PARENTHESIS

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

Click Source Link

Usage

From source file:com.liferay.journal.service.persistence.impl.JournalArticlePersistenceImpl.java

License:Open Source License

/**
 * Returns the number of journal articles where resourcePrimKey = ? and indexable = ? and status = any ?.
 *
 * @param resourcePrimKey the resource prim key
 * @param indexable the indexable/*from  www  . j ava  2  s . c  om*/
 * @param statuses the statuses
 * @return the number of matching journal articles
 */
@Override
public int countByR_I_S(long resourcePrimKey, boolean indexable, int[] statuses) {
    if (statuses == null) {
        statuses = new int[0];
    } else if (statuses.length > 1) {
        statuses = ArrayUtil.unique(statuses);

        Arrays.sort(statuses);
    }

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

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

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

        query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);

        query.append(_FINDER_COLUMN_R_I_S_RESOURCEPRIMKEY_2);

        query.append(_FINDER_COLUMN_R_I_S_INDEXABLE_2);

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

            query.append(_FINDER_COLUMN_R_I_S_STATUS_7);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(StringPool.CLOSE_PARENTHESIS);
        }

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(resourcePrimKey);

            qPos.add(indexable);

            count = (Long) q.uniqueResult();

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

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

    return count.intValue();
}

From source file:com.liferay.journal.service.persistence.impl.JournalArticlePersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the journal articles that the user has permission to view where groupId = ? and folderId = ? and status = any ?.
 *
 * <p>/*w  w w. 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link JournalArticleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param groupId the group ID
 * @param folderId the folder ID
 * @param statuses the statuses
 * @param start the lower bound of the range of journal articles
 * @param end the upper bound of the range of journal articles (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching journal articles that the user has permission to view
 */
@Override
public List<JournalArticle> filterFindByG_F_ST(long groupId, long folderId, int[] statuses, int start, int end,
        OrderByComparator<JournalArticle> orderByComparator) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return findByG_F_ST(groupId, folderId, statuses, start, end, orderByComparator);
    }

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

        Arrays.sort(statuses);
    }

    StringBundler query = new StringBundler();

    if (getDB().isSupportsInlineDistinct()) {
        query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
    } else {
        query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
    }

    query.append(_FINDER_COLUMN_G_F_ST_GROUPID_2);

    query.append(_FINDER_COLUMN_G_F_ST_FOLDERID_2);

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

        query.append(_FINDER_COLUMN_G_F_ST_STATUS_7);

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

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(StringPool.CLOSE_PARENTHESIS);
    }

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

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

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

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

    Session session = null;

    try {
        session = openSession();

        SQLQuery q = session.createSynchronizedSQLQuery(sql);

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

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        qPos.add(folderId);

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

From source file:com.liferay.journal.service.persistence.impl.JournalArticlePersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the journal articles where groupId = &#63; and folderId = &#63; and status = &#63;, optionally using the finder cache.
 *
 * <p>//from w  w  w  .  j  av  a 2 s. c  om
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link JournalArticleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param groupId the group ID
 * @param folderId the folder ID
 * @param status the status
 * @param start the lower bound of the range of journal articles
 * @param end the upper bound of the range of journal articles (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @param retrieveFromCache whether to retrieve from the finder cache
 * @return the ordered range of matching journal articles
 */
@Override
public List<JournalArticle> findByG_F_ST(long groupId, long folderId, int[] statuses, int start, int end,
        OrderByComparator<JournalArticle> orderByComparator, boolean retrieveFromCache) {
    if (statuses == null) {
        statuses = new int[0];
    } else if (statuses.length > 1) {
        statuses = ArrayUtil.unique(statuses);

        Arrays.sort(statuses);
    }

    if (statuses.length == 1) {
        return findByG_F_ST(groupId, folderId, statuses[0], start, end, orderByComparator);
    }

    boolean pagination = true;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderArgs = new Object[] { groupId, folderId, StringUtil.merge(statuses) };
    } else {
        finderArgs = new Object[] { groupId, folderId, StringUtil.merge(statuses),

                start, end, orderByComparator };
    }

    List<JournalArticle> list = null;

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

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

                    break;
                }
            }
        }
    }

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

        query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);

        query.append(_FINDER_COLUMN_G_F_ST_GROUPID_2);

        query.append(_FINDER_COLUMN_G_F_ST_FOLDERID_2);

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

            query.append(_FINDER_COLUMN_G_F_ST_STATUS_7);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(StringPool.CLOSE_PARENTHESIS);
        }

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

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(groupId);

            qPos.add(folderId);

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

                Collections.sort(list);

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

            cacheResult(list);

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

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

    return list;
}

From source file:com.liferay.journal.service.persistence.impl.JournalArticlePersistenceImpl.java

License:Open Source License

/**
 * Returns the number of journal articles where groupId = &#63; and folderId = &#63; and status = any &#63;.
 *
 * @param groupId the group ID//w  w  w  .j  a  v a 2  s . c o  m
 * @param folderId the folder ID
 * @param statuses the statuses
 * @return the number of matching journal articles
 */
@Override
public int countByG_F_ST(long groupId, long folderId, int[] statuses) {
    if (statuses == null) {
        statuses = new int[0];
    } else if (statuses.length > 1) {
        statuses = ArrayUtil.unique(statuses);

        Arrays.sort(statuses);
    }

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

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

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

        query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);

        query.append(_FINDER_COLUMN_G_F_ST_GROUPID_2);

        query.append(_FINDER_COLUMN_G_F_ST_FOLDERID_2);

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

            query.append(_FINDER_COLUMN_G_F_ST_STATUS_7);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(StringPool.CLOSE_PARENTHESIS);
        }

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(groupId);

            qPos.add(folderId);

            count = (Long) q.uniqueResult();

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

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

    return count.intValue();
}

From source file:com.liferay.journal.service.persistence.impl.JournalArticlePersistenceImpl.java

License:Open Source License

/**
 * Returns the number of journal articles that the user has permission to view where groupId = &#63; and folderId = &#63; and status = any &#63;.
 *
 * @param groupId the group ID//from  ww w  .  j av a  2 s  . c o  m
 * @param folderId the folder ID
 * @param statuses the statuses
 * @return the number of matching journal articles that the user has permission to view
 */
@Override
public int filterCountByG_F_ST(long groupId, long folderId, int[] statuses) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return countByG_F_ST(groupId, folderId, statuses);
    }

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

        Arrays.sort(statuses);
    }

    StringBundler query = new StringBundler();

    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);

    query.append(_FINDER_COLUMN_G_F_ST_GROUPID_2);

    query.append(_FINDER_COLUMN_G_F_ST_FOLDERID_2);

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

        query.append(_FINDER_COLUMN_G_F_ST_STATUS_7);

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

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(StringPool.CLOSE_PARENTHESIS);
    }

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

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

    Session session = null;

    try {
        session = openSession();

        SQLQuery q = session.createSynchronizedSQLQuery(sql);

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

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

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

License:Open Source License

/**
 * Returns an ordered range of all the journal articles that the user has permission to view where groupId = &#63; and articleId = &#63; and status = any &#63;.
 *
 * <p>/*from www  .  ja  v  a  2  s.co m*/
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link JournalArticleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param groupId the group ID
 * @param articleId the article ID
 * @param statuses the statuses
 * @param start the lower bound of the range of journal articles
 * @param end the upper bound of the range of journal articles (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching journal articles that the user has permission to view
 */
@Override
public List<JournalArticle> filterFindByG_A_ST(long groupId, String articleId, int[] statuses, int start,
        int end, OrderByComparator<JournalArticle> orderByComparator) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return findByG_A_ST(groupId, articleId, statuses, start, end, orderByComparator);
    }

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

        Arrays.sort(statuses);
    }

    StringBundler query = new StringBundler();

    if (getDB().isSupportsInlineDistinct()) {
        query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
    } else {
        query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
    }

    query.append(_FINDER_COLUMN_G_A_ST_GROUPID_2);

    boolean bindArticleId = false;

    if (articleId == null) {
        query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_1);
    } else if (articleId.equals(StringPool.BLANK)) {
        query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_3);
    } else {
        bindArticleId = true;

        query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_2);
    }

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

        query.append(_FINDER_COLUMN_G_A_ST_STATUS_7);

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

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(StringPool.CLOSE_PARENTHESIS);
    }

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

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

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

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

    Session session = null;

    try {
        session = openSession();

        SQLQuery q = session.createSynchronizedSQLQuery(sql);

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

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        if (bindArticleId) {
            qPos.add(articleId);
        }

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

From source file:com.liferay.journal.service.persistence.impl.JournalArticlePersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the journal articles where groupId = &#63; and articleId = &#63; and status = &#63;, optionally using the finder cache.
 *
 * <p>//from w w  w . j a v a2s  . com
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link JournalArticleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param groupId the group ID
 * @param articleId the article ID
 * @param status the status
 * @param start the lower bound of the range of journal articles
 * @param end the upper bound of the range of journal articles (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @param retrieveFromCache whether to retrieve from the finder cache
 * @return the ordered range of matching journal articles
 */
@Override
public List<JournalArticle> findByG_A_ST(long groupId, String articleId, int[] statuses, int start, int end,
        OrderByComparator<JournalArticle> orderByComparator, boolean retrieveFromCache) {
    if (statuses == null) {
        statuses = new int[0];
    } else if (statuses.length > 1) {
        statuses = ArrayUtil.unique(statuses);

        Arrays.sort(statuses);
    }

    if (statuses.length == 1) {
        return findByG_A_ST(groupId, articleId, statuses[0], start, end, orderByComparator);
    }

    boolean pagination = true;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderArgs = new Object[] { groupId, articleId, StringUtil.merge(statuses) };
    } else {
        finderArgs = new Object[] { groupId, articleId, StringUtil.merge(statuses),

                start, end, orderByComparator };
    }

    List<JournalArticle> list = null;

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

        if ((list != null) && !list.isEmpty()) {
            for (JournalArticle journalArticle : list) {
                if ((groupId != journalArticle.getGroupId())
                        || !Objects.equals(articleId, journalArticle.getArticleId())
                        || !ArrayUtil.contains(statuses, journalArticle.getStatus())) {
                    list = null;

                    break;
                }
            }
        }
    }

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

        query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);

        query.append(_FINDER_COLUMN_G_A_ST_GROUPID_2);

        boolean bindArticleId = false;

        if (articleId == null) {
            query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_1);
        } else if (articleId.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_3);
        } else {
            bindArticleId = true;

            query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_2);
        }

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

            query.append(_FINDER_COLUMN_G_A_ST_STATUS_7);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(StringPool.CLOSE_PARENTHESIS);
        }

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

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(groupId);

            if (bindArticleId) {
                qPos.add(articleId);
            }

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

                Collections.sort(list);

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

            cacheResult(list);

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

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

    return list;
}

From source file:com.liferay.journal.service.persistence.impl.JournalArticlePersistenceImpl.java

License:Open Source License

/**
 * Returns the number of journal articles where groupId = &#63; and articleId = &#63; and status = any &#63;.
 *
 * @param groupId the group ID// w  w w. j a va 2  s  .  c om
 * @param articleId the article ID
 * @param statuses the statuses
 * @return the number of matching journal articles
 */
@Override
public int countByG_A_ST(long groupId, String articleId, int[] statuses) {
    if (statuses == null) {
        statuses = new int[0];
    } else if (statuses.length > 1) {
        statuses = ArrayUtil.unique(statuses);

        Arrays.sort(statuses);
    }

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

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

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

        query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);

        query.append(_FINDER_COLUMN_G_A_ST_GROUPID_2);

        boolean bindArticleId = false;

        if (articleId == null) {
            query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_1);
        } else if (articleId.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_3);
        } else {
            bindArticleId = true;

            query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_2);
        }

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

            query.append(_FINDER_COLUMN_G_A_ST_STATUS_7);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(StringPool.CLOSE_PARENTHESIS);
        }

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(groupId);

            if (bindArticleId) {
                qPos.add(articleId);
            }

            count = (Long) q.uniqueResult();

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

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

    return count.intValue();
}

From source file:com.liferay.journal.service.persistence.impl.JournalArticlePersistenceImpl.java

License:Open Source License

/**
 * Returns the number of journal articles that the user has permission to view where groupId = &#63; and articleId = &#63; and status = any &#63;.
 *
 * @param groupId the group ID/* w  w  w. ja  v  a  2 s  .com*/
 * @param articleId the article ID
 * @param statuses the statuses
 * @return the number of matching journal articles that the user has permission to view
 */
@Override
public int filterCountByG_A_ST(long groupId, String articleId, int[] statuses) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return countByG_A_ST(groupId, articleId, statuses);
    }

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

        Arrays.sort(statuses);
    }

    StringBundler query = new StringBundler();

    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);

    query.append(_FINDER_COLUMN_G_A_ST_GROUPID_2);

    boolean bindArticleId = false;

    if (articleId == null) {
        query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_1);
    } else if (articleId.equals(StringPool.BLANK)) {
        query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_3);
    } else {
        bindArticleId = true;

        query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_2);
    }

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

        query.append(_FINDER_COLUMN_G_A_ST_STATUS_7);

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

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(StringPool.CLOSE_PARENTHESIS);
    }

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

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

    Session session = null;

    try {
        session = openSession();

        SQLQuery q = session.createSynchronizedSQLQuery(sql);

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

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        if (bindArticleId) {
            qPos.add(articleId);
        }

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

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

From source file:com.liferay.journal.service.persistence.impl.JournalArticlePersistenceImpl.java

License:Open Source License

@Override
public Map<Serializable, JournalArticle> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }//from  w  w  w . ja va 2s.c o m

    Map<Serializable, JournalArticle> map = new HashMap<Serializable, JournalArticle>();

    if (primaryKeys.size() == 1) {
        Iterator<Serializable> iterator = primaryKeys.iterator();

        Serializable primaryKey = iterator.next();

        JournalArticle journalArticle = fetchByPrimaryKey(primaryKey);

        if (journalArticle != null) {
            map.put(primaryKey, journalArticle);
        }

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        Serializable serializable = entityCache.getResult(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
                JournalArticleImpl.class, primaryKey);

        if (serializable != nullModel) {
            if (serializable == null) {
                if (uncachedPrimaryKeys == null) {
                    uncachedPrimaryKeys = new HashSet<Serializable>();
                }

                uncachedPrimaryKeys.add(primaryKey);
            } else {
                map.put(primaryKey, (JournalArticle) serializable);
            }
        }
    }

    if (uncachedPrimaryKeys == null) {
        return map;
    }

    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1);

    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE_PKS_IN);

    for (Serializable primaryKey : uncachedPrimaryKeys) {
        query.append((long) primaryKey);

        query.append(StringPool.COMMA);
    }

    query.setIndex(query.index() - 1);

    query.append(StringPool.CLOSE_PARENTHESIS);

    String sql = query.toString();

    Session session = null;

    try {
        session = openSession();

        Query q = session.createQuery(sql);

        for (JournalArticle journalArticle : (List<JournalArticle>) q.list()) {
            map.put(journalArticle.getPrimaryKeyObj(), journalArticle);

            cacheResult(journalArticle);

            uncachedPrimaryKeys.remove(journalArticle.getPrimaryKeyObj());
        }

        for (Serializable primaryKey : uncachedPrimaryKeys) {
            entityCache.putResult(JournalArticleModelImpl.ENTITY_CACHE_ENABLED, JournalArticleImpl.class,
                    primaryKey, nullModel);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    return map;
}