Reputation: 1423
I have a DAO class for updating a note if a note already exists for a particular date. If note, the DAO creates a new note. Here's the DAO interface:
@Insert(onConflict = OnConflictStrategy.REPLACE)
public long insertNote(Note note);
@Update
public int updateNote(Note note);
Here's how I read all the data from the Database:
viewModel = ViewModelProviders.of(this).get(NoteListViewModel.class);
viewModel.getNoteList().observe(MainActivity.this, new Observer<List<Note>>() {
@Override
public void onChanged(@Nullable List<Note> noteList) {
Log.d("Note List Items", noteList.toString());
}
});
Now, I don't know to check, compare and update existing rows in the database.
Upvotes: 0
Views: 4179
Reputation: 1006584
Your Note
@Entity
class has a primary key. updateNote()
will update the row based on that primary key.
Upvotes: 3