use of io.requery.query.Result in project requery by requery.
the class EntityDataStore method delete.
@Override
public <E extends T> Void delete(Iterable<E> entities) {
if (entities instanceof Result) {
// work around for sqlite since the read cursor can't be open during the transaction
@SuppressWarnings("unchecked") Result<E> result = (Result<E>) entities;
entities = result.toList();
}
Iterator<E> iterator = entities.iterator();
if (iterator.hasNext()) {
try (TransactionScope transaction = new TransactionScope(transactionProvider)) {
E entity = iterator.next();
EntityProxy<E> proxy = context.proxyOf(entity, true);
EntityWriter<E, T> writer = context.write(proxy.type().getClassType());
writer.delete(entities);
transaction.commit();
}
}
return null;
}
use of io.requery.query.Result in project requery by requery.
the class RxTest method testQuerySelfObservable.
@Test
public void testQuerySelfObservable() throws Exception {
final AtomicInteger count = new AtomicInteger();
data.select(Person.class).get().toSelfObservable().subscribe(new Action1<Result<Person>>() {
@Override
public void call(Result<Person> persons) {
count.incrementAndGet();
}
});
data.insert(randomPerson()).toBlocking().value();
data.insert(randomPerson()).toBlocking().value();
assertEquals(3, count.get());
}
use of io.requery.query.Result in project requery by requery.
the class RxTest method testQuerySelfObservableRelational.
@Test
public void testQuerySelfObservableRelational() throws Exception {
final AtomicInteger count = new AtomicInteger();
Subscription subscription = data.select(Person.class).get().toSelfObservable().subscribe(new Action1<Result<Person>>() {
@Override
public void call(Result<Person> persons) {
count.incrementAndGet();
}
});
Person person = randomPerson();
data.insert(person).toBlocking().value();
Phone phone = randomPhone();
person.getPhoneNumbers().add(phone);
data.update(person).toBlocking().value();
data.delete(phone).toBlocking().value();
assertEquals(4, count.get());
subscription.unsubscribe();
}
use of io.requery.query.Result in project requery by requery.
the class ReactiveTest method testQuerySelfObservableRelational.
@Test
public void testQuerySelfObservableRelational() throws Exception {
final AtomicInteger count = new AtomicInteger();
Disposable disposable = data.select(Person.class).get().observableResult().subscribe(new Consumer<Result<Person>>() {
@Override
public void accept(Result<Person> persons) {
count.incrementAndGet();
}
});
Person person = randomPerson();
data.insert(person).blockingGet();
Phone phone = randomPhone();
person.getPhoneNumbers().add(phone);
data.update(person).blockingGet();
data.delete(phone).blockingGet();
assertEquals(4, count.get());
disposable.dispose();
}
use of io.requery.query.Result in project requery by requery.
the class RxTest method testSelfObservableDelete.
@Test
public void testSelfObservableDelete() throws Exception {
final AtomicInteger count = new AtomicInteger();
Subscription subscription = data.select(Person.class).get().toSelfObservable().subscribe(new Action1<Result<Person>>() {
@Override
public void call(Result<Person> persons) {
count.incrementAndGet();
}
});
Person person = randomPerson();
data.insert(person).toBlocking().value();
data.delete(person).toBlocking().value();
assertEquals(3, count.get());
subscription.unsubscribe();
}
Aggregations