Ejemplo n.º 1
0
  protected void addOrder(
      Criteria criteria, OrderByComparator orderByComparator, String... skipFields) {

    if (orderByComparator == null) {
      return;
    }

    String[] orderByFields = orderByComparator.getOrderByFields();

    Arrays.sort(skipFields);

    for (String orderByField : orderByFields) {
      Order order = null;

      String jbpmField = _fieldMap.get(orderByField);

      if (jbpmField == null) {
        jbpmField = orderByField;
      }

      if (Arrays.binarySearch(skipFields, jbpmField) < 0) {
        if (orderByComparator.isAscending()) {
          order = Order.asc(jbpmField);
        } else {
          order = Order.desc(jbpmField);
        }

        criteria.addOrder(order);
      }
    }
  }
Ejemplo n.º 2
0
  public String replaceOrderBy(String sql, OrderByComparator obc) {
    if (obc == null) {
      return sql;
    }

    return removeOrderBy(sql).concat(_ORDER_BY_CLAUSE).concat(obc.getOrderBy());
  }
  /**
   * 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;
  }
  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;
  }
  /**
   * Returns an ordered range of all the social equity histories.
   *
   * <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 start the lower bound of the range of social equity histories
   * @param end the upper bound of the range of social equity histories (not inclusive)
   * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
   * @return the ordered range of social equity histories
   * @throws SystemException if a system exception occurred
   */
  public List<SocialEquityHistory> findAll(int start, int end, OrderByComparator orderByComparator)
      throws SystemException {
    Object[] finderArgs =
        new Object[] {
          String.valueOf(start), String.valueOf(end), String.valueOf(orderByComparator)
        };

    List<SocialEquityHistory> list =
        (List<SocialEquityHistory>)
            FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL, finderArgs, this);

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

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

        query.append(_SQL_SELECT_SOCIALEQUITYHISTORY);

        appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);

        sql = query.toString();
      } else {
        sql = _SQL_SELECT_SOCIALEQUITYHISTORY;
      }

      Session session = null;

      try {
        session = openSession();

        Query q = session.createQuery(sql);

        if (orderByComparator == null) {
          list = (List<SocialEquityHistory>) QueryUtil.list(q, getDialect(), start, end, false);

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

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

        closeSession(session);
      }
    }

    return list;
  }
  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<ViewListTitleCompetencies> findAll(int start, int end, OrderByComparator obc)
      throws SystemException {
    Object[] finderArgs =
        new Object[] {String.valueOf(start), String.valueOf(end), String.valueOf(obc)};

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

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

      try {
        session = openSession();

        StringBuilder query = new StringBuilder();

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

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

        if (obc == null) {
          list =
              (List<ViewListTitleCompetencies>) QueryUtil.list(q, getDialect(), start, end, false);

          Collections.sort(list);
        } else {
          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_ALL, finderArgs, list);

        closeSession(session);
      }
    }

    return list;
  }
  public SoPhongVanBanNoiBo[] findByPhongVanBanNoiBo_PrevAndNext(
      SoPhongVanBanNoiBoPK soPhongVanBanNoiBoPK, String phongVanBanNoiBoId, OrderByComparator obc)
      throws NoSuchSoPhongVanBanNoiBoException, SystemException {
    SoPhongVanBanNoiBo soPhongVanBanNoiBo = findByPrimaryKey(soPhongVanBanNoiBoPK);

    int count = countByPhongVanBanNoiBo(phongVanBanNoiBoId);

    Session session = null;

    try {
      session = openSession();

      StringBuilder query = new StringBuilder();

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

      if (phongVanBanNoiBoId == null) {
        query.append("phongVanBanNoiBoId IS NULL");
      } else {
        query.append("phongVanBanNoiBoId = ?");
      }

      query.append(" ");

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

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

      QueryPos qPos = QueryPos.getInstance(q);

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

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

      SoPhongVanBanNoiBo[] array = new SoPhongVanBanNoiBoImpl[3];

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

      return array;
    } catch (Exception e) {
      throw processException(e);
    } finally {
      closeSession(session);
    }
  }
  /**
   * Returns an ordered range of all the h r holidaies associated with the h r office.
   *
   * <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 pk the primary key of the h r office
   * @param start the lower bound of the range of h r offices
   * @param end the upper bound of the range of h r offices (not inclusive)
   * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
   * @return the ordered range of h r holidaies associated with the h r office
   * @throws SystemException if a system exception occurred
   */
  public List<com.liferay.hr.model.HRHoliday> getHRHolidaies(
      long pk, int start, int end, OrderByComparator orderByComparator) throws SystemException {
    Object[] finderArgs =
        new Object[] {
          pk, String.valueOf(start), String.valueOf(end), String.valueOf(orderByComparator)
        };

    List<com.liferay.hr.model.HRHoliday> list =
        (List<com.liferay.hr.model.HRHoliday>)
            FinderCacheUtil.getResult(FINDER_PATH_GET_HRHOLIDAIES, finderArgs, this);

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

      try {
        session = openSession();

        String sql = null;

        if (orderByComparator != null) {
          sql = _SQL_GETHRHOLIDAIES.concat(ORDER_BY_CLAUSE).concat(orderByComparator.getOrderBy());
        } else {
          sql = _SQL_GETHRHOLIDAIES;
        }

        SQLQuery q = session.createSQLQuery(sql);

        q.addEntity("HRHoliday", com.liferay.hr.model.impl.HRHolidayImpl.class);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(pk);

        list = (List<com.liferay.hr.model.HRHoliday>) QueryUtil.list(q, getDialect(), start, end);
      } catch (Exception e) {
        throw processException(e);
      } finally {
        if (list == null) {
          FinderCacheUtil.removeResult(FINDER_PATH_GET_HRHOLIDAIES, finderArgs);
        } else {
          hrHolidayPersistence.cacheResult(list);

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

        closeSession(session);
      }
    }

    return list;
  }
  public ViewListTitleCompetencies[] findByTitleId_PrevAndNext(
      String id, int titleId, OrderByComparator obc)
      throws NoSuchViewListTitleCompetenciesException, SystemException {
    ViewListTitleCompetencies viewListTitleCompetencies = findByPrimaryKey(id);

    int count = countByTitleId(titleId);

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

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

      ViewListTitleCompetencies[] array = new ViewListTitleCompetenciesImpl[3];

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

      return array;
    } catch (Exception e) {
      throw processException(e);
    } finally {
      closeSession(session);
    }
  }
  /**
   * Returns an ordered range of all the shopping item fields where itemId = &#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 itemId the item ID
   * @param start the lower bound of the range of shopping item fields
   * @param end the upper bound of the range of shopping item fields (not inclusive)
   * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
   * @return the ordered range of matching shopping item fields
   * @throws SystemException if a system exception occurred
   */
  public List<ShoppingItemField> findByItemId(
      long itemId, int start, int end, OrderByComparator orderByComparator) throws SystemException {
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
      finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID;
      finderArgs = new Object[] {itemId};
    } else {
      finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ITEMID;
      finderArgs = new Object[] {itemId, start, end, orderByComparator};
    }

    List<ShoppingItemField> list =
        (List<ShoppingItemField>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
      for (ShoppingItemField shoppingItemField : list) {
        if ((itemId != shoppingItemField.getItemId())) {
          list = null;

          break;
        }
      }
    }

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

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

      query.append(_SQL_SELECT_SHOPPINGITEMFIELD_WHERE);

      query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);

      if (orderByComparator != null) {
        appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
      } else {
        query.append(ShoppingItemFieldModelImpl.ORDER_BY_JPQL);
      }

      String sql = query.toString();

      Session session = null;

      try {
        session = openSession();

        Query q = session.createQuery(sql);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(itemId);

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

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

        closeSession(session);
      }
    }

    return list;
  }
  public List<PmlEdmLevelSend> findAll(int start, int end, OrderByComparator obc)
      throws SystemException {
    boolean finderClassNameCacheEnabled = PmlEdmLevelSendModelImpl.CACHE_ENABLED;
    String finderClassName = PmlEdmLevelSend.class.getName();
    String finderMethodName = "findAll";
    String[] finderParams =
        new String[] {
          "java.lang.Integer",
          "java.lang.Integer",
          "com.liferay.portal.kernel.util.OrderByComparator"
        };
    Object[] finderArgs =
        new Object[] {String.valueOf(start), String.valueOf(end), String.valueOf(obc)};

    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.pmllevelsend.model.PmlEdmLevelSend ");

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

        List<PmlEdmLevelSend> list =
            (List<PmlEdmLevelSend>) QueryUtil.list(q, getDialect(), start, end);

        if (obc == null) {
          Collections.sort(list);
        }

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

        return list;
      } catch (Exception e) {
        throw processException(e);
      } finally {
        closeSession(session);
      }
    } else {
      return (List<PmlEdmLevelSend>) result;
    }
  }
  /**
   * Returns an ordered range of all the images where size &lt; &#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 size the size
   * @param start the lower bound of the range of images
   * @param end the upper bound of the range of images (not inclusive)
   * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
   * @return the ordered range of matching images
   * @throws SystemException if a system exception occurred
   */
  public List<Image> findByLtSize(int size, int start, int end, OrderByComparator orderByComparator)
      throws SystemException {
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LTSIZE;
    finderArgs = new Object[] {size, start, end, orderByComparator};

    List<Image> list = (List<Image>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
      for (Image image : list) {
        if ((size != image.getSize())) {
          list = null;

          break;
        }
      }
    }

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

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

      query.append(_SQL_SELECT_IMAGE_WHERE);

      query.append(_FINDER_COLUMN_LTSIZE_SIZE_2);

      if (orderByComparator != null) {
        appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
      } else {
        query.append(ImageModelImpl.ORDER_BY_JPQL);
      }

      String sql = query.toString();

      Session session = null;

      try {
        session = openSession();

        Query q = session.createQuery(sql);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(size);

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

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

        closeSession(session);
      }
    }

    return list;
  }
  protected ShoppingItemPrice getByItemId_PrevAndNext(
      Session session,
      ShoppingItemPrice shoppingItemPrice,
      long itemId,
      OrderByComparator<ShoppingItemPrice> orderByComparator,
      boolean previous) {
    StringBundler query = null;

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

    query.append(_SQL_SELECT_SHOPPINGITEMPRICE_WHERE);

    query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);

    if (orderByComparator != null) {
      String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

      if (orderByConditionFields.length > 0) {
        query.append(WHERE_AND);
      }

      for (int i = 0; i < orderByConditionFields.length; i++) {
        query.append(_ORDER_BY_ENTITY_ALIAS);
        query.append(orderByConditionFields[i]);

        if ((i + 1) < orderByConditionFields.length) {
          if (orderByComparator.isAscending() ^ previous) {
            query.append(WHERE_GREATER_THAN_HAS_NEXT);
          } else {
            query.append(WHERE_LESSER_THAN_HAS_NEXT);
          }
        } else {
          if (orderByComparator.isAscending() ^ previous) {
            query.append(WHERE_GREATER_THAN);
          } else {
            query.append(WHERE_LESSER_THAN);
          }
        }
      }

      query.append(ORDER_BY_CLAUSE);

      String[] orderByFields = orderByComparator.getOrderByFields();

      for (int i = 0; i < orderByFields.length; i++) {
        query.append(_ORDER_BY_ENTITY_ALIAS);
        query.append(orderByFields[i]);

        if ((i + 1) < orderByFields.length) {
          if (orderByComparator.isAscending() ^ previous) {
            query.append(ORDER_BY_ASC_HAS_NEXT);
          } else {
            query.append(ORDER_BY_DESC_HAS_NEXT);
          }
        } else {
          if (orderByComparator.isAscending() ^ previous) {
            query.append(ORDER_BY_ASC);
          } else {
            query.append(ORDER_BY_DESC);
          }
        }
      }
    } else {
      query.append(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
    }

    String sql = query.toString();

    Query q = session.createQuery(sql);

    q.setFirstResult(0);
    q.setMaxResults(2);

    QueryPos qPos = QueryPos.getInstance(q);

    qPos.add(itemId);

    if (orderByComparator != null) {
      Object[] values = orderByComparator.getOrderByConditionValues(shoppingItemPrice);

      for (Object value : values) {
        qPos.add(value);
      }
    }

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

    if (list.size() == 2) {
      return list.get(1);
    } else {
      return null;
    }
  }
  public DebateItemReference[] findByDebateItemIdItemVersionStatus_PrevAndNext(
      Long debateItemReferencePK,
      Long debateItemId,
      Long itemVersion,
      String status,
      OrderByComparator obc)
      throws NoSuchDebateItemReferenceException, SystemException {
    DebateItemReference debateItemReference = findByPrimaryKey(debateItemReferencePK);

    int count = countByDebateItemIdItemVersionStatus(debateItemId, itemVersion, status);

    Session session = null;

    try {
      session = openSession();

      StringBuilder query = new StringBuilder();

      query.append("FROM com.ext.portlet.debaterevision.model.DebateItemReference WHERE ");

      if (debateItemId == null) {
        query.append("debateItemId IS NULL");
      } else {
        query.append("debateItemId = ?");
      }

      query.append(" AND ");

      if (itemVersion == null) {
        query.append("itemVersion IS NULL");
      } else {
        query.append("itemVersion = ?");
      }

      query.append(" AND ");

      if (status == null) {
        query.append("status IS NULL");
      } else {
        query.append("status = ?");
      }

      query.append(" ");

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

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

      QueryPos qPos = QueryPos.getInstance(q);

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

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

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

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

      DebateItemReference[] array = new DebateItemReferenceImpl[3];

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

      return array;
    } catch (Exception e) {
      throw processException(e);
    } finally {
      closeSession(session);
    }
  }
  /**
   * Returns an ordered range of all the class names.
   *
   * <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 start the lower bound of the range of class names
   * @param end the upper bound of the range of class names (not inclusive)
   * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
   * @return the ordered range of class names
   * @throws SystemException if a system exception occurred
   */
  public List<ClassName> findAll(int start, int end, OrderByComparator orderByComparator)
      throws SystemException {
    FinderPath finderPath = null;
    Object[] finderArgs = new Object[] {start, end, orderByComparator};

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
      finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
      finderArgs = FINDER_ARGS_EMPTY;
    } else {
      finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
      finderArgs = new Object[] {start, end, orderByComparator};
    }

    List<ClassName> list =
        (List<ClassName>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

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

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

        query.append(_SQL_SELECT_CLASSNAME);

        appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);

        sql = query.toString();
      } else {
        sql = _SQL_SELECT_CLASSNAME;
      }

      Session session = null;

      try {
        session = openSession();

        Query q = session.createQuery(sql);

        if (orderByComparator == null) {
          list = (List<ClassName>) QueryUtil.list(q, getDialect(), start, end, false);

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

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

        closeSession(session);
      }
    }

    return list;
  }
  public List<SoPhongVanBanNoiBo> findBySoVanBanNoiBo_PhongVanBanNoiBo(
      long soVanBanNoiBoId, String phongVanBanNoiBoId, int start, int end, OrderByComparator obc)
      throws SystemException {
    boolean finderClassNameCacheEnabled = SoPhongVanBanNoiBoModelImpl.CACHE_ENABLED;
    String finderClassName = SoPhongVanBanNoiBo.class.getName();
    String finderMethodName = "findBySoVanBanNoiBo_PhongVanBanNoiBo";
    String[] finderParams =
        new String[] {
          Long.class.getName(),
          String.class.getName(),
          "java.lang.Integer",
          "java.lang.Integer",
          "com.liferay.portal.kernel.util.OrderByComparator"
        };
    Object[] finderArgs =
        new Object[] {
          new Long(soVanBanNoiBoId),
          phongVanBanNoiBoId,
          String.valueOf(start),
          String.valueOf(end),
          String.valueOf(obc)
        };

    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(" AND ");

        if (phongVanBanNoiBoId == null) {
          query.append("phongVanBanNoiBoId IS NULL");
        } else {
          query.append("phongVanBanNoiBoId = ?");
        }

        query.append(" ");

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

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

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(soVanBanNoiBoId);

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

        List<SoPhongVanBanNoiBo> list =
            (List<SoPhongVanBanNoiBo>) QueryUtil.list(q, getDialect(), start, end);

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

        return list;
      } catch (Exception e) {
        throw processException(e);
      } finally {
        closeSession(session);
      }
    } else {
      return (List<SoPhongVanBanNoiBo>) result;
    }
  }
  /**
   * Returns an ordered range of all the d l sync events where modifiedTime &gt; &#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. If <code>orderByComparator</code> is specified, then the query
   * will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and
   * pagination is required (<code>start</code> and <code>end</code> are not {@link
   * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default
   * ORDER BY logic from {@link
   * com.liferay.portlet.documentlibrary.model.impl.DLSyncEventModelImpl}. If both <code>
   * orderByComparator</code> and pagination are absent, for performance reasons, the query will not
   * have an ORDER BY clause and the returned result set will be sorted on by the primary key in an
   * ascending order.
   *
   * @param modifiedTime the modified time
   * @param start the lower bound of the range of d l sync events
   * @param end the upper bound of the range of d l sync events (not inclusive)
   * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
   * @return the ordered range of matching d l sync events
   * @throws SystemException if a system exception occurred
   */
  @Override
  public List<DLSyncEvent> findByModifiedTime(
      long modifiedTime, int start, int end, OrderByComparator orderByComparator)
      throws SystemException {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_MODIFIEDTIME;
    finderArgs = new Object[] {modifiedTime, start, end, orderByComparator};

    List<DLSyncEvent> list =
        (List<DLSyncEvent>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
      for (DLSyncEvent dlSyncEvent : list) {
        if ((modifiedTime >= dlSyncEvent.getModifiedTime())) {
          list = null;

          break;
        }
      }
    }

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

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

      query.append(_SQL_SELECT_DLSYNCEVENT_WHERE);

      query.append(_FINDER_COLUMN_MODIFIEDTIME_MODIFIEDTIME_2);

      if (orderByComparator != null) {
        appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
      } else if (pagination) {
        query.append(DLSyncEventModelImpl.ORDER_BY_JPQL);
      }

      String sql = query.toString();

      Session session = null;

      try {
        session = openSession();

        Query q = session.createQuery(sql);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(modifiedTime);

        if (!pagination) {
          list = (List<DLSyncEvent>) QueryUtil.list(q, getDialect(), start, end, false);

          Collections.sort(list);

          list = Collections.unmodifiableList(list);
        } else {
          list = (List<DLSyncEvent>) QueryUtil.list(q, getDialect(), start, end);
        }

        cacheResult(list);

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

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

    return list;
  }
  /**
   * Returns an ordered range of all the projects entries where userId = &#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. If <code>orderByComparator</code> is specified, then the query
   * will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and
   * pagination is required (<code>start</code> and <code>end</code> are not {@link
   * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default
   * ORDER BY logic from {@link com.liferay.so.model.impl.ProjectsEntryModelImpl}. If both <code>
   * orderByComparator</code> and pagination are absent, for performance reasons, the query will not
   * have an ORDER BY clause and the returned result set will be sorted on by the primary key in an
   * ascending order.
   *
   * @param userId the user ID
   * @param start the lower bound of the range of projects entries
   * @param end the upper bound of the range of projects entries (not inclusive)
   * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
   * @return the ordered range of matching projects entries
   * @throws SystemException if a system exception occurred
   */
  @Override
  public List<ProjectsEntry> findByUserId(
      long userId, int start, int end, OrderByComparator orderByComparator) throws SystemException {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
      pagination = false;
      finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
      finderArgs = new Object[] {userId};
    } else {
      finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
      finderArgs = new Object[] {userId, start, end, orderByComparator};
    }

    List<ProjectsEntry> list =
        (List<ProjectsEntry>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
      for (ProjectsEntry projectsEntry : list) {
        if ((userId != projectsEntry.getUserId())) {
          list = null;

          break;
        }
      }
    }

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

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

      query.append(_SQL_SELECT_PROJECTSENTRY_WHERE);

      query.append(_FINDER_COLUMN_USERID_USERID_2);

      if (orderByComparator != null) {
        appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
      } else if (pagination) {
        query.append(ProjectsEntryModelImpl.ORDER_BY_JPQL);
      }

      String sql = query.toString();

      Session session = null;

      try {
        session = openSession();

        Query q = session.createQuery(sql);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(userId);

        if (!pagination) {
          list = (List<ProjectsEntry>) QueryUtil.list(q, getDialect(), start, end, false);

          Collections.sort(list);

          list = Collections.unmodifiableList(list);
        } else {
          list = (List<ProjectsEntry>) QueryUtil.list(q, getDialect(), start, end);
        }

        cacheResult(list);

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

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

    return list;
  }
  protected DLSyncEvent getByModifiedTime_PrevAndNext(
      Session session,
      DLSyncEvent dlSyncEvent,
      long modifiedTime,
      OrderByComparator orderByComparator,
      boolean previous) {
    StringBundler query = null;

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

    query.append(_SQL_SELECT_DLSYNCEVENT_WHERE);

    query.append(_FINDER_COLUMN_MODIFIEDTIME_MODIFIEDTIME_2);

    if (orderByComparator != null) {
      String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

      if (orderByConditionFields.length > 0) {
        query.append(WHERE_AND);
      }

      for (int i = 0; i < orderByConditionFields.length; i++) {
        query.append(_ORDER_BY_ENTITY_ALIAS);
        query.append(orderByConditionFields[i]);

        if ((i + 1) < orderByConditionFields.length) {
          if (orderByComparator.isAscending() ^ previous) {
            query.append(WHERE_GREATER_THAN_HAS_NEXT);
          } else {
            query.append(WHERE_LESSER_THAN_HAS_NEXT);
          }
        } else {
          if (orderByComparator.isAscending() ^ previous) {
            query.append(WHERE_GREATER_THAN);
          } else {
            query.append(WHERE_LESSER_THAN);
          }
        }
      }

      query.append(ORDER_BY_CLAUSE);

      String[] orderByFields = orderByComparator.getOrderByFields();

      for (int i = 0; i < orderByFields.length; i++) {
        query.append(_ORDER_BY_ENTITY_ALIAS);
        query.append(orderByFields[i]);

        if ((i + 1) < orderByFields.length) {
          if (orderByComparator.isAscending() ^ previous) {
            query.append(ORDER_BY_ASC_HAS_NEXT);
          } else {
            query.append(ORDER_BY_DESC_HAS_NEXT);
          }
        } else {
          if (orderByComparator.isAscending() ^ previous) {
            query.append(ORDER_BY_ASC);
          } else {
            query.append(ORDER_BY_DESC);
          }
        }
      }
    } else {
      query.append(DLSyncEventModelImpl.ORDER_BY_JPQL);
    }

    String sql = query.toString();

    Query q = session.createQuery(sql);

    q.setFirstResult(0);
    q.setMaxResults(2);

    QueryPos qPos = QueryPos.getInstance(q);

    qPos.add(modifiedTime);

    if (orderByComparator != null) {
      Object[] values = orderByComparator.getOrderByConditionValues(dlSyncEvent);

      for (Object value : values) {
        qPos.add(value);
      }
    }

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

    if (list.size() == 2) {
      return list.get(1);
    } else {
      return null;
    }
  }
Ejemplo n.º 21
0
  public List<User> findByC_FN_MN_LN_SN_EA_S(
      long companyId,
      String[] firstNames,
      String[] middleNames,
      String[] lastNames,
      String[] screenNames,
      String[] emailAddresses,
      int status,
      LinkedHashMap<String, Object> params,
      boolean andOperator,
      int start,
      int end,
      OrderByComparator obc)
      throws SystemException {

    firstNames = CustomSQLUtil.keywords(firstNames);
    middleNames = CustomSQLUtil.keywords(middleNames);
    lastNames = CustomSQLUtil.keywords(lastNames);
    screenNames = CustomSQLUtil.keywords(screenNames);
    emailAddresses = CustomSQLUtil.keywords(emailAddresses);

    if (params == null) {
      params = _emptyLinkedHashMap;
    }

    Long[] groupIds = null;

    if (params.get("usersGroups") instanceof Long) {
      Long groupId = (Long) params.get("usersGroups");

      if (groupId > 0) {
        groupIds = new Long[] {groupId};
      }
    } else {
      groupIds = (Long[]) params.get("usersGroups");
    }

    boolean inherit = GetterUtil.getBoolean(params.get("inherit"));

    boolean doUnion = Validator.isNotNull(groupIds) && inherit;

    LinkedHashMap<String, Object> params1 = params;

    LinkedHashMap<String, Object> params2 = null;

    LinkedHashMap<String, Object> params3 = null;

    if (doUnion) {
      params2 = new LinkedHashMap<String, Object>(params1);

      params2.remove("usersGroups");

      params3 = new LinkedHashMap<String, Object>(params1);

      params3.remove("usersGroups");

      List<Long> organizationIds = new ArrayList<Long>();
      List<Long> userGroupIds = new ArrayList<Long>();

      for (long groupId : groupIds) {
        Group group = GroupLocalServiceUtil.fetchGroup(groupId);

        if ((group != null) && group.isOrganization()) {
          organizationIds.add(group.getOrganizationId());
        }

        List<Organization> organizations = GroupUtil.getOrganizations(groupId);

        for (Organization organization : organizations) {
          organizationIds.add(organization.getOrganizationId());
        }

        List<UserGroup> userGroups = GroupUtil.getUserGroups(groupId);

        for (int i = 0; i < userGroups.size(); i++) {
          UserGroup userGroup = userGroups.get(i);

          userGroupIds.add(userGroup.getUserGroupId());
        }
      }

      params2.put("usersOrgs", organizationIds.toArray(new Long[organizationIds.size()]));

      params3.put("usersUserGroups", userGroupIds.toArray(new Long[userGroupIds.size()]));
    }

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(FIND_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);
      }

      StringBundler sb = new StringBundler();

      sb.append(StringPool.OPEN_PARENTHESIS);
      sb.append(replaceJoinAndWhere(sql, params1));
      sb.append(StringPool.CLOSE_PARENTHESIS);

      if (doUnion) {
        sb.append(" UNION (");
        sb.append(replaceJoinAndWhere(sql, params2));
        sb.append(") UNION (");
        sb.append(replaceJoinAndWhere(sql, params3));
        sb.append(StringPool.CLOSE_PARENTHESIS);
      }

      if (obc != null) {
        sb.append(" ORDER BY ");
        sb.append(obc.toString());
      }

      sql = sb.toString();

      sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);

      SQLQuery q = session.createSQLQuery(sql);

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

      QueryPos qPos = QueryPos.getInstance(q);

      setJoin(qPos, params1);

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

      if (doUnion) {
        setJoin(qPos, params2);

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

        setJoin(qPos, params3);

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

      List<Long> userIds = (List<Long>) QueryUtil.list(q, getDialect(), start, end);

      List<User> users = new ArrayList<User>(userIds.size());

      for (Long userId : userIds) {
        User user = UserUtil.findByPrimaryKey(userId);

        users.add(user);
      }

      return users;
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }
  }
  protected JIRAChangeItem getByJiraChangeGroupId_PrevAndNext(
      Session session,
      JIRAChangeItem jiraChangeItem,
      long jiraChangeGroupId,
      OrderByComparator orderByComparator,
      boolean previous) {
    StringBundler query = null;

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

    query.append(_SQL_SELECT_JIRACHANGEITEM_WHERE);

    query.append(_FINDER_COLUMN_JIRACHANGEGROUPID_JIRACHANGEGROUPID_2);

    if (orderByComparator != null) {
      String[] orderByFields = orderByComparator.getOrderByFields();

      if (orderByFields.length > 0) {
        query.append(WHERE_AND);
      }

      for (int i = 0; i < orderByFields.length; i++) {
        query.append(_ORDER_BY_ENTITY_ALIAS);
        query.append(orderByFields[i]);

        if ((i + 1) < orderByFields.length) {
          if (orderByComparator.isAscending() ^ previous) {
            query.append(WHERE_GREATER_THAN_HAS_NEXT);
          } else {
            query.append(WHERE_LESSER_THAN_HAS_NEXT);
          }
        } else {
          if (orderByComparator.isAscending() ^ previous) {
            query.append(WHERE_GREATER_THAN);
          } else {
            query.append(WHERE_LESSER_THAN);
          }
        }
      }

      query.append(ORDER_BY_CLAUSE);

      for (int i = 0; i < orderByFields.length; i++) {
        query.append(_ORDER_BY_ENTITY_ALIAS);
        query.append(orderByFields[i]);

        if ((i + 1) < orderByFields.length) {
          if (orderByComparator.isAscending() ^ previous) {
            query.append(ORDER_BY_ASC_HAS_NEXT);
          } else {
            query.append(ORDER_BY_DESC_HAS_NEXT);
          }
        } else {
          if (orderByComparator.isAscending() ^ previous) {
            query.append(ORDER_BY_ASC);
          } else {
            query.append(ORDER_BY_DESC);
          }
        }
      }
    }

    String sql = query.toString();

    Query q = session.createQuery(sql);

    q.setFirstResult(0);
    q.setMaxResults(2);

    QueryPos qPos = QueryPos.getInstance(q);

    qPos.add(jiraChangeGroupId);

    if (orderByComparator != null) {
      Object[] values = orderByComparator.getOrderByValues(jiraChangeItem);

      for (Object value : values) {
        qPos.add(value);
      }
    }

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

    if (list.size() == 2) {
      return list.get(1);
    } else {
      return null;
    }
  }
  /**
   * Returns an ordered range of all the bars where text = &#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. If <code>orderByComparator</code> is specified, then the query
   * will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and
   * pagination is required (<code>start</code> and <code>end</code> are not {@link
   * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default
   * ORDER BY logic from {@link com.liferay.testtransaction.model.impl.BarModelImpl}. If both <code>
   * orderByComparator</code> and pagination are absent, for performance reasons, the query will not
   * have an ORDER BY clause and the returned result set will be sorted on by the primary key in an
   * ascending order.
   *
   * @param text the text
   * @param start the lower bound of the range of bars
   * @param end the upper bound of the range of bars (not inclusive)
   * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
   * @return the ordered range of matching bars
   */
  @Override
  public List<Bar> findByText(
      String text, int start, int end, OrderByComparator<Bar> orderByComparator) {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
      pagination = false;
      finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEXT;
      finderArgs = new Object[] {text};
    } else {
      finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TEXT;
      finderArgs = new Object[] {text, start, end, orderByComparator};
    }

    List<Bar> list = (List<Bar>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
      for (Bar bar : list) {
        if (!Validator.equals(text, bar.getText())) {
          list = null;

          break;
        }
      }
    }

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

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

      query.append(_SQL_SELECT_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);
      }

      if (orderByComparator != null) {
        appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
      } else if (pagination) {
        query.append(BarModelImpl.ORDER_BY_JPQL);
      }

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

        if (!pagination) {
          list = (List<Bar>) QueryUtil.list(q, getDialect(), start, end, false);

          Collections.sort(list);

          list = Collections.unmodifiableList(list);
        } else {
          list = (List<Bar>) QueryUtil.list(q, getDialect(), start, end);
        }

        cacheResult(list);

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

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

    return list;
  }
  /**
   * Returns an ordered range of all the bars where text = &#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 text the text
   * @param start the lower bound of the range of bars
   * @param end the upper bound of the range of bars (not inclusive)
   * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
   * @return the ordered range of matching bars
   * @throws SystemException if a system exception occurred
   */
  public List<Bar> findByText(String text, int start, int end, OrderByComparator orderByComparator)
      throws SystemException {
    Object[] finderArgs =
        new Object[] {
          text, String.valueOf(start), String.valueOf(end), String.valueOf(orderByComparator)
        };

    List<Bar> list =
        (List<Bar>) FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_TEXT, finderArgs, this);

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

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

      query.append(_SQL_SELECT_BAR_WHERE);

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

      if (orderByComparator != null) {
        appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
      } else {
        query.append(BarModelImpl.ORDER_BY_JPQL);
      }

      String sql = query.toString();

      Session session = null;

      try {
        session = openSession();

        Query q = session.createQuery(sql);

        QueryPos qPos = QueryPos.getInstance(q);

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

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

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

        closeSession(session);
      }
    }

    return list;
  }
  protected Bar getByText_PrevAndNext(
      Session session,
      Bar bar,
      String text,
      OrderByComparator<Bar> orderByComparator,
      boolean previous) {
    StringBundler query = null;

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

    query.append(_SQL_SELECT_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);
    }

    if (orderByComparator != null) {
      String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

      if (orderByConditionFields.length > 0) {
        query.append(WHERE_AND);
      }

      for (int i = 0; i < orderByConditionFields.length; i++) {
        query.append(_ORDER_BY_ENTITY_ALIAS);
        query.append(orderByConditionFields[i]);

        if ((i + 1) < orderByConditionFields.length) {
          if (orderByComparator.isAscending() ^ previous) {
            query.append(WHERE_GREATER_THAN_HAS_NEXT);
          } else {
            query.append(WHERE_LESSER_THAN_HAS_NEXT);
          }
        } else {
          if (orderByComparator.isAscending() ^ previous) {
            query.append(WHERE_GREATER_THAN);
          } else {
            query.append(WHERE_LESSER_THAN);
          }
        }
      }

      query.append(ORDER_BY_CLAUSE);

      String[] orderByFields = orderByComparator.getOrderByFields();

      for (int i = 0; i < orderByFields.length; i++) {
        query.append(_ORDER_BY_ENTITY_ALIAS);
        query.append(orderByFields[i]);

        if ((i + 1) < orderByFields.length) {
          if (orderByComparator.isAscending() ^ previous) {
            query.append(ORDER_BY_ASC_HAS_NEXT);
          } else {
            query.append(ORDER_BY_DESC_HAS_NEXT);
          }
        } else {
          if (orderByComparator.isAscending() ^ previous) {
            query.append(ORDER_BY_ASC);
          } else {
            query.append(ORDER_BY_DESC);
          }
        }
      }
    } else {
      query.append(BarModelImpl.ORDER_BY_JPQL);
    }

    String sql = query.toString();

    Query q = session.createQuery(sql);

    q.setFirstResult(0);
    q.setMaxResults(2);

    QueryPos qPos = QueryPos.getInstance(q);

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

    if (orderByComparator != null) {
      Object[] values = orderByComparator.getOrderByConditionValues(bar);

      for (Object value : values) {
        qPos.add(value);
      }
    }

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

    if (list.size() == 2) {
      return list.get(1);
    } else {
      return null;
    }
  }
  /**
   * Returns an ordered range of all the shopping item prices where itemId = &#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 QueryUtil#ALL_POS} will return the full result set. If
   * <code>orderByComparator</code> is specified, then the query will include the given ORDER BY
   * logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start
   * </code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include
   * the default ORDER BY logic from {@link ShoppingItemPriceModelImpl}. If both <code>
   * orderByComparator</code> and pagination are absent, for performance reasons, the query will not
   * have an ORDER BY clause and the returned result set will be sorted on by the primary key in an
   * ascending order.
   *
   * @param itemId the item ID
   * @param start the lower bound of the range of shopping item prices
   * @param end the upper bound of the range of shopping item prices (not inclusive)
   * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
   * @param retrieveFromCache whether to retrieve from the finder cache
   * @return the ordered range of matching shopping item prices
   */
  @Override
  public List<ShoppingItemPrice> findByItemId(
      long itemId,
      int start,
      int end,
      OrderByComparator<ShoppingItemPrice> orderByComparator,
      boolean retrieveFromCache) {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
      pagination = false;
      finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID;
      finderArgs = new Object[] {itemId};
    } else {
      finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ITEMID;
      finderArgs = new Object[] {itemId, start, end, orderByComparator};
    }

    List<ShoppingItemPrice> list = null;

    if (retrieveFromCache) {
      list = (List<ShoppingItemPrice>) finderCache.getResult(finderPath, finderArgs, this);

      if ((list != null) && !list.isEmpty()) {
        for (ShoppingItemPrice shoppingItemPrice : list) {
          if ((itemId != shoppingItemPrice.getItemId())) {
            list = null;

            break;
          }
        }
      }
    }

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

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

      query.append(_SQL_SELECT_SHOPPINGITEMPRICE_WHERE);

      query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);

      if (orderByComparator != null) {
        appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
      } else if (pagination) {
        query.append(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
      }

      String sql = query.toString();

      Session session = null;

      try {
        session = openSession();

        Query q = session.createQuery(sql);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(itemId);

        if (!pagination) {
          list = (List<ShoppingItemPrice>) QueryUtil.list(q, getDialect(), start, end, false);

          Collections.sort(list);

          list = Collections.unmodifiableList(list);
        } else {
          list = (List<ShoppingItemPrice>) QueryUtil.list(q, getDialect(), start, end);
        }

        cacheResult(list);

        finderCache.putResult(finderPath, finderArgs, list);
      } catch (Exception e) {
        finderCache.removeResult(finderPath, finderArgs);

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

    return list;
  }
  /**
   * Returns an ordered range of all the projects entries.
   *
   * <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. If <code>orderByComparator</code> is specified, then the query
   * will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and
   * pagination is required (<code>start</code> and <code>end</code> are not {@link
   * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default
   * ORDER BY logic from {@link com.liferay.so.model.impl.ProjectsEntryModelImpl}. If both <code>
   * orderByComparator</code> and pagination are absent, for performance reasons, the query will not
   * have an ORDER BY clause and the returned result set will be sorted on by the primary key in an
   * ascending order.
   *
   * @param start the lower bound of the range of projects entries
   * @param end the upper bound of the range of projects entries (not inclusive)
   * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
   * @return the ordered range of projects entries
   * @throws SystemException if a system exception occurred
   */
  @Override
  public List<ProjectsEntry> findAll(int start, int end, OrderByComparator orderByComparator)
      throws SystemException {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
      pagination = false;
      finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
      finderArgs = FINDER_ARGS_EMPTY;
    } else {
      finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
      finderArgs = new Object[] {start, end, orderByComparator};
    }

    List<ProjectsEntry> list =
        (List<ProjectsEntry>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

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

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

        query.append(_SQL_SELECT_PROJECTSENTRY);

        appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);

        sql = query.toString();
      } else {
        sql = _SQL_SELECT_PROJECTSENTRY;

        if (pagination) {
          sql = sql.concat(ProjectsEntryModelImpl.ORDER_BY_JPQL);
        }
      }

      Session session = null;

      try {
        session = openSession();

        Query q = session.createQuery(sql);

        if (!pagination) {
          list = (List<ProjectsEntry>) QueryUtil.list(q, getDialect(), start, end, false);

          Collections.sort(list);

          list = Collections.unmodifiableList(list);
        } else {
          list = (List<ProjectsEntry>) QueryUtil.list(q, getDialect(), start, end);
        }

        cacheResult(list);

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

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

    return list;
  }
  public List<DebateItemReference> findByDebateItemIdItemVersionStatus(
      Long debateItemId, Long itemVersion, String status, int start, int end, OrderByComparator obc)
      throws SystemException {
    Object[] finderArgs =
        new Object[] {
          debateItemId,
          itemVersion,
          status,
          String.valueOf(start),
          String.valueOf(end),
          String.valueOf(obc)
        };

    List<DebateItemReference> list =
        (List<DebateItemReference>)
            FinderCacheUtil.getResult(
                FINDER_PATH_FIND_BY_OBC_DEBATEITEMIDITEMVERSIONSTATUS, finderArgs, this);

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

      try {
        session = openSession();

        StringBuilder query = new StringBuilder();

        query.append("FROM com.ext.portlet.debaterevision.model.DebateItemReference WHERE ");

        if (debateItemId == null) {
          query.append("debateItemId IS NULL");
        } else {
          query.append("debateItemId = ?");
        }

        query.append(" AND ");

        if (itemVersion == null) {
          query.append("itemVersion IS NULL");
        } else {
          query.append("itemVersion = ?");
        }

        query.append(" AND ");

        if (status == null) {
          query.append("status IS NULL");
        } else {
          query.append("status = ?");
        }

        query.append(" ");

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

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

        QueryPos qPos = QueryPos.getInstance(q);

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

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

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

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

        cacheResult(list);

        FinderCacheUtil.putResult(
            FINDER_PATH_FIND_BY_OBC_DEBATEITEMIDITEMVERSIONSTATUS, finderArgs, list);

        closeSession(session);
      }
    }

    return list;
  }
  protected ProjectsEntry getByUserId_PrevAndNext(
      Session session,
      ProjectsEntry projectsEntry,
      long userId,
      OrderByComparator orderByComparator,
      boolean previous) {
    StringBundler query = null;

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

    query.append(_SQL_SELECT_PROJECTSENTRY_WHERE);

    query.append(_FINDER_COLUMN_USERID_USERID_2);

    if (orderByComparator != null) {
      String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

      if (orderByConditionFields.length > 0) {
        query.append(WHERE_AND);
      }

      for (int i = 0; i < orderByConditionFields.length; i++) {
        query.append(_ORDER_BY_ENTITY_ALIAS);
        query.append(orderByConditionFields[i]);

        if ((i + 1) < orderByConditionFields.length) {
          if (orderByComparator.isAscending() ^ previous) {
            query.append(WHERE_GREATER_THAN_HAS_NEXT);
          } else {
            query.append(WHERE_LESSER_THAN_HAS_NEXT);
          }
        } else {
          if (orderByComparator.isAscending() ^ previous) {
            query.append(WHERE_GREATER_THAN);
          } else {
            query.append(WHERE_LESSER_THAN);
          }
        }
      }

      query.append(ORDER_BY_CLAUSE);

      String[] orderByFields = orderByComparator.getOrderByFields();

      for (int i = 0; i < orderByFields.length; i++) {
        query.append(_ORDER_BY_ENTITY_ALIAS);
        query.append(orderByFields[i]);

        if ((i + 1) < orderByFields.length) {
          if (orderByComparator.isAscending() ^ previous) {
            query.append(ORDER_BY_ASC_HAS_NEXT);
          } else {
            query.append(ORDER_BY_DESC_HAS_NEXT);
          }
        } else {
          if (orderByComparator.isAscending() ^ previous) {
            query.append(ORDER_BY_ASC);
          } else {
            query.append(ORDER_BY_DESC);
          }
        }
      }
    } else {
      query.append(ProjectsEntryModelImpl.ORDER_BY_JPQL);
    }

    String sql = query.toString();

    Query q = session.createQuery(sql);

    q.setFirstResult(0);
    q.setMaxResults(2);

    QueryPos qPos = QueryPos.getInstance(q);

    qPos.add(userId);

    if (orderByComparator != null) {
      Object[] values = orderByComparator.getOrderByConditionValues(projectsEntry);

      for (Object value : values) {
        qPos.add(value);
      }
    }

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

    if (list.size() == 2) {
      return list.get(1);
    } else {
      return null;
    }
  }
  /**
   * Returns an ordered range of all the d l syncs where companyId = &#63; and modifiedDate &gt;
   * &#63; and repositoryId = &#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. If <code>orderByComparator</code> is specified, then the query
   * will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and
   * pagination is required (<code>start</code> and <code>end</code> are not {@link
   * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default
   * ORDER BY logic from {@link com.liferay.portlet.documentlibrary.model.impl.DLSyncModelImpl}. If
   * both <code>orderByComparator</code> and pagination are absent, for performance reasons, the
   * query will not have an ORDER BY clause and the returned result set will be sorted on by the
   * primary key in an ascending order.
   *
   * @param companyId the company ID
   * @param modifiedDate the modified date
   * @param repositoryId the repository ID
   * @param start the lower bound of the range of d l syncs
   * @param end the upper bound of the range of d l syncs (not inclusive)
   * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
   * @return the ordered range of matching d l syncs
   * @throws SystemException if a system exception occurred
   */
  public List<DLSync> findByC_M_R(
      long companyId,
      long modifiedDate,
      long repositoryId,
      int start,
      int end,
      OrderByComparator orderByComparator)
      throws SystemException {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_M_R;
    finderArgs =
        new Object[] {
          companyId, modifiedDate, repositoryId,
          start, end, orderByComparator
        };

    List<DLSync> list = (List<DLSync>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
      for (DLSync dlSync : list) {
        if ((companyId != dlSync.getCompanyId())
            || (modifiedDate != dlSync.getModifiedDate())
            || (repositoryId != dlSync.getRepositoryId())) {
          list = null;

          break;
        }
      }
    }

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

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

      query.append(_SQL_SELECT_DLSYNC_WHERE);

      query.append(_FINDER_COLUMN_C_M_R_COMPANYID_2);

      query.append(_FINDER_COLUMN_C_M_R_MODIFIEDDATE_2);

      query.append(_FINDER_COLUMN_C_M_R_REPOSITORYID_2);

      if (orderByComparator != null) {
        appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
      } else if (pagination) {
        query.append(DLSyncModelImpl.ORDER_BY_JPQL);
      }

      String sql = query.toString();

      Session session = null;

      try {
        session = openSession();

        Query q = session.createQuery(sql);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(companyId);

        qPos.add(modifiedDate);

        qPos.add(repositoryId);

        if (!pagination) {
          list = (List<DLSync>) QueryUtil.list(q, getDialect(), start, end, false);

          Collections.sort(list);

          list = new UnmodifiableList<DLSync>(list);
        } else {
          list = (List<DLSync>) QueryUtil.list(q, getDialect(), start, end);
        }

        cacheResult(list);

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

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

    return list;
  }