Android GreenDAO3.0 -- Introduction, androidgreendao3.0

Source: Internet
Author: User

Android GreenDAO3.0 -- Introduction, androidgreendao3.0
Introduction

Recently, learning is scattered and all kinds of knowledge are mixed, so you can write down the learning records to avoid forgetting.

Http://greenrobot.org/greendao/documentation/introduction/

First, we will introduce what greenDAO is, and add GreenDAO between the java object and the SQLite database, so that our application does not directly operate the database, but calls the interface provided by greenDAO to complete database operations.

The advantage of doing so is that we can avoid writing a lot of database operation code, and avoid some low-level errors due to fatigue.

GreenDAO core class
  • DaOMaster -- this class holds database objects, manages DAO classes (a class file), and contains methods for creating and deleting table data tables. Its internal classes OpenHelper and DevOpenHelper are the implementation of the SQLite interface SQLiteOpenHelper. Therefore, this class has the potential to operate databases.
  • DaoSession: manages all available DAO objects. DaoSession provides methods similar to insert, load, update, refresh, and delete.
  • DAOs -- all called Data access objects. For Entity, DAO can be generated through GreenDao. In addition, the database operation methods provided by this object are redundant DAOSession.
  • Entity -- java POJO or JavaBean

It is the relationship between core classes. It is a very obvious structural relationship.

GreenDAO core class initialization

This code can be inserted in the application of the Android app project.

// 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();

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.