本文整理汇总了Java中io.objectbox.query.Query.setParameter方法的典型用法代码示例。如果您正苦于以下问题:Java Query.setParameter方法的具体用法?Java Query.setParameter怎么用?Java Query.setParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.objectbox.query.Query
的用法示例。
在下文中一共展示了Query.setParameter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
示例2: 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());
}
示例3: 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());
}