List of usage examples for com.liferay.portal.kernel.util StringPool OPEN_PARENTHESIS
String OPEN_PARENTHESIS
To view the source code for com.liferay.portal.kernel.util StringPool OPEN_PARENTHESIS.
Click Source Link
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 w w w .jav a 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 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/* w w w . jav a 2s. c om*/ * @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.report.service.persistence.impl.ReportDefinitionPersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the report definitions that the user has permission to view where category = any ? and companyId = ? and groupId = ?. * * <p>//from w ww .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 ReportDefinitionModelImpl}. 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 categories the categories * @param companyId the company ID * @param groupId the group ID * @param start the lower bound of the range of report definitions * @param end the upper bound of the range of report definitions (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching report definitions that the user has permission to view */ @Override public List<ReportDefinition> filterFindByC_C_G(String[] categories, long companyId, long groupId, int start, int end, OrderByComparator<ReportDefinition> orderByComparator) { if (!InlineSQLHelperUtil.isEnabled(groupId)) { return findByC_C_G(categories, companyId, groupId, start, end, orderByComparator); } if (categories == null) { categories = new String[0]; } else if (categories.length > 1) { categories = ArrayUtil.distinct(categories, NULL_SAFE_STRING_COMPARATOR); Arrays.sort(categories, NULL_SAFE_STRING_COMPARATOR); } StringBundler query = new StringBundler(); if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_REPORTDEFINITION_WHERE); } else { query.append(_FILTER_SQL_SELECT_REPORTDEFINITION_NO_INLINE_DISTINCT_WHERE_1); } if (categories.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < categories.length; i++) { String category = categories[i]; if (category == null) { query.append(_FINDER_COLUMN_C_C_G_CATEGORY_4); } else if (category.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_C_C_G_CATEGORY_6); } else { query.append(_FINDER_COLUMN_C_C_G_CATEGORY_5); } if ((i + 1) < categories.length) { query.append(WHERE_OR); } } query.append(StringPool.CLOSE_PARENTHESIS); query.append(WHERE_AND); } query.append(_FINDER_COLUMN_C_C_G_COMPANYID_2); query.append(_FINDER_COLUMN_C_C_G_GROUPID_2); query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)), query.index() - 1); if (!getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_REPORTDEFINITION_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(ReportDefinitionModelImpl.ORDER_BY_JPQL); } else { query.append(ReportDefinitionModelImpl.ORDER_BY_SQL); } } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), ReportDefinition.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, ReportDefinitionImpl.class); } else { q.addEntity(_FILTER_ENTITY_TABLE, ReportDefinitionImpl.class); } QueryPos qPos = QueryPos.getInstance(q); for (String category : categories) { if ((category != null) && !category.isEmpty()) { qPos.add(category); } } qPos.add(companyId); qPos.add(groupId); return (List<ReportDefinition>) QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } }
From source file:com.bemis.portal.report.service.persistence.impl.ReportDefinitionPersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the report definitions where category = ? and companyId = ? and groupId = ?, optionally using the finder cache. * * <p>/* w w w . j a va 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 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 ReportDefinitionModelImpl}. 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 category the category * @param companyId the company ID * @param groupId the group ID * @param start the lower bound of the range of report definitions * @param end the upper bound of the range of report definitions (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 report definitions */ @Override public List<ReportDefinition> findByC_C_G(String[] categories, long companyId, long groupId, int start, int end, OrderByComparator<ReportDefinition> orderByComparator, boolean retrieveFromCache) { if (categories == null) { categories = new String[0]; } else if (categories.length > 1) { categories = ArrayUtil.distinct(categories, NULL_SAFE_STRING_COMPARATOR); Arrays.sort(categories, NULL_SAFE_STRING_COMPARATOR); } if (categories.length == 1) { return findByC_C_G(categories[0], companyId, groupId, 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(categories), companyId, groupId }; } else { finderArgs = new Object[] { StringUtil.merge(categories), companyId, groupId, start, end, orderByComparator }; } List<ReportDefinition> list = null; if (retrieveFromCache) { list = (List<ReportDefinition>) finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_G, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (ReportDefinition reportDefinition : list) { if (!ArrayUtil.contains(categories, reportDefinition.getCategory()) || (companyId != reportDefinition.getCompanyId()) || (groupId != reportDefinition.getGroupId())) { list = null; break; } } } } if (list == null) { StringBundler query = new StringBundler(); query.append(_SQL_SELECT_REPORTDEFINITION_WHERE); if (categories.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < categories.length; i++) { String category = categories[i]; if (category == null) { query.append(_FINDER_COLUMN_C_C_G_CATEGORY_4); } else if (category.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_C_C_G_CATEGORY_6); } else { query.append(_FINDER_COLUMN_C_C_G_CATEGORY_5); } if ((i + 1) < categories.length) { query.append(WHERE_OR); } } query.append(StringPool.CLOSE_PARENTHESIS); query.append(WHERE_AND); } query.append(_FINDER_COLUMN_C_C_G_COMPANYID_2); query.append(_FINDER_COLUMN_C_C_G_GROUPID_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(ReportDefinitionModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); for (String category : categories) { if ((category != null) && !category.isEmpty()) { qPos.add(category); } } qPos.add(companyId); qPos.add(groupId); if (!pagination) { list = (List<ReportDefinition>) QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<ReportDefinition>) QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_G, finderArgs, list); } catch (Exception e) { finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_G, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; }
From source file:com.bemis.portal.report.service.persistence.impl.ReportDefinitionPersistenceImpl.java
License:Open Source License
/** * Returns the number of report definitions where category = any ? and companyId = ? and groupId = ?. * * @param categories the categories/* w ww.ja v a2 s . c o m*/ * @param companyId the company ID * @param groupId the group ID * @return the number of matching report definitions */ @Override public int countByC_C_G(String[] categories, long companyId, long groupId) { if (categories == null) { categories = new String[0]; } else if (categories.length > 1) { categories = ArrayUtil.distinct(categories, NULL_SAFE_STRING_COMPARATOR); Arrays.sort(categories, NULL_SAFE_STRING_COMPARATOR); } Object[] finderArgs = new Object[] { StringUtil.merge(categories), companyId, groupId }; Long count = (Long) finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_C_G, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(); query.append(_SQL_COUNT_REPORTDEFINITION_WHERE); if (categories.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < categories.length; i++) { String category = categories[i]; if (category == null) { query.append(_FINDER_COLUMN_C_C_G_CATEGORY_4); } else if (category.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_C_C_G_CATEGORY_6); } else { query.append(_FINDER_COLUMN_C_C_G_CATEGORY_5); } if ((i + 1) < categories.length) { query.append(WHERE_OR); } } query.append(StringPool.CLOSE_PARENTHESIS); query.append(WHERE_AND); } query.append(_FINDER_COLUMN_C_C_G_COMPANYID_2); query.append(_FINDER_COLUMN_C_C_G_GROUPID_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); for (String category : categories) { if ((category != null) && !category.isEmpty()) { qPos.add(category); } } qPos.add(companyId); qPos.add(groupId); count = (Long) q.uniqueResult(); finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_C_G, finderArgs, count); } catch (Exception e) { finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_C_G, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); }
From source file:com.bemis.portal.report.service.persistence.impl.ReportDefinitionPersistenceImpl.java
License:Open Source License
/** * Returns the number of report definitions that the user has permission to view where category = any ? and companyId = ? and groupId = ?. * * @param categories the categories/*from w ww . ja v a 2s. c o m*/ * @param companyId the company ID * @param groupId the group ID * @return the number of matching report definitions that the user has permission to view */ @Override public int filterCountByC_C_G(String[] categories, long companyId, long groupId) { if (!InlineSQLHelperUtil.isEnabled(groupId)) { return countByC_C_G(categories, companyId, groupId); } if (categories == null) { categories = new String[0]; } else if (categories.length > 1) { categories = ArrayUtil.distinct(categories, NULL_SAFE_STRING_COMPARATOR); Arrays.sort(categories, NULL_SAFE_STRING_COMPARATOR); } StringBundler query = new StringBundler(); query.append(_FILTER_SQL_COUNT_REPORTDEFINITION_WHERE); if (categories.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < categories.length; i++) { String category = categories[i]; if (category == null) { query.append(_FINDER_COLUMN_C_C_G_CATEGORY_4); } else if (category.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_C_C_G_CATEGORY_6); } else { query.append(_FINDER_COLUMN_C_C_G_CATEGORY_5); } if ((i + 1) < categories.length) { query.append(WHERE_OR); } } query.append(StringPool.CLOSE_PARENTHESIS); query.append(WHERE_AND); } query.append(_FINDER_COLUMN_C_C_G_COMPANYID_2); query.append(_FINDER_COLUMN_C_C_G_GROUPID_2); query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)), query.index() - 1); String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), ReportDefinition.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); for (String category : categories) { if ((category != null) && !category.isEmpty()) { qPos.add(category); } } qPos.add(companyId); qPos.add(groupId); Long count = (Long) q.uniqueResult(); return count.intValue(); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } }
From source file:com.bemis.portal.report.service.persistence.impl.ReportRequestPersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the report requests where reportDefinitionCategory = ? and userId = ?, optionally using the finder cache. * * <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 ReportRequestModelImpl}. 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 reportDefinitionCategory the report definition category * @param userId the user ID * @param start the lower bound of the range of report requests * @param end the upper bound of the range of report requests (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 report requests */ @Override public List<ReportRequest> findByRDC_U(String[] reportDefinitionCategories, long userId, int start, int end, OrderByComparator<ReportRequest> orderByComparator, boolean retrieveFromCache) { if (reportDefinitionCategories == null) { reportDefinitionCategories = new String[0]; } else if (reportDefinitionCategories.length > 1) { reportDefinitionCategories = ArrayUtil.distinct(reportDefinitionCategories, NULL_SAFE_STRING_COMPARATOR); Arrays.sort(reportDefinitionCategories, NULL_SAFE_STRING_COMPARATOR); } if (reportDefinitionCategories.length == 1) { return findByRDC_U(reportDefinitionCategories[0], userId, 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(reportDefinitionCategories), userId }; } else { finderArgs = new Object[] { StringUtil.merge(reportDefinitionCategories), userId, start, end, orderByComparator }; } List<ReportRequest> list = null; if (retrieveFromCache) { list = (List<ReportRequest>) finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_RDC_U, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (ReportRequest reportRequest : list) { if (!ArrayUtil.contains(reportDefinitionCategories, reportRequest.getReportDefinitionCategory()) || (userId != reportRequest.getUserId())) { list = null; break; } } } } if (list == null) { StringBundler query = new StringBundler(); query.append(_SQL_SELECT_REPORTREQUEST_WHERE); if (reportDefinitionCategories.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < reportDefinitionCategories.length; i++) { String reportDefinitionCategory = reportDefinitionCategories[i]; if (reportDefinitionCategory == null) { query.append(_FINDER_COLUMN_RDC_U_REPORTDEFINITIONCATEGORY_4); } else if (reportDefinitionCategory.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_RDC_U_REPORTDEFINITIONCATEGORY_6); } else { query.append(_FINDER_COLUMN_RDC_U_REPORTDEFINITIONCATEGORY_5); } if ((i + 1) < reportDefinitionCategories.length) { query.append(WHERE_OR); } } query.append(StringPool.CLOSE_PARENTHESIS); query.append(WHERE_AND); } query.append(_FINDER_COLUMN_RDC_U_USERID_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(ReportRequestModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); for (String reportDefinitionCategory : reportDefinitionCategories) { if ((reportDefinitionCategory != null) && !reportDefinitionCategory.isEmpty()) { qPos.add(reportDefinitionCategory); } } qPos.add(userId); if (!pagination) { list = (List<ReportRequest>) QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<ReportRequest>) QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_RDC_U, finderArgs, list); } catch (Exception e) { finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_RDC_U, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; }
From source file:com.bemis.portal.report.service.persistence.impl.ReportRequestPersistenceImpl.java
License:Open Source License
/** * Returns the number of report requests where reportDefinitionCategory = any ? and userId = ?. * * @param reportDefinitionCategories the report definition categories * @param userId the user ID//from w w w . jav a 2 s.c o m * @return the number of matching report requests */ @Override public int countByRDC_U(String[] reportDefinitionCategories, long userId) { if (reportDefinitionCategories == null) { reportDefinitionCategories = new String[0]; } else if (reportDefinitionCategories.length > 1) { reportDefinitionCategories = ArrayUtil.distinct(reportDefinitionCategories, NULL_SAFE_STRING_COMPARATOR); Arrays.sort(reportDefinitionCategories, NULL_SAFE_STRING_COMPARATOR); } Object[] finderArgs = new Object[] { StringUtil.merge(reportDefinitionCategories), userId }; Long count = (Long) finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_RDC_U, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(); query.append(_SQL_COUNT_REPORTREQUEST_WHERE); if (reportDefinitionCategories.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < reportDefinitionCategories.length; i++) { String reportDefinitionCategory = reportDefinitionCategories[i]; if (reportDefinitionCategory == null) { query.append(_FINDER_COLUMN_RDC_U_REPORTDEFINITIONCATEGORY_4); } else if (reportDefinitionCategory.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_RDC_U_REPORTDEFINITIONCATEGORY_6); } else { query.append(_FINDER_COLUMN_RDC_U_REPORTDEFINITIONCATEGORY_5); } if ((i + 1) < reportDefinitionCategories.length) { query.append(WHERE_OR); } } query.append(StringPool.CLOSE_PARENTHESIS); query.append(WHERE_AND); } query.append(_FINDER_COLUMN_RDC_U_USERID_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); for (String reportDefinitionCategory : reportDefinitionCategories) { if ((reportDefinitionCategory != null) && !reportDefinitionCategory.isEmpty()) { qPos.add(reportDefinitionCategory); } } qPos.add(userId); count = (Long) q.uniqueResult(); finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_RDC_U, finderArgs, count); } catch (Exception e) { finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_RDC_U, 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>/* 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 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 . j a va 2 s. 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(); }