Пример #1
0
  @Test
  public void testNegativeLowerBound() {
    DynamicQuery dynamicQuery = ClassNameLocalServiceUtil.dynamicQuery();

    dynamicQuery.addOrder(OrderFactoryUtil.asc("classNameId"));
    dynamicQuery.setLimit(-50, _allClassNames.size());

    Assert.assertEquals(
        _allClassNames, ClassNameLocalServiceUtil.<ClassName>dynamicQuery(dynamicQuery));
  }
Пример #2
0
  @Test
  public void testUpperBound() {
    DynamicQuery dynamicQuery = ClassNameLocalServiceUtil.dynamicQuery();

    dynamicQuery.addOrder(OrderFactoryUtil.asc("classNameId"));
    dynamicQuery.setLimit(QueryUtil.ALL_POS, 10);

    Assert.assertEquals(
        _allClassNames.subList(0, 10),
        ClassNameLocalServiceUtil.<ClassName>dynamicQuery(dynamicQuery));
  }
Пример #3
0
  @Test
  public void testSingleResult() {
    DynamicQuery dynamicQuery = ClassNameLocalServiceUtil.dynamicQuery();

    dynamicQuery.addOrder(OrderFactoryUtil.asc("classNameId"));
    dynamicQuery.setLimit(10, 11);

    List<ClassName> dynamicQueryClassNames = ClassNameLocalServiceUtil.dynamicQuery(dynamicQuery);

    Assert.assertEquals(1, dynamicQueryClassNames.size());
    Assert.assertEquals(_allClassNames.get(10), dynamicQueryClassNames.get(0));
  }
Пример #4
0
  @Test
  public void testNoLimit() {
    DynamicQuery dynamicQuery = ClassNameLocalServiceUtil.dynamicQuery();

    dynamicQuery.addOrder(OrderFactoryUtil.asc("classNameId"));

    List<ClassName> classNames = ClassNameLocalServiceUtil.dynamicQuery(dynamicQuery);

    for (ClassName className : _allClassNames) {
      if (!classNames.contains(className)) {
        Assert.fail("Class names do not contain " + className);
      }
    }
  }
  public int populateMessages(
      List<Message> messages,
      long folderId,
      String keywords,
      int pageNumber,
      int messagesPerPage,
      String orderByField,
      String orderByType)
      throws SystemException {

    DynamicQuery countDynamicQuery =
        DynamicQueryFactoryUtil.forClass(Message.class, getClassLoader());

    countDynamicQuery.add(RestrictionsFactoryUtil.eq("folderId", folderId));

    DynamicQuery messageDynamicQuery =
        DynamicQueryFactoryUtil.forClass(Message.class, getClassLoader());

    messageDynamicQuery.add(RestrictionsFactoryUtil.eq("folderId", folderId));

    if (Validator.isNotNull(keywords)) {
      String value = "%" + keywords + "%";

      Disjunction disjunction = RestrictionsFactoryUtil.disjunction();

      disjunction.add(RestrictionsFactoryUtil.ilike("subject", value));
      disjunction.add(RestrictionsFactoryUtil.ilike("body", value));

      countDynamicQuery.add(disjunction);

      messageDynamicQuery.add(disjunction);
    }

    if (orderByType.equals("desc")) {
      messageDynamicQuery.addOrder(OrderFactoryUtil.desc(orderByField));
    } else {
      messageDynamicQuery.addOrder(OrderFactoryUtil.asc(orderByField));
    }

    int start = messagesPerPage * (pageNumber - 1);
    int end = messagesPerPage * pageNumber;

    messages.addAll(messagePersistence.findWithDynamicQuery(messageDynamicQuery, start, end));

    return (int) dynamicQueryCount(countDynamicQuery);
  }
Пример #6
0
  @SuppressWarnings("unchecked")
  public List<Asset> getAssets(String pattern, boolean ticker) {
    List<Asset> results = new ArrayList<Asset>();
    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(AssetImpl.class);

    dynamicQuery.add(
        RestrictionsFactoryUtil.like(
            ticker ? "security_ticker" : "id_isin",
            StringPool.PERCENT + pattern + StringPool.PERCENT));
    dynamicQuery.addOrder(OrderFactoryUtil.asc(ticker ? "security_ticker" : "id_isin"));

    try {
      results = assetLocalService.dynamicQuery(dynamicQuery);
    } catch (SystemException e) {
      e.printStackTrace();
    }

    return results;
  }
Пример #7
0
  public static List<CalEvent> getEventFromDateRange(
      ThemeDisplay themeDisplay, Date startDate, Date endDate) {
    List<CalEvent> lstEvents = null;
    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(CalEvent.class);
    dynamicQuery.add(PropertyFactoryUtil.forName("groupId").eq(themeDisplay.getScopeGroupId()));

    Criterion criterion = null;

    criterion = RestrictionsFactoryUtil.between("startDate", startDate, endDate);
    Order defaultOrder = OrderFactoryUtil.asc("startDate");

    dynamicQuery.add(criterion);
    dynamicQuery.addOrder(defaultOrder);
    try {
      lstEvents = CalEventLocalServiceUtil.dynamicQuery(dynamicQuery);
    } catch (SystemException e) {

      _log.error(e);
    }

    return lstEvents;
  }
  public Message getRemoteMessage(long folderId, boolean oldest)
      throws PortalException, SystemException {

    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(Message.class, getClassLoader());

    dynamicQuery.add(RestrictionsFactoryUtil.eq("folderId", folderId));
    dynamicQuery.add(RestrictionsFactoryUtil.gt("remoteMessageId", new Long(0)));

    if (oldest) {
      dynamicQuery.addOrder(OrderFactoryUtil.asc("remoteMessageId"));
    } else {
      dynamicQuery.addOrder(OrderFactoryUtil.desc("remoteMessageId"));
    }

    List<Message> messages = messagePersistence.findWithDynamicQuery(dynamicQuery, 0, 1);

    if (messages.isEmpty()) {
      throw new NoSuchMessageException();
    }

    return messages.get(0);
  }