ORM is object-relational Mapping, Object Relational mapping. A simple understanding is to map our Java objects to the records in the database, to persist the entity objects to the database, and to map the records of queries to Java objects. ORM frees us up, and there's no need to write long, obscure SQL statements, everything is done through frameworks, and it's a great boon to programmers.
The principle of ORM framework implementation is also very simple, that is, the use of Java reflection mechanism of the object and Database Record Mapping Association. For example, when storing, the object's attributes are taken out as the attribute value of the record, and the query is automatically constructed into a SQL statement, and the result set of the query is converted into a list of objects. Java EE has a ibatis,hibernate framework, we have Android greendao,ormlite,xutils,afinal and so on. They all work the same way, and the difference is in detail. If the interest of the classmate, recommended reading under the activeandroid source. Reading the fucking code!
Previously wrote a series of articles about Xutils, the Finaldb module is an ORM framework, which is also used in my work. The Activeandroid API we are introducing today is also quite simple and friendly and powerful. Activeandroid Concise API gives people a feeling that it is comfortable to use, and today is mainly about the simple use of crud.
First, initialization
There are two ways, one is to configure the application Name property of the Androidmanifest, and optionally configure the name and version of DB in the Meta-data tab The second is to inherit the application of activeandroid in its own application class, the first two ways are too intrusive, and there is a static injection of two methods in a custom application.
Ii. Defining entity Classes
Entity classes need to inherit model to customize the name of the field corresponding to the table name and attribute
Back to the column page: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/