com.yahoo.squidb.sql.Query.limit()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(256)

本文整理了Java中com.yahoo.squidb.sql.Query.limit方法的一些代码示例,展示了Query.limit的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.limit方法的具体详情如下:
包路径:com.yahoo.squidb.sql.Query
类名称:Query
方法名:limit

Query.limit介绍

[英]Set the limit of this statement. Using a negative value removes the limit.
[中]设置此语句的限制。使用负值可以消除限制。

代码示例

代码示例来源:origin: yahoo/squidb

  1. /**
  2. * Set the limit of this statement. Using a negative value removes the limit.
  3. *
  4. * @param limit the maximum number of rows this query should return
  5. * @return this Query object, to allow chaining method calls
  6. */
  7. public Query limit(int limit) {
  8. return limit(limit < 0 ? NO_LIMIT : Field.<Integer>field(Integer.toString(limit)));
  9. }

代码示例来源:origin: yahoo/squidb

  1. /**
  2. * Set the limit and offset of this statement. Use a negative value for limit to remove the limit. Use a value less
  3. * than one for offset to remove the offset.
  4. *
  5. * @param limit the maximum number of rows this query should return
  6. * @param offset the number of rows this query should skip
  7. * @return this Query object, to allow chaining method calls
  8. */
  9. public Query limit(int limit, int offset) {
  10. return limit(limit < 0 ? NO_LIMIT : Field.<Integer>field(Integer.toString(limit)),
  11. offset < 1 ? NO_OFFSET : Field.<Integer>field(Integer.toString(offset)));
  12. }

代码示例来源:origin: yahoo/squidb

  1. protected <TYPE extends AbstractModel> SquidCursor<TYPE> fetchFirstItem(Class<TYPE> modelClass, Query query) {
  2. boolean immutableQuery = query.isImmutable();
  3. Field<Integer> beforeLimit = query.getLimit();
  4. SqlTable<?> beforeTable = query.getTable();
  5. query = query.limit(1); // If argument was frozen, we may get a new object
  6. SquidCursor<TYPE> cursor = query(modelClass, query);
  7. if (!immutableQuery) {
  8. query.from(beforeTable).limit(beforeLimit); // Reset for user
  9. }
  10. cursor.moveToFirst();
  11. return cursor;
  12. }

代码示例来源:origin: yahoo/squidb

  1. /**
  2. * Set the limit of this statement as a SQL expression; e.g. a {@link Function} or the result of
  3. * {@link #asFunction()} to use a subquery. Use {@link #NO_LIMIT} to remove the limit.
  4. *
  5. * @param limit the maximum number of rows this query should return
  6. * @return this Query object, to allow chaining method calls
  7. */
  8. public Query limit(Field<Integer> limit) {
  9. if (limit == null) {
  10. limit = NO_LIMIT;
  11. }
  12. if (immutable) {
  13. return fork().limit(limit);
  14. }
  15. if (!this.limit.equals(limit)) {
  16. this.limit = limit;
  17. invalidateCompileCache();
  18. }
  19. return this;
  20. }

代码示例来源:origin: yahoo/squidb

  1. /**
  2. * Set the limit of this statement as a SQL expression; e.g. a {@link Function} or the result of
  3. * {@link #asFunction()} to use a subquery. Use {@link #NO_LIMIT} for limit to remove the limit. Use
  4. * {@link #NO_OFFSET} for offset to remove the offset.
  5. *
  6. * @param limit the maximum number of rows this query should return
  7. * @param offset the number of rows this query should skip
  8. * @return this Query object, to allow chaining method calls
  9. */
  10. public Query limit(Field<Integer> limit, Field<Integer> offset) {
  11. if (limit == null) {
  12. limit = NO_LIMIT;
  13. }
  14. if (offset == null) {
  15. offset = NO_OFFSET;
  16. }
  17. if (immutable) {
  18. return fork().limit(limit, offset);
  19. }
  20. if (!this.limit.equals(limit) || !this.offset.equals(offset)) {
  21. this.limit = limit;
  22. this.offset = offset;
  23. invalidateCompileCache();
  24. }
  25. return this;
  26. }

代码示例来源:origin: yahoo/squidb

  1. public void testFork() {
  2. Query base = Query.select().from(Employee.TABLE).limit(1);
  3. Query fork = base.fork().limit(2);
  4. base.limit(3);
  5. assertFalse(base == fork);
  6. assertEquals(Field.field("3"), base.getLimit());
  7. assertEquals(Field.field("2"), fork.getLimit());
  8. assertEquals(base.getTable(), fork.getTable());
  9. }

代码示例来源:origin: yahoo/squidb

  1. public void testQueryFreeze() {
  2. Query base = Query.select().from(Employee.TABLE).limit(1).freeze();
  3. Query fork = base.limit(2);
  4. assertFalse(base == fork);
  5. assertEquals(Field.field("1"), base.getLimit());
  6. assertEquals(Field.field("2"), fork.getLimit());
  7. assertEquals(base.getTable(), fork.getTable());
  8. }

代码示例来源:origin: com.yahoo.squidb/squidb

  1. /**
  2. * Set the limit of this statement. Using a negative value removes the limit.
  3. *
  4. * @param limit the maximum number of rows this query should return
  5. * @return this Query object, to allow chaining method calls
  6. */
  7. public Query limit(int limit) {
  8. return limit(limit < 0 ? NO_LIMIT : Field.<Integer>field(Integer.toString(limit)));
  9. }

代码示例来源:origin: yahoo/squidb

  1. private void testRecyclerAdapterInternal(LongProperty idProperty, RecyclerAdapterTest test) {
  2. Query query = Query.select(TestModel.PROPERTIES)
  3. .orderBy(TestModel.BIRTHDAY.asc())
  4. .limit(2);
  5. if (idProperty != null) {
  6. query.selectMore(idProperty);
  7. }
  8. SquidCursor<TestModel> cursor = database.query(TestModel.class, query);
  9. TestRecyclerAdapter adapter = new TestRecyclerAdapter(idProperty);
  10. adapter.changeCursor(cursor);
  11. try {
  12. test.testRecyclerAdapter(adapter);
  13. } finally {
  14. cursor.close();
  15. }
  16. }

代码示例来源:origin: yahoo/squidb

  1. public void testOrderByArray() {
  2. Long[] order = new Long[]{5L, 1L, 4L};
  3. SquidCursor<Employee> cursor = database.query(Employee.class,
  4. Query.select(Employee.ID).limit(order.length).orderBy(Employee.ID.byArray(order)));
  5. try {
  6. assertEquals(order.length, cursor.getCount());
  7. for (int i = 0; i < order.length; i++) {
  8. cursor.moveToPosition(i);
  9. assertEquals(order[i], cursor.get(Employee.ID));
  10. }
  11. } finally {
  12. cursor.close();
  13. }
  14. }

代码示例来源:origin: com.yahoo.squidb/squidb

  1. /**
  2. * Set the limit and offset of this statement. Use a negative value for limit to remove the limit. Use a value less
  3. * than one for offset to remove the offset.
  4. *
  5. * @param limit the maximum number of rows this query should return
  6. * @param offset the number of rows this query should skip
  7. * @return this Query object, to allow chaining method calls
  8. */
  9. public Query limit(int limit, int offset) {
  10. return limit(limit < 0 ? NO_LIMIT : Field.<Integer>field(Integer.toString(limit)),
  11. offset < 1 ? NO_OFFSET : Field.<Integer>field(Integer.toString(offset)));
  12. }

代码示例来源:origin: yahoo/squidb

  1. cursor = database.query(Employee.class, query.limit(limit, offset));
  2. assertEquals(expectedCount, cursor.getCount());
  3. try {

代码示例来源:origin: yahoo/squidb

  1. public void testFrozenQueryWorksWithDatabase() {
  2. Query query = Query.select().limit(2).freeze();
  3. SquidCursor<Employee> cursor = database.query(Employee.class, query);
  4. try {
  5. assertEquals(2, cursor.getCount());
  6. assertNull(query.getTable());
  7. } finally {
  8. cursor.close();
  9. }
  10. Employee employee = database.fetchByQuery(Employee.class, query);
  11. assertNotNull(employee);
  12. assertNull(query.getTable());
  13. assertEquals(Field.field("2"), query.getLimit());
  14. }

代码示例来源:origin: yahoo/squidb

  1. public void testInsertWithDefaultValues() {
  2. // insert into things default values;
  3. Insert insert = Insert.into(Thing.TABLE).defaultValues();
  4. CompiledStatement compiled = insert.compile(database.getCompileContext());
  5. verifyCompiledSqlArgs(compiled, 0);
  6. int rowsBeforeInsert = database.countAll(Thing.class);
  7. assertEquals(3, database.insert(insert));
  8. int rowsAfterInsert = database.countAll(Thing.class);
  9. assertEquals(rowsBeforeInsert + 1, rowsAfterInsert);
  10. // get the newest
  11. Thing newThing = null;
  12. SquidCursor<Thing> cursor = null;
  13. try {
  14. cursor = database.query(Thing.class, Query.select(Thing.PROPERTIES).orderBy(Order.desc(Thing.ID)).limit(1));
  15. if (cursor.moveToFirst()) {
  16. newThing = new Thing(cursor);
  17. }
  18. } finally {
  19. if (cursor != null) {
  20. cursor.close();
  21. }
  22. }
  23. assertNotNull(newThing);
  24. assertEquals(Thing.DEFAULT_FOO, newThing.getFoo());
  25. assertEquals(Thing.DEFAULT_BAR, newThing.getBar().intValue());
  26. assertEquals(Thing.DEFAULT_IS_ALIVE, newThing.isAlive().booleanValue());
  27. }

代码示例来源:origin: com.yahoo.squidb/squidb

  1. protected <TYPE extends AbstractModel> SquidCursor<TYPE> fetchFirstItem(Class<TYPE> modelClass, Query query) {
  2. boolean immutableQuery = query.isImmutable();
  3. Field<Integer> beforeLimit = query.getLimit();
  4. SqlTable<?> beforeTable = query.getTable();
  5. query = query.limit(1); // If argument was frozen, we may get a new object
  6. SquidCursor<TYPE> cursor = query(modelClass, query);
  7. if (!immutableQuery) {
  8. query.from(beforeTable).limit(beforeLimit); // Reset for user
  9. }
  10. cursor.moveToFirst();
  11. return cursor;
  12. }

代码示例来源:origin: com.yahoo.squidb/squidb

  1. /**
  2. * Set the limit of this statement as a SQL expression; e.g. a {@link Function} or the result of
  3. * {@link #asFunction()} to use a subquery. Use {@link #NO_LIMIT} to remove the limit.
  4. *
  5. * @param limit the maximum number of rows this query should return
  6. * @return this Query object, to allow chaining method calls
  7. */
  8. public Query limit(Field<Integer> limit) {
  9. if (limit == null) {
  10. limit = NO_LIMIT;
  11. }
  12. if (immutable) {
  13. return fork().limit(limit);
  14. }
  15. if (!this.limit.equals(limit)) {
  16. this.limit = limit;
  17. invalidateCompileCache();
  18. }
  19. return this;
  20. }

代码示例来源:origin: yahoo/squidb

  1. public void testFetchByQueryResetsLimitAndTable() {
  2. TestModel model1 = new TestModel().setFirstName("Sam1").setLastName("Bosley1");
  3. TestModel model2 = new TestModel().setFirstName("Sam2").setLastName("Bosley2");
  4. TestModel model3 = new TestModel().setFirstName("Sam3").setLastName("Bosley3");
  5. database.persist(model1);
  6. database.persist(model2);
  7. database.persist(model3);
  8. Query query = Query.select().limit(2, 1);
  9. TestModel fetched = database.fetchByQuery(TestModel.class, query);
  10. assertEquals(model2.getRowId(), fetched.getRowId());
  11. assertEquals(Field.field("2"), query.getLimit());
  12. assertEquals(Field.field("1"), query.getOffset());
  13. assertEquals(null, query.getTable());
  14. }

代码示例来源:origin: yahoo/squidb

  1. public void testLimitAndOffsetWithExpressions() {
  2. // limit = 1 + (count(*) / 4), offset = count(*) / 2
  3. Field<Integer> limit = Function.add(1, Function.divide(
  4. Query.select(IntegerProperty.countProperty()).from(Employee.TABLE).asFunction(), 4));
  5. Field<Integer> offset = Function.divide(
  6. Query.select(IntegerProperty.countProperty()).from(Employee.TABLE).asFunction(), 2);
  7. Query query = Query.select().orderBy(Employee.NAME.asc()).limit(limit, offset);
  8. SquidCursor<Employee> cursor = database.query(Employee.class, query);
  9. try {
  10. assertEquals(2, cursor.getCount());
  11. cursor.moveToFirst();
  12. assertEquals(elmo, new Employee(cursor));
  13. cursor.moveToNext();
  14. assertEquals(ernie, new Employee(cursor));
  15. } finally {
  16. cursor.close();
  17. }
  18. }

代码示例来源:origin: com.yahoo.squidb/squidb

  1. /**
  2. * Set the limit of this statement as a SQL expression; e.g. a {@link Function} or the result of
  3. * {@link #asFunction()} to use a subquery. Use {@link #NO_LIMIT} for limit to remove the limit. Use
  4. * {@link #NO_OFFSET} for offset to remove the offset.
  5. *
  6. * @param limit the maximum number of rows this query should return
  7. * @param offset the number of rows this query should skip
  8. * @return this Query object, to allow chaining method calls
  9. */
  10. public Query limit(Field<Integer> limit, Field<Integer> offset) {
  11. if (limit == null) {
  12. limit = NO_LIMIT;
  13. }
  14. if (offset == null) {
  15. offset = NO_OFFSET;
  16. }
  17. if (immutable) {
  18. return fork().limit(limit, offset);
  19. }
  20. if (!this.limit.equals(limit) || !this.offset.equals(offset)) {
  21. this.limit = limit;
  22. this.offset = offset;
  23. invalidateCompileCache();
  24. }
  25. return this;
  26. }

相关文章