@Override
  public List<LayoutReference> findByC_P_P(
      long companyId, String portletId, String preferencesKey, String preferencesValue) {

    String preferences =
        "%<preference><name>" + preferencesKey + "</name><value>" + preferencesValue + "</value>%";

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(FIND_BY_C_P_P);

      SQLQuery q = session.createSynchronizedSQLQuery(sql);

      q.addScalar("layoutPlid", Type.LONG);
      q.addScalar("preferencesPortletId", Type.STRING);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(companyId);
      qPos.add(portletId);
      qPos.add(portletId.concat("_INSTANCE_%"));
      qPos.add(preferences);

      List<LayoutReference> layoutReferences = new ArrayList<>();

      Iterator<Object[]> itr = q.iterate();

      while (itr.hasNext()) {
        Object[] array = itr.next();

        Long layoutPlid = (Long) array[0];
        String preferencesPortletId = (String) array[1];

        Layout layout = LayoutUtil.findByPrimaryKey(layoutPlid.longValue());

        layoutReferences.add(
            new LayoutReference(LayoutSoap.toSoapModel(layout), preferencesPortletId));
      }

      return layoutReferences;
    } 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);
    }
  }
예제 #3
0
  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);
    }
  }
예제 #4
0
  @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);
    }
  }
 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);
   }
 }
예제 #6
0
  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);
    }
  }
예제 #7
0
  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 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);
    }
  }
  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);
    }
  }
예제 #10
0
  @Override
  public int countByG_U_LPD(
      long groupId, long userId, Date lastPostDate, QueryDefinition queryDefinition)
      throws SystemException {

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(COUNT_BY_G_U_LPD);

      if (userId <= 0) {
        sql = StringUtil.replace(sql, _INNER_JOIN_SQL, StringPool.BLANK);
        sql = StringUtil.replace(sql, _USER_ID_SQL, StringPool.BLANK);
      }

      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(lastPostDate);

      if (userId > 0) {
        qPos.add(userId);
      }

      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);
    }
  }
예제 #11
0
  protected int doCountByG_C(long groupId, List<Long> categoryIds, boolean inlineSQLHelper)
      throws SystemException {

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(COUNT_BY_G_C);

      if (inlineSQLHelper) {
        sql =
            InlineSQLHelperUtil.replacePermissionCheck(
                sql, ShoppingItem.class.getName(), "ShoppingItem.itemId", groupId);
      }

      sql = StringUtil.replace(sql, "[$CATEGORY_ID$]", getCategoryIds(categoryIds));

      SQLQuery q = session.createSynchronizedSQLQuery(sql);

      q.addScalar(COUNT_COLUMN_NAME, Type.LONG);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(groupId);

      for (int i = 0; i < categoryIds.size(); i++) {
        Long categoryId = categoryIds.get(i);

        qPos.add(categoryId);
      }

      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);
    }
  }
예제 #12
0
  public int countByU_FN_EA(
      long userId, String[] fullNames, String[] emailAddresses, boolean andOperator)
      throws SystemException {

    fullNames = CustomSQLUtil.keywords(fullNames, true);
    emailAddresses = CustomSQLUtil.keywords(emailAddresses, true);

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(COUNT_BY_U_FN_EA);

      sql =
          CustomSQLUtil.replaceKeywords(sql, "lower(fullName)", StringPool.LIKE, false, fullNames);
      sql =
          CustomSQLUtil.replaceKeywords(
              sql, "lower(emailAddress)", StringPool.LIKE, true, emailAddresses);
      sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);

      SQLQuery q = session.createSynchronizedSQLQuery(sql);

      q.addScalar(COUNT_COLUMN_NAME, Type.LONG);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(userId);
      qPos.add(fullNames, 2);
      qPos.add(emailAddresses, 2);

      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);
    }
  }
