本文整理了Java中io.objectbox.query.Query
类的一些代码示例,展示了Query
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query
类的具体详情如下:
包路径:io.objectbox.query.Query
类名称:Query
[英]A repeatable query returning entities.
[中]返回实体的可重复查询。
代码示例来源:origin: objectbox/objectbox-java
@Override
public void run() {
List<T> result = query.find();
observer.onData(result);
}
});
代码示例来源:origin: objectbox/objectbox-java
/**
* Convenience for {@link #subscribe()} with a subsequent call to
* {@link SubscriptionBuilder#dataSubscriptionList(DataSubscriptionList)}.
*
* @param dataSubscriptionList the resulting {@link io.objectbox.reactive.DataSubscription} will be added to it
*/
public SubscriptionBuilder<List<T>> subscribe(DataSubscriptionList dataSubscriptionList) {
SubscriptionBuilder<List<T>> subscriptionBuilder = subscribe();
subscriptionBuilder.dataSubscriptionList(dataSubscriptionList);
return subscriptionBuilder;
}
代码示例来源:origin: objectbox/objectbox-java
@Override
public void run() {
query.setParameter(EntityLongIndex_.indexedLong, initialValue);
EntityLongIndex unique = query.findUnique();
assertNull(unique);
latchRead1.countDown();
System.out.println("BEFORE put: " + box.getReaderDebugInfo());
System.out.println("count before: " + box.count());
try {
latchPut.await();
} catch (InterruptedException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
System.out.println("AFTER put: " + box.getReaderDebugInfo());
System.out.println("count after: " + box.count());
query.setParameter(EntityLongIndex_.indexedLong, initialValue);
results[0] = query.findUnique();
results[1] = box.get(1);
results[2] = query.findUnique();
query.setParameter(EntityLongIndex_.indexedLong, 0);
results[3] = query.findUnique();
latchRead2.countDown();
}
}.start();
代码示例来源:origin: objectbox/objectbox-java
/**
* Find all Objects matching the query without actually loading the Objects. See @{@link LazyList} for details.
*/
public LazyList<T> findLazy() {
ensureNoFilterNoComparator();
return new LazyList<>(box, findIds(), false);
}
代码示例来源:origin: objectbox/objectbox-java
@Override
public void run() {
LazyList<T> lazyList = new LazyList<>(box, findIds(), false);
int size = lazyList.size();
for (int i = 0; i < size; i++) {
T entity = lazyList.get(i);
if (entity == null) {
throw new IllegalStateException("Internal error: data object was null");
}
if (filter != null) {
if (!filter.keep(entity)) {
continue;
}
}
if (eagerRelations != null) {
resolveEagerRelationForNonNullEagerRelations(entity, i);
}
try {
consumer.accept(entity);
} catch (BreakForEach breakForEach) {
break;
}
}
}
});
代码示例来源: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 testStringGreater() {
putTestEntitiesStrings();
putTestEntity("FOO", 100);
Query<TestEntity> query = box.query().greater(simpleString, "banana juice").order(simpleString).build();
List<TestEntity> entities = query.find();
assertEquals(4, entities.size());
assertEquals("banana milk shake", entities.get(0).getSimpleString());
assertEquals("bar", entities.get(1).getSimpleString());
assertEquals("FOO", entities.get(2).getSimpleString());
assertEquals("foo bar", entities.get(3).getSimpleString());
query.setParameter(simpleString, "FO");
entities = query.find();
assertEquals(2, entities.size());
assertEquals("FOO", entities.get(0).getSimpleString());
assertEquals("foo bar", entities.get(1).getSimpleString());
// Case sensitive
query = box.query().greater(simpleString, "banana", StringOrder.CASE_SENSITIVE).order(simpleString).build();
entities = query.find();
assertEquals(3, entities.size());
assertEquals("banana milk shake", entities.get(0).getSimpleString());
assertEquals("bar", entities.get(1).getSimpleString());
assertEquals("foo bar", entities.get(2).getSimpleString());
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testSetParameter2Floats() {
putTestEntitiesScalars();
Query<TestEntity> query = box.query().between(simpleFloat, 400.15, 400.75).parameterAlias("foo").build();
assertEquals(6, query.count());
query.setParameters(simpleFloat, 400.65, 400.85);
List<TestEntity> entities = query.find();
assertEquals(2, entities.size());
assertEquals(8, entities.get(0).getId());
assertEquals(9, entities.get(1).getId());
query.setParameters("foo", 400.45, 400.55);
assertEquals(6, query.findUnique().getId());
}
代码示例来源:origin: objectbox/objectbox-java
List<Order> orders = orderBox.query().eager(Order_.customer).build().find();
assertEquals(2, orders.size());
assertTrue(orders.get(0).customer__toOne.isResolved());
orders = orderBox.query().eager(Order_.customer).build().find(0, 10);
assertEquals(2, orders.size());
assertTrue(orders.get(0).customer__toOne.isResolved());
orders = orderBox.query().eager(1, Order_.customer).build().find();
assertEquals(2, orders.size());
assertTrue(orders.get(0).customer__toOne.isResolved());
customerBox.query().eager(1, Customer_.orders).build().forEach(new QueryConsumer<Customer>() {
@Override
public void accept(Customer data) {
Order order = orderBox.query().eager(Order_.customer).build().findFirst();
assertTrue(order.customer__toOne.isResolved());
order = orderBox.query().eager(Order_.customer).build().findUnique();
assertTrue(order.customer__toOne.isResolved());
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testScalarEqual() {
putTestEntitiesScalars();
Query<TestEntity> query = box.query().equal(simpleInt, 2007).build();
assertEquals(1, query.count());
assertEquals(8, query.findFirst().getId());
assertEquals(8, query.findUnique().getId());
List<TestEntity> all = query.find();
assertEquals(1, all.size());
assertEquals(8, all.get(0).getId());
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testStringLess() {
putTestEntitiesStrings();
putTestEntity("BaNaNa Split", 100);
Query<TestEntity> query = box.query().less(simpleString, "banana juice").order(simpleString).build();
List<TestEntity> entities = query.find();
assertEquals(2, entities.size());
assertEquals("apple", entities.get(0).getSimpleString());
assertEquals("banana", entities.get(1).getSimpleString());
query.setParameter(simpleString, "BANANA MZ");
entities = query.find();
assertEquals(3, entities.size());
assertEquals("apple", entities.get(0).getSimpleString());
assertEquals("banana", entities.get(1).getSimpleString());
assertEquals("banana milk shake", entities.get(2).getSimpleString());
// Case sensitive
query = box.query().less(simpleString, "BANANA", StringOrder.CASE_SENSITIVE).order(simpleString).build();
assertEquals(0, query.count());
query.setParameter(simpleString, "banana a");
entities = query.find();
assertEquals(3, entities.size());
assertEquals("apple", entities.get(0).getSimpleString());
assertEquals("banana", entities.get(1).getSimpleString());
assertEquals("BaNaNa Split", entities.get(2).getSimpleString());
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testNoConditions() {
List<TestEntity> entities = putTestEntitiesScalars();
Query<TestEntity> query = box.query().build();
List<TestEntity> all = query.find();
assertEquals(entities.size(), all.size());
assertEquals(entities.size(), query.count());
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testObserver() {
int[] valuesInt = {2003, 2007, 2002};
Query<TestEntity> query = box.query().in(simpleInt, valuesInt).build();
assertEquals(0, query.count());
query.subscribe().observer(this);
assertLatchCountedDown(latch, 5);
assertEquals(1, receivedChanges.size());
assertEquals(0, receivedChanges.get(0).size());
receivedChanges.clear();
latch = new CountDownLatch(1);
putTestEntitiesScalars();
assertLatchCountedDown(latch, 5);
assertEquals(1, receivedChanges.size());
assertEquals(3, receivedChanges.get(0).size());
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testStringIn() {
putTestEntitiesStrings();
putTestEntity("BAR", 100);
String[] values = {"bar", "foo bar"};
Query<TestEntity> query = box.query().in(simpleString, values).order(simpleString, OrderFlags.CASE_SENSITIVE)
.build();
List<TestEntity> entities = query.find();
assertEquals(3, entities.size());
assertEquals("BAR", entities.get(0).getSimpleString());
assertEquals("bar", entities.get(1).getSimpleString());
assertEquals("foo bar", entities.get(2).getSimpleString());
String[] values2 = {"bar"};
query.setParameters(simpleString, values2);
entities = query.find();
assertEquals(2, entities.size());
assertEquals("BAR", entities.get(0).getSimpleString());
assertEquals("bar", entities.get(1).getSimpleString());
// Case sensitive
query = box.query().in(simpleString, values, StringOrder.CASE_SENSITIVE).order(simpleString).build();
entities = query.find();
assertEquals(2, entities.size());
assertEquals("bar", entities.get(0).getSimpleString());
assertEquals("foo bar", entities.get(1).getSimpleString());
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testBooleanEqual() {
putTestEntitiesScalars();
Query<TestEntity> query = box.query().equal(simpleBoolean, true).build();
assertEquals(5, query.count());
assertEquals(1, query.findFirst().getId());
query.setParameter(simpleBoolean, false);
assertEquals(5, query.count());
assertEquals(2, query.findFirst().getId());
}
代码示例来源:origin: objectbox/objectbox-java
/**
* Sets a parameter previously given to the {@link QueryBuilder} to a new value.
*/
public Query<T> setParameter(Property property, boolean value) {
return setParameter(property, value ? 1 : 0);
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testFailedUnique_exceptionListener() {
final Exception[] exs = {null};
DbExceptionListener exceptionListener = new DbExceptionListener() {
@Override
public void onDbException(Exception e) {
exs[0] = e;
}
};
putTestEntitiesStrings();
Query<TestEntity> query = box.query().build();
store.setDbExceptionListener(exceptionListener);
try {
query.findUnique();
fail("Should have thrown");
} catch (NonUniqueResultException e) {
assertSame(e, exs[0]);
}
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testLongIn() {
putTestEntitiesScalars();
long[] valuesLong = {1, 1, 2, 3, 3003, 3007, 3002, -1};
Query<TestEntity> query = box.query().in(simpleLong, valuesLong).parameterAlias("long").build();
assertEquals(3, query.count());
long[] valuesLong2 = {3003};
query.setParameters(simpleLong, valuesLong2);
assertEquals(1, query.count());
long[] valuesLong3 = {3003, 3007};
query.setParameters("long", valuesLong3);
assertEquals(2, query.count());
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testSetParameterFloat() {
putTestEntitiesScalars();
Query<TestEntity> query = box.query().greater(simpleFloat, 400.65).parameterAlias("foo").build();
assertEquals(3, query.count());
query.setParameter(simpleFloat, 400.75);
assertEquals(2, query.count());
query.setParameter("foo", 400.85);
assertEquals(1, query.count());
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testFindInt() {
Query<TestEntity> query = box.query().greater(simpleLong, 1002).build();
assertNull(query.property(simpleInt).findInt());
assertNull(query.property(simpleInt).unique().findInt());
putTestEntities(5);
assertEquals(3, (int) query.property(simpleInt).findInt());
query = box.query().greater(simpleLong, 1004).build();
assertEquals(5, (int) query.property(simpleInt).distinct().unique().findInt());
TestEntityCursor.INT_NULL_HACK = true;
try {
putTestEntity(null, 6);
} finally {
TestEntityCursor.INT_NULL_HACK = false;
}
query.setParameter(simpleLong, 1005);
assertEquals(-99, (int) query.property(simpleInt).nullValue(-99).unique().findInt());
}
内容来源于网络,如有侵权,请联系作者删除!