use of com.liferay.knowledgebase.model.KBArticle in project liferay-ide by liferay.
the class KBArticlePersistenceImpl method getByR_G_PrevAndNext.
protected KBArticle getByR_G_PrevAndNext(Session session, KBArticle kbArticle, long resourcePrimKey, long groupId, 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_KBARTICLE_WHERE);
query.append(_FINDER_COLUMN_R_G_RESOURCEPRIMKEY_2);
query.append(_FINDER_COLUMN_R_G_GROUPID_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(KBArticleModelImpl.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(resourcePrimKey);
qPos.add(groupId);
if (orderByComparator != null) {
Object[] values = orderByComparator.getOrderByConditionValues(kbArticle);
for (Object value : values) {
qPos.add(value);
}
}
List<KBArticle> list = q.list();
if (list.size() == 2) {
return list.get(1);
} else {
return null;
}
}
use of com.liferay.knowledgebase.model.KBArticle in project liferay-ide by liferay.
the class KBArticlePersistenceImpl method findByG_M_PrevAndNext.
/**
* Returns the k b articles before and after the current k b article in the ordered set where groupId = ? and main = ?.
*
* @param kbArticleId the primary key of the current k b article
* @param groupId the group ID
* @param main the main
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the previous, current, and next k b article
* @throws com.liferay.knowledgebase.NoSuchArticleException if a k b article with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
@Override
public KBArticle[] findByG_M_PrevAndNext(long kbArticleId, long groupId, boolean main, OrderByComparator orderByComparator) throws NoSuchArticleException, SystemException {
KBArticle kbArticle = findByPrimaryKey(kbArticleId);
Session session = null;
try {
session = openSession();
KBArticle[] array = new KBArticleImpl[3];
array[0] = getByG_M_PrevAndNext(session, kbArticle, groupId, main, orderByComparator, true);
array[1] = kbArticle;
array[2] = getByG_M_PrevAndNext(session, kbArticle, groupId, main, orderByComparator, false);
return array;
} catch (Exception e) {
throw processException(e);
} finally {
closeSession(session);
}
}
use of com.liferay.knowledgebase.model.KBArticle in project liferay-ide by liferay.
the class KBArticlePersistenceImpl method findByG_P_S_L_First.
/**
* Returns the first k b article in the ordered set where groupId = ? and parentResourcePrimKey = ? and sections LIKE ? and latest = ?.
*
* @param groupId the group ID
* @param parentResourcePrimKey the parent resource prim key
* @param sections the sections
* @param latest the latest
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the first matching k b article
* @throws com.liferay.knowledgebase.NoSuchArticleException if a matching k b article could not be found
* @throws SystemException if a system exception occurred
*/
@Override
public KBArticle findByG_P_S_L_First(long groupId, long parentResourcePrimKey, String sections, boolean latest, OrderByComparator orderByComparator) throws NoSuchArticleException, SystemException {
KBArticle kbArticle = fetchByG_P_S_L_First(groupId, parentResourcePrimKey, sections, latest, orderByComparator);
if (kbArticle != null) {
return kbArticle;
}
StringBundler msg = new StringBundler(10);
msg.append(_NO_SUCH_ENTITY_WITH_KEY);
msg.append("groupId=");
msg.append(groupId);
msg.append(", parentResourcePrimKey=");
msg.append(parentResourcePrimKey);
msg.append(", sections=");
msg.append(sections);
msg.append(", latest=");
msg.append(latest);
msg.append(StringPool.CLOSE_CURLY_BRACE);
throw new NoSuchArticleException(msg.toString());
}
use of com.liferay.knowledgebase.model.KBArticle in project liferay-ide by liferay.
the class KBArticlePersistenceImpl method findByResourcePrimKey_First.
/**
* Returns the first k b article in the ordered set where resourcePrimKey = ?.
*
* @param resourcePrimKey the resource prim key
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the first matching k b article
* @throws com.liferay.knowledgebase.NoSuchArticleException if a matching k b article could not be found
* @throws SystemException if a system exception occurred
*/
@Override
public KBArticle findByResourcePrimKey_First(long resourcePrimKey, OrderByComparator orderByComparator) throws NoSuchArticleException, SystemException {
KBArticle kbArticle = fetchByResourcePrimKey_First(resourcePrimKey, orderByComparator);
if (kbArticle != null) {
return kbArticle;
}
StringBundler msg = new StringBundler(4);
msg.append(_NO_SUCH_ENTITY_WITH_KEY);
msg.append("resourcePrimKey=");
msg.append(resourcePrimKey);
msg.append(StringPool.CLOSE_CURLY_BRACE);
throw new NoSuchArticleException(msg.toString());
}
use of com.liferay.knowledgebase.model.KBArticle in project liferay-ide by liferay.
the class KBArticlePersistenceImpl method findByR_S_First.
/**
* Returns the first k b article in the ordered set where resourcePrimKey = ? and status = ?.
*
* @param resourcePrimKey the resource prim key
* @param status the status
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the first matching k b article
* @throws com.liferay.knowledgebase.NoSuchArticleException if a matching k b article could not be found
* @throws SystemException if a system exception occurred
*/
@Override
public KBArticle findByR_S_First(long resourcePrimKey, int status, OrderByComparator orderByComparator) throws NoSuchArticleException, SystemException {
KBArticle kbArticle = fetchByR_S_First(resourcePrimKey, status, orderByComparator);
if (kbArticle != null) {
return kbArticle;
}
StringBundler msg = new StringBundler(6);
msg.append(_NO_SUCH_ENTITY_WITH_KEY);
msg.append("resourcePrimKey=");
msg.append(resourcePrimKey);
msg.append(", status=");
msg.append(status);
msg.append(StringPool.CLOSE_CURLY_BRACE);
throw new NoSuchArticleException(msg.toString());
}
Aggregations