Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the object orientation of ObjectiveSql

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to understand the object-oriented of ObjectiveSql". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Recently, I have seen some videos about "hyperemia model" and "anemia model", as well as ActiveRecord mode. If we understand it from a higher point of view, "anemia model" is the "struct" in C language, and the hyperemia model is Class in Java. Whether it is "struct" or Class should stand in different positions of the system to understand, both have reasons for existence, but the "anemia model" will implicitly exist. My understanding is that "anemia model" usually exists in data transmission, it is only a definition of transmission protocol, can be used for data transfer between different subsystems or databases, of course, "anemia model" is not only set and get methods, it should encapsulate protocol-related behaviors (usually these behaviors are encapsulated in other control Class), Google ProtoBuffer is a good practice. The "hyperemia model" and ActiveRecord are artificial definitions. In essence, they are only the basic concepts (encapsulation of state and behavior) in object-oriented design, and they are purely manufacturing concepts.

The topic of object-oriented is very large, so I will briefly introduce the practical problems in my project.

DomainModelpublic class Order {private String no; private Integer memberId; private Float amount; private Float quantity; @ Column (transition = SqlDateTimeTransitional.class) private Timestamp salesAt; @ Relation (relationType = RelationType.BELONGS_TO) private Member member; @ Relation (relationType = RelationType.HAS_MANY) private List orderLines; @ Transactional @ DataSourceName ("test") public static void makeOrder (Order order, OrderLine... OrderLines) throws SQLException {Order.create (order, false); OrderLine.create (orderLines, false);}}

DomainModel exists in the form of Annotation in the project, which is used to identify whether a Class is a model in the application system. The model should include the state and logic of the business. It should also describe the relationship between the model and other models. The specific explanation is as follows:

@ DomainModel associates the state of the model with the tables in the database

@ Column (transition = SqlDateTimeTransitional.class) defines how the field is converted to the database

@ Relation (relationType = RelationType.BELONGS_TO) defines the relationship between Order and Member

@ Transactional identifies that the data operation of this method will be committed as a transaction

@ DataSourceName ("test") is used to specify the database to which the data in this method belongs when using multiple data sources

Order model can be called ActiveRecord or hyperemia model, but in essence it is a standard Class of Java, which accords with the general principle of object-oriented design, subdivides the problem domain, then encapsulates it. It only abstracts the "order" in the problem domain, designs the state and behavior, reduces the problem domain to atomic granularity, deduces from the business logic concept without ambiguity, and enables the code to clearly describe the logic and state. Separate the purely technical code, and after the above definition is complete, you can use it directly like this:

Member member = Member.queryByPrimaryKey (1); List members = Member.query ("id between? and?", 10, 20); int count = Member.count ("id >?", 10); so much for "how to understand the object-oriented of ObjectiveSql". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report