Android GreenDAO3.0——介紹,androidgreendao3.0

來源:互聯網
上載者:User

Android GreenDAO3.0——介紹,androidgreendao3.0
引言

最近,學東西比較零散,各種知識混雜,於是記下學習記錄,免得又忘了。

官方網址:http://greenrobot.org/greendao/documentation/introduction/

首先介紹一下什麼是greenDAO,在java object 對象與SQLite資料庫之間加入GreenDAO,使得我們的應用程式不直接操作資料庫,而是調用greenDAO提供的介面完成資料庫操作。

這樣做的好處是可以避免我們寫大量的資料庫作業碼,避免因為疲勞犯下一些低級的錯誤。

                                     

GreenDAO核心類
  • DaOMaster——該類持有資料庫物件,並管理DAO classes(是class檔案),並包含建立和刪除資料表table的方法。它的內部類OpenHelper和DevOpenHelper是SQLite介面SQLiteOpenHelper 的實現,因此該類具有操作資料庫的潛質。
  • DaoSession——管理所有的可用DAO 對象, DaoSession提供類似insert, load, update, refresh,delete 的方法。
  • DAOs——全稱為Data access objects,對於Entity,都可以通過GreenDao產生DAO。並且該對象提供的操作資料庫方法多餘DAOSession。
  • Entity——java POJO或者JavaBean                                                                 

                                                                       

就是核心類之間的關係,很明顯的結構關係哦。

GreenDAO核心類的初始化

 該段代碼可以在Android app項目的application中插入。

// do this once, for example in your Application classhelper = new DaoMaster.DevOpenHelper(this, "notes-db", null);db = helper.getWritableDatabase();daoMaster = new DaoMaster(db);daoSession = daoMaster.newSession();// do this in your activities/fragments to get hold of a DAOnoteDao = daoSession.getNoteDao();

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.