protected int doCountByG_C( long groupId, long categoryId, QueryDefinition queryDefinition, boolean inlineSQLHelper) throws SystemException { if (!inlineSQLHelper || !InlineSQLHelperUtil.isEnabled(groupId)) { if (queryDefinition.isExcludeStatus()) { return MBThreadUtil.countByG_C_NotS(groupId, categoryId, queryDefinition.getStatus()); } else { if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) { return MBThreadUtil.countByG_C_S(groupId, categoryId, queryDefinition.getStatus()); } else { return MBThreadUtil.countByG_C(groupId, categoryId); } } } Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(COUNT_BY_G_C); sql = updateSQL(sql, queryDefinition); sql = InlineSQLHelperUtil.replacePermissionCheck( sql, MBMessage.class.getName(), "MBThread.rootMessageId", groupId); SQLQuery q = session.createSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, Type.LONG); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); qPos.add(categoryId); if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) { qPos.add(queryDefinition.getStatus()); } Iterator<Long> itr = q.iterate(); if (itr.hasNext()) { Long count = itr.next(); if (count != null) { return count.intValue(); } } return 0; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } }
@Override public List<MBThread> findByS_G_U(long groupId, long userId, QueryDefinition queryDefinition) throws SystemException { Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_S_G_U); sql = updateSQL(sql, queryDefinition); SQLQuery q = session.createSQLQuery(sql); q.addEntity("MBThread", MBThreadImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(PortalUtil.getClassNameId(MBThread.class.getName())); qPos.add(groupId); qPos.add(userId); if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) { qPos.add(queryDefinition.getStatus()); } return (List<MBThread>) QueryUtil.list(q, getDialect(), queryDefinition.getStart(), queryDefinition.getEnd()); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
public List<MBCategory> findByS_G_U(long groupId, long userId, int start, int end) throws SystemException { Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_S_G_U); SQLQuery q = session.createSQLQuery(sql); q.addEntity("MBCategory", MBCategoryImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(PortalUtil.getClassNameId(MBCategory.class.getName())); qPos.add(groupId); qPos.add(userId); return (List<MBCategory>) QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
@Override public int countByG_U_C_A( long groupId, long userId, long[] categoryIds, boolean anonymous, QueryDefinition queryDefinition) throws SystemException { Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(COUNT_BY_G_U_C); if (ArrayUtil.isEmpty(categoryIds)) { sql = StringUtil.replace(sql, "(MBThread.categoryId = ?) AND", StringPool.BLANK); } else { sql = StringUtil.replace( sql, "MBThread.categoryId = ?", "MBThread.categoryId = " + StringUtil.merge(categoryIds, " OR MBThread.categoryId = ")); } sql = updateSQL(sql, queryDefinition); SQLQuery q = session.createSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, Type.LONG); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); qPos.add(userId); qPos.add(anonymous); if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) { qPos.add(queryDefinition.getStatus()); } Iterator<Long> itr = q.iterate(); if (itr.hasNext()) { Long count = itr.next(); if (count != null) { return count.intValue(); } } return 0; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
@Override public List<CalEvent> findByFutureReminders() { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.HOUR, -24); Timestamp calendar_TS = CalendarUtil.getTimestamp(calendar.getTime()); Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_FUTURE_REMINDERS); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addEntity("CalEvent", CalEventImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(CalEventConstants.REMIND_BY_NONE); qPos.add(calendar_TS); qPos.add(calendar_TS); return q.list(true); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
public int countByS_G_U(long groupId, long userId) throws SystemException { Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(COUNT_BY_S_G_U); SQLQuery q = session.createSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, Type.LONG); QueryPos qPos = QueryPos.getInstance(q); qPos.add(PortalUtil.getClassNameId(MBCategory.class.getName())); qPos.add(groupId); qPos.add(userId); Iterator<Long> itr = q.list().iterator(); if (itr.hasNext()) { Long count = itr.next(); if (count != null) { return count.intValue(); } } return 0; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
public int countByGroupId(long groupId) throws SystemException { Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(COUNT_BY_GROUP_ID); SQLQuery q = session.createSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, Type.LONG); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); Iterator<Long> itr = q.iterate(); if (itr.hasNext()) { Long count = itr.next(); if (count != null) { return count.intValue(); } } return 0; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
@Override public List<ResourcePermission> findByResource( long companyId, long groupId, String name, String primKey) throws SystemException { Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_RESOURCE); SQLQuery q = session.createSQLQuery(sql); q.addEntity("ResourcePermission", ResourcePermissionImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); qPos.add(name); qPos.add(primKey); qPos.add(String.valueOf(groupId)); return (List<ResourcePermission>) QueryUtil.list(q, getDialect(), QueryUtil.ALL_POS, QueryUtil.ALL_POS); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
public int countByParents(String listParent) throws SystemException { Session session = null; try { session = openSession(); StringBuffer query = new StringBuffer(); query.append("SELECT COUNT(*) as total FROM Vlookupprice WHERE listParent LIKE ?"); SQLQuery q = session.createSQLQuery(query.toString()); q.addScalar("total", Type.LONG); int queryPos = 0; q.setString(queryPos++, "%" + listParent + "%"); Long count = null; Iterator ite = q.list().iterator(); while (ite.hasNext()) { count = (Long) ite.next(); } if (count == null) { count = new Long(0); } return count.intValue(); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
public List<SocialActivity> findByUserOrganizations(long userId, int start, int end) throws SystemException { Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_USER_ORGANIZATIONS); SQLQuery q = session.createSQLQuery(sql); q.addEntity("SocialActivity", SocialActivityImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(userId); return (List<SocialActivity>) QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
public List<MicroblogsEntry> findByU_T_MU( long userId, int type, long microblogsEntryUserId, int start, int end) throws SystemException { Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_U_MU); SQLQuery q = session.createSQLQuery(sql); q.addEntity("MicroblogsEntry", MicroblogsEntryImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(MicroblogsEntryConstants.TYPE_EVERYONE); qPos.add(userId); qPos.add(type); qPos.add(microblogsEntryUserId); return (List<MicroblogsEntry>) QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
@Override public List<Layout> findByScopeGroup(long groupId, boolean privateLayout) { Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_SCOPE_GROUP); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addEntity("Layout", LayoutImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); qPos.add(privateLayout); return q.list(true); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
@Override public List<Layout> findByNoPermissions(long roleId) { Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_NO_PERMISSIONS); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addEntity("Layout", LayoutImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(ResourceConstants.SCOPE_INDIVIDUAL); qPos.add(roleId); return q.list(true); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
@Override public List<MBThread> filterFindByG_C(long groupId, long categoryId, int start, int end) throws SystemException { if (!InlineSQLHelperUtil.isEnabled(groupId)) { return MBThreadUtil.findByG_C(groupId, categoryId, start, end); } Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_G_C); sql = InlineSQLHelperUtil.replacePermissionCheck( sql, MBMessage.class.getName(), "MBThread.rootMessageId", groupId); SQLQuery q = session.createSQLQuery(sql); q.addEntity("MBThread", MBThreadImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); qPos.add(categoryId); return (List<MBThread>) QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
@Override public List<ResourcePermission> findByR_S(long roleId, int[] scopes, int start, int end) throws SystemException { Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_R_S); sql = StringUtil.replace(sql, "[$SCOPE$]", getScopes(scopes)); SQLQuery q = session.createSQLQuery(sql); q.addEntity("ResourcePermission", ResourcePermissionImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(roleId); qPos.add(scopes); return (List<ResourcePermission>) QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
@Override public List<JournalArticle> findByReviewDate( long classNameId, Date reviewDateLT, Date reviewDateGT) { Timestamp reviewDateLT_TS = CalendarUtil.getTimestamp(reviewDateLT); Timestamp reviewDateGT_TS = CalendarUtil.getTimestamp(reviewDateGT); Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_REVIEW_DATE); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addEntity(JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(classNameId); qPos.add(reviewDateGT_TS); qPos.add(reviewDateLT_TS); return q.list(true); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
@Override public List<JournalArticle> findByExpirationDate( long classNameId, Date expirationDateLT, QueryDefinition<JournalArticle> queryDefinition) { Timestamp expirationDateLT_TS = CalendarUtil.getTimestamp(expirationDateLT); Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_EXPIRATION_DATE, queryDefinition); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addEntity(JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(classNameId); qPos.add(queryDefinition.getStatus()); qPos.add(expirationDateLT_TS); return q.list(true); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
public List<NotificationEntry> getNotificationEntryByUserId( long usreId, String typeNotification, int start, int end) throws SystemException { List list = null; // / This stuff is basic set up Session session = null; try { session = openSession(); // Here ends the basic set up;x` String sql = ""; // now we build the query. Note that we use the name of the tables // from the database! if (typeNotification.equals("NOTIFICATIONUSERIDFROM")) { sql = CustomSQLUtil.get(SQL_getNotificationEntryByUserIdFrom); } else { sql = CustomSQLUtil.get(SQL_getNotificationEntryByUserIdTo); } SQLQuery query = session.createSQLQuery(sql); query.addEntity("NotificationEntry", NotificationEntryImpl.class); QueryPos qPos = QueryPos.getInstance(query); qPos.add(usreId); list = QueryUtil.list(query, getDialect(), start, end); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } finally { closeSession(session); } return list; }
public List<JIRAAction> findByCD_P(Date createDate, long projectId, int start, int end) throws SystemException { Timestamp createDate_TS = CalendarUtil.getTimestamp(createDate); Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_CD_P); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addEntity("jiraaction", JIRAActionImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(projectId); qPos.add(createDate_TS); return (List<JIRAAction>) QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
public List<WallEntry> findByG1_G2_U1_U2( long groupId1, long groupId2, long userId1, long userId2, int start, int end) throws SystemException { Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_G1_G2_U1_U2); SQLQuery q = session.createSQLQuery(sql); q.addEntity("SN_WallEntry", WallEntryImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId1); qPos.add(groupId2); qPos.add(userId1); qPos.add(userId2); return (List<WallEntry>) QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
public int getNotificationEntryByUserIdCount(long usreId, String typeNotification) throws SystemException { Session session = null; int count = 0; try { session = openSession(); String sql = ""; if (typeNotification.equals("NOTIFICATIONUSERIDFROM")) { sql = CustomSQLUtil.get(SQL_getNotificationEntryByUserIdCountFrom); } else { sql = CustomSQLUtil.get(SQL_getNotificationEntryByUserIdCountTo); } SQLQuery query = session.createSQLQuery(sql); // query.addEntity("vrbt_service", ServiceImpl.class); QueryPos qPos = QueryPos.getInstance(query); qPos.add(usreId); Object obj = query.uniqueResult(); count = Integer.valueOf(obj.toString()); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); throw processException(e); } finally { closeSession(session); } return count; }
public List<MicroblogsEntry> findByUserId(long userId, int start, int end) throws SystemException { Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_USER_ID); sql = StringUtil.replace(sql, "[$JOIN_BY_SOCIAL_RELATION$]", _joinBySocialRelationSQL); SQLQuery q = session.createSQLQuery(sql); q.addEntity("MicroblogsEntry", MicroblogsEntryImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(MicroblogsEntryConstants.TYPE_EVERYONE); qPos.add(userId); qPos.add(userId); qPos.add(userId); return (List<MicroblogsEntry>) QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
protected List<Long> countByC_FN_MN_LN_SN_EA_S( Session session, long companyId, String[] firstNames, String[] middleNames, String[] lastNames, String[] screenNames, String[] emailAddresses, int status, LinkedHashMap<String, Object> params, boolean andOperator) { String sql = CustomSQLUtil.get(COUNT_BY_C_FN_MN_LN_SN_EA_S); sql = CustomSQLUtil.replaceKeywords( sql, "lower(User_.firstName)", StringPool.LIKE, false, firstNames); sql = CustomSQLUtil.replaceKeywords( sql, "lower(User_.middleName)", StringPool.LIKE, false, middleNames); sql = CustomSQLUtil.replaceKeywords( sql, "lower(User_.lastName)", StringPool.LIKE, false, lastNames); sql = CustomSQLUtil.replaceKeywords( sql, "lower(User_.screenName)", StringPool.LIKE, false, screenNames); sql = CustomSQLUtil.replaceKeywords( sql, "lower(User_.emailAddress)", StringPool.LIKE, true, emailAddresses); if (status == WorkflowConstants.STATUS_ANY) { sql = StringUtil.replace(sql, _STATUS_SQL, StringPool.BLANK); } sql = replaceJoinAndWhere(sql, params); sql = CustomSQLUtil.replaceAndOperator(sql, andOperator); SQLQuery q = session.createSQLQuery(sql); q.addScalar("userId", Type.LONG); QueryPos qPos = QueryPos.getInstance(q); setJoin(qPos, params); qPos.add(companyId); qPos.add(false); qPos.add(firstNames, 2); qPos.add(middleNames, 2); qPos.add(lastNames, 2); qPos.add(screenNames, 2); qPos.add(emailAddresses, 2); if (status != WorkflowConstants.STATUS_ANY) { qPos.add(status); } return q.list(true); }
@Override public List<ShoppingItem> findByKeywords( long groupId, long[] categoryIds, String keywords, int start, int end) throws SystemException { Session session = null; try { session = openSession(); StringBundler query = new StringBundler(); query.append("SELECT {ShoppingItem.*} FROM ShoppingItem "); query.append("WHERE "); query.append("ShoppingItem.groupId = ? AND ("); if (ArrayUtil.isNotEmpty(categoryIds)) { query.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < categoryIds.length; i++) { query.append("ShoppingItem.categoryId = ? "); if ((i + 1) < categoryIds.length) { query.append("OR "); } } query.append(") AND "); } query.append("(ShoppingItem.name LIKE ? OR "); query.append("ShoppingItem.description LIKE ? OR "); query.append("ShoppingItem.properties LIKE ?))"); keywords = '%' + keywords + '%'; SQLQuery q = session.createSynchronizedSQLQuery(query.toString()); q.addEntity("ShoppingItem", ShoppingItemImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); for (long categoryId : categoryIds) { qPos.add(categoryId); } qPos.add(keywords); qPos.add(keywords); qPos.add(keywords); return (List<ShoppingItem>) QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
@Override public int countByOrganizationIds( List<Long> organizationIds, Date displayDate, QueryDefinition<BlogsEntry> queryDefinition) { Timestamp displayDate_TS = CalendarUtil.getTimestamp(displayDate); Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(COUNT_BY_ORGANIZATION_IDS); if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) { if (queryDefinition.isExcludeStatus()) { sql = CustomSQLUtil.appendCriteria(sql, "AND (BlogsEntry.status != ?)"); } else { sql = CustomSQLUtil.appendCriteria(sql, "AND (BlogsEntry.status = ?)"); } } sql = StringUtil.replace(sql, "[$ORGANIZATION_ID$]", getOrganizationIds(organizationIds)); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, Type.LONG); QueryPos qPos = QueryPos.getInstance(q); for (int i = 0; i < organizationIds.size(); i++) { Long organizationId = organizationIds.get(i); qPos.add(organizationId); } qPos.add(displayDate_TS); if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) { qPos.add(queryDefinition.getStatus()); } Iterator<Long> itr = q.iterate(); if (itr.hasNext()) { Long count = itr.next(); if (count != null) { return count.intValue(); } } return 0; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
@Override public List<ShoppingItem> findByFeatured(long groupId, long[] categoryIds, int numOfItems) throws SystemException { int countByFeatured = countByFeatured(groupId, categoryIds); Session session = null; try { session = openSession(); StringBundler query = new StringBundler(); query.append("SELECT {ShoppingItem.*} FROM ShoppingItem "); query.append("WHERE "); query.append("ShoppingItem.groupId = ? AND ("); if (ArrayUtil.isNotEmpty(categoryIds)) { query.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < categoryIds.length; i++) { query.append("ShoppingItem.categoryId = ? "); if ((i + 1) < categoryIds.length) { query.append("OR "); } } query.append(") AND "); } query.append("ShoppingItem.featured = ? AND "); query.append("ShoppingItem.smallImage = ?"); SQLQuery q = session.createSynchronizedSQLQuery(query.toString()); q.addEntity("ShoppingItem", ShoppingItemImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); for (long categoryId : categoryIds) { qPos.add(categoryId); } qPos.add(true); qPos.add(true); return (List<ShoppingItem>) QueryUtil.randomList(q, getDialect(), countByFeatured, numOfItems); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
protected int doCountByG_F( long groupId, List<Long> folderIds, QueryDefinition<JournalArticle> queryDefinition, boolean inlineSQLHelper) { Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(COUNT_BY_G_F, queryDefinition, "JournalArticle"); sql = replaceStatusJoin(sql, queryDefinition); if (inlineSQLHelper) { sql = InlineSQLHelperUtil.replacePermissionCheck( sql, JournalArticle.class.getName(), "JournalArticle.resourcePrimKey", groupId); } sql = StringUtil.replace( sql, "[$FOLDER_ID$]", getFolderIds(folderIds, JournalArticleImpl.TABLE_NAME)); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, Type.LONG); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); qPos.add(queryDefinition.getStatus()); for (int i = 0; i < folderIds.size(); i++) { Long folderId = folderIds.get(i); qPos.add(folderId); } Iterator<Long> itr = q.iterate(); if (itr.hasNext()) { Long count = itr.next(); if (count != null) { return count.intValue(); } } return 0; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
protected List<MBThread> doFindByS_G_U_C( long groupId, long userId, long[] categoryIds, QueryDefinition queryDefinition, boolean inlineSQLHelper) throws SystemException { Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_S_G_U_C); if (ArrayUtil.isEmpty(categoryIds)) { sql = StringUtil.replace(sql, "(MBThread.categoryId = ?) AND", StringPool.BLANK); } else { sql = StringUtil.replace( sql, "MBThread.categoryId = ?", "MBThread.categoryId = " + StringUtil.merge(categoryIds, " OR MBThread.categoryId = ")); } sql = updateSQL(sql, queryDefinition); if (inlineSQLHelper) { sql = InlineSQLHelperUtil.replacePermissionCheck( sql, MBMessage.class.getName(), "MBThread.rootMessageId", groupId); } SQLQuery q = session.createSQLQuery(sql); q.addEntity("MBThread", MBThreadImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(PortalUtil.getClassNameId(MBThread.class.getName())); qPos.add(groupId); qPos.add(userId); if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) { qPos.add(queryDefinition.getStatus()); } return (List<MBThread>) QueryUtil.list(q, getDialect(), queryDefinition.getStart(), queryDefinition.getEnd()); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
@Override public int countByG_SD_T( long groupId, Date startDateGT, Date startDateLT, boolean timeZoneSensitive, String[] types) throws SystemException { Timestamp startDateGT_TS = CalendarUtil.getTimestamp(startDateGT); Timestamp startDateLT_TS = CalendarUtil.getTimestamp(startDateLT); Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(COUNT_BY_G_SD_T); sql = StringUtil.replace(sql, "[$TYPE$]", getTypes(types)); SQLQuery q = session.createSQLQuery(sql); q.addEntity("CalEvent", CalEventImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); qPos.add(startDateGT_TS); qPos.add(startDateLT_TS); qPos.add(timeZoneSensitive); qPos.add(false); if ((types != null) && (types.length > 0) && ((types.length > 1) || Validator.isNotNull(types[0]))) { for (String type : types) { qPos.add(type); } } Iterator<Long> itr = q.iterate(); if (itr.hasNext()) { Long count = itr.next(); if (count != null) { return count.intValue(); } } return 0; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
@Override public List<SyncDLObject> findByModifiedTime( long modifiedTime, long repositoryId, long parentFolderId, String type, int start, int end) { Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(getClass(), FIND_BY_MODIFIED_TIME); if (modifiedTime <= 0) { sql = StringUtil.replace(sql, "(SyncDLObject.modifiedTime > ?) AND", StringPool.BLANK); } if (parentFolderId == 0) { sql = StringUtil.replace(sql, "AND (SyncDLObject.treePath LIKE ?)", StringPool.BLANK); } if (type == null) { sql = StringUtil.replace(sql, "AND (SyncDLObject.type_ = ?)", StringPool.BLANK); } if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS)) { sql = CustomSQLUtil.removeOrderBy(sql); } SQLQuery sqlQuery = session.createSynchronizedSQLQuery(sql); sqlQuery.addEntity("SyncDLObject", SyncDLObjectImpl.class); QueryPos qPos = QueryPos.getInstance(sqlQuery); if (modifiedTime > 0) { qPos.add(modifiedTime); } qPos.add(repositoryId); if (parentFolderId != 0) { qPos.add("%/" + parentFolderId + "/%"); } if (type != null) { qPos.add(type); } return (List<SyncDLObject>) QueryUtil.list(sqlQuery, getDialect(), start, end); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }