3. ORM Component xcode (Introduction)

Source: Internet
Author: User

Xcode is a lightweight ORM Component (Object-to-relational database ing) that provides object-oriented database operations to address more than 90% of database operation scenarios.

As the most important component of X Series, xcode adheres to the simple and practical features and strives to solve the most common problems with the simplest practices.

The biggest disadvantage of xcode is that it does not support multi-table queries!Why is double quotation marks not supported? That's because xcode actually supports multi-table queries, but it is very complicated to use and cannot be clearly stated, which seriously affects the learning and understanding of basic functions. Therefore, I cannot answer all questions! As for the disadvantage, double quotation marks are added because xcode has a complete set of alternatives, which is superior to multi-table queries in most cases.

If xcode is used, you have to mention the development mode. Every ORM Component performs the most well in a certain development mode. xcode is no exception. We call it the xcode development mode. Of course, everyone has their own ideas and Development habits. You can try using xcode based on your habits, or slightly modify your habits. This may be a better use.

Xcode focuses on Object-to-relational database ing, and has two internal layers:

1. The lower layer uses Dal as the entrance and idatabase as the interface. Various databases implement a class to implement this interface to support multiple databases.The two major representatives of dal are select (query SQL, return dataset) and execute (Execute SQL, Return Affected rows), and use SQL as the key, with support for level-1 cache. Dal also supports dbcommand query and operations, but it is not supported by a level-1 cache.

(DAL layer structure)

2. The upper layer uses entity as the generic base class, And all entity classes inherit from it.The classic loaddata can convert dataset or able into a collection of object objects. Each record in each row instantiate an object, and the values of each table field are assigned to the attributes of the object. Therefore, you can get the dataset in other ways and use loaddata to convert it into a collection of object objects, instead of necessarily needing Dal. We can see that xcode supports views, and complex queries or multi-table queries can be solved in disguised form through views. However, this is generally not recommended. In addition, deletion, modification, query, and other operations, xcode dynamically concatenates SQL statements using metadata and other information of the object class, and then calls the Dal layer for implementation.

(Loading record sets and data tables)

(Execute the insert operation. concatenate the SQL statement and then execute it)

The two-layer structure description is actually the core principle of xcode. Anyone can implement their own ORM based on this principle. As for the merits and demerits of the result component, you can view the respective strengths and the details.

The concept of xcode is object-oriented, so everything related to this object is written in this object.So xcode isCongestion Model.

All query operations (such as find, findall, and findcount) are static methods because they are irrelevant to specific objects. Object operations (such as insert, update, save, and delete) are member methods, because it is closely related to a specific object, it represents operations on a specific object. This is the basic idea of the xcode model. Similarly, you can write services for the entity class.CodeThis principle should also be strictly followed, which should be static and which should be members, and should be strictly separated.

Of course, xcode entity classes also support some operation methods of the anemia model, but the operation class is still itself. For example, insert, update, save, and delete also have static methods, and parameters are object class objects.

The xcode model also has a very important significance, that is, it fully meets the requirements of the Data Source component objectdatasource, so that the xcode entity class can directly act as a data provider.

(For the findall/findcount pairs, the parameters are exactly the same, which is exactly the requirement of objectdatasource)

This article is only an introduction to xcode. It describes the structure and development mode of xcode. For more details, see the following article.

Big stone

New Life Development Team


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.