This article covers the following topics:
Greendao is an artifact of the operational database, which has been used by a wide range of developers after a 2.0 version of the upgrade. Really is very useful, easy to get started, can be left to the database of the table operation and database SQL write, Bo Master used once, and the previous database operation a lot of code will be shrunk into a sentence, comfortable
Before knowing Greendao, you must know that an ORM (object Relation Mapping-relational mapping) is represented by the association of a database and a Bean object through Greendao, which is represented in the form
Greendao is very popular, and its advantages are closely related, from the official website can see such a picture, it represents in the mainstream ORM third-party library, its database operation speed is the fastest
Moreover, the advantages include the following points
Greendao configuration is very simple, but it is important to note that some people follow the correct configuration but frequently error, the individual has experienced, the last reason is the network has a problem. Because the campus network of the DNS service is poor, so the resolution of Greendao dependent Web site
One, you need to add dependencies in the Build.gradle of the Project (project)
Second, add dependencies in the Build.gradle of the project (Module)
The configuration is successful here.
After the configuration is complete, the most important thing is the use of Greendao, perhaps used bmob third-party back-end Cloud alumni know that their API is somewhat similar, all through the API to assemble SQL statements
The following is a shopping cart in the actual combat to use the Greendao, here the shopping cart display chart is as follows
We know the database operation needs: database name, table name, field name, is indispensable, the following is the creation of these three items
Greendao the Bean object needs to be created, the Bean object is the name of the table, and its property value is the field name, and its implementation is implemented by means of annotations, the following is the bean object of the shopping cart (one table per bean object)
It is important to note that after the creation is complete, build gradle is required to complete our code auto-generation. The automatically generated code has
This explains the comment for the Bean object.
database table names and fields have been built, below the creation of a database, below through the traditional and Greendao comparison to experience its advantages
① Traditional Database creation
②greendao Database Creation
As you can see, Greendao has shrunk our database creation to a few words, and the code automatically creates the Bean object as a table, no longer a traditional handwritten SQL statement. The database creation here only needs to be performed once in application, where several classes are explained
Since we have created the Bean object for daosession and shop, we will automatically generate our Shopdao object after compiling, which can be obtained by daosession
The DAO (data Access Object) here refers to an API that provides database operations, which can be used by DAO for additional pruning and checking operations.
The table names, fields, and databases of the database are all set up, and the following is a comparison of the advantages of the database by traditional and greendao operations.
① traditional additions and deletions and changes
②greendao additions and deletions to search
The effect is obvious, Greendao packaging more concise, semantic clarity, QS under the face of Greendao DAO object other API Introduction
About the basic concept of Greendao and basic operation here, more for Greendao database operation also need to explore from the actual combat, here is just a quick start guide. Greendao advanced operation also includes: multi-table query, multi-table association, session cache and other uses, can go to Greendao's official website to study
Android Combat--greendao3.2 Use, admiringly