Search in sources :

Example 16 with KBComment

use of com.liferay.knowledgebase.model.KBComment in project liferay-ide by liferay.

the class KBCommentPersistenceImpl method getByG_C_PrevAndNext.

protected KBComment getByG_C_PrevAndNext(Session session, KBComment kbComment, long groupId, long classNameId, OrderByComparator orderByComparator, boolean previous) {
    StringBundler query = null;
    if (orderByComparator != null) {
        query = new StringBundler(6 + (orderByComparator.getOrderByFields().length * 6));
    } else {
        query = new StringBundler(3);
    }
    query.append(_SQL_SELECT_KBCOMMENT_WHERE);
    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
    query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
    if (orderByComparator != null) {
        String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
        if (orderByConditionFields.length > 0) {
            query.append(WHERE_AND);
        }
        for (int i = 0; i < orderByConditionFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByConditionFields[i]);
            if ((i + 1) < orderByConditionFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
                } else {
                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN);
                } else {
                    query.append(WHERE_LESSER_THAN);
                }
            }
        }
        query.append(ORDER_BY_CLAUSE);
        String[] orderByFields = orderByComparator.getOrderByFields();
        for (int i = 0; i < orderByFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByFields[i]);
            if ((i + 1) < orderByFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC_HAS_NEXT);
                } else {
                    query.append(ORDER_BY_DESC_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC);
                } else {
                    query.append(ORDER_BY_DESC);
                }
            }
        }
    } else {
        query.append(KBCommentModelImpl.ORDER_BY_JPQL);
    }
    String sql = query.toString();
    Query q = session.createQuery(sql);
    q.setFirstResult(0);
    q.setMaxResults(2);
    QueryPos qPos = QueryPos.getInstance(q);
    qPos.add(groupId);
    qPos.add(classNameId);
    if (orderByComparator != null) {
        Object[] values = orderByComparator.getOrderByConditionValues(kbComment);
        for (Object value : values) {
            qPos.add(value);
        }
    }
    List<KBComment> list = q.list();
    if (list.size() == 2) {
        return list.get(1);
    } else {
        return null;
    }
}
Also used : KBComment(com.liferay.knowledgebase.model.KBComment) Query(com.liferay.portal.kernel.dao.orm.Query) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 17 with KBComment

use of com.liferay.knowledgebase.model.KBComment in project liferay-ide by liferay.

the class KBCommentPersistenceImpl method findByUuid_PrevAndNext.

