ORM is object-relational Mapping, Object Relational mapping.
The simple idea is to map our Java objects to the records in the database. The ability to persist entity objects into the database. You can also map a queried record to a Java object. The ORM lets us be completely liberated, without having to write lengthy, obscure SQL statements, all through the framework. Must be said to be a great boon for procedural apes.
The ORM Framework implementation principle is also very easy, is to use the Java reflection mechanism to associate objects and database record mapping. For example, when storing, the object's attributes are taken out to be inserted as the attribute value of the record. When querying, it is to construct the query condition itself into an SQL statement, and turn the result set of the query into the object list. There is a ibatis,hibernate framework for the Java EE, and we have greendao,ormlite Android. Xutils. Afinal and so on. They all have the same principle, and the difference is just the details of the process.
If interested classmates, recommend reading the source code under Activeandroid. Reading the fucking code!
Once wrote a series of articles introducing Xutils, the FINALDB module is an ORM framework, which is often used in my work. Today we introduced the Activeandroid API is quite simple and friendly. And the function of the same powerful. Activeandroid Simple API gives people a very comfortable use of the feeling, today is mainly about the simple use of crud.
First, initialize
There are two ways of doing this. One is the Name property of the application that configures Androidmanifest, and the name and version of the configuration db that is optional in the Meta-data tab at the same time. The second is to inherit the application of Activeandroid in their application class; The first two methods are too intrusive. The other is simply to inject two methods statically in the application you define.
Ii. Definition of entity classes
Entity classes must inherit model. You can define the corresponding field names for the table name and property.
Third, insert
Ability to implement single data insertions. It is also possible to bulk insert and support transactions at the same time.
Iv. deletion
Supports a single, reference-based record deletion, and also supports bulk deletion by condition.
Five, update
The Save method inherited from the model. Not only can insert, but also update, at the same time can be based on the conditions for batch updates.
Vi. Inquiries
Activeandroid's query API is basically consistent with the keyword of SQL statements and is more friendly. This is the same thing as Xutils.
Written in the end: ORM Frameworks are really handy to use, and coding improves efficiency, but it also has deadly drawbacks.
We also introduced the implementation of the ORM principle is the reflection mechanism of Java, reflection has a disadvantage. Is the result of inefficient, long-time phenomenon. When there is data in bulk operation, it will take time to add several times longer. So when it comes to having a lot of records to deal with in the business, we don't recommend using frames. Or honest writing is more reliable.
This is the end of today's dry goods sharing, hope to help everyone.
If you think it's helpful, you're welcome to subscribe to my public account-Android dry Sharing (Id:android_share). The following is the QR code. To provide you with timely high-quality Android dry. Technical Exchange QQ Group: 318588906, welcome everyone to add a group, together to explore the next Android and Java technology, together to expand our dry sharing community.
?
ORM Lightweight Framework---activeandroid