Esempio n. 1
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);
    }
  }
Esempio n. 2
0
  @Override
  public List<MBThread> findByG_U(long groupId, long userId, QueryDefinition queryDefinition)
      throws SystemException {

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(FIND_BY_G_U);

      sql = updateSQL(sql, queryDefinition);

      SQLQuery q = session.createSQLQuery(sql);

      q.addEntity("MBThread", MBThreadImpl.class);

      QueryPos qPos = QueryPos.getInstance(q);

      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<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<MicroblogsEntry> findByU_MU(
      long userId, 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(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<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);
    }
  }
  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;
  }
  @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);
    }
  }
  @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);
    }
  }
  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 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);
    }
  }
Esempio n. 13
0
  @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);
    }
  }
Esempio n. 14
0
  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 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);
    }
  }
Esempio n. 16
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);
    }
  }
Esempio n. 17
0
  @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);
    }
  }
  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);
    }
  }
  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);
    }
  }
Esempio n. 20
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);
  }
  /**
   * Returns an ordered range of all the layout sets where groupId = &#63;.
   *
   * <p>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.
   *
   * @param groupId the group ID
   * @param start the lower bound of the range of layout sets
   * @param end the upper bound of the range of layout sets (not inclusive)
   * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
   * @return the ordered range of matching layout sets
   * @throws SystemException if a system exception occurred
   */
  public List<LayoutSet> findByGroupId(
      long groupId, int start, int end, OrderByComparator orderByComparator)
      throws SystemException {
    Object[] finderArgs =
        new Object[] {
          groupId, String.valueOf(start), String.valueOf(end), String.valueOf(orderByComparator)
        };

    List<LayoutSet> list =
        (List<LayoutSet>) FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID, finderArgs, this);

    if (list == null) {
      StringBundler query = null;

      if (orderByComparator != null) {
        query = new StringBundler(3 + (orderByComparator.getOrderByFields().length * 3));
      } else {
        query = new StringBundler(2);
      }

      query.append(_SQL_SELECT_LAYOUTSET_WHERE);

      query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);

      if (orderByComparator != null) {
        appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
      }

      String sql = query.toString();

      Session session = null;

      try {
        session = openSession();

        Query q = session.createQuery(sql);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        list = (List<LayoutSet>) QueryUtil.list(q, getDialect(), start, end);
      } catch (Exception e) {
        throw processException(e);
      } finally {
        if (list == null) {
          FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_GROUPID, finderArgs);
        } else {
          cacheResult(list);

          FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID, finderArgs, list);
        }

        closeSession(session);
      }
    }

    return list;
  }
  /**
   * Returns the number of entries where userId = &#63; and emailAddress = &#63;.
   *
   * @param userId the user ID
   * @param emailAddress the email address
   * @return the number of matching entries
   * @throws SystemException if a system exception occurred
   */
  @Override
  public int countByU_EA(long userId, String emailAddress) throws SystemException {
    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_EA;

    Object[] finderArgs = new Object[] {userId, emailAddress};

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

    if (count == null) {
      StringBundler query = new StringBundler(3);

      query.append(_SQL_COUNT_ENTRY_WHERE);

      query.append(_FINDER_COLUMN_U_EA_USERID_2);

      boolean bindEmailAddress = false;

      if (emailAddress == null) {
        query.append(_FINDER_COLUMN_U_EA_EMAILADDRESS_1);
      } else if (emailAddress.equals(StringPool.BLANK)) {
        query.append(_FINDER_COLUMN_U_EA_EMAILADDRESS_3);
      } else {
        bindEmailAddress = true;

        query.append(_FINDER_COLUMN_U_EA_EMAILADDRESS_2);
      }

      String sql = query.toString();

      Session session = null;

      try {
        session = openSession();

        Query q = session.createQuery(sql);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(userId);

        if (bindEmailAddress) {
          qPos.add(emailAddress);
        }

        count = (Long) q.uniqueResult();

        FinderCacheUtil.putResult(finderPath, finderArgs, count);
      } catch (Exception e) {
        FinderCacheUtil.removeResult(finderPath, finderArgs);

        throw processException(e);
      } finally {
        closeSession(session);
      }
    }

    return count.intValue();
  }
  public List<ViewListTitleCompetencies> findByTitleId(
      int titleId, int start, int end, OrderByComparator obc) throws SystemException {
    Object[] finderArgs =
        new Object[] {
          new Integer(titleId), String.valueOf(start), String.valueOf(end), String.valueOf(obc)
        };

    List<ViewListTitleCompetencies> list =
        (List<ViewListTitleCompetencies>)
            FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_TITLEID, finderArgs, this);

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

      try {
        session = openSession();

        StringBuilder query = new StringBuilder();

        query.append("FROM larion.progate.cds.model.ViewListTitleCompetencies WHERE ");

        query.append("title_id = ?");

        query.append(" ");

        if (obc != null) {
          query.append("ORDER BY ");
          query.append(obc.getOrderBy());
        } else {
          query.append("ORDER BY ");

          query.append("competency_number_order ASC");
        }

        Query q = session.createQuery(query.toString());

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(titleId);

        list = (List<ViewListTitleCompetencies>) QueryUtil.list(q, getDialect(), start, end);
      } catch (Exception e) {
        throw processException(e);
      } finally {
        if (list == null) {
          list = new ArrayList<ViewListTitleCompetencies>();
        }

        cacheResult(list);

        FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_TITLEID, finderArgs, list);

        closeSession(session);
      }
    }

    return list;
  }
  @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);
    }
  }
