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.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 = ? and kbFolderId = ? and urlTitle = ? and status = any ?.
 *
 * @param groupId the group ID/*from   w w w. j a  va2  s  .c o m*/
 * @param kbFolderId the kb folder ID
 * @param urlTitle the url title
 * @param statuses the statuses
 * @return the number of matching k b articles that the user has permission to view
 */
@Override
public int filterCountByG_KBFI_UT_ST(long groupId, long kbFolderId, String urlTitle, int[] statuses) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return countByG_KBFI_UT_ST(groupId, kbFolderId, urlTitle, statuses);
    }

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

    StringBundler query = new StringBundler();

    query.append(_FILTER_SQL_COUNT_KBARTICLE_WHERE);

    query.append(_FINDER_COLUMN_G_KBFI_UT_ST_GROUPID_2);

    query.append(_FINDER_COLUMN_G_KBFI_UT_ST_KBFOLDERID_2);

    boolean bindUrlTitle = false;

    if (urlTitle == null) {
        query.append(_FINDER_COLUMN_G_KBFI_UT_ST_URLTITLE_1);
    } else if (urlTitle.equals(StringPool.BLANK)) {
        query.append(_FINDER_COLUMN_G_KBFI_UT_ST_URLTITLE_3);
    } else {
        bindUrlTitle = true;

        query.append(_FINDER_COLUMN_G_KBFI_UT_ST_URLTITLE_2);
    }

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

        query.append(_FINDER_COLUMN_G_KBFI_UT_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(), 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(kbFolderId);

        if (bindUrlTitle) {
            qPos.add(urlTitle);
        }

        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

@Override
public Map<Serializable, KBArticle> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }//from  ww  w  .  j  av  a  2  s.  c  om

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

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

        Serializable primaryKey = iterator.next();

        KBArticle kbArticle = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        KBArticle kbArticle = (KBArticle) EntityCacheUtil.getResult(KBArticleModelImpl.ENTITY_CACHE_ENABLED,
                KBArticleImpl.class, primaryKey);

        if (kbArticle == null) {
            if (uncachedPrimaryKeys == null) {
                uncachedPrimaryKeys = new HashSet<Serializable>();
            }

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

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

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

    query.append(_SQL_SELECT_KBARTICLE_WHERE_PKS_IN);

    for (Serializable primaryKey : uncachedPrimaryKeys) {
        query.append(String.valueOf(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 (KBArticle kbArticle : (List<KBArticle>) q.list()) {
            map.put(kbArticle.getPrimaryKeyObj(), kbArticle);

            cacheResult(kbArticle);

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

        for (Serializable primaryKey : uncachedPrimaryKeys) {
            EntityCacheUtil.putResult(KBArticleModelImpl.ENTITY_CACHE_ENABLED, KBArticleImpl.class, primaryKey,
                    _nullKBArticle);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    return map;
}

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

License:Open Source License

/**
 * Returns an ordered range of all the k b comments where classNameId = &#63; and classPK = &#63; and status = any &#63;.
 *
 * <p>/*w  w  w. j  a  va2  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.KBCommentModelImpl}. 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 classNameId the class name ID
 * @param classPK the class p k
 * @param statuses the statuses
 * @param start the lower bound of the range of k b comments
 * @param end the upper bound of the range of k b comments (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching k b comments
 */
@Override
public List<KBComment> findByC_C_S(long classNameId, long classPK, int[] statuses, int start, int end,
        OrderByComparator<KBComment> orderByComparator) {
    if (statuses == null) {
        statuses = new int[0];
    } else {
        statuses = ArrayUtil.unique(statuses);
    }

    if (statuses.length == 1) {
        return findByC_C_S(classNameId, classPK, 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[] { classNameId, classPK, StringUtil.merge(statuses) };
    } else {
        finderArgs = new Object[] { classNameId, classPK, StringUtil.merge(statuses),

                start, end, orderByComparator };
    }

    List<KBComment> list = (List<KBComment>) FinderCacheUtil
            .getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (KBComment kbComment : list) {
            if ((classNameId != kbComment.getClassNameId()) || (classPK != kbComment.getClassPK())
                    || !ArrayUtil.contains(statuses, kbComment.getStatus())) {
                list = null;

                break;
            }
        }
    }

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

        query.append(_SQL_SELECT_KBCOMMENT_WHERE);

        query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);

        query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);

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

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

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(KBCommentModelImpl.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(classNameId);

            qPos.add(classPK);

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

                Collections.sort(list);

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

            cacheResult(list);

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

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

    return list;
}

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

License:Open Source License

/**
 * Returns the number of k b comments where classNameId = &#63; and classPK = &#63; and status = any &#63;.
 *
 * @param classNameId the class name ID//from   ww w  .java  2s  .  c  om
 * @param classPK the class p k
 * @param statuses the statuses
 * @return the number of matching k b comments
 */
@Override
public int countByC_C_S(long classNameId, long classPK, int[] statuses) {
    if (statuses == null) {
        statuses = new int[0];
    } else {
        statuses = ArrayUtil.unique(statuses);
    }

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

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

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

        query.append(_SQL_COUNT_KBCOMMENT_WHERE);

        query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);

        query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);

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

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

            qPos.add(classPK);

            count = (Long) q.uniqueResult();

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

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

    return count.intValue();
}

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

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        KBComment kbComment = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        KBComment kbComment = (KBComment) EntityCacheUtil.getResult(KBCommentModelImpl.ENTITY_CACHE_ENABLED,
                KBCommentImpl.class, primaryKey);

        if (kbComment == null) {
            if (uncachedPrimaryKeys == null) {
                uncachedPrimaryKeys = new HashSet<Serializable>();
            }

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

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

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

    query.append(_SQL_SELECT_KBCOMMENT_WHERE_PKS_IN);

    for (Serializable primaryKey : uncachedPrimaryKeys) {
        query.append(String.valueOf(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 (KBComment kbComment : (List<KBComment>) q.list()) {
            map.put(kbComment.getPrimaryKeyObj(), kbComment);

            cacheResult(kbComment);

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

        for (Serializable primaryKey : uncachedPrimaryKeys) {
            EntityCacheUtil.putResult(KBCommentModelImpl.ENTITY_CACHE_ENABLED, KBCommentImpl.class, primaryKey,
                    _nullKBComment);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    return map;
}

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

License:Open Source License

@Override
public Map<Serializable, KBFolder> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }//from  ww w  . j  a  va  2  s  .  co  m

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

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

        Serializable primaryKey = iterator.next();

        KBFolder kbFolder = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        KBFolder kbFolder = (KBFolder) EntityCacheUtil.getResult(KBFolderModelImpl.ENTITY_CACHE_ENABLED,
                KBFolderImpl.class, primaryKey);

        if (kbFolder == null) {
            if (uncachedPrimaryKeys == null) {
                uncachedPrimaryKeys = new HashSet<Serializable>();
            }

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

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

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

    query.append(_SQL_SELECT_KBFOLDER_WHERE_PKS_IN);

    for (Serializable primaryKey : uncachedPrimaryKeys) {
        query.append(String.valueOf(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 (KBFolder kbFolder : (List<KBFolder>) q.list()) {
            map.put(kbFolder.getPrimaryKeyObj(), kbFolder);

            cacheResult(kbFolder);

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

        for (Serializable primaryKey : uncachedPrimaryKeys) {
            EntityCacheUtil.putResult(KBFolderModelImpl.ENTITY_CACHE_ENABLED, KBFolderImpl.class, primaryKey,
                    _nullKBFolder);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    return map;
}

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

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        KBTemplate kbTemplate = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        KBTemplate kbTemplate = (KBTemplate) EntityCacheUtil.getResult(KBTemplateModelImpl.ENTITY_CACHE_ENABLED,
                KBTemplateImpl.class, primaryKey);

        if (kbTemplate == null) {
            if (uncachedPrimaryKeys == null) {
                uncachedPrimaryKeys = new HashSet<Serializable>();
            }

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

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

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

    query.append(_SQL_SELECT_KBTEMPLATE_WHERE_PKS_IN);

    for (Serializable primaryKey : uncachedPrimaryKeys) {
        query.append(String.valueOf(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 (KBTemplate kbTemplate : (List<KBTemplate>) q.list()) {
            map.put(kbTemplate.getPrimaryKeyObj(), kbTemplate);

            cacheResult(kbTemplate);

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

        for (Serializable primaryKey : uncachedPrimaryKeys) {
            EntityCacheUtil.putResult(KBTemplateModelImpl.ENTITY_CACHE_ENABLED, KBTemplateImpl.class,
                    primaryKey, _nullKBTemplate);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    return map;
}

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

License:Open Source License

/**
 * Returns an ordered range of all the k b articles where resourcePrimKey = any &#63; and latest = &#63;.
 *
 * <p>//from ww w. j  a va  2s  .  c o m
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
 * </p>
 *
 * @param resourcePrimKeies the resource prim keies
 * @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
 * @throws SystemException if a system exception occurred
 */
public List<KBArticle> findByR_L(long[] resourcePrimKeies, boolean latest, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_L;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        finderArgs = new Object[] { StringUtil.merge(resourcePrimKeies), latest };
    } else {
        finderArgs = new Object[] { StringUtil.merge(resourcePrimKeies), latest,

                start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (KBArticle kbArticle : list) {
            if (!ArrayUtil.contains(resourcePrimKeies, kbArticle.getResourcePrimKey())
                    || (latest != kbArticle.getLatest())) {
                list = null;

                break;
            }
        }
    }

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

        query.append(_SQL_SELECT_KBARTICLE_WHERE);

        boolean conjunctionable = false;

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

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < resourcePrimKeies.length; i++) {
                query.append(_FINDER_COLUMN_R_L_RESOURCEPRIMKEY_5);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

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

        query.append(_FINDER_COLUMN_R_L_LATEST_5);

        conjunctionable = true;

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

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

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

            qPos.add(latest);

            list = (List<KBArticle>) 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.knowledgebase.service.persistence.KBArticlePersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the k b articles where resourcePrimKey = any &#63; and main = &#63;.
 *
 * <p>// w w  w.j av 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.
 * </p>
 *
 * @param resourcePrimKeies the 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
 * @throws SystemException if a system exception occurred
 */
public List<KBArticle> findByR_M(long[] resourcePrimKeies, boolean main, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_M;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        finderArgs = new Object[] { StringUtil.merge(resourcePrimKeies), main };
    } else {
        finderArgs = new Object[] { StringUtil.merge(resourcePrimKeies), main,

                start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (KBArticle kbArticle : list) {
            if (!ArrayUtil.contains(resourcePrimKeies, kbArticle.getResourcePrimKey())
                    || (main != kbArticle.getMain())) {
                list = null;

                break;
            }
        }
    }

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

        query.append(_SQL_SELECT_KBARTICLE_WHERE);

        boolean conjunctionable = false;

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

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < resourcePrimKeies.length; i++) {
                query.append(_FINDER_COLUMN_R_M_RESOURCEPRIMKEY_5);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

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

        query.append(_FINDER_COLUMN_R_M_MAIN_5);

        conjunctionable = true;

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

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

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

            qPos.add(main);

            list = (List<KBArticle>) 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.knowledgebase.service.persistence.KBArticlePersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the k b articles where resourcePrimKey = any &#63; and status = &#63;.
 *
 * <p>//from   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 resourcePrimKeies the 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
 * @throws SystemException if a system exception occurred
 */
public List<KBArticle> findByR_S(long[] resourcePrimKeies, int status, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_S;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        finderArgs = new Object[] { StringUtil.merge(resourcePrimKeies), status };
    } else {
        finderArgs = new Object[] { StringUtil.merge(resourcePrimKeies), status,

                start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (KBArticle kbArticle : list) {
            if (!ArrayUtil.contains(resourcePrimKeies, kbArticle.getResourcePrimKey())
                    || (status != kbArticle.getStatus())) {
                list = null;

                break;
            }
        }
    }

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

        query.append(_SQL_SELECT_KBARTICLE_WHERE);

        boolean conjunctionable = false;

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

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < resourcePrimKeies.length; i++) {
                query.append(_FINDER_COLUMN_R_S_RESOURCEPRIMKEY_5);

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

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

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

        query.append(_FINDER_COLUMN_R_S_STATUS_5);

        conjunctionable = true;

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

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

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

            qPos.add(status);

            list = (List<KBArticle>) 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;
}