예제 #13
0
  public int countByTransactionAndPaymentMethod(
      long transactionId, long paymentMethodId, Boolean configured) throws SystemException {
    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(COUNT_BY_TRANSACTIONID_AND_PAYMENTMETHODID);

      if (configured == null) {
        sql = StringUtil.replace(sql, "(Payment_PaymentPlugin.configured = ?) AND", "");
        sql = StringUtil.replace(sql, "(Payment_PaymentPluginConfig.configured = ?) AND", "");
      }

      SQLQuery q = session.createSQLQuery(sql);

      q.addScalar(COUNT_COLUMN_NAME, Type.LONG);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(transactionId);
      qPos.add(paymentMethodId);
      if (configured != null) {
        qPos.add(configured);
        qPos.add(configured);
      }

      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);
    }
  }
예제 #14
0
  @Override
  public int countByG_U_A(
      long groupId, long userId, boolean anonymous, QueryDefinition queryDefinition)
      throws SystemException {

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(COUNT_BY_G_U_A);

      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);
    }
  }
예제 #15
0
  @Override
  public int filterCountByG_C(long groupId, long categoryId) throws SystemException {

    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
      return MBThreadUtil.countByG_C(groupId, categoryId);
    }

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(COUNT_BY_G_C);

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

      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);
    }
  }
예제 #16
0
  protected int doCountByS_G_U(long groupId, long userId, QueryDefinition queryDefinition)
      throws SystemException {

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(COUNT_BY_S_G_U);

      sql = updateSQL(sql, queryDefinition);

      SQLQuery q = session.createSQLQuery(sql);

      q.addScalar(COUNT_COLUMN_NAME, Type.LONG);

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

      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);
    }
  }
예제 #17
0
  // dem tong so luong van ban ma touser nhan duoc, ko can biet do la vb den hay di
  public int getTotalDocumentByUser(List<Long> fromUserList, long toUserId) throws Exception {

    String fromUserString = "";
    if (fromUserList.size() != 0) {
      for (int i = 0; i < fromUserList.size() - 1; i++) {
        fromUserString += fromUserList.get(i) + ", ";
      }
      fromUserString += fromUserList.get(fromUserList.size() - 1);
    } else {
      fromUserString += "0";
    }

    Session session = null;
    try {
      session = openSession();

      String sql = "SELECT COUNT(fromuserid) AS COUNT_VALUE FROM pml_message_note";
      sql += " WHERE fromuserid in (" + fromUserString + ") AND touserid = " + toUserId;
      sql += " AND isalert = false";

      SQLQuery q = session.createSQLQuery(sql);
      q.addScalar(COUNT_COLUMN_NAME, Type.LONG);

      Long count = null;

      Iterator<Long> itr = q.list().iterator();

      if (itr.hasNext()) {
        count = itr.next();
      }

      if (count == null) {
        count = new Long(0);
      }

      return count.intValue();
    } catch (Exception e) {
      throw processException(e);
    } finally {
      closeSession(session);
    }
  }
 public int countByPrice(String title, String listParent, int formPrice, int toPrice)
     throws SystemException {
   Session session = null;
   try {
     session = openSession();
     StringBuffer query = new StringBuffer();
     query.append(
         "SELECT COUNT(*) as total FROM Vlookupprice WHERE (listParent LIKE ?) AND (title LIKE ?) ");
     if (formPrice != 0) {
       query.append("AND (price >= ?) ");
     }
     if (toPrice != 0) {
       query.append("AND (price <= ?) ");
     }
     SQLQuery q = session.createSQLQuery(query.toString());
     q.addScalar("total", Type.LONG);
     int queryPos = 0;
     q.setString(queryPos++, "%" + listParent + "%");
     q.setString(queryPos++, "%" + title + "%");
     if (formPrice != 0) {
       q.setInteger(queryPos++, formPrice);
     }
     if (toPrice != 0) {
       q.setInteger(queryPos++, toPrice);
     }
     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 int countByUser(long userId, LinkedHashMap<String, Object> params) throws SystemException {

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(COUNT_BY_USER);

      sql = StringUtil.replace(sql, "[$JOIN$]", getJoin(params));
      sql = StringUtil.replace(sql, "[$WHERE$]", getWhere(params));

      SQLQuery q = session.createSQLQuery(sql);

      q.addScalar(COUNT_COLUMN_NAME, Type.LONG);

      QueryPos qPos = QueryPos.getInstance(q);

      setJoin(qPos, params);

      qPos.add(userId);

      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);
    }
  }
  public List<SocialActivity> findByUserGroupsAndOrganizations(long userId, int start, int end)
      throws SystemException {

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(FIND_BY_USER_GROUPS_AND_ORGANIZATIONS);

      SQLQuery q = session.createSQLQuery(sql);

      q.addScalar("activityId", Type.LONG);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(userId);
      qPos.add(userId);

      List<SocialActivity> socialActivities = new ArrayList<SocialActivity>();

      Iterator<Long> itr = (Iterator<Long>) QueryUtil.iterate(q, getDialect(), start, end);

      while (itr.hasNext()) {
        Long activityId = itr.next();

        SocialActivity socialActivity = SocialActivityUtil.findByPrimaryKey(activityId);

        socialActivities.add(socialActivity);
      }

      return socialActivities;
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }
  }
  public int countByU_T_MU(long userId, int type, long microblogsEntryUserId)
      throws SystemException {

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(COUNT_BY_U_MU);

      SQLQuery q = session.createSQLQuery(sql);

      q.addScalar(COUNT_COLUMN_NAME, Type.LONG);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(MicroblogsEntryConstants.TYPE_EVERYONE);
      qPos.add(userId);
      qPos.add(type);
      qPos.add(microblogsEntryUserId);

      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);
    }
  }
  public int countByUserId(long userId) throws SystemException {
    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(COUNT_BY_USER_ID);

      sql = StringUtil.replace(sql, "[$JOIN_BY_SOCIAL_RELATION$]", _joinBySocialRelationSQL);

      SQLQuery q = session.createSQLQuery(sql);

      q.addScalar(COUNT_COLUMN_NAME, Type.LONG);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(MicroblogsEntryConstants.TYPE_EVERYONE);
      qPos.add(userId);
      qPos.add(userId);
      qPos.add(userId);

      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);
    }
  }
