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); } }