List of usage examples for com.liferay.portal.kernel.security.permission InlineSQLHelperUtil replacePermissionCheck
public static String replacePermissionCheck(String sql, String className, String classPKField, String userIdField)
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 permissions to view where companyId = ? and groupId = ?. * * <p>// w ww .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 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 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_G(long companyId, long groupId, int start, int end, OrderByComparator<ReportDefinition> orderByComparator) { if (!InlineSQLHelperUtil.isEnabled(groupId)) { return findByC_G(companyId, groupId, start, end, orderByComparator); } StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(4 + (orderByComparator.getOrderByFields().length * 2)); } else { query = new StringBundler(5); } if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_REPORTDEFINITION_WHERE); } else { query.append(_FILTER_SQL_SELECT_REPORTDEFINITION_NO_INLINE_DISTINCT_WHERE_1); } query.append(_FINDER_COLUMN_C_G_COMPANYID_2); query.append(_FINDER_COLUMN_C_G_GROUPID_2); 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); 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
protected ReportDefinition filterGetByC_G_PrevAndNext(Session session, ReportDefinition reportDefinition, long companyId, long groupId, OrderByComparator<ReportDefinition> orderByComparator, boolean previous) { StringBundler query = null;//from w w w . ja va 2 s .c om if (orderByComparator != null) { query = new StringBundler(6 + (orderByComparator.getOrderByConditionFields().length * 3) + (orderByComparator.getOrderByFields().length * 3)); } else { query = new StringBundler(5); } if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_REPORTDEFINITION_WHERE); } else { query.append(_FILTER_SQL_SELECT_REPORTDEFINITION_NO_INLINE_DISTINCT_WHERE_1); } query.append(_FINDER_COLUMN_C_G_COMPANYID_2); query.append(_FINDER_COLUMN_C_G_GROUPID_2); if (!getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_REPORTDEFINITION_NO_INLINE_DISTINCT_WHERE_2); } if (orderByComparator != null) { String[] orderByConditionFields = orderByComparator.getOrderByConditionFields(); if (orderByConditionFields.length > 0) { query.append(WHERE_AND); } for (int i = 0; i < orderByConditionFields.length; i++) { if (getDB().isSupportsInlineDistinct()) { query.append(_ORDER_BY_ENTITY_ALIAS); } else { query.append(_ORDER_BY_ENTITY_TABLE); } query.append(orderByConditionFields[i]); if ((i + 1) < orderByConditionFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN_HAS_NEXT); } else { query.append(WHERE_LESSER_THAN_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN); } else { query.append(WHERE_LESSER_THAN); } } } query.append(ORDER_BY_CLAUSE); String[] orderByFields = orderByComparator.getOrderByFields(); for (int i = 0; i < orderByFields.length; i++) { if (getDB().isSupportsInlineDistinct()) { query.append(_ORDER_BY_ENTITY_ALIAS); } else { query.append(_ORDER_BY_ENTITY_TABLE); } query.append(orderByFields[i]); if ((i + 1) < orderByFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC_HAS_NEXT); } else { query.append(ORDER_BY_DESC_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC); } else { query.append(ORDER_BY_DESC); } } } } else { 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); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.setFirstResult(0); q.setMaxResults(2); if (getDB().isSupportsInlineDistinct()) { q.addEntity(_FILTER_ENTITY_ALIAS, ReportDefinitionImpl.class); } else { q.addEntity(_FILTER_ENTITY_TABLE, ReportDefinitionImpl.class); } QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); qPos.add(groupId); if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(reportDefinition); for (Object value : values) { qPos.add(value); } } List<ReportDefinition> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } }
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 companyId = ? and groupId = ?. * * @param companyId the company ID// ww w .j a v a 2 s. co m * @param groupId the group ID * @return the number of matching report definitions that the user has permission to view */ @Override public int filterCountByC_G(long companyId, long groupId) { if (!InlineSQLHelperUtil.isEnabled(groupId)) { return countByC_G(companyId, groupId); } StringBundler query = new StringBundler(3); query.append(_FILTER_SQL_COUNT_REPORTDEFINITION_WHERE); query.append(_FINDER_COLUMN_C_G_COMPANYID_2); query.append(_FINDER_COLUMN_C_G_GROUPID_2); 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); 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.ReportDefinitionPersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the report definitions that the user has permissions to view where category = ? and companyId = ? and groupId = ?. * * <p>/*from w ww . 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 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>) * @return the ordered range of matching report definitions that the user has permission to view */ @Override public List<ReportDefinition> filterFindByC_C_G(String category, long companyId, long groupId, int start, int end, OrderByComparator<ReportDefinition> orderByComparator) { if (!InlineSQLHelperUtil.isEnabled(groupId)) { return findByC_C_G(category, companyId, groupId, start, end, orderByComparator); } StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(5 + (orderByComparator.getOrderByFields().length * 2)); } else { query = new StringBundler(6); } if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_REPORTDEFINITION_WHERE); } else { query.append(_FILTER_SQL_SELECT_REPORTDEFINITION_NO_INLINE_DISTINCT_WHERE_1); } boolean bindCategory = false; if (category == null) { query.append(_FINDER_COLUMN_C_C_G_CATEGORY_1); } else if (category.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_C_C_G_CATEGORY_3); } else { bindCategory = true; query.append(_FINDER_COLUMN_C_C_G_CATEGORY_2); } query.append(_FINDER_COLUMN_C_C_G_COMPANYID_2); query.append(_FINDER_COLUMN_C_C_G_GROUPID_2); 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); if (bindCategory) { 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
protected ReportDefinition filterGetByC_C_G_PrevAndNext(Session session, ReportDefinition reportDefinition, String category, long companyId, long groupId, OrderByComparator<ReportDefinition> orderByComparator, boolean previous) { StringBundler query = null;/* w w w . j a v a2 s .c o m*/ if (orderByComparator != null) { query = new StringBundler(7 + (orderByComparator.getOrderByConditionFields().length * 3) + (orderByComparator.getOrderByFields().length * 3)); } else { query = new StringBundler(6); } if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_REPORTDEFINITION_WHERE); } else { query.append(_FILTER_SQL_SELECT_REPORTDEFINITION_NO_INLINE_DISTINCT_WHERE_1); } boolean bindCategory = false; if (category == null) { query.append(_FINDER_COLUMN_C_C_G_CATEGORY_1); } else if (category.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_C_C_G_CATEGORY_3); } else { bindCategory = true; query.append(_FINDER_COLUMN_C_C_G_CATEGORY_2); } query.append(_FINDER_COLUMN_C_C_G_COMPANYID_2); query.append(_FINDER_COLUMN_C_C_G_GROUPID_2); if (!getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_REPORTDEFINITION_NO_INLINE_DISTINCT_WHERE_2); } if (orderByComparator != null) { String[] orderByConditionFields = orderByComparator.getOrderByConditionFields(); if (orderByConditionFields.length > 0) { query.append(WHERE_AND); } for (int i = 0; i < orderByConditionFields.length; i++) { if (getDB().isSupportsInlineDistinct()) { query.append(_ORDER_BY_ENTITY_ALIAS); } else { query.append(_ORDER_BY_ENTITY_TABLE); } query.append(orderByConditionFields[i]); if ((i + 1) < orderByConditionFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN_HAS_NEXT); } else { query.append(WHERE_LESSER_THAN_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN); } else { query.append(WHERE_LESSER_THAN); } } } query.append(ORDER_BY_CLAUSE); String[] orderByFields = orderByComparator.getOrderByFields(); for (int i = 0; i < orderByFields.length; i++) { if (getDB().isSupportsInlineDistinct()) { query.append(_ORDER_BY_ENTITY_ALIAS); } else { query.append(_ORDER_BY_ENTITY_TABLE); } query.append(orderByFields[i]); if ((i + 1) < orderByFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC_HAS_NEXT); } else { query.append(ORDER_BY_DESC_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC); } else { query.append(ORDER_BY_DESC); } } } } else { 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); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.setFirstResult(0); q.setMaxResults(2); if (getDB().isSupportsInlineDistinct()) { q.addEntity(_FILTER_ENTITY_ALIAS, ReportDefinitionImpl.class); } else { q.addEntity(_FILTER_ENTITY_TABLE, ReportDefinitionImpl.class); } QueryPos qPos = QueryPos.getInstance(q); if (bindCategory) { qPos.add(category); } qPos.add(companyId); qPos.add(groupId); if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(reportDefinition); for (Object value : values) { qPos.add(value); } } List<ReportDefinition> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } }
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 w w . j av a2s .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 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 the number of report definitions that the user has permission to view where category = ? and companyId = ? and groupId = ?. * * @param category the category/*from w w w . j av a 2s .co 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 category, long companyId, long groupId) { if (!InlineSQLHelperUtil.isEnabled(groupId)) { return countByC_C_G(category, companyId, groupId); } StringBundler query = new StringBundler(4); query.append(_FILTER_SQL_COUNT_REPORTDEFINITION_WHERE); boolean bindCategory = false; if (category == null) { query.append(_FINDER_COLUMN_C_C_G_CATEGORY_1); } else if (category.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_C_C_G_CATEGORY_3); } else { bindCategory = true; query.append(_FINDER_COLUMN_C_C_G_CATEGORY_2); } query.append(_FINDER_COLUMN_C_C_G_COMPANYID_2); query.append(_FINDER_COLUMN_C_C_G_GROUPID_2); 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); if (bindCategory) { 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.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//w ww . j a v a2 s.c om * @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 that the user has permissions to view where companyId = ? and groupId = ?. * * <p>// 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 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 companyId the company ID * @param groupId the group 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>) * @return the ordered range of matching report requests that the user has permission to view */ @Override public List<ReportRequest> filterFindByC_G(long companyId, long groupId, int start, int end, OrderByComparator<ReportRequest> orderByComparator) { if (!InlineSQLHelperUtil.isEnabled(groupId)) { return findByC_G(companyId, groupId, start, end, orderByComparator); } StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(4 + (orderByComparator.getOrderByFields().length * 2)); } else { query = new StringBundler(5); } if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_REPORTREQUEST_WHERE); } else { query.append(_FILTER_SQL_SELECT_REPORTREQUEST_NO_INLINE_DISTINCT_WHERE_1); } query.append(_FINDER_COLUMN_C_G_COMPANYID_2); query.append(_FINDER_COLUMN_C_G_GROUPID_2); if (!getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_REPORTREQUEST_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(ReportRequestModelImpl.ORDER_BY_JPQL); } else { query.append(ReportRequestModelImpl.ORDER_BY_SQL); } } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), ReportRequest.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, ReportRequestImpl.class); } else { q.addEntity(_FILTER_ENTITY_TABLE, ReportRequestImpl.class); } QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); qPos.add(groupId); return (List<ReportRequest>) 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.ReportRequestPersistenceImpl.java
License:Open Source License
protected ReportRequest filterGetByC_G_PrevAndNext(Session session, ReportRequest reportRequest, long companyId, long groupId, OrderByComparator<ReportRequest> orderByComparator, boolean previous) { StringBundler query = null;//from ww w .j a v a 2s . com if (orderByComparator != null) { query = new StringBundler(6 + (orderByComparator.getOrderByConditionFields().length * 3) + (orderByComparator.getOrderByFields().length * 3)); } else { query = new StringBundler(5); } if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_REPORTREQUEST_WHERE); } else { query.append(_FILTER_SQL_SELECT_REPORTREQUEST_NO_INLINE_DISTINCT_WHERE_1); } query.append(_FINDER_COLUMN_C_G_COMPANYID_2); query.append(_FINDER_COLUMN_C_G_GROUPID_2); if (!getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_REPORTREQUEST_NO_INLINE_DISTINCT_WHERE_2); } if (orderByComparator != null) { String[] orderByConditionFields = orderByComparator.getOrderByConditionFields(); if (orderByConditionFields.length > 0) { query.append(WHERE_AND); } for (int i = 0; i < orderByConditionFields.length; i++) { if (getDB().isSupportsInlineDistinct()) { query.append(_ORDER_BY_ENTITY_ALIAS); } else { query.append(_ORDER_BY_ENTITY_TABLE); } query.append(orderByConditionFields[i]); if ((i + 1) < orderByConditionFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN_HAS_NEXT); } else { query.append(WHERE_LESSER_THAN_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN); } else { query.append(WHERE_LESSER_THAN); } } } query.append(ORDER_BY_CLAUSE); String[] orderByFields = orderByComparator.getOrderByFields(); for (int i = 0; i < orderByFields.length; i++) { if (getDB().isSupportsInlineDistinct()) { query.append(_ORDER_BY_ENTITY_ALIAS); } else { query.append(_ORDER_BY_ENTITY_TABLE); } query.append(orderByFields[i]); if ((i + 1) < orderByFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC_HAS_NEXT); } else { query.append(ORDER_BY_DESC_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC); } else { query.append(ORDER_BY_DESC); } } } } else { if (getDB().isSupportsInlineDistinct()) { query.append(ReportRequestModelImpl.ORDER_BY_JPQL); } else { query.append(ReportRequestModelImpl.ORDER_BY_SQL); } } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), ReportRequest.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.setFirstResult(0); q.setMaxResults(2); if (getDB().isSupportsInlineDistinct()) { q.addEntity(_FILTER_ENTITY_ALIAS, ReportRequestImpl.class); } else { q.addEntity(_FILTER_ENTITY_TABLE, ReportRequestImpl.class); } QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); qPos.add(groupId); if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(reportRequest); for (Object value : values) { qPos.add(value); } } List<ReportRequest> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } }