List of usage examples for com.liferay.portal.kernel.util ArrayUtil unique
public static String[] unique(String[] array)
From source file:com.bemis.portal.order.service.persistence.impl.ReleasePersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the releases where orderId = ?, optionally using the finder cache. * * <p>/*from ww w . ja v a2s . 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link ReleaseModelImpl}. 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 orderId the order ID * @param start the lower bound of the range of releases * @param end the upper bound of the range of releases (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @param retrieveFromCache whether to retrieve from the finder cache * @return the ordered range of matching releases */ @Override public List<Release> findByOrderId(long[] orderIds, int start, int end, OrderByComparator<Release> orderByComparator, boolean retrieveFromCache) { if (orderIds == null) { orderIds = new long[0]; } else if (orderIds.length > 1) { orderIds = ArrayUtil.unique(orderIds); Arrays.sort(orderIds); } if (orderIds.length == 1) { return findByOrderId(orderIds[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[] { StringUtil.merge(orderIds) }; } else { finderArgs = new Object[] { StringUtil.merge(orderIds), start, end, orderByComparator }; } List<Release> list = null; if (retrieveFromCache) { list = (List<Release>) finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_ORDERID, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (Release release : list) { if (!ArrayUtil.contains(orderIds, release.getOrderId())) { list = null; break; } } } } if (list == null) { StringBundler query = new StringBundler(); query.append(_SQL_SELECT_RELEASE_WHERE); if (orderIds.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_ORDERID_ORDERID_7); query.append(StringUtil.merge(orderIds)); 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(ReleaseModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); if (!pagination) { list = (List<Release>) QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Release>) QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_ORDERID, finderArgs, list); } catch (Exception e) { finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_ORDERID, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; }
From source file:com.bemis.portal.order.service.persistence.impl.ReleasePersistenceImpl.java
License:Open Source License
/** * Returns the number of releases where orderId = any ?. * * @param orderIds the order IDs/*from w ww. j a va2 s. c o m*/ * @return the number of matching releases */ @Override public int countByOrderId(long[] orderIds) { if (orderIds == null) { orderIds = new long[0]; } else if (orderIds.length > 1) { orderIds = ArrayUtil.unique(orderIds); Arrays.sort(orderIds); } Object[] finderArgs = new Object[] { StringUtil.merge(orderIds) }; Long count = (Long) finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_ORDERID, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(); query.append(_SQL_COUNT_RELEASE_WHERE); if (orderIds.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_ORDERID_ORDERID_7); query.append(StringUtil.merge(orderIds)); 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); count = (Long) q.uniqueResult(); finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_ORDERID, finderArgs, count); } catch (Exception e) { finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_ORDERID, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); }
From source file:com.bemis.portal.shipment.service.persistence.impl.ShipmentPersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the shipments where orderId = ?, optionally using the finder cache. * * <p>//from w w w. j a v a2s . 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link ShipmentModelImpl}. 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 orderId the order ID * @param start the lower bound of the range of shipments * @param end the upper bound of the range of shipments (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @param retrieveFromCache whether to retrieve from the finder cache * @return the ordered range of matching shipments */ @Override public List<Shipment> findByOrderId(long[] orderIds, int start, int end, OrderByComparator<Shipment> orderByComparator, boolean retrieveFromCache) { if (orderIds == null) { orderIds = new long[0]; } else if (orderIds.length > 1) { orderIds = ArrayUtil.unique(orderIds); Arrays.sort(orderIds); } if (orderIds.length == 1) { return findByOrderId(orderIds[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[] { StringUtil.merge(orderIds) }; } else { finderArgs = new Object[] { StringUtil.merge(orderIds), start, end, orderByComparator }; } List<Shipment> list = null; if (retrieveFromCache) { list = (List<Shipment>) finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_ORDERID, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (Shipment shipment : list) { if (!ArrayUtil.contains(orderIds, shipment.getOrderId())) { list = null; break; } } } } if (list == null) { StringBundler query = new StringBundler(); query.append(_SQL_SELECT_SHIPMENT_WHERE); if (orderIds.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_ORDERID_ORDERID_7); query.append(StringUtil.merge(orderIds)); 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(ShipmentModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); if (!pagination) { list = (List<Shipment>) QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Shipment>) QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_ORDERID, finderArgs, list); } catch (Exception e) { finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_ORDERID, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; }
From source file:com.bemis.portal.shipment.service.persistence.impl.ShipmentPersistenceImpl.java
License:Open Source License
/** * Returns the number of shipments where orderId = any ?. * * @param orderIds the order IDs//w w w.ja v a2s .c o m * @return the number of matching shipments */ @Override public int countByOrderId(long[] orderIds) { if (orderIds == null) { orderIds = new long[0]; } else if (orderIds.length > 1) { orderIds = ArrayUtil.unique(orderIds); Arrays.sort(orderIds); } Object[] finderArgs = new Object[] { StringUtil.merge(orderIds) }; Long count = (Long) finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_ORDERID, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(); query.append(_SQL_COUNT_SHIPMENT_WHERE); if (orderIds.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_ORDERID_ORDERID_7); query.append(StringUtil.merge(orderIds)); 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); count = (Long) q.uniqueResult(); finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_ORDERID, finderArgs, count); } catch (Exception e) { finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_ORDERID, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); }
From source file:com.liferay.blogs.service.persistence.impl.BlogsEntryPersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the blogs entries that the user has permission to view where groupId = ? and userId = ? and status = any ?. * * <p>/*from w ww . j a va 2 s. c om*/ * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link BlogsEntryModelImpl}. 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 groupId the group ID * @param userId the user ID * @param statuses the statuses * @param start the lower bound of the range of blogs entries * @param end the upper bound of the range of blogs entries (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching blogs entries that the user has permission to view */ @Override public List<BlogsEntry> filterFindByG_U_S(long groupId, long userId, int[] statuses, int start, int end, OrderByComparator<BlogsEntry> orderByComparator) { if (!InlineSQLHelperUtil.isEnabled(groupId)) { return findByG_U_S(groupId, userId, statuses, start, end, orderByComparator); } if (statuses == null) { statuses = new int[0]; } else if (statuses.length > 1) { statuses = ArrayUtil.unique(statuses); Arrays.sort(statuses); } StringBundler query = new StringBundler(); if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_BLOGSENTRY_WHERE); } else { query.append(_FILTER_SQL_SELECT_BLOGSENTRY_NO_INLINE_DISTINCT_WHERE_1); } query.append(_FINDER_COLUMN_G_U_S_GROUPID_2); query.append(_FINDER_COLUMN_G_U_S_USERID_2); if (statuses.length > 0) { query.append("("); query.append(_FINDER_COLUMN_G_U_S_STATUS_7); query.append(StringUtil.merge(statuses)); query.append(")"); query.append(")"); } query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)), query.index() - 1); if (!getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_BLOGSENTRY_NO_INLINE_DISTINCT_WHERE_2); } if (orderByComparator != null) { if (getDB().isSupportsInlineDistinct()) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator, true); } else { appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE, orderByComparator, true); } } else { if (getDB().isSupportsInlineDistinct()) { query.append(BlogsEntryModelImpl.ORDER_BY_JPQL); } else { query.append(BlogsEntryModelImpl.ORDER_BY_SQL); } } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), BlogsEntry.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId); Session session = null; try { session = openSession(); SQLQuery q = session.createSynchronizedSQLQuery(sql); if (getDB().isSupportsInlineDistinct()) { q.addEntity(_FILTER_ENTITY_ALIAS, BlogsEntryImpl.class); } else { q.addEntity(_FILTER_ENTITY_TABLE, BlogsEntryImpl.class); } QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); qPos.add(userId); return (List<BlogsEntry>) QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } }
From source file:com.liferay.blogs.service.persistence.impl.BlogsEntryPersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the blogs entries where groupId = ? and userId = ? and status = ?, optionally using the finder cache. * * <p>/*from w w w . jav 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link BlogsEntryModelImpl}. 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 groupId the group ID * @param userId the user ID * @param status the status * @param start the lower bound of the range of blogs entries * @param end the upper bound of the range of blogs entries (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @param retrieveFromCache whether to retrieve from the finder cache * @return the ordered range of matching blogs entries */ @Override public List<BlogsEntry> findByG_U_S(long groupId, long userId, int[] statuses, int start, int end, OrderByComparator<BlogsEntry> orderByComparator, boolean retrieveFromCache) { if (statuses == null) { statuses = new int[0]; } else if (statuses.length > 1) { statuses = ArrayUtil.unique(statuses); Arrays.sort(statuses); } if (statuses.length == 1) { return findByG_U_S(groupId, userId, 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[] { groupId, userId, StringUtil.merge(statuses) }; } else { finderArgs = new Object[] { groupId, userId, StringUtil.merge(statuses), start, end, orderByComparator }; } List<BlogsEntry> list = null; if (retrieveFromCache) { list = (List<BlogsEntry>) finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (BlogsEntry blogsEntry : list) { if ((groupId != blogsEntry.getGroupId()) || (userId != blogsEntry.getUserId()) || !ArrayUtil.contains(statuses, blogsEntry.getStatus())) { list = null; break; } } } } if (list == null) { StringBundler query = new StringBundler(); query.append(_SQL_SELECT_BLOGSENTRY_WHERE); query.append(_FINDER_COLUMN_G_U_S_GROUPID_2); query.append(_FINDER_COLUMN_G_U_S_USERID_2); if (statuses.length > 0) { query.append("("); query.append(_FINDER_COLUMN_G_U_S_STATUS_7); query.append(StringUtil.merge(statuses)); query.append(")"); query.append(")"); } 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(BlogsEntryModelImpl.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(groupId); qPos.add(userId); if (!pagination) { list = (List<BlogsEntry>) QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<BlogsEntry>) QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S, finderArgs, list); } catch (Exception e) { finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; }
From source file:com.liferay.blogs.service.persistence.impl.BlogsEntryPersistenceImpl.java
License:Open Source License
/** * Returns the number of blogs entries where groupId = ? and userId = ? and status = any ?. * * @param groupId the group ID/*from w w w. j a v a 2 s . com*/ * @param userId the user ID * @param statuses the statuses * @return the number of matching blogs entries */ @Override public int countByG_U_S(long groupId, long userId, int[] statuses) { if (statuses == null) { statuses = new int[0]; } else if (statuses.length > 1) { statuses = ArrayUtil.unique(statuses); Arrays.sort(statuses); } Object[] finderArgs = new Object[] { groupId, userId, StringUtil.merge(statuses) }; Long count = (Long) finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_U_S, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(); query.append(_SQL_COUNT_BLOGSENTRY_WHERE); query.append(_FINDER_COLUMN_G_U_S_GROUPID_2); query.append(_FINDER_COLUMN_G_U_S_USERID_2); if (statuses.length > 0) { query.append("("); query.append(_FINDER_COLUMN_G_U_S_STATUS_7); query.append(StringUtil.merge(statuses)); query.append(")"); query.append(")"); } 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(groupId); qPos.add(userId); count = (Long) q.uniqueResult(); finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_U_S, finderArgs, count); } catch (Exception e) { finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_U_S, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); }
From source file:com.liferay.blogs.service.persistence.impl.BlogsEntryPersistenceImpl.java
License:Open Source License
/** * Returns the number of blogs entries that the user has permission to view where groupId = ? and userId = ? and status = any ?. * * @param groupId the group ID/*w w w . j a va2 s .c om*/ * @param userId the user ID * @param statuses the statuses * @return the number of matching blogs entries that the user has permission to view */ @Override public int filterCountByG_U_S(long groupId, long userId, int[] statuses) { if (!InlineSQLHelperUtil.isEnabled(groupId)) { return countByG_U_S(groupId, userId, statuses); } if (statuses == null) { statuses = new int[0]; } else if (statuses.length > 1) { statuses = ArrayUtil.unique(statuses); Arrays.sort(statuses); } StringBundler query = new StringBundler(); query.append(_FILTER_SQL_COUNT_BLOGSENTRY_WHERE); query.append(_FINDER_COLUMN_G_U_S_GROUPID_2); query.append(_FINDER_COLUMN_G_U_S_USERID_2); if (statuses.length > 0) { query.append("("); query.append(_FINDER_COLUMN_G_U_S_STATUS_7); query.append(StringUtil.merge(statuses)); query.append(")"); query.append(")"); } query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)), query.index() - 1); String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), BlogsEntry.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(userId); Long count = (Long) q.uniqueResult(); return count.intValue(); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } }
From source file:com.liferay.bookmarks.service.persistence.impl.BookmarksEntryPersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the bookmarks entries that the user has permission to view where groupId = ? and folderId = any ?. * * <p>// w w w. 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link BookmarksEntryModelImpl}. 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 groupId the group ID * @param folderIds the folder IDs * @param start the lower bound of the range of bookmarks entries * @param end the upper bound of the range of bookmarks entries (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching bookmarks entries that the user has permission to view */ @Override public List<BookmarksEntry> filterFindByG_F(long groupId, long[] folderIds, int start, int end, OrderByComparator<BookmarksEntry> orderByComparator) { if (!InlineSQLHelperUtil.isEnabled(groupId)) { return findByG_F(groupId, folderIds, start, end, orderByComparator); } if (folderIds == null) { folderIds = new long[0]; } else if (folderIds.length > 1) { folderIds = ArrayUtil.unique(folderIds); Arrays.sort(folderIds); } StringBundler query = new StringBundler(); query.append(_SQL_SELECT_BOOKMARKSENTRY_WHERE); query.append(_FINDER_COLUMN_G_F_GROUPID_2); if (folderIds.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_G_F_FOLDERID_7); query.append(StringUtil.merge(folderIds)); 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 { query.append(BookmarksEntryModelImpl.ORDER_BY_JPQL); } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), BookmarksEntry.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, _FILTER_ENTITY_TABLE_FILTER_USERID_COLUMN, groupId); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); return (List<BookmarksEntry>) QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } }
From source file:com.liferay.bookmarks.service.persistence.impl.BookmarksEntryPersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the bookmarks entries where groupId = ? and folderId = ?, optionally using the finder cache. * * <p>//w w w. j ava 2s . 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link BookmarksEntryModelImpl}. 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 groupId the group ID * @param folderId the folder ID * @param start the lower bound of the range of bookmarks entries * @param end the upper bound of the range of bookmarks entries (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @param retrieveFromCache whether to retrieve from the finder cache * @return the ordered range of matching bookmarks entries */ @Override public List<BookmarksEntry> findByG_F(long groupId, long[] folderIds, int start, int end, OrderByComparator<BookmarksEntry> orderByComparator, boolean retrieveFromCache) { if (folderIds == null) { folderIds = new long[0]; } else if (folderIds.length > 1) { folderIds = ArrayUtil.unique(folderIds); Arrays.sort(folderIds); } if (folderIds.length == 1) { return findByG_F(groupId, folderIds[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[] { groupId, StringUtil.merge(folderIds) }; } else { finderArgs = new Object[] { groupId, StringUtil.merge(folderIds), start, end, orderByComparator }; } List<BookmarksEntry> list = null; if (retrieveFromCache) { list = (List<BookmarksEntry>) finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (BookmarksEntry bookmarksEntry : list) { if ((groupId != bookmarksEntry.getGroupId()) || !ArrayUtil.contains(folderIds, bookmarksEntry.getFolderId())) { list = null; break; } } } } if (list == null) { StringBundler query = new StringBundler(); query.append(_SQL_SELECT_BOOKMARKSENTRY_WHERE); query.append(_FINDER_COLUMN_G_F_GROUPID_2); if (folderIds.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_G_F_FOLDERID_7); query.append(StringUtil.merge(folderIds)); 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(BookmarksEntryModelImpl.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(groupId); if (!pagination) { list = (List<BookmarksEntry>) QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<BookmarksEntry>) QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F, finderArgs, list); } catch (Exception e) { finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; }