List of usage examples for com.liferay.portal.kernel.util StringPool CLOSE_PARENTHESIS
String CLOSE_PARENTHESIS
To view the source code for com.liferay.portal.kernel.util StringPool CLOSE_PARENTHESIS.
Click Source Link
From source file:com.liferay.knowledgebase.service.persistence.impl.KBArticlePersistenceImpl.java
License:Open Source License
/** * Returns the number of k b articles where resourcePrimKey = any ? and latest = ?. * * @param resourcePrimKeies the resource prim keies * @param latest the latest//from w w w . j a va 2 s .c o m * @return the number of matching k b articles */ @Override public int countByR_L(long[] resourcePrimKeies, boolean latest) { if (resourcePrimKeies == null) { resourcePrimKeies = new long[0]; } else { resourcePrimKeies = ArrayUtil.unique(resourcePrimKeies); } Object[] finderArgs = new Object[] { StringUtil.merge(resourcePrimKeies), latest }; Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_R_L, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(); query.append(_SQL_COUNT_KBARTICLE_WHERE); if (resourcePrimKeies.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_R_L_RESOURCEPRIMKEY_7); query.append(StringUtil.merge(resourcePrimKeies)); query.append(StringPool.CLOSE_PARENTHESIS); query.append(StringPool.CLOSE_PARENTHESIS); query.append(WHERE_AND); } query.append(_FINDER_COLUMN_R_L_LATEST_2); 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(latest); count = (Long) q.uniqueResult(); FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_R_L, finderArgs, count); } catch (Exception e) { FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_R_L, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); }
From source file:com.liferay.knowledgebase.service.persistence.impl.KBArticlePersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the k b articles where resourcePrimKey = any ? and main = ?. * * <p>/*from w w w .j a v a 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. 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.KBArticleModelImpl}. 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 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 */ @Override public List<KBArticle> findByR_M(long[] resourcePrimKeies, boolean main, int start, int end, OrderByComparator<KBArticle> orderByComparator) { if (resourcePrimKeies == null) { resourcePrimKeies = new long[0]; } else { resourcePrimKeies = ArrayUtil.unique(resourcePrimKeies); } if (resourcePrimKeies.length == 1) { return findByR_M(resourcePrimKeies[0], main, 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[] { StringUtil.merge(resourcePrimKeies), main }; } else { finderArgs = new Object[] { StringUtil.merge(resourcePrimKeies), main, start, end, orderByComparator }; } List<KBArticle> list = (List<KBArticle>) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_R_M, 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); if (resourcePrimKeies.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_R_M_RESOURCEPRIMKEY_7); query.append(StringUtil.merge(resourcePrimKeies)); query.append(StringPool.CLOSE_PARENTHESIS); query.append(StringPool.CLOSE_PARENTHESIS); query.append(WHERE_AND); } query.append(_FINDER_COLUMN_R_M_MAIN_2); 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(KBArticleModelImpl.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(main); if (!pagination) { list = (List<KBArticle>) QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<KBArticle>) QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_R_M, finderArgs, list); } catch (Exception e) { FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_R_M, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; }
From source file:com.liferay.knowledgebase.service.persistence.impl.KBArticlePersistenceImpl.java
License:Open Source License
/** * Returns the number of k b articles where resourcePrimKey = any ? and main = ?. * * @param resourcePrimKeies the resource prim keies * @param main the main//from w w w . j a v a 2 s .c o m * @return the number of matching k b articles */ @Override public int countByR_M(long[] resourcePrimKeies, boolean main) { if (resourcePrimKeies == null) { resourcePrimKeies = new long[0]; } else { resourcePrimKeies = ArrayUtil.unique(resourcePrimKeies); } Object[] finderArgs = new Object[] { StringUtil.merge(resourcePrimKeies), main }; Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_R_M, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(); query.append(_SQL_COUNT_KBARTICLE_WHERE); if (resourcePrimKeies.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_R_M_RESOURCEPRIMKEY_7); query.append(StringUtil.merge(resourcePrimKeies)); query.append(StringPool.CLOSE_PARENTHESIS); query.append(StringPool.CLOSE_PARENTHESIS); query.append(WHERE_AND); } query.append(_FINDER_COLUMN_R_M_MAIN_2); 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(main); count = (Long) q.uniqueResult(); FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_R_M, finderArgs, count); } catch (Exception e) { FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_R_M, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); }
From source file:com.liferay.knowledgebase.service.persistence.impl.KBArticlePersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the k b articles where resourcePrimKey = any ? and status = ?. * * <p>/*from w w w .jav 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. 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.KBArticleModelImpl}. 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 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 */ @Override public List<KBArticle> findByR_S(long[] resourcePrimKeies, int status, int start, int end, OrderByComparator<KBArticle> orderByComparator) { if (resourcePrimKeies == null) { resourcePrimKeies = new long[0]; } else { resourcePrimKeies = ArrayUtil.unique(resourcePrimKeies); } if (resourcePrimKeies.length == 1) { return findByR_S(resourcePrimKeies[0], status, 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[] { StringUtil.merge(resourcePrimKeies), status }; } else { finderArgs = new Object[] { StringUtil.merge(resourcePrimKeies), status, start, end, orderByComparator }; } List<KBArticle> list = (List<KBArticle>) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_R_S, 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); if (resourcePrimKeies.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_R_S_RESOURCEPRIMKEY_7); query.append(StringUtil.merge(resourcePrimKeies)); query.append(StringPool.CLOSE_PARENTHESIS); query.append(StringPool.CLOSE_PARENTHESIS); query.append(WHERE_AND); } query.append(_FINDER_COLUMN_R_S_STATUS_2); 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(KBArticleModelImpl.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(status); if (!pagination) { list = (List<KBArticle>) QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<KBArticle>) QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_R_S, finderArgs, list); } catch (Exception e) { FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_R_S, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; }
From source file:com.liferay.knowledgebase.service.persistence.impl.KBArticlePersistenceImpl.java
License:Open Source License
/** * Returns the number of k b articles where resourcePrimKey = any ? and status = ?. * * @param resourcePrimKeies the resource prim keies * @param status the status/* w w w .j a v a 2 s.c o m*/ * @return the number of matching k b articles */ @Override public int countByR_S(long[] resourcePrimKeies, int status) { if (resourcePrimKeies == null) { resourcePrimKeies = new long[0]; } else { resourcePrimKeies = ArrayUtil.unique(resourcePrimKeies); } Object[] finderArgs = new Object[] { StringUtil.merge(resourcePrimKeies), status }; Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_R_S, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(); query.append(_SQL_COUNT_KBARTICLE_WHERE); if (resourcePrimKeies.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_R_S_RESOURCEPRIMKEY_7); query.append(StringUtil.merge(resourcePrimKeies)); query.append(StringPool.CLOSE_PARENTHESIS); query.append(StringPool.CLOSE_PARENTHESIS); query.append(WHERE_AND); } query.append(_FINDER_COLUMN_R_S_STATUS_2); 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(status); count = (Long) q.uniqueResult(); FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_R_S, finderArgs, count); } catch (Exception e) { FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_R_S, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); }
From source file:com.liferay.knowledgebase.service.persistence.impl.KBArticlePersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the k b articles where parentResourcePrimKey = any ? and latest = ?. * * <p>//from w ww . 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 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.KBArticleModelImpl}. 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 parentResourcePrimKeies the parent 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 */ @Override public List<KBArticle> findByP_L(long[] parentResourcePrimKeies, boolean latest, int start, int end, OrderByComparator<KBArticle> orderByComparator) { if (parentResourcePrimKeies == null) { parentResourcePrimKeies = new long[0]; } else { parentResourcePrimKeies = ArrayUtil.unique(parentResourcePrimKeies); } if (parentResourcePrimKeies.length == 1) { return findByP_L(parentResourcePrimKeies[0], latest, 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[] { StringUtil.merge(parentResourcePrimKeies), latest }; } else { finderArgs = new Object[] { StringUtil.merge(parentResourcePrimKeies), latest, start, end, orderByComparator }; } List<KBArticle> list = (List<KBArticle>) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_P_L, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (KBArticle kbArticle : list) { if (!ArrayUtil.contains(parentResourcePrimKeies, kbArticle.getParentResourcePrimKey()) || (latest != kbArticle.getLatest())) { list = null; break; } } } if (list == null) { StringBundler query = new StringBundler(); query.append(_SQL_SELECT_KBARTICLE_WHERE); if (parentResourcePrimKeies.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_P_L_PARENTRESOURCEPRIMKEY_7); query.append(StringUtil.merge(parentResourcePrimKeies)); query.append(StringPool.CLOSE_PARENTHESIS); query.append(StringPool.CLOSE_PARENTHESIS); query.append(WHERE_AND); } query.append(_FINDER_COLUMN_P_L_LATEST_2); 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(KBArticleModelImpl.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(latest); if (!pagination) { list = (List<KBArticle>) QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<KBArticle>) QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_P_L, finderArgs, list); } catch (Exception e) { FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_P_L, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; }
From source file:com.liferay.knowledgebase.service.persistence.impl.KBArticlePersistenceImpl.java
License:Open Source License
/** * Returns the number of k b articles where parentResourcePrimKey = any ? and latest = ?. * * @param parentResourcePrimKeies the parent resource prim keies * @param latest the latest//from w w w . j av a 2 s. c o m * @return the number of matching k b articles */ @Override public int countByP_L(long[] parentResourcePrimKeies, boolean latest) { if (parentResourcePrimKeies == null) { parentResourcePrimKeies = new long[0]; } else { parentResourcePrimKeies = ArrayUtil.unique(parentResourcePrimKeies); } Object[] finderArgs = new Object[] { StringUtil.merge(parentResourcePrimKeies), latest }; Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_P_L, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(); query.append(_SQL_COUNT_KBARTICLE_WHERE); if (parentResourcePrimKeies.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_P_L_PARENTRESOURCEPRIMKEY_7); query.append(StringUtil.merge(parentResourcePrimKeies)); query.append(StringPool.CLOSE_PARENTHESIS); query.append(StringPool.CLOSE_PARENTHESIS); query.append(WHERE_AND); } query.append(_FINDER_COLUMN_P_L_LATEST_2); 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(latest); count = (Long) q.uniqueResult(); FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_P_L, finderArgs, count); } catch (Exception e) { FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_P_L, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); }
From source file:com.liferay.knowledgebase.service.persistence.impl.KBArticlePersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the k b articles where parentResourcePrimKey = any ? and main = ?. * * <p>//from w w w .j a 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 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.KBArticleModelImpl}. 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 parentResourcePrimKeies the parent 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 */ @Override public List<KBArticle> findByP_M(long[] parentResourcePrimKeies, boolean main, int start, int end, OrderByComparator<KBArticle> orderByComparator) { if (parentResourcePrimKeies == null) { parentResourcePrimKeies = new long[0]; } else { parentResourcePrimKeies = ArrayUtil.unique(parentResourcePrimKeies); } if (parentResourcePrimKeies.length == 1) { return findByP_M(parentResourcePrimKeies[0], main, 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[] { StringUtil.merge(parentResourcePrimKeies), main }; } else { finderArgs = new Object[] { StringUtil.merge(parentResourcePrimKeies), main, start, end, orderByComparator }; } List<KBArticle> list = (List<KBArticle>) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_P_M, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (KBArticle kbArticle : list) { if (!ArrayUtil.contains(parentResourcePrimKeies, kbArticle.getParentResourcePrimKey()) || (main != kbArticle.getMain())) { list = null; break; } } } if (list == null) { StringBundler query = new StringBundler(); query.append(_SQL_SELECT_KBARTICLE_WHERE); if (parentResourcePrimKeies.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_P_M_PARENTRESOURCEPRIMKEY_7); query.append(StringUtil.merge(parentResourcePrimKeies)); query.append(StringPool.CLOSE_PARENTHESIS); query.append(StringPool.CLOSE_PARENTHESIS); query.append(WHERE_AND); } query.append(_FINDER_COLUMN_P_M_MAIN_2); 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(KBArticleModelImpl.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(main); if (!pagination) { list = (List<KBArticle>) QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<KBArticle>) QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_P_M, finderArgs, list); } catch (Exception e) { FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_P_M, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; }
From source file:com.liferay.knowledgebase.service.persistence.impl.KBArticlePersistenceImpl.java
License:Open Source License
/** * Returns the number of k b articles where parentResourcePrimKey = any ? and main = ?. * * @param parentResourcePrimKeies the parent resource prim keies * @param main the main/*from w w w . ja v a 2 s . co m*/ * @return the number of matching k b articles */ @Override public int countByP_M(long[] parentResourcePrimKeies, boolean main) { if (parentResourcePrimKeies == null) { parentResourcePrimKeies = new long[0]; } else { parentResourcePrimKeies = ArrayUtil.unique(parentResourcePrimKeies); } Object[] finderArgs = new Object[] { StringUtil.merge(parentResourcePrimKeies), main }; Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_P_M, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(); query.append(_SQL_COUNT_KBARTICLE_WHERE); if (parentResourcePrimKeies.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_P_M_PARENTRESOURCEPRIMKEY_7); query.append(StringUtil.merge(parentResourcePrimKeies)); query.append(StringPool.CLOSE_PARENTHESIS); query.append(StringPool.CLOSE_PARENTHESIS); query.append(WHERE_AND); } query.append(_FINDER_COLUMN_P_M_MAIN_2); 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(main); count = (Long) q.uniqueResult(); FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_P_M, finderArgs, count); } catch (Exception e) { FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_P_M, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); }
From source file:com.liferay.knowledgebase.service.persistence.impl.KBArticlePersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the k b articles where parentResourcePrimKey = any ? and status = ?. * * <p>/*www .j a v a 2 s .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 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.KBArticleModelImpl}. 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 parentResourcePrimKeies the parent 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 */ @Override public List<KBArticle> findByP_S(long[] parentResourcePrimKeies, int status, int start, int end, OrderByComparator<KBArticle> orderByComparator) { if (parentResourcePrimKeies == null) { parentResourcePrimKeies = new long[0]; } else { parentResourcePrimKeies = ArrayUtil.unique(parentResourcePrimKeies); } if (parentResourcePrimKeies.length == 1) { return findByP_S(parentResourcePrimKeies[0], status, 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[] { StringUtil.merge(parentResourcePrimKeies), status }; } else { finderArgs = new Object[] { StringUtil.merge(parentResourcePrimKeies), status, start, end, orderByComparator }; } List<KBArticle> list = (List<KBArticle>) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_P_S, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (KBArticle kbArticle : list) { if (!ArrayUtil.contains(parentResourcePrimKeies, kbArticle.getParentResourcePrimKey()) || (status != kbArticle.getStatus())) { list = null; break; } } } if (list == null) { StringBundler query = new StringBundler(); query.append(_SQL_SELECT_KBARTICLE_WHERE); if (parentResourcePrimKeies.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_P_S_PARENTRESOURCEPRIMKEY_7); query.append(StringUtil.merge(parentResourcePrimKeies)); query.append(StringPool.CLOSE_PARENTHESIS); query.append(StringPool.CLOSE_PARENTHESIS); query.append(WHERE_AND); } query.append(_FINDER_COLUMN_P_S_STATUS_2); 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(KBArticleModelImpl.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(status); if (!pagination) { list = (List<KBArticle>) QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<KBArticle>) QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_P_S, finderArgs, list); } catch (Exception e) { FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_P_S, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; }