Search in sources :

Example 1 with Result

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;
}
Also used : INSERT(io.requery.query.element.QueryType.INSERT) SELECT(io.requery.query.element.QueryType.SELECT) UPDATE(io.requery.query.element.QueryType.UPDATE) DELETE(io.requery.query.element.QueryType.DELETE) Result(io.requery.query.Result)

Example 2 with Result

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());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Person(io.requery.test.model.Person) RxResult(io.requery.rx.RxResult) Result(io.requery.query.Result) Test(org.junit.Test)

Example 3 with Result

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();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Phone(io.requery.test.model.Phone) Subscription(rx.Subscription) Person(io.requery.test.model.Person) RxResult(io.requery.rx.RxResult) Result(io.requery.query.Result) Test(org.junit.Test)

Example 4 with Result

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();
}
Also used : Disposable(io.reactivex.disposables.Disposable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Phone(io.requery.test.model.Phone) Person(io.requery.test.model.Person) ReactiveResult(io.requery.reactivex.ReactiveResult) Result(io.requery.query.Result) Test(org.junit.Test)

Example 5 with Result

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();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(rx.Subscription) Person(io.requery.test.model.Person) RxResult(io.requery.rx.RxResult) Result(io.requery.query.Result) Test(org.junit.Test)

Aggregations

Result (io.requery.query.Result)9 Person (io.requery.test.model.Person)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 Test (org.junit.Test)8 ReactiveResult (io.requery.reactivex.ReactiveResult)4 RxResult (io.requery.rx.RxResult)4 Disposable (io.reactivex.disposables.Disposable)3 Subscription (rx.Subscription)3 Phone (io.requery.test.model.Phone)2 DELETE (io.requery.query.element.QueryType.DELETE)1 INSERT (io.requery.query.element.QueryType.INSERT)1 SELECT (io.requery.query.element.QueryType.SELECT)1 UPDATE (io.requery.query.element.QueryType.UPDATE)1