ORM Lightweight Framework---activeandroid

Source: Internet
Author: User

ORM is object-relational Mapping, Object Relational mapping. The simple idea is to map our Java objects to the records in the database, to persist the entity objects to the database, and to map the queried records into Java objects. The ORM frees us up and does not need to write lengthy, obscure SQL statements, everything is done through the framework, and has to be a great boon for programmers.

The implementation of ORM Framework is also very simple, that is, using the reflection mechanism of Java to associate objects with database record mapping. 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 an SQL statement, and the query result set is converted to the object list. Java EE has ibatis,hibernate framework, we also have Android greendao,ormlite,xutils,afinal and so on. They all have the same principle, and the difference is just the details of the process. If interested students, recommend reading under the activeandroid source. Reading the fucking code!

Previously wrote a series of articles introducing Xutils, of which the Finaldb module is an ORM framework, which is commonly used in my work. Today we introduced the Activeandroid API is quite simple and friendly, but also the same powerful features. Activeandroid Simple API gives people a comfortable feeling, today is mainly about the simple use of crud.

First, initialize

There are two ways, one is to configure the Name property of the Androidmanifest application, and the optional configuration DB name and version in the Meta-data tab The second is to inherit Activeandroid's application in their own application class; The first two approaches are too intrusive, and there is a static injection of only two methods in a custom application.

Ii. Definition of entity classes

Entity classes inherit the model, and the field names corresponding to the table names and attributes can be customized

Third, insert

A single data insert can be implemented, or it can be bulk inserted, while also supporting transactions.

Iv. deletion

Supports a single, reference-based record deletion, and also supports bulk deletion based on conditions.

Five, update

The Save method inherited from the model can not only insert, but also update, and can also be based on the conditions of batch updates.

Vi. Inquiries

Activeandroid's query API is basically consistent with the keyword of the SQL statement and is relatively 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 drawback, is to create inefficient, time-consuming phenomenon. When there is data in bulk operation, it will take time to add several times longer. So when the business has a lot of records to deal with, it is not recommended that you use the framework, or honest writing more reliable. This is the end of today's dry goods sharing, hope can help everyone.

If you find it helpful, you are welcome to subscribe to my public account-Android dry Sharing (Id:android_share). Below is the QR code, to provide you with timely high-quality Android dry.

?

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.