Ejemplo n.º 1
0
 @Override
 default Query join(Query l, Query r) {
   if (l == null) return r;
   else if (r == null) return l;
   else {
     ArrayList<String> res = new ArrayList<String>();
     res.addAll(l.query());
     res.addAll(r.query());
     return () -> res;
   }
 }
  /** @see DATAMONGO-445 */
  @Test
  public void shouldTakeSkipAndLimitSettingsFromGivenQuery() {

    int limit = 10;
    int skip = 5;
    NearQuery query =
        NearQuery.near(new Point(1, 1))
            .query(Query.query(Criteria.where("foo").is("bar")).limit(limit).skip(skip));

    assertThat(query.getSkip(), is(skip));
    assertThat((Integer) query.toDBObject().get("num"), is(limit));
  }
  /** @see DATAMONGO-445 */
  @Test
  public void shouldTakeSkipAndLimitSettingsFromPageableEvenIfItWasSpecifiedOnQuery() {

    int limit = 10;
    int skip = 5;
    Pageable pageable = new PageRequest(3, 5);
    NearQuery query =
        NearQuery.near(new Point(1, 1))
            .query(Query.query(Criteria.where("foo").is("bar")).limit(limit).skip(skip))
            .with(pageable);

    assertThat(query.getSkip(), is(pageable.getPageNumber() * pageable.getPageSize()));
    assertThat(
        (Integer) query.toDBObject().get("num"),
        is((pageable.getPageNumber() + 1) * pageable.getPageSize()));
  }
Ejemplo n.º 4
0
 public int update() {
   int count;
   session.getUser().checkRight(table, Right.INSERT);
   session.getUser().checkRight(table, Right.UPDATE);
   setCurrentRowNumber(0);
   if (list.size() > 0) {
     count = 0;
     for (int x = 0, size = list.size(); x < size; x++) {
       Expression[] expr = list.get(x);
       Row newRow;
       try {
         newRow = createRow(expr, x);
         if (newRow == null) {
           continue;
         }
       } catch (DbException ex) {
         throw setRow(ex, count + 1, getSQL(expr));
       }
       setCurrentRowNumber(++count);
       merge(newRow);
     }
   } else {
     ResultInterface rows = query.query(0);
     count = 0;
     table.fire(session, Trigger.UPDATE | Trigger.INSERT, true);
     table.lock(session, true, false);
     while (rows.next()) {
       Value[] values = rows.currentRow();
       Row newRow;
       try {
         newRow = createRow(values);
         if (newRow == null) {
           continue;
         }
       } catch (DbException ex) {
         throw setRow(ex, count + 1, getSQL(values));
       }
       setCurrentRowNumber(++count);
       merge(newRow);
     }
     rows.close();
     table.fire(session, Trigger.UPDATE | Trigger.INSERT, false);
   }
   return count;
 }