/**
 * Returns the k b comments before and after the current k b comment in the ordered set where uuid = &#63;.
 *
 * @param kbCommentId the primary key of the current k b comment
 * @param uuid the uuid
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the previous, current, and next k b comment
 * @throws com.liferay.knowledgebase.NoSuchCommentException if a k b comment with the primary key could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public KBComment[] findByUuid_PrevAndNext(long kbCommentId, String uuid, OrderByComparator orderByComparator) throws NoSuchCommentException, SystemException {
    KBComment kbComment = findByPrimaryKey(kbCommentId);
    Session session = null;
    try {
        session = openSession();
        KBComment[] array = new KBCommentImpl[3];
        array[0] = getByUuid_PrevAndNext(session, kbComment, uuid, orderByComparator, true);
        array[1] = kbComment;
        array[2] = getByUuid_PrevAndNext(session, kbComment, uuid, orderByComparator, false);
        return array;
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}
Also used : KBComment(com.liferay.knowledgebase.model.KBComment) KBCommentImpl(com.liferay.knowledgebase.model.impl.KBCommentImpl) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchCommentException(com.liferay.knowledgebase.NoSuchCommentException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 18 with KBComment

use of com.liferay.knowledgebase.model.KBComment in project liferay-ide by liferay.

the class KBCommentPersistenceImpl method getByU_C_C_PrevAndNext.

protected KBComment getByU_C_C_PrevAndNext(Session session, KBComment kbComment, long userId, long classNameId, long classPK, OrderByComparator orderByComparator, boolean previous) {
    StringBundler query = null;
    if (orderByComparator != null) {
        query = new StringBundler(6 + (orderByComparator.getOrderByFields().length * 6));
    } else {
        query = new StringBundler(3);
    }
    query.append(_SQL_SELECT_KBCOMMENT_WHERE);
    query.append(_FINDER_COLUMN_U_C_C_USERID_2);
    query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
    query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
    if (orderByComparator != null) {
        String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
        if (orderByConditionFields.length > 0) {
            query.append(WHERE_AND);
        }
        for (int i = 0; i < orderByConditionFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByConditionFields[i]);
            if ((i + 1) < orderByConditionFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
                } else {
                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN);
                } else {
                    query.append(WHERE_LESSER_THAN);
                }
            }
        }
        query.append(ORDER_BY_CLAUSE);
        String[] orderByFields = orderByComparator.getOrderByFields();
        for (int i = 0; i < orderByFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByFields[i]);
            if ((i + 1) < orderByFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC_HAS_NEXT);
                } else {
                    query.append(ORDER_BY_DESC_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC);
                } else {
                    query.append(ORDER_BY_DESC);
                }
            }
        }
    } else {
        query.append(KBCommentModelImpl.ORDER_BY_JPQL);
    }
    String sql = query.toString();
    Query q = session.createQuery(sql);
    q.setFirstResult(0);
    q.setMaxResults(2);
    QueryPos qPos = QueryPos.getInstance(q);
    qPos.add(userId);
    qPos.add(classNameId);
    qPos.add(classPK);
    if (orderByComparator != null) {
        Object[] values = orderByComparator.getOrderByConditionValues(kbComment);
        for (Object value : values) {
            qPos.add(value);
        }
    }
    List<KBComment> list = q.list();
    if (list.size() == 2) {
        return list.get(1);
    } else {
        return null;
    }
}
Also used : KBComment(com.liferay.knowledgebase.model.KBComment) Query(com.liferay.portal.kernel.dao.orm.Query) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 19 with KBComment

use of com.liferay.knowledgebase.model.KBComment in project liferay-ide by liferay.

the class KBCommentPersistenceImpl method fetchByPrimaryKey.

/**
 * Returns the k b comment with the primary key or returns <code>null</code> if it could not be found.
 *
 * @param primaryKey the primary key of the k b comment
 * @return the k b comment, or <code>null</code> if a k b comment with the primary key could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public KBComment fetchByPrimaryKey(Serializable primaryKey) throws SystemException {
    KBComment kbComment = (KBComment) EntityCacheUtil.getResult(KBCommentModelImpl.ENTITY_CACHE_ENABLED, KBCommentImpl.class, primaryKey);
    if (kbComment == _nullKBComment) {
        return null;
    }
    if (kbComment == null) {
        Session session = null;
        try {
            session = openSession();
            kbComment = (KBComment) session.get(KBCommentImpl.class, primaryKey);
            if (kbComment != null) {
                cacheResult(kbComment);
            } else {
                EntityCacheUtil.putResult(KBCommentModelImpl.ENTITY_CACHE_ENABLED, KBCommentImpl.class, primaryKey, _nullKBComment);
            }
        } catch (Exception e) {
            EntityCacheUtil.removeResult(KBCommentModelImpl.ENTITY_CACHE_ENABLED, KBCommentImpl.class, primaryKey);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    return kbComment;
}
Also used : KBComment(com.liferay.knowledgebase.model.KBComment) KBCommentImpl(com.liferay.knowledgebase.model.impl.KBCommentImpl) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchCommentException(com.liferay.knowledgebase.NoSuchCommentException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 20 with KBComment

use of com.liferay.knowledgebase.model.KBComment in project liferay-ide by liferay.

the class KBCommentPersistenceImpl method findByC_C_S_First.

/**
 * Returns the first k b comment in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
 *
 * @param classNameId the class name ID
 * @param classPK the class p k
 * @param status the status
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the first matching k b comment
 * @throws com.liferay.knowledgebase.NoSuchCommentException if a matching k b comment could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public KBComment findByC_C_S_First(long classNameId, long classPK, int status, OrderByComparator orderByComparator) throws NoSuchCommentException, SystemException {
    KBComment kbComment = fetchByC_C_S_First(classNameId, classPK, status, orderByComparator);
    if (kbComment != null) {
        return kbComment;
    }
    StringBundler msg = new StringBundler(8);
    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
    msg.append("classNameId=");
    msg.append(classNameId);
    msg.append(", classPK=");
    msg.append(classPK);
    msg.append(", status=");
    msg.append(status);
    msg.append(StringPool.CLOSE_CURLY_BRACE);
    throw new NoSuchCommentException(msg.toString());
}
Also used : KBComment(com.liferay.knowledgebase.model.KBComment) NoSuchCommentException(com.liferay.knowledgebase.NoSuchCommentException) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Aggregations

KBComment (com.liferay.knowledgebase.model.KBComment)60 NoSuchCommentException (com.liferay.knowledgebase.NoSuchCommentException)38 StringBundler (com.liferay.portal.kernel.util.StringBundler)36 Session (com.liferay.portal.kernel.dao.orm.Session)21 SystemException (com.liferay.portal.kernel.exception.SystemException)21 Query (com.liferay.portal.kernel.dao.orm.Query)19 QueryPos (com.liferay.portal.kernel.dao.orm.QueryPos)18 KBCommentImpl (com.liferay.knowledgebase.model.impl.KBCommentImpl)11 UnmodifiableList (com.liferay.portal.kernel.util.UnmodifiableList)11 ArrayList (java.util.ArrayList)11 List (java.util.List)11 FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)9 JSONObject (com.liferay.portal.kernel.json.JSONObject)2 ServiceContext (com.liferay.portal.service.ServiceContext)2 KBArticle (com.liferay.knowledgebase.model.KBArticle)1 KBTemplate (com.liferay.knowledgebase.model.KBTemplate)1 User (com.liferay.portal.model.User)1 ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)1 Date (java.util.Date)1 Map (java.util.Map)1