Android 与绿道的交易
我写这篇文章是因为我不明白使用GreenDao时事务是如何工作的,我想得到一些解释/最近的教程 尽管读了这本书,我还是不明白主要的活动是如何进行的。例如:Android 与绿道的交易,android,transactions,greendao,Android,Transactions,Greendao,我写这篇文章是因为我不明白使用GreenDao时事务是如何工作的,我想得到一些解释/最近的教程 尽管读了这本书,我还是不明白主要的活动是如何进行的。例如: ... Note note = new Note(null, noteText, comment, new Date(), NoteType.TEXT); noteDao.insert(note) .observeOn(AndroidSchedulers.mainThread())
...
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();
}
});
...
...
public void testConcurrentInsertDuringTx() throws InterruptedException {
...
Runnable runnable2 = new Runnable() {
@Override
public void run() {
dao.insertInTx(createEntity(null));
}
};
Runnable runnable3 = new Runnable() {
@Override
public void run() {
daoSession.runInTx(new Runnable() {
@Override
public void run() {
dao.insert(createEntity(null));
}
});
}
};
...
// Builds the statement so it is ready immediately in the thread
dao.insert(createEntity(null));
doTx(new Runnable() {
@Override
public void run() {
dao.insert(createEntity(null));
}
});
latchThreadsDone.await();
assertEquals(7, dao.count());
}
...
我知道这是一个例子,但我不知道使用rx方法和observeOn/subscribe方法的区别
protected void doTx(final Runnable runnableInsideTx) {
daoSession.runInTx(new Runnable() {
@Override
public void run() {
latchInsideTx.countDown();
// Give the concurrent thread time so it will try to acquire locks
try {
Thread.sleep(TIME_TO_WAIT_FOR_THREAD);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
runnableInsideTx.run();
}
});
}
我读过一些关于交易的话题,但它们已经过时了,或者可能我没有正确理解它们:
有人能帮我解释一下/最近的教程吗?Greendao将这些方法作为实验。提前感谢您能否尝试缩短您的问题,并更清楚地说明您到底想知道什么?您好@greenrobot,我只想知道一般情况下如何使用与GreenDao的交易?使用runInTx()。我刚刚为ObjectBox写了一篇文章:基础应该是相同的减去读取事务和并发。好的,我会读它。谢谢你能不能尽量缩短你的问题,更清楚地说明你到底想知道什么?嗨@greenrobot,我只想知道一般情况下如何使用GreenDao的事务?使用runInTx()。我刚刚为ObjectBox写了一篇文章:基础应该是相同的减去读取事务和并发。好的,我会读它。谢谢