本文整理汇总了Java中io.objectbox.query.Query类的典型用法代码示例。如果您正苦于以下问题:Java Query类的具体用法?Java Query怎么用?Java Query使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Query类属于io.objectbox.query包,在下文中一共展示了Query类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createListItemEmitter
import io.objectbox.query.Query; //导入依赖的package包/类
static <T> void createListItemEmitter(final Query<T> query, final FlowableEmitter<T> emitter) {
final DataSubscription dataSubscription = query.subscribe().observer(new DataObserver<List<T>>() {
@Override
public void onData(List<T> data) {
for (T datum : data) {
if (emitter.isCancelled()) {
return;
} else {
emitter.onNext(datum);
}
}
if (!emitter.isCancelled()) {
emitter.onComplete();
}
}
});
emitter.setCancellable(new Cancellable() {
@Override
public void cancel() throws Exception {
dataSubscription.cancel();
}
});
}
示例2: observable
import io.objectbox.query.Query; //导入依赖的package包/类
/**
* The returned Observable emits Query results as Lists.
* Never completes, so you will get updates when underlying data changes.
*/
public static <T> Observable<List<T>> observable(final Query<T> query) {
return Observable.create(new ObservableOnSubscribe<List<T>>() {
@Override
public void subscribe(final ObservableEmitter<List<T>> emitter) throws Exception {
final DataSubscription dataSubscription = query.subscribe().observer(new DataObserver<List<T>>() {
@Override
public void onData(List<T> data) {
if (!emitter.isDisposed()) {
emitter.onNext(data);
}
}
});
emitter.setCancellable(new Cancellable() {
@Override
public void cancel() throws Exception {
dataSubscription.cancel();
}
});
}
});
}
示例3: single
import io.objectbox.query.Query; //导入依赖的package包/类
/**
* The returned Single emits one Query result as a List.
*/
public static <T> Single<List<T>> single(final Query<T> query) {
return Single.create(new SingleOnSubscribe<List<T>>() {
@Override
public void subscribe(final SingleEmitter<List<T>> emitter) throws Exception {
final DataSubscription dataSubscription = query.subscribe().single().observer(new DataObserver<List<T>>() {
@Override
public void onData(List<T> data) {
if (!emitter.isDisposed()) {
emitter.onSuccess(data);
}
}
});
emitter.setCancellable(new Cancellable() {
@Override
public void cancel() throws Exception {
dataSubscription.cancel();
}
});
}
});
}
示例4: testOldReaderWithIndex
import io.objectbox.query.Query; //导入依赖的package包/类
@Test
public void testOldReaderWithIndex() throws InterruptedException {
final Box<EntityLongIndex> box = store.boxFor(EntityLongIndex.class);
final int initialValue = 1;
final Query<EntityLongIndex> query = box.query().equal(EntityLongIndex_.indexedLong, 0).build();
assertNull(query.findUnique());
System.out.println("BEFORE put: " + box.getReaderDebugInfo());
System.out.println("count before: " + box.count());
box.put(createEntityLongIndex(initialValue));
System.out.println("AFTER put: " + box.getReaderDebugInfo());
System.out.println("count after: " + box.count());
query.setParameter(EntityLongIndex_.indexedLong, initialValue);
assertNotNull(query.findUnique());
query.setParameter(EntityLongIndex_.indexedLong, 0);
assertNull(query.findUnique());
}
示例5: flowableOneByOne
import io.objectbox.query.Query; //导入依赖的package包/类
/**
* The returned Flowable emits Query results one by one. Once all results have been processed, onComplete is called.
* Uses given BackpressureStrategy.
*/
public static <T> Flowable<T> flowableOneByOne(final Query<T> query, BackpressureStrategy strategy) {
return Flowable.create(new FlowableOnSubscribe<T>() {
@Override
public void subscribe(final FlowableEmitter<T> emitter) throws Exception {
createListItemEmitter(query, emitter);
}
}, strategy);
}
示例6: updateUI
import io.objectbox.query.Query; //导入依赖的package包/类
private void updateUI() {
// getting items and refreshing list
Query<TrainingSet> querySetsBySessionId
= mTrainingSetBox.query().equal(TrainingSet_.sessionId, mSessionId)
.build();
List<TrainingSet> filteredRecords = querySetsBySessionId.find();
refreshList(filteredRecords);
}
示例7: updateUI
import io.objectbox.query.Query; //导入依赖的package包/类
private void updateUI() {
// getting items and refreshing list
Query<TrainingSession> queryAll
= mTrainingSessionBox.query()
.build();
List<TrainingSession> filteredRecords = queryAll.find();
refreshList(filteredRecords);
}
示例8: queryAnimeList
import io.objectbox.query.Query; //导入依赖的package包/类
@Override
public Query<Anime> queryAnimeList(String serverUrl) {
QueryBuilder<Anime> query = getAnimeBox().query();
query.contains(Anime_.url, serverUrl);
query.order(Anime_.title);
return query.build();
}
示例9: queryEpisodes
import io.objectbox.query.Query; //导入依赖的package包/类
@Override
public Query<Episode> queryEpisodes(String animeUrl) {
QueryBuilder<Episode> query = getEpisodeBox().query();
query.contains(Episode_.animeUrl, animeUrl);
query.order(Episode_.index);
return query.build();
}
示例10: testRelationToOneQuery
import io.objectbox.query.Query; //导入依赖的package包/类
@Test
public void testRelationToOneQuery() {
Customer customer = putCustomer();
Order order = putOrder(customer, "Bananas");
Query<Order> query = orderBox.query().equal(Order_.customerId, customer.getId()).build();
Order orderFound = query.findUnique();
assertEquals(order.getId(), orderFound.getId());
}
示例11: testEagerToMany_NoResult
import io.objectbox.query.Query; //导入依赖的package包/类
@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) {
}
});
}
示例12: testEagerToSingle_NoResult
import io.objectbox.query.Query; //导入依赖的package包/类
@Test
public void testEagerToSingle_NoResult() {
Query<Order> query = orderBox.query().eager(Order_.customer).build();
query.find();
query.findFirst();
query.forEach(new QueryConsumer<Order>() {
@Override
public void accept(Order data) {
}
});
}
示例13: testOverwriteIndexedValue
import io.objectbox.query.Query; //导入依赖的package包/类
@Test
public void testOverwriteIndexedValue() throws InterruptedException {
final Box<EntityLongIndex> box = store.boxFor(EntityLongIndex.class);
final int initialValue = 1;
final EntityLongIndex[] transformResults = {null, null, null};
final CountDownLatch transformLatch1 = new CountDownLatch(1);
final CountDownLatch transformLatch2 = new CountDownLatch(1);
final AtomicInteger transformerCallCount = new AtomicInteger();
final Query<EntityLongIndex> query = box.query().equal(EntityLongIndex_.indexedLong, 0).build();
store.subscribe(EntityLongIndex.class).transform(new DataTransformer<Class<EntityLongIndex>, EntityLongIndex>() {
@Override
public EntityLongIndex transform(Class<EntityLongIndex> clazz) throws Exception {
int callCount = transformerCallCount.incrementAndGet();
if (callCount == 1) {
query.setParameter(EntityLongIndex_.indexedLong, 1);
EntityLongIndex unique = query.findUnique();
transformLatch1.countDown();
return unique;
} else if (callCount == 2) {
query.setParameter(EntityLongIndex_.indexedLong, 1);
transformResults[0] = query.findUnique();
transformResults[1] = query.findUnique();
query.setParameter(EntityLongIndex_.indexedLong, 0);
transformResults[2] = query.findUnique();
transformLatch2.countDown();
return transformResults[0];
} else {
throw new RuntimeException("Unexpected: " + callCount);
}
}
}).observer(new DataObserver<EntityLongIndex>() {
@Override
public void onData(EntityLongIndex data) {
// Dummy
}
});
assertTrue(transformLatch1.await(5, TimeUnit.SECONDS));
box.put(createEntityLongIndex(initialValue));
assertTrue(transformLatch2.await(5, TimeUnit.SECONDS));
assertEquals(2, transformerCallCount.intValue());
assertNotNull(transformResults[0]);
assertNotNull(transformResults[1]);
assertNull(transformResults[2]);
query.setParameter(EntityLongIndex_.indexedLong, initialValue);
assertNotNull(query.findUnique());
query.setParameter(EntityLongIndex_.indexedLong, initialValue);
assertNotNull(query.findUnique());
assertNotNull(query.findUnique());
}
示例14: testOldReaderInThread
import io.objectbox.query.Query; //导入依赖的package包/类
@Test
public void testOldReaderInThread() throws InterruptedException {
final Box<EntityLongIndex> box = store.boxFor(EntityLongIndex.class);
final int initialValue = 1;
final EntityLongIndex[] results = new EntityLongIndex[5];
final CountDownLatch latchRead1 = new CountDownLatch(1);
final CountDownLatch latchPut = new CountDownLatch(1);
final CountDownLatch latchRead2 = new CountDownLatch(1);
final Query<EntityLongIndex> query = box.query().equal(EntityLongIndex_.indexedLong, 0).build();
new Thread() {
@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();
assertTrue(latchRead1.await(5, TimeUnit.SECONDS));
box.put(createEntityLongIndex(initialValue));
latchPut.countDown();
assertTrue(latchRead2.await(5, TimeUnit.SECONDS));
assertNotNull(results[1]);
assertNotNull(results[0]);
assertNotNull(results[2]);
assertNull(results[3]);
query.setParameter(EntityLongIndex_.indexedLong, initialValue);
assertNotNull(query.findUnique());
query.setParameter(EntityLongIndex_.indexedLong, initialValue);
assertNotNull(query.findUnique());
assertNotNull(query.findUnique());
}
示例15: queryAnimeList
import io.objectbox.query.Query; //导入依赖的package包/类
Query<Anime> queryAnimeList(String serverUrl);