예제 #23
0
  @Override
  public int countByR_S(long roleId, int[] scopes) throws SystemException {
    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(COUNT_BY_R_S);

      sql = StringUtil.replace(sql, "[$SCOPE$]", getScopes(scopes));

      SQLQuery q = session.createSQLQuery(sql);

      q.addScalar(COUNT_COLUMN_NAME, Type.LONG);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(roleId);
      qPos.add(scopes);

      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);
    }
  }
  public int countByCD_P(Date createDate, long projectId) throws SystemException {

    Timestamp createDate_TS = CalendarUtil.getTimestamp(createDate);

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(COUNT_BY_CD_P);

      SQLQuery q = session.createSynchronizedSQLQuery(sql);

      q.addScalar(COUNT_COLUMN_NAME, Type.LONG);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(projectId);
      qPos.add(createDate_TS);

      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);
    }
  }
  public int countByUserGroupsAndOrganizations(long userId) throws SystemException {

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(COUNT_BY_USER_GROUPS_AND_ORGANIZATIONS);

      SQLQuery q = session.createSQLQuery(sql);

      q.addScalar(COUNT_COLUMN_NAME, Type.LONG);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(userId);
      qPos.add(userId);

      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);
    }
  }
  @Override
  public List<Long> filterFindByR_U_T(long groupId, long userId, long[] typePKs) {

    if (ArrayUtil.isEmpty(typePKs)) {
      return Collections.emptyList();
    }

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(getClass(), FIND_BY_TYPE_PKS);

      sql =
          StringUtil.replace(
              sql,
              new String[] {"[$TYPE_PKS$]", "[$ROLE_IDS_OR_OWNER_ID$]"},
              new String[] {getTypePKsSQL(typePKs), getRoleOwnerIdsSQL(groupId, userId)});

      SQLQuery sqlQuery = session.createSynchronizedSQLQuery(sql);

      sqlQuery.addScalar("primKey", Type.LONG);

      QueryPos qPos = QueryPos.getInstance(sqlQuery);

      qPos.add(CompanyThreadLocal.getCompanyId());
      qPos.add(ResourceConstants.SCOPE_INDIVIDUAL);

      return (List<Long>) sqlQuery.list();
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }
  }
  /**
   * Returns the number of h r holidaies associated with the h r office.
   *
   * @param pk the primary key of the h r office
   * @return the number of h r holidaies associated with the h r office
   * @throws SystemException if a system exception occurred
   */
  public int getHRHolidaiesSize(long pk) throws SystemException {
    Object[] finderArgs = new Object[] {pk};

    Long count =
        (Long) FinderCacheUtil.getResult(FINDER_PATH_GET_HRHOLIDAIES_SIZE, finderArgs, this);

    if (count == null) {
      Session session = null;

      try {
        session = openSession();

        SQLQuery q = session.createSQLQuery(_SQL_GETHRHOLIDAIESSIZE);

        q.addScalar(COUNT_COLUMN_NAME, com.liferay.portal.kernel.dao.orm.Type.LONG);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(pk);

        count = (Long) q.uniqueResult();
      } catch (Exception e) {
        throw processException(e);
      } finally {
        if (count == null) {
          count = Long.valueOf(0);
        }

        FinderCacheUtil.putResult(FINDER_PATH_GET_HRHOLIDAIES_SIZE, finderArgs, count);

        closeSession(session);
      }
    }

    return count.intValue();
  }