Esempio n. 25
0
  @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);
    }
  }
  public PmlEdmLevelSend[] findByLevelSendName_PrevAndNext(
      int levelSendId, String levelSendName, OrderByComparator obc)
      throws NoSuchPmlEdmLevelSendException, SystemException {
    PmlEdmLevelSend pmlEdmLevelSend = findByPrimaryKey(levelSendId);

    int count = countByLevelSendName(levelSendName);

    Session session = null;

    try {
      session = openSession();

      StringBuilder query = new StringBuilder();

      query.append("FROM com.sgs.portlet.pmllevelsend.model.PmlEdmLevelSend WHERE ");

      if (levelSendName == null) {
        query.append("levelsendname LIKE null");
      } else {
        query.append("levelsendname LIKE ?");
      }

      query.append(" ");

      if (obc != null) {
        query.append("ORDER BY ");
        query.append(obc.getOrderBy());
      } else {
        query.append("ORDER BY ");

        query.append("levelsendname ASC");
      }

      Query q = session.createQuery(query.toString());

      QueryPos qPos = QueryPos.getInstance(q);

      if (levelSendName != null) {
        qPos.add(levelSendName);
      }

      Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, pmlEdmLevelSend);

      PmlEdmLevelSend[] array = new PmlEdmLevelSendImpl[3];

      array[0] = (PmlEdmLevelSend) objArray[0];
      array[1] = (PmlEdmLevelSend) objArray[1];
      array[2] = (PmlEdmLevelSend) objArray[2];

      return array;
    } catch (Exception e) {
      throw processException(e);
    } finally {
      closeSession(session);
    }
  }
  public List<SoPhongVanBanNoiBo> findBySoVanBanNoiBo(long soVanBanNoiBoId) throws SystemException {
    boolean finderClassNameCacheEnabled = SoPhongVanBanNoiBoModelImpl.CACHE_ENABLED;
    String finderClassName = SoPhongVanBanNoiBo.class.getName();
    String finderMethodName = "findBySoVanBanNoiBo";
    String[] finderParams = new String[] {Long.class.getName()};
    Object[] finderArgs = new Object[] {new Long(soVanBanNoiBoId)};

    Object result = null;

    if (finderClassNameCacheEnabled) {
      result =
          FinderCacheUtil.getResult(
              finderClassName, finderMethodName, finderParams, finderArgs, this);
    }

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

      try {
        session = openSession();

        StringBuilder query = new StringBuilder();

        query.append("FROM com.sgs.portlet.sovanbannoibo.model.SoPhongVanBanNoiBo WHERE ");

        query.append("soVanBanNoiBoId = ?");

        query.append(" ");

        Query q = session.createQuery(query.toString());

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(soVanBanNoiBoId);

        List<SoPhongVanBanNoiBo> list = q.list();

        FinderCacheUtil.putResult(
            finderClassNameCacheEnabled,
            finderClassName,
            finderMethodName,
            finderParams,
            finderArgs,
            list);

        return list;
      } catch (Exception e) {
        throw processException(e);
      } finally {
        closeSession(session);
      }
    } else {
      return (List<SoPhongVanBanNoiBo>) result;
    }
  }
Esempio n. 29
0
  @Override
  public int countByG_U_C(
      long groupId, long userId, long[] categoryIds, 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);

      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);
    }
  }
  /**
   * Returns the number of bars where text = &#63;.
   *
   * @param text the text
   * @return the number of matching bars
   */
  @Override
  public int countByText(String text) {
    FinderPath finderPath = FINDER_PATH_COUNT_BY_TEXT;

    Object[] finderArgs = new Object[] {text};

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

    if (count == null) {
      StringBundler query = new StringBundler(2);

      query.append(_SQL_COUNT_BAR_WHERE);

      boolean bindText = false;

      if (text == null) {
        query.append(_FINDER_COLUMN_TEXT_TEXT_1);
      } else if (text.equals(StringPool.BLANK)) {
        query.append(_FINDER_COLUMN_TEXT_TEXT_3);
      } else {
        bindText = true;

        query.append(_FINDER_COLUMN_TEXT_TEXT_2);
      }

      String sql = query.toString();

      Session session = null;

      try {
        session = openSession();

        Query q = session.createQuery(sql);

        QueryPos qPos = QueryPos.getInstance(q);

        if (bindText) {
          qPos.add(text);
        }

        count = (Long) q.uniqueResult();

        FinderCacheUtil.putResult(finderPath, finderArgs, count);
      } catch (Exception e) {
        FinderCacheUtil.removeResult(finderPath, finderArgs);

        throw processException(e);
      } finally {
        closeSession(session);
      }
    }

    return count.intValue();
  }