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.liferay.bookmarks.service.persistence.impl.BookmarksFolderFinderImpl.java
License:Open Source License
protected int doCountF_E_ByG_F(long groupId, long folderId, QueryDefinition<?> queryDefinition, boolean inlineSQLHelper) { Session session = null;/*w w w . ja v a2s . c om*/ try { session = openSession(); StringBundler sb = new StringBundler(5); sb.append(StringPool.OPEN_PARENTHESIS); String sql = null; if (queryDefinition.getStatus() == WorkflowConstants.STATUS_ANY) { sql = CustomSQLUtil.get(getClass(), COUNT_F_BY_G_P); } else { sql = CustomSQLUtil.get(getClass(), COUNT_F_BY_G_P_S); sql = replaceExcludeStatus(sql, queryDefinition); } if (inlineSQLHelper) { sql = InlineSQLHelperUtil.replacePermissionCheck(sql, BookmarksFolder.class.getName(), "BookmarksFolder.folderId", groupId); } sb.append(sql); sb.append(") UNION ALL ("); if (queryDefinition.getStatus() == WorkflowConstants.STATUS_ANY) { sql = CustomSQLUtil.get(getClass(), COUNT_E_BY_G_F); } else { sql = CustomSQLUtil.get(getClass(), COUNT_E_BY_G_F_S); sql = replaceExcludeStatus(sql, queryDefinition); } if (inlineSQLHelper) { sql = InlineSQLHelperUtil.replacePermissionCheck(sql, BookmarksEntry.class.getName(), "BookmarksEntry.fileEntryId", groupId); } sb.append(sql); sb.append(StringPool.CLOSE_PARENTHESIS); sql = sb.toString(); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, Type.LONG); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); qPos.add(folderId); if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) { qPos.add(queryDefinition.getStatus()); } qPos.add(groupId); qPos.add(folderId); if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) { qPos.add(queryDefinition.getStatus()); } int count = 0; Iterator<Long> itr = q.iterate(); while (itr.hasNext()) { Long l = itr.next(); if (l != null) { count += l.intValue(); } } return count; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
From source file:com.liferay.calendar.service.persistence.CalendarResourcePersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the calendar resources where groupId = any ? and code LIKE ? and active = ?. * * <p>// ww w .j ava 2 s . c o m * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. * </p> * * @param groupIds the group IDs * @param code the code * @param active the active * @param start the lower bound of the range of calendar resources * @param end the upper bound of the range of calendar resources (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching calendar resources * @throws SystemException if a system exception occurred */ public List<CalendarResource> findByG_C_A(long[] groupIds, String code, boolean active, int start, int end, OrderByComparator orderByComparator) throws SystemException { FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_A; Object[] finderArgs = null; if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) { finderArgs = new Object[] { StringUtil.merge(groupIds), code, active }; } else { finderArgs = new Object[] { StringUtil.merge(groupIds), code, active, start, end, orderByComparator }; } List<CalendarResource> list = (List<CalendarResource>) FinderCacheUtil.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (CalendarResource calendarResource : list) { if (!ArrayUtil.contains(groupIds, calendarResource.getGroupId()) || !Validator.equals(code, calendarResource.getCode()) || (active != calendarResource.getActive())) { list = null; break; } } } if (list == null) { StringBundler query = new StringBundler(); query.append(_SQL_SELECT_CALENDARRESOURCE_WHERE); boolean conjunctionable = false; if ((groupIds == null) || (groupIds.length > 0)) { if (conjunctionable) { query.append(WHERE_AND); } query.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < groupIds.length; i++) { query.append(_FINDER_COLUMN_G_C_A_GROUPID_5); if ((i + 1) < groupIds.length) { query.append(WHERE_OR); } } query.append(StringPool.CLOSE_PARENTHESIS); conjunctionable = true; } if (conjunctionable) { query.append(WHERE_AND); } if (code == null) { query.append(_FINDER_COLUMN_G_C_A_CODE_4); } else { if (code.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_G_C_A_CODE_6); } else { query.append(_FINDER_COLUMN_G_C_A_CODE_5); } } conjunctionable = true; if (conjunctionable) { query.append(WHERE_AND); } query.append(_FINDER_COLUMN_G_C_A_ACTIVE_5); conjunctionable = true; if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else { query.append(CalendarResourceModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (groupIds != null) { qPos.add(groupIds); } if (code != null) { qPos.add(code); } qPos.add(active); list = (List<CalendarResource>) QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw processException(e); } finally { if (list == null) { FinderCacheUtil.removeResult(finderPath, finderArgs); } else { cacheResult(list); FinderCacheUtil.putResult(finderPath, finderArgs, list); } closeSession(session); } } return list; }
From source file:com.liferay.calendar.service.persistence.CalendarResourcePersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the calendar resources where groupId = any ? and name LIKE ? and active = ?. * * <p>//from w w w.j a va2s.c o m * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. * </p> * * @param groupIds the group IDs * @param name the name * @param active the active * @param start the lower bound of the range of calendar resources * @param end the upper bound of the range of calendar resources (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching calendar resources * @throws SystemException if a system exception occurred */ public List<CalendarResource> findByG_N_A(long[] groupIds, String name, boolean active, int start, int end, OrderByComparator orderByComparator) throws SystemException { FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_A; Object[] finderArgs = null; if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) { finderArgs = new Object[] { StringUtil.merge(groupIds), name, active }; } else { finderArgs = new Object[] { StringUtil.merge(groupIds), name, active, start, end, orderByComparator }; } List<CalendarResource> list = (List<CalendarResource>) FinderCacheUtil.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (CalendarResource calendarResource : list) { if (!ArrayUtil.contains(groupIds, calendarResource.getGroupId()) || !Validator.equals(name, calendarResource.getName()) || (active != calendarResource.getActive())) { list = null; break; } } } if (list == null) { StringBundler query = new StringBundler(); query.append(_SQL_SELECT_CALENDARRESOURCE_WHERE); boolean conjunctionable = false; if ((groupIds == null) || (groupIds.length > 0)) { if (conjunctionable) { query.append(WHERE_AND); } query.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < groupIds.length; i++) { query.append(_FINDER_COLUMN_G_N_A_GROUPID_5); if ((i + 1) < groupIds.length) { query.append(WHERE_OR); } } query.append(StringPool.CLOSE_PARENTHESIS); conjunctionable = true; } if (conjunctionable) { query.append(WHERE_AND); } if (name == null) { query.append(_FINDER_COLUMN_G_N_A_NAME_4); } else { if (name.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_G_N_A_NAME_6); } else { query.append(_FINDER_COLUMN_G_N_A_NAME_5); } } conjunctionable = true; if (conjunctionable) { query.append(WHERE_AND); } query.append(_FINDER_COLUMN_G_N_A_ACTIVE_5); conjunctionable = true; if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else { query.append(CalendarResourceModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (groupIds != null) { qPos.add(groupIds); } if (name != null) { qPos.add(name); } qPos.add(active); list = (List<CalendarResource>) QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw processException(e); } finally { if (list == null) { FinderCacheUtil.removeResult(finderPath, finderArgs); } else { cacheResult(list); FinderCacheUtil.putResult(finderPath, finderArgs, list); } closeSession(session); } } return list; }
From source file:com.liferay.calendar.service.persistence.CalendarResourcePersistenceImpl.java
License:Open Source License
/** * Returns the number of calendar resources where groupId = any ? and code LIKE ? and active = ?. * * @param groupIds the group IDs//from www. j av a 2 s . c o m * @param code the code * @param active the active * @return the number of matching calendar resources * @throws SystemException if a system exception occurred */ public int countByG_C_A(long[] groupIds, String code, boolean active) throws SystemException { Object[] finderArgs = new Object[] { StringUtil.merge(groupIds), code, active }; Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_A, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(); query.append(_SQL_COUNT_CALENDARRESOURCE_WHERE); boolean conjunctionable = false; if ((groupIds == null) || (groupIds.length > 0)) { if (conjunctionable) { query.append(WHERE_AND); } query.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < groupIds.length; i++) { query.append(_FINDER_COLUMN_G_C_A_GROUPID_5); if ((i + 1) < groupIds.length) { query.append(WHERE_OR); } } query.append(StringPool.CLOSE_PARENTHESIS); conjunctionable = true; } if (conjunctionable) { query.append(WHERE_AND); } if (code == null) { query.append(_FINDER_COLUMN_G_C_A_CODE_4); } else { if (code.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_G_C_A_CODE_6); } else { query.append(_FINDER_COLUMN_G_C_A_CODE_5); } } conjunctionable = true; if (conjunctionable) { query.append(WHERE_AND); } query.append(_FINDER_COLUMN_G_C_A_ACTIVE_5); conjunctionable = true; String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (groupIds != null) { qPos.add(groupIds); } if (code != null) { qPos.add(code); } qPos.add(active); count = (Long) q.uniqueResult(); } catch (Exception e) { throw processException(e); } finally { if (count == null) { count = Long.valueOf(0); } FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_A, finderArgs, count); closeSession(session); } } return count.intValue(); }
From source file:com.liferay.calendar.service.persistence.CalendarResourcePersistenceImpl.java
License:Open Source License
/** * Returns the number of calendar resources where groupId = any ? and name LIKE ? and active = ?. * * @param groupIds the group IDs//w w w. j a v a 2s .com * @param name the name * @param active the active * @return the number of matching calendar resources * @throws SystemException if a system exception occurred */ public int countByG_N_A(long[] groupIds, String name, boolean active) throws SystemException { Object[] finderArgs = new Object[] { StringUtil.merge(groupIds), name, active }; Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_N_A, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(); query.append(_SQL_COUNT_CALENDARRESOURCE_WHERE); boolean conjunctionable = false; if ((groupIds == null) || (groupIds.length > 0)) { if (conjunctionable) { query.append(WHERE_AND); } query.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < groupIds.length; i++) { query.append(_FINDER_COLUMN_G_N_A_GROUPID_5); if ((i + 1) < groupIds.length) { query.append(WHERE_OR); } } query.append(StringPool.CLOSE_PARENTHESIS); conjunctionable = true; } if (conjunctionable) { query.append(WHERE_AND); } if (name == null) { query.append(_FINDER_COLUMN_G_N_A_NAME_4); } else { if (name.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_G_N_A_NAME_6); } else { query.append(_FINDER_COLUMN_G_N_A_NAME_5); } } conjunctionable = true; if (conjunctionable) { query.append(WHERE_AND); } query.append(_FINDER_COLUMN_G_N_A_ACTIVE_5); conjunctionable = true; String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (groupIds != null) { qPos.add(groupIds); } if (name != null) { qPos.add(name); } qPos.add(active); count = (Long) q.uniqueResult(); } catch (Exception e) { throw processException(e); } finally { if (count == null) { count = Long.valueOf(0); } FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_N_A, finderArgs, count); closeSession(session); } } return count.intValue(); }
From source file:com.liferay.calendar.service.persistence.impl.CalendarBookingPersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the calendar bookings where calendarId = ? and status = any ?. * * <p>/*from w w w . j a v a 2 s .com*/ * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.calendar.model.impl.CalendarBookingModelImpl}. 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 calendarId the calendar ID * @param statuses the statuses * @param start the lower bound of the range of calendar bookings * @param end the upper bound of the range of calendar bookings (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching calendar bookings */ @Override public List<CalendarBooking> findByC_S(long calendarId, int[] statuses, int start, int end, OrderByComparator<CalendarBooking> orderByComparator) { if (statuses == null) { statuses = new int[0]; } else { statuses = ArrayUtil.unique(statuses); } if (statuses.length == 1) { return findByC_S(calendarId, 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[] { calendarId, StringUtil.merge(statuses) }; } else { finderArgs = new Object[] { calendarId, StringUtil.merge(statuses), start, end, orderByComparator }; } List<CalendarBooking> list = (List<CalendarBooking>) FinderCacheUtil .getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (CalendarBooking calendarBooking : list) { if ((calendarId != calendarBooking.getCalendarId()) || !ArrayUtil.contains(statuses, calendarBooking.getStatus())) { list = null; break; } } } if (list == null) { StringBundler query = new StringBundler(); query.append(_SQL_SELECT_CALENDARBOOKING_WHERE); query.append(_FINDER_COLUMN_C_S_CALENDARID_2); if (statuses.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_C_S_STATUS_7); query.append(StringUtil.merge(statuses)); 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(CalendarBookingModelImpl.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(calendarId); if (!pagination) { list = (List<CalendarBooking>) QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<CalendarBooking>) QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S, finderArgs, list); } catch (Exception e) { FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; }
From source file:com.liferay.calendar.service.persistence.impl.CalendarBookingPersistenceImpl.java
License:Open Source License
/** * Returns the number of calendar bookings where calendarId = ? and status = any ?. * * @param calendarId the calendar ID//from w w w . j ava 2 s . c om * @param statuses the statuses * @return the number of matching calendar bookings */ @Override public int countByC_S(long calendarId, int[] statuses) { if (statuses == null) { statuses = new int[0]; } else { statuses = ArrayUtil.unique(statuses); } Object[] finderArgs = new Object[] { calendarId, StringUtil.merge(statuses) }; Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_S, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(); query.append(_SQL_COUNT_CALENDARBOOKING_WHERE); query.append(_FINDER_COLUMN_C_S_CALENDARID_2); if (statuses.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_C_S_STATUS_7); query.append(StringUtil.merge(statuses)); 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); QueryPos qPos = QueryPos.getInstance(q); qPos.add(calendarId); count = (Long) q.uniqueResult(); FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_S, finderArgs, count); } catch (Exception e) { FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_S, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); }
From source file:com.liferay.calendar.service.persistence.impl.CalendarResourcePersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the calendar resources that the user has permission to view where groupId = any ? and code = ?. * * <p>//ww w .j a va 2 s. c o m * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.calendar.model.impl.CalendarResourceModelImpl}. 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 groupIds the group IDs * @param code the code * @param start the lower bound of the range of calendar resources * @param end the upper bound of the range of calendar resources (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching calendar resources that the user has permission to view */ @Override public List<CalendarResource> filterFindByG_C(long[] groupIds, String code, int start, int end, OrderByComparator<CalendarResource> orderByComparator) { if (!InlineSQLHelperUtil.isEnabled(groupIds)) { return findByG_C(groupIds, code, start, end, orderByComparator); } if (groupIds == null) { groupIds = new long[0]; } else { groupIds = ArrayUtil.unique(groupIds); } StringBundler query = new StringBundler(); query.append(_SQL_SELECT_CALENDARRESOURCE_WHERE); if (groupIds.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_G_C_GROUPID_7); query.append(StringUtil.merge(groupIds)); query.append(StringPool.CLOSE_PARENTHESIS); query.append(StringPool.CLOSE_PARENTHESIS); query.append(WHERE_AND); } boolean bindCode = false; if (code == null) { query.append(_FINDER_COLUMN_G_C_CODE_1); } else if (code.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_G_C_CODE_3); } else { bindCode = true; query.append(_FINDER_COLUMN_G_C_CODE_2); } query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)), query.index() - 1); if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else { query.append(CalendarResourceModelImpl.ORDER_BY_JPQL); } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), CalendarResource.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, _FILTER_ENTITY_TABLE_FILTER_USERID_COLUMN, groupIds); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (bindCode) { qPos.add(code); } return (List<CalendarResource>) QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } }
From source file:com.liferay.calendar.service.persistence.impl.CalendarResourcePersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the calendar resources where groupId = any ? and code = ?. * * <p>/*w w w . j a v a2 s . c o m*/ * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.calendar.model.impl.CalendarResourceModelImpl}. 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 groupIds the group IDs * @param code the code * @param start the lower bound of the range of calendar resources * @param end the upper bound of the range of calendar resources (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching calendar resources */ @Override public List<CalendarResource> findByG_C(long[] groupIds, String code, int start, int end, OrderByComparator<CalendarResource> orderByComparator) { if (groupIds == null) { groupIds = new long[0]; } else { groupIds = ArrayUtil.unique(groupIds); } if (groupIds.length == 1) { return findByG_C(groupIds[0], code, 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(groupIds), code }; } else { finderArgs = new Object[] { StringUtil.merge(groupIds), code, start, end, orderByComparator }; } List<CalendarResource> list = (List<CalendarResource>) FinderCacheUtil .getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (CalendarResource calendarResource : list) { if (!ArrayUtil.contains(groupIds, calendarResource.getGroupId()) || !Validator.equals(code, calendarResource.getCode())) { list = null; break; } } } if (list == null) { StringBundler query = new StringBundler(); query.append(_SQL_SELECT_CALENDARRESOURCE_WHERE); if (groupIds.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_G_C_GROUPID_7); query.append(StringUtil.merge(groupIds)); query.append(StringPool.CLOSE_PARENTHESIS); query.append(StringPool.CLOSE_PARENTHESIS); query.append(WHERE_AND); } boolean bindCode = false; if (code == null) { query.append(_FINDER_COLUMN_G_C_CODE_1); } else if (code.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_G_C_CODE_3); } else { bindCode = true; query.append(_FINDER_COLUMN_G_C_CODE_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(CalendarResourceModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (bindCode) { qPos.add(code); } if (!pagination) { list = (List<CalendarResource>) QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<CalendarResource>) QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C, finderArgs, list); } catch (Exception e) { FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; }
From source file:com.liferay.calendar.service.persistence.impl.CalendarResourcePersistenceImpl.java
License:Open Source License
/** * Returns the number of calendar resources where groupId = any ? and code = ?. * * @param groupIds the group IDs/*www. j a v a2 s .c o m*/ * @param code the code * @return the number of matching calendar resources */ @Override public int countByG_C(long[] groupIds, String code) { if (groupIds == null) { groupIds = new long[0]; } else { groupIds = ArrayUtil.unique(groupIds); } Object[] finderArgs = new Object[] { StringUtil.merge(groupIds), code }; Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(); query.append(_SQL_COUNT_CALENDARRESOURCE_WHERE); if (groupIds.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_G_C_GROUPID_7); query.append(StringUtil.merge(groupIds)); query.append(StringPool.CLOSE_PARENTHESIS); query.append(StringPool.CLOSE_PARENTHESIS); query.append(WHERE_AND); } boolean bindCode = false; if (code == null) { query.append(_FINDER_COLUMN_G_C_CODE_1); } else if (code.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_G_C_CODE_3); } else { bindCode = true; query.append(_FINDER_COLUMN_G_C_CODE_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); if (bindCode) { qPos.add(code); } count = (Long) q.uniqueResult(); FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C, finderArgs, count); } catch (Exception e) { FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); }