예제 #28
0
  @Override
  public int countByFeatured(long groupId, long[] categoryIds) throws SystemException {

    Session session = null;

    try {
      session = openSession();

      StringBundler query = new StringBundler();

      query.append("SELECT COUNT(*) AS COUNT_VALUE 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.addScalar(COUNT_COLUMN_NAME, Type.LONG);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(groupId);

      for (long categoryId : categoryIds) {
        qPos.add(categoryId);
      }

      qPos.add(true);
      qPos.add(true);

      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 int doCountByC_G_C_N_D(
      long companyId,
      long[] groupIds,
      long[] calendarResourceIds,
      String[] names,
      String[] descriptions,
      boolean andOperator,
      boolean inlineSQLHelper)
      throws SystemException {

    if (groupIds == null) {
      groupIds = new long[0];
    }

    names = CustomSQLUtil.keywords(names);
    descriptions = CustomSQLUtil.keywords(descriptions, false);

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(COUNT_BY_C_G_C_N_D);

      if (inlineSQLHelper) {
        sql =
            InlineSQLHelperUtil.replacePermissionCheck(
                sql, Calendar.class.getName(), "Calendar.calendarId", groupIds);
      }

      sql = StringUtil.replace(sql, "[$GROUP_ID$]", getGroupIds(groupIds));
      sql =
          StringUtil.replace(
              sql, "[$CALENDAR_RESOURCE_ID$]", getCalendarResourceIds(calendarResourceIds));
      sql = CustomSQLUtil.replaceKeywords(sql, "lower(name)", StringPool.LIKE, false, names);
      sql = CustomSQLUtil.replaceKeywords(sql, "description", StringPool.LIKE, false, descriptions);
      sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);

      SQLQuery q = session.createSynchronizedSQLQuery(sql);

      q.addScalar(COUNT_COLUMN_NAME, Type.LONG);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(companyId);
      qPos.add(groupIds);

      if (ArrayUtil.isNotEmpty(calendarResourceIds)) {
        qPos.add(calendarResourceIds);
      }

      qPos.add(names, 2);
      qPos.add(descriptions, 2);

      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 int doCountByC_G_F_C_A_V_T_D_C_S_T_D_R(
      long companyId,
      long groupId,
      List<Long> folderIds,
      long classNameId,
      String[] articleIds,
      Double version,
      String[] titles,
      String[] descriptions,
      String[] contents,
      String[] ddmStructureKeys,
      String[] ddmTemplateKeys,
      Date displayDateGT,
      Date displayDateLT,
      Date reviewDate,
      boolean andOperator,
      QueryDefinition<JournalArticle> queryDefinition,
      boolean inlineSQLHelper) {

    articleIds = CustomSQLUtil.keywords(articleIds, false);
    titles = CustomSQLUtil.keywords(titles);
    descriptions = CustomSQLUtil.keywords(descriptions, false);
    contents = CustomSQLUtil.keywords(contents, false);
    ddmStructureKeys = CustomSQLUtil.keywords(ddmStructureKeys, false);
    ddmTemplateKeys = CustomSQLUtil.keywords(ddmTemplateKeys, false);
    Timestamp displayDateGT_TS = CalendarUtil.getTimestamp(displayDateGT);
    Timestamp displayDateLT_TS = CalendarUtil.getTimestamp(displayDateLT);
    Timestamp reviewDate_TS = CalendarUtil.getTimestamp(reviewDate);

    Session session = null;

    try {
      session = openSession();

      String sql =
          CustomSQLUtil.get(COUNT_BY_C_G_F_C_A_V_T_D_C_S_T_D_R, queryDefinition, "JournalArticle");

      sql = replaceStatusJoin(sql, queryDefinition);

      if (groupId <= 0) {
        sql = StringUtil.replace(sql, "(JournalArticle.groupId = ?) AND", StringPool.BLANK);
      }

      if (folderIds.isEmpty()) {
        sql = StringUtil.replace(sql, "([$FOLDER_ID$]) AND", StringPool.BLANK);
      } else {
        sql =
            StringUtil.replace(
                sql, "[$FOLDER_ID$]", getFolderIds(folderIds, JournalArticleImpl.TABLE_NAME));
      }

      sql =
          CustomSQLUtil.replaceKeywords(
              sql, "JournalArticle.articleId", StringPool.LIKE, false, articleIds);

      if ((version == null) || (version <= 0)) {
        sql =
            StringUtil.replace(
                sql, "(JournalArticle.version = ?) [$AND_OR_CONNECTOR$]", StringPool.BLANK);
      }

      sql =
          CustomSQLUtil.replaceKeywords(
              sql, "lower(JournalArticle.title)", StringPool.LIKE, false, titles);
      sql =
          CustomSQLUtil.replaceKeywords(
              sql, "JournalArticle.description", StringPool.LIKE, false, descriptions);
      sql =
          CustomSQLUtil.replaceKeywords(
              sql, "JournalArticle.content", StringPool.LIKE, false, contents);

      sql = replaceStructureTemplate(sql, ddmStructureKeys, ddmTemplateKeys);

      if (!isNullArray(ddmStructureKeys)) {
        sql =
            CustomSQLUtil.replaceKeywords(
                sql, "JournalArticle.DDMStructureKey", StringPool.LIKE, false, ddmStructureKeys);
      }

      if (!isNullArray(ddmTemplateKeys)) {
        sql =
            CustomSQLUtil.replaceKeywords(
                sql, "JournalArticle.DDMTemplateKey", StringPool.LIKE, false, ddmTemplateKeys);
      }

      sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);

      if (inlineSQLHelper) {
        sql =
            InlineSQLHelperUtil.replacePermissionCheck(
                sql, JournalArticle.class.getName(), "JournalArticle.resourcePrimKey", groupId);

        sql = StringUtil.replace(sql, "(companyId", "(JournalArticle.companyId");
      }

      SQLQuery q = session.createSynchronizedSQLQuery(sql);

      q.addScalar(COUNT_COLUMN_NAME, Type.LONG);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(companyId);

      if (groupId > 0) {
        qPos.add(groupId);
      }

      for (long folderId : folderIds) {
        qPos.add(folderId);
      }

      qPos.add(classNameId);
      qPos.add(queryDefinition.getStatus());

      if (!isNullArray(ddmStructureKeys)) {
        qPos.add(ddmStructureKeys, 2);
      }

      if (!isNullArray(ddmTemplateKeys)) {
        qPos.add(ddmTemplateKeys, 2);
      }

      qPos.add(articleIds, 2);

      if ((version != null) && (version > 0)) {
        qPos.add(version);
      }

      qPos.add(titles, 2);
      qPos.add(descriptions, 2);
      qPos.add(contents, 2);
      qPos.add(displayDateGT_TS);
      qPos.add(displayDateGT_TS);
      qPos.add(displayDateLT_TS);
      qPos.add(displayDateLT_TS);
      qPos.add(reviewDate_TS);
      qPos.add(reviewDate_TS);

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