greendao的使用增删改查<3>

greendao的增删改查

public class MainActivity extends AppCompatActivity {
    private NoteDao noteDao;
    private Note note;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        DaoSession daoSession = ((AppApplication) getApplication()).getDaoSession();
        noteDao = daoSession.getNoteDao();

        addNote();
        queryNote();
        updateNote();
        deleteNote();
    }

    public void addNote() {
        note = new Note();
        note.setText("this is test note!");
        note.setComment("this is comment");
        noteDao.insert(note);
        Log.d("DaoExample", "Inserted new note, ID: " + note.getId());
    }

    public void deleteNote() {
        noteDao.delete(note);
    }

    public void updateNote() {
        note.setText("this is after modify note!");
        noteDao.update(note);
    }

    public void queryNote() {
       List noteList = noteDao.queryBuilder().where(NoteDao.Properties.Text.eq("this is after modify note!")).build().list();
    }

}

使用stetho查看数据库
android调试桥工具stetho的使用

你可能感兴趣的:(greendao的使用增删改查<3>)