Android 房间数据库-插入后如何返回整行?

Android 房间数据库-插入后如何返回整行?,android,rx-java,android-room,rx-java2,rx-android,Android,Rx Java,Android Room,Rx Java2,Rx Android,我有一个插入行的查询 @Dao public interface NoteDao { @Insert Long insert(Note note); } 我正在使用RxJava在后台线程上执行查询: public void insert(Note note) { Single.fromCallable(() -> noteDao.insert(note)) .subscribeOn(Schedulers.newThrea

我有一个插入行的查询

@Dao
public interface NoteDao {
    @Insert
    Long insert(Note note);

}
我正在使用RxJava在后台线程上执行查询:

 public void insert(Note note) {
        Single.fromCallable(() -> noteDao.insert(note))
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SingleObserver<Long>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onSuccess(@NonNull Long aLong) {
                        Log.d(TAG, "onSuccess: New row Id: " + aLong);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                    }
                });

    }

不确定如何使用文件室库,如的文档中所述,如果要一次性执行两个查询,则必须使用事务,据我所知,标准数据库操作没有其他选项

检查下面我们正在做的事情,你应该做类似的事情

 @Dao
 public interface NoteDao {
    @Insert
    Long insert(Note note);

    @@Query(“SELECT * FROM Note WHERE noteId = :id)
    Long getNote(id Long);

    @Transaction
    public void insertAndRetrieve(Note note):Note {
         // Anything inside this method runs in a single transaction.

         val id =  insert(note);
        return getNote(id);
     }
 }
 @Dao
 public interface NoteDao {
    @Insert
    Long insert(Note note);

    @@Query(“SELECT * FROM Note WHERE noteId = :id)
    Long getNote(id Long);

    @Transaction
    public void insertAndRetrieve(Note note):Note {
         // Anything inside this method runs in a single transaction.

         val id =  insert(note);
        return getNote(id);
     }
 }