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;
}
}
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 = ?.
*
* @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);
}
}
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;
}
}
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;
}
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 = ? and classPK = ? and status = ?.
*
* @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());
}
Aggregations