private void addNote() { String noteText = editText.getText().toString(); editText.setText(""); final DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); String comment = "Added on " + df.format(new Date()); Note note = new Note(null, noteText, comment, new Date(), NoteType.TEXT); noteDao.insert(note) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Action1<Note>() { @Override public void call(Note note) { Log.d("DaoExample", "Inserted new note, ID: " + note.getId()); updateNotes(); } }); }
/** * The returned RxDao is a special DAO that let's you interact with Rx Observables using RX's IO scheduler for * subscribeOn. * * @see #rxPlain() */ @Experimental public RxDao<T, K> rx() { if (rxDao == null) { rxDao = new RxDao<>(this, Schedulers.io()); } return rxDao; }
@Override public void delete(final NewsTypeInfo data) { mDbDao.rx().delete(data) .subscribeOn(Schedulers.io()) .subscribe(new Subscriber<Void>() { @Override public void onCompleted() { mRxBus.post(new ChannelEvent(ChannelEvent.DEL_EVENT, data)); } @Override public void onError(Throwable e) { Logger.e(e.toString()); } @Override public void onNext(Void aVoid) { } }); }
/** * Rx version of {@link AbstractDao#count()} returning an Observable. */ @Experimental public Observable<Long> count() { return wrap(new Callable<Long>() { @Override public Long call() throws Exception { return dao.count(); } }); }
@Override public void onNoteClick(int position) { Note note = notesAdapter.getNote(position); final Long noteId = note.getId(); noteDao.deleteByKey(noteId) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Action1<Void>() { @Override public void call(Void aVoid) { Log.d("DaoExample", "Deleted note, ID: " + noteId); updateNotes(); } }); } };
public void testDeleteByKeyInTxList() { TestEntity foo = insertEntity("foo"); TestEntity bar = insertEntity("bar"); List<Long> list = new ArrayList<>(); list.add(foo.getId()); list.add(bar.getId()); assertDeleted(rxDao.deleteByKeyInTx(list)); }
public void testDeleteInTxList() { TestEntity foo = insertEntity("foo"); TestEntity bar = insertEntity("bar"); List<TestEntity> list = new ArrayList<>(); list.add(foo); list.add(bar); assertDeleted(rxDao.deleteInTx(list)); }
public void testDeleteAll() { insertEntity("foo"); insertEntity("bar"); assertDeleted(rxDao.deleteAll()); }
public void testCount() { insertEntity("foo"); TestSubscriber<Long> testSubscriber = RxTestHelper.awaitTestSubscriber(rxDao.count()); assertEquals(1, testSubscriber.getValueCount()); Long count = testSubscriber.getOnNextEvents().get(0); assertEquals(1L, (long) count); }
/** * Rx version of {@link AbstractDao#deleteAll()} returning an Observable. */ @Experimental public Observable<Void> deleteAll() { return wrap(new Callable<Void>() { @Override public Void call() throws Exception { dao.deleteAll(); return null; } }); }
public void testDeleteByKey() { TestEntity foo = insertEntity("foo"); assertDeleted(rxDao.deleteByKey(foo.getId())); }
public void testDeleteByKeyInTx() { TestEntity foo = insertEntity("foo"); TestEntity bar = insertEntity("bar"); assertDeleted(rxDao.deleteByKeyInTx(foo.getId(), bar.getId())); }
public void testDeleteInTx() { TestEntity foo = insertEntity("foo"); TestEntity bar = insertEntity("bar"); assertDeleted(rxDao.deleteInTx(foo, bar)); }
/** * Rx version of {@link AbstractDao#loadAll()} returning an Observable. */ @Experimental public Observable<List<T>> loadAll() { return wrap(new Callable<List<T>>() { @Override public List<T> call() throws Exception { return dao.loadAll(); } }); }
@Override public void insert(final NewsTypeInfo data) { mDbDao.rx().insert(data) .subscribeOn(Schedulers.io()) .subscribe(new Subscriber<NewsTypeInfo>() { @Override public void onCompleted() { mRxBus.post(new ChannelEvent(ChannelEvent.ADD_EVENT, data)); } @Override public void onError(Throwable e) { Logger.e(e.toString()); } @Override public void onNext(NewsTypeInfo newsTypeBean) { Logger.w(newsTypeBean.toString()); } }); }
/** * The returned RxDao is a special DAO that let's you interact with Rx Observables without any Scheduler set * for subscribeOn. * * @see #rx() */ @Experimental public RxDao<T, K> rxPlain() { if (rxDaoPlain == null) { rxDaoPlain = new RxDao<>(this); } return rxDaoPlain; }
public void testDelete() { TestEntity foo = insertEntity("foo"); assertDeleted(rxDao.delete(foo)); }
/** * Rx version of {@link AbstractDao#loadAll()} returning an Observable. */ @Experimental public Observable<T> load(final K key) { return wrap(new Callable<T>() { @Override public T call() throws Exception { return dao.load(key); } }); }
public void testInsert() { TestEntity foo = RxTestHelper.createEntity("foo"); TestSubscriber<TestEntity> testSubscriber = RxTestHelper.awaitTestSubscriber(rxDao.insert(foo)); assertEquals(1, testSubscriber.getValueCount()); TestEntity foo2 = testSubscriber.getOnNextEvents().get(0); assertSame(foo, foo2); List<TestEntity> all = dao.loadAll(); assertEquals(1, all.size()); assertEquals(foo.getSimpleStringNotNull(), all.get(0).getSimpleStringNotNull()); }
/** * The returned RxDao is a special DAO that let's you interact with Rx Observables using RX's IO scheduler for * subscribeOn. * * @see #rxPlain() */ @Experimental public RxDao<T, K> rx() { if (rxDao == null) { rxDao = new RxDao<>(this, Schedulers.io()); } return rxDao; }