本文整理了Java中io.objectbox.Box.query()
方法的一些代码示例,展示了Box.query()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Box.query()
方法的具体详情如下:
包路径:io.objectbox.Box
类名称:Box
方法名:query
[英]Returns a builder to create queries for Object matching supplied criteria.
[中]返回生成器以创建与提供的条件匹配的对象查询。
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testBuild() {
Query query = box.query().build();
assertNotNull(query);
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testByteArrayLess() {
putTestEntitiesScalars();
byte[] value = {1, 2, (byte) 2005};
Query<TestEntity> query = box.query().less(simpleByteArray, value).build();
List<TestEntity> results = query.find();
assertEquals(5, results.size());
// Java does not have compareTo for arrays, so just make sure its not equal to the value
for (TestEntity result : results) {
assertFalse(Arrays.equals(value, result.getSimpleByteArray()));
}
}
代码示例来源:origin: objectbox/objectbox-java
@Test(expected = IllegalArgumentException.class)
public void testFindInts_wrongPropertyType() {
putTestEntitiesStrings();
box.query().build().property(simpleLong).findInts();
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testScalarNotEqual() {
List<TestEntity> entities = putTestEntitiesScalars();
Query<TestEntity> query = box.query().notEqual(simpleInt, 2007).notEqual(simpleInt, 2002).build();
assertEquals(entities.size() - 2, query.count());
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testEagerToMany_NoResult() {
Query<Customer> query = customerBox.query().eager(Customer_.orders).build();
query.find();
query.findFirst();
query.forEach(new QueryConsumer<Customer>() {
@Override
public void accept(Customer data) {
}
});
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testIterator() {
List<TestEntity> list = putTestEntities(100);
LazyList<TestEntity> listLazy = getTestEntityBox().query().build().findLazyCached();
testIterator(list, listLazy, false);
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testFindIds() {
putTestEntitiesScalars();
assertEquals(10, box.query().build().findIds().length);
Query<TestEntity> query = box.query().greater(simpleInt, 2006).build();
long[] keys = query.findIds();
assertEquals(3, keys.length);
assertEquals(8, keys[0]);
assertEquals(9, keys[1]);
assertEquals(10, keys[2]);
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testGetAll100Uncached() {
List<TestEntity> list = putTestEntities(100);
LazyList<TestEntity> listLazy = getTestEntityBox().query().build()
.findLazy();
assertIds(list, listLazy);
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testAnd() {
putTestEntitiesScalars();
// OR precedence (wrong): {}, AND precedence (expected): 2008
Query<TestEntity> query = box.query().equal(simpleInt, 2006).and().equal(simpleInt, 2007).or().equal(simpleInt, 2008).build();
List<TestEntity> entities = query.find();
assertEquals(1, entities.size());
assertEquals(2008, entities.get(0).getSimpleInt());
}
代码示例来源:origin: objectbox/objectbox-java
@Test(expected = DbException.class)
public void testFindInt_uniqueFails() {
putTestEntity(null, 1);
putTestEntity(null, 1);
box.query().build().property(simpleInt).unique().findInt();
}
代码示例来源:origin: objectbox/objectbox-java
@Test(expected = DbException.class)
public void testFindShort_uniqueFails() {
putTestEntity(null, 1);
putTestEntity(null, 1);
box.query().build().property(simpleShort).unique().findShort();
}
代码示例来源:origin: objectbox/objectbox-java
@Test(expected = DbException.class)
public void testFindBoolean_uniqueFails() {
putTestEntity(null, 1);
putTestEntity(null, 1);
box.query().build().property(simpleBoolean).unique().findBoolean();
}
代码示例来源:origin: objectbox/objectbox-java
@Test(expected = DbException.class)
public void testFindFloat_uniqueFails() {
putTestEntity(null, 1);
putTestEntity(null, 1);
box.query().build().property(simpleFloat).unique().findFloat();
}
代码示例来源:origin: objectbox/objectbox-java
@Test(expected = DbException.class)
public void testFindDouble_uniqueFails() {
putTestEntity(null, 1);
putTestEntity(null, 1);
box.query().build().property(simpleDouble).unique().findDouble();
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testEmpty() {
putTestEntities(1);
LazyList<TestEntity> listLazy = getTestEntityBox().query().equal(TestEntity_.simpleInt, -1).build().findLazyCached();
assertTrue(listLazy.isEmpty());
try {
listLazy.get(0);
fail("Not empty");
} catch (RuntimeException e) {
// Expected, OK
}
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testFindShort() {
Query<TestEntity> query = box.query().greater(simpleLong, 1002).build();
assertNull(query.property(simpleShort).findShort());
assertNull(query.property(simpleShort).unique().findShort());
putTestEntities(5);
assertEquals(103, (short) query.property(simpleShort).findShort());
query = box.query().greater(simpleLong, 1004).build();
assertEquals(105, (short) query.property(simpleShort).distinct().unique().findShort());
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testFindBoolean() {
Query<TestEntity> query = box.query().greater(simpleLong, 1002).build();
assertNull(query.property(simpleBoolean).findBoolean());
assertNull(query.property(simpleBoolean).unique().findBoolean());
putTestEntities(5);
assertFalse(query.property(simpleBoolean).findBoolean());
query = box.query().greater(simpleLong, 1004).build();
assertFalse(query.property(simpleBoolean).distinct().unique().findBoolean());
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testFindFloat() {
Query<TestEntity> query = box.query().greater(simpleLong, 1002).build();
assertNull(query.property(simpleFloat).findFloat());
assertNull(query.property(simpleFloat).unique().findFloat());
putTestEntities(5);
assertEquals(200.3f, query.property(simpleFloat).findFloat(), 0.001f);
query = box.query().greater(simpleLong, 1004).build();
assertEquals(200.5f, query.property(simpleFloat).distinct().unique().findFloat(), 0.001f);
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testFindDouble() {
Query<TestEntity> query = box.query().greater(simpleLong, 1002).build();
assertNull(query.property(simpleDouble).findDouble());
assertNull(query.property(simpleDouble).unique().findDouble());
putTestEntities(5);
assertEquals(2000.03, query.property(simpleDouble).findDouble(), 0.001);
query = box.query().greater(simpleLong, 1004).build();
assertEquals(2000.05, query.property(simpleDouble).distinct().unique().findDouble(), 0.001);
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testSetParameterString() {
putTestEntitiesStrings();
Query<TestEntity> query = box.query().equal(simpleString, "banana").parameterAlias("foo").build();
assertEquals(1, query.findUnique().getId());
query.setParameter(simpleString, "bar");
assertEquals(3, query.findUnique().getId());
assertNull(query.setParameter(simpleString, "not here!").findUnique());
query.setParameter("foo", "apple");
assertEquals(2, query.findUnique().getId());
}
内容来源于网络,如有侵权,请联系作者删除!