本文整理了Java中com.yahoo.squidb.sql.Query.limit
方法的一些代码示例,展示了Query.limit
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.limit
方法的具体详情如下:
包路径:com.yahoo.squidb.sql.Query
类名称:Query
方法名:limit
[英]Set the limit of this statement. Using a negative value removes the limit.
[中]设置此语句的限制。使用负值可以消除限制。
代码示例来源:origin: yahoo/squidb
/**
* Set the limit of this statement. Using a negative value removes the limit.
*
* @param limit the maximum number of rows this query should return
* @return this Query object, to allow chaining method calls
*/
public Query limit(int limit) {
return limit(limit < 0 ? NO_LIMIT : Field.<Integer>field(Integer.toString(limit)));
}
代码示例来源:origin: yahoo/squidb
/**
* Set the limit and offset of this statement. Use a negative value for limit to remove the limit. Use a value less
* than one for offset to remove the offset.
*
* @param limit the maximum number of rows this query should return
* @param offset the number of rows this query should skip
* @return this Query object, to allow chaining method calls
*/
public Query limit(int limit, int offset) {
return limit(limit < 0 ? NO_LIMIT : Field.<Integer>field(Integer.toString(limit)),
offset < 1 ? NO_OFFSET : Field.<Integer>field(Integer.toString(offset)));
}
代码示例来源:origin: yahoo/squidb
protected <TYPE extends AbstractModel> SquidCursor<TYPE> fetchFirstItem(Class<TYPE> modelClass, Query query) {
boolean immutableQuery = query.isImmutable();
Field<Integer> beforeLimit = query.getLimit();
SqlTable<?> beforeTable = query.getTable();
query = query.limit(1); // If argument was frozen, we may get a new object
SquidCursor<TYPE> cursor = query(modelClass, query);
if (!immutableQuery) {
query.from(beforeTable).limit(beforeLimit); // Reset for user
}
cursor.moveToFirst();
return cursor;
}
代码示例来源:origin: yahoo/squidb
/**
* Set the limit of this statement as a SQL expression; e.g. a {@link Function} or the result of
* {@link #asFunction()} to use a subquery. Use {@link #NO_LIMIT} to remove the limit.
*
* @param limit the maximum number of rows this query should return
* @return this Query object, to allow chaining method calls
*/
public Query limit(Field<Integer> limit) {
if (limit == null) {
limit = NO_LIMIT;
}
if (immutable) {
return fork().limit(limit);
}
if (!this.limit.equals(limit)) {
this.limit = limit;
invalidateCompileCache();
}
return this;
}
代码示例来源:origin: yahoo/squidb
/**
* Set the limit of this statement as a SQL expression; e.g. a {@link Function} or the result of
* {@link #asFunction()} to use a subquery. Use {@link #NO_LIMIT} for limit to remove the limit. Use
* {@link #NO_OFFSET} for offset to remove the offset.
*
* @param limit the maximum number of rows this query should return
* @param offset the number of rows this query should skip
* @return this Query object, to allow chaining method calls
*/
public Query limit(Field<Integer> limit, Field<Integer> offset) {
if (limit == null) {
limit = NO_LIMIT;
}
if (offset == null) {
offset = NO_OFFSET;
}
if (immutable) {
return fork().limit(limit, offset);
}
if (!this.limit.equals(limit) || !this.offset.equals(offset)) {
this.limit = limit;
this.offset = offset;
invalidateCompileCache();
}
return this;
}
代码示例来源:origin: yahoo/squidb
public void testFork() {
Query base = Query.select().from(Employee.TABLE).limit(1);
Query fork = base.fork().limit(2);
base.limit(3);
assertFalse(base == fork);
assertEquals(Field.field("3"), base.getLimit());
assertEquals(Field.field("2"), fork.getLimit());
assertEquals(base.getTable(), fork.getTable());
}
代码示例来源:origin: yahoo/squidb
public void testQueryFreeze() {
Query base = Query.select().from(Employee.TABLE).limit(1).freeze();
Query fork = base.limit(2);
assertFalse(base == fork);
assertEquals(Field.field("1"), base.getLimit());
assertEquals(Field.field("2"), fork.getLimit());
assertEquals(base.getTable(), fork.getTable());
}
代码示例来源:origin: com.yahoo.squidb/squidb
/**
* Set the limit of this statement. Using a negative value removes the limit.
*
* @param limit the maximum number of rows this query should return
* @return this Query object, to allow chaining method calls
*/
public Query limit(int limit) {
return limit(limit < 0 ? NO_LIMIT : Field.<Integer>field(Integer.toString(limit)));
}
代码示例来源:origin: yahoo/squidb
private void testRecyclerAdapterInternal(LongProperty idProperty, RecyclerAdapterTest test) {
Query query = Query.select(TestModel.PROPERTIES)
.orderBy(TestModel.BIRTHDAY.asc())
.limit(2);
if (idProperty != null) {
query.selectMore(idProperty);
}
SquidCursor<TestModel> cursor = database.query(TestModel.class, query);
TestRecyclerAdapter adapter = new TestRecyclerAdapter(idProperty);
adapter.changeCursor(cursor);
try {
test.testRecyclerAdapter(adapter);
} finally {
cursor.close();
}
}
代码示例来源:origin: yahoo/squidb
public void testOrderByArray() {
Long[] order = new Long[]{5L, 1L, 4L};
SquidCursor<Employee> cursor = database.query(Employee.class,
Query.select(Employee.ID).limit(order.length).orderBy(Employee.ID.byArray(order)));
try {
assertEquals(order.length, cursor.getCount());
for (int i = 0; i < order.length; i++) {
cursor.moveToPosition(i);
assertEquals(order[i], cursor.get(Employee.ID));
}
} finally {
cursor.close();
}
}
代码示例来源:origin: com.yahoo.squidb/squidb
/**
* Set the limit and offset of this statement. Use a negative value for limit to remove the limit. Use a value less
* than one for offset to remove the offset.
*
* @param limit the maximum number of rows this query should return
* @param offset the number of rows this query should skip
* @return this Query object, to allow chaining method calls
*/
public Query limit(int limit, int offset) {
return limit(limit < 0 ? NO_LIMIT : Field.<Integer>field(Integer.toString(limit)),
offset < 1 ? NO_OFFSET : Field.<Integer>field(Integer.toString(offset)));
}
代码示例来源:origin: yahoo/squidb
cursor = database.query(Employee.class, query.limit(limit, offset));
assertEquals(expectedCount, cursor.getCount());
try {
代码示例来源:origin: yahoo/squidb
public void testFrozenQueryWorksWithDatabase() {
Query query = Query.select().limit(2).freeze();
SquidCursor<Employee> cursor = database.query(Employee.class, query);
try {
assertEquals(2, cursor.getCount());
assertNull(query.getTable());
} finally {
cursor.close();
}
Employee employee = database.fetchByQuery(Employee.class, query);
assertNotNull(employee);
assertNull(query.getTable());
assertEquals(Field.field("2"), query.getLimit());
}
代码示例来源:origin: yahoo/squidb
public void testInsertWithDefaultValues() {
// insert into things default values;
Insert insert = Insert.into(Thing.TABLE).defaultValues();
CompiledStatement compiled = insert.compile(database.getCompileContext());
verifyCompiledSqlArgs(compiled, 0);
int rowsBeforeInsert = database.countAll(Thing.class);
assertEquals(3, database.insert(insert));
int rowsAfterInsert = database.countAll(Thing.class);
assertEquals(rowsBeforeInsert + 1, rowsAfterInsert);
// get the newest
Thing newThing = null;
SquidCursor<Thing> cursor = null;
try {
cursor = database.query(Thing.class, Query.select(Thing.PROPERTIES).orderBy(Order.desc(Thing.ID)).limit(1));
if (cursor.moveToFirst()) {
newThing = new Thing(cursor);
}
} finally {
if (cursor != null) {
cursor.close();
}
}
assertNotNull(newThing);
assertEquals(Thing.DEFAULT_FOO, newThing.getFoo());
assertEquals(Thing.DEFAULT_BAR, newThing.getBar().intValue());
assertEquals(Thing.DEFAULT_IS_ALIVE, newThing.isAlive().booleanValue());
}
代码示例来源:origin: com.yahoo.squidb/squidb
protected <TYPE extends AbstractModel> SquidCursor<TYPE> fetchFirstItem(Class<TYPE> modelClass, Query query) {
boolean immutableQuery = query.isImmutable();
Field<Integer> beforeLimit = query.getLimit();
SqlTable<?> beforeTable = query.getTable();
query = query.limit(1); // If argument was frozen, we may get a new object
SquidCursor<TYPE> cursor = query(modelClass, query);
if (!immutableQuery) {
query.from(beforeTable).limit(beforeLimit); // Reset for user
}
cursor.moveToFirst();
return cursor;
}
代码示例来源:origin: com.yahoo.squidb/squidb
/**
* Set the limit of this statement as a SQL expression; e.g. a {@link Function} or the result of
* {@link #asFunction()} to use a subquery. Use {@link #NO_LIMIT} to remove the limit.
*
* @param limit the maximum number of rows this query should return
* @return this Query object, to allow chaining method calls
*/
public Query limit(Field<Integer> limit) {
if (limit == null) {
limit = NO_LIMIT;
}
if (immutable) {
return fork().limit(limit);
}
if (!this.limit.equals(limit)) {
this.limit = limit;
invalidateCompileCache();
}
return this;
}
代码示例来源:origin: yahoo/squidb
public void testFetchByQueryResetsLimitAndTable() {
TestModel model1 = new TestModel().setFirstName("Sam1").setLastName("Bosley1");
TestModel model2 = new TestModel().setFirstName("Sam2").setLastName("Bosley2");
TestModel model3 = new TestModel().setFirstName("Sam3").setLastName("Bosley3");
database.persist(model1);
database.persist(model2);
database.persist(model3);
Query query = Query.select().limit(2, 1);
TestModel fetched = database.fetchByQuery(TestModel.class, query);
assertEquals(model2.getRowId(), fetched.getRowId());
assertEquals(Field.field("2"), query.getLimit());
assertEquals(Field.field("1"), query.getOffset());
assertEquals(null, query.getTable());
}
代码示例来源:origin: yahoo/squidb
public void testLimitAndOffsetWithExpressions() {
// limit = 1 + (count(*) / 4), offset = count(*) / 2
Field<Integer> limit = Function.add(1, Function.divide(
Query.select(IntegerProperty.countProperty()).from(Employee.TABLE).asFunction(), 4));
Field<Integer> offset = Function.divide(
Query.select(IntegerProperty.countProperty()).from(Employee.TABLE).asFunction(), 2);
Query query = Query.select().orderBy(Employee.NAME.asc()).limit(limit, offset);
SquidCursor<Employee> cursor = database.query(Employee.class, query);
try {
assertEquals(2, cursor.getCount());
cursor.moveToFirst();
assertEquals(elmo, new Employee(cursor));
cursor.moveToNext();
assertEquals(ernie, new Employee(cursor));
} finally {
cursor.close();
}
}
代码示例来源:origin: com.yahoo.squidb/squidb
/**
* Set the limit of this statement as a SQL expression; e.g. a {@link Function} or the result of
* {@link #asFunction()} to use a subquery. Use {@link #NO_LIMIT} for limit to remove the limit. Use
* {@link #NO_OFFSET} for offset to remove the offset.
*
* @param limit the maximum number of rows this query should return
* @param offset the number of rows this query should skip
* @return this Query object, to allow chaining method calls
*/
public Query limit(Field<Integer> limit, Field<Integer> offset) {
if (limit == null) {
limit = NO_LIMIT;
}
if (offset == null) {
offset = NO_OFFSET;
}
if (immutable) {
return fork().limit(limit, offset);
}
if (!this.limit.equals(limit) || !this.offset.equals(offset)) {
this.limit = limit;
this.offset = offset;
invalidateCompileCache();
}
return this;
}
内容来源于网络,如有侵权,请联系作者删除!