Database adapter based on domain-driven design and object relation mapping technology

By adopting a database adapter based on domain-driven design and object relationship mapping technology in the database operation and maintenance platform, the business-side transformation complexity problem caused by database replacement is solved, the effect of simplifying database interaction and improving development efficiency is achieved, and the performance of the application is improved through automatic query optimization function.

CN120144121APending Publication Date: 2025-06-13SHENZHEN YIXING HEYI TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510227108.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-27
Publication Date
2025-06-13

AI Technical Summary

Technical Problem

When facing the transformation of business information innovation and innovation, the existing database operation and maintenance platform is difficult to effectively deal with the complexity of business-side transformation brought about by database replacement, and the operation design lacks field-driven design ideas, resulting in low development efficiency and high risks.

Method used

The database adapter based on domain-driven design and object-relational mapping technology is adopted to encapsulate complex database domain logic, build a unified service interface, decouple the infrastructure layer, simplify the interaction between applications and databases, and provide automatic query optimization functions.

Benefits of technology

The underlying database replacement and integration process in the information and innovation transformation of application systems has been simplified, development efficiency has been improved, R&D manpower has been saved, and the performance of the application has been improved through automatic query optimization function.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120144121A_ABST
    Figure CN120144121A_ABST
Patent Text Reader

Abstract

The invention relates to the field of databases, and discloses a database adapter based on domain-driven design and an object relation mapping technology, comprising: a business domain model used for analyzing and modeling a business domain, defining concepts in a business system, facilitating lateral promotion of a business side, and establishing a business domain model; the business domain model divides objects of a business system into a group of related objects, and the group of objects can be operated independently and can be created, read, updated and deleted independently; the interface layer defines basic operation functions of the group of related objects and realizes robustness of an interface, and the interface does not need to be modified even if business requirements change; and service logic. According to the adapter device for simplifying interaction between the application program and the database, the replacement and integration process of the bottom database in the creative transformation process of an application system is greatly simplified, the development efficiency is improved, and research and development manpower is saved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of databases, and in particular to a database adapter based on domain-driven design and object-relational mapping technology. Background Art

[0002] With the advancement of informatization and digitalization processes, the construction of business systems has gradually accelerated. The types and quantity scales of databases at the backend of the system have increased rapidly. Therefore, some database operation and maintenance platforms or cloud database services (RDS) have emerged to manage large-scale and multi-type databases of enterprises. In such known platforms, there are the following problems in the operation and use of databases:

[0003] The operation content is hard-coded in the platform code. The design lacks the design concept of domain-driven design and still focuses on operations. Every time a new operation or a new type of database is added, new code needs to be added to the platform to implement it. The entire software R & D cycle process is required from the front-end user interface to the back-end functions, resulting in slow timeliness and high labor consumption.

[0004] Such platforms often focus on the centralized management and construction of various types of databases in the infrastructure layer. The platform cannot effectively cope with the complexity of business-side transformation brought about by database replacement during the business information creation transformation process. For example, when an application undergoes information creation transformation, the original SQLServer database may need to be migrated to a Gauss database or an Oceanbase database. At this time, changes in aspects such as the data type, index support, and SQL syntax of the database require the business side to almost reconstruct the database docking code and related logic in order to better adapt to the information creation database. This forms a huge barrier to the promotion of business information creation transformation, and the transformation efficiency is low and the risk is high.

[0005] By establishing a mapping relationship between a relational database and an object-oriented programming language through object-relational mapping, and by using metadata that describes the mapping between objects and the database, the objects in the program are automatically persisted into the relational database, effectively solving the mismatch between object-oriented programming languages and relational databases. However, since object-relational mapping requires conversion between objects and database tables, and when dealing with some complex queries, multiple database interactions may be required, which will increase the performance overhead. Therefore, it is necessary to effectively optimize SQL statements through technical means to improve query efficiency. Summary of the Invention

[0006] The present invention provides a database adapter based on domain-driven design and object-relational mapping technology. Through this database adapter, complex database domain logic can be encapsulated in an adapter class. By constructing a unified service interface, the mismatch between object-oriented programming languages and relational databases can be effectively solved. In this way, the dependencies in the infrastructure layer can be decoupled from the domain layer, simplifying the interaction between the application program and the database, enabling the domain layer to focus more on business logic rather than infrastructure details, and effectively maintaining the purity of the domain layer.

[0007] The present invention provides a database adapter based on domain-driven design and object-relational mapping technology, including:

[0008] A business domain model, which is used to analyze and model the business domain, clarify the concepts in the business system, and facilitate the horizontal promotion and application on the business side. The business domain model divides the objects in the business system into a group of related objects. Such a group of objects can be operated independently and can be created, read, updated, and deleted separately;

[0009] An interface layer, which defines the basic operation functions of this group of related objects and realizes the robustness of the interface. Even if the business requirements change, the interface does not need to be modified;

[0010] Service logic, which is encapsulated by the following method: prepare and organize the configuration information such as database connection information and driver program for domestic databases, and construct a configuration data source for the adapter connection process; then use the object-relational mapping technology framework to define ordinary Java objects, establish a mapping relationship between ordinary JAVA objects and data tables of various domestic databases through configuration files and annotations, and automatically generate SQL statements for specific domestic database objects according to the definition of entity classes; convert the query results into corresponding entity class objects and feedback them to the user layer or application program through the interface layer.

[0011] Furthermore, the interface layer has an optimization module. The optimization module has an automatic query optimization function. The optimization module can analyze the generated unified query statements adapted to multiple databases to determine the information of the queried tables, fields, and condition ranges. By querying the statistical information of the tables and indexes of the databases docked based on the adapter, more efficient equivalent queries are produced. The optimization module can generate an execution plan according to the analysis results of the query statements. This plan describes how to execute the query and which indexes to access. At the same time, multiple possible execution plans are generated according to the statistical information and cost model, and the best one is selected. The optimization module will evaluate the generated execution plan, considering various factors to determine the optimal execution plan. The optimization module can execute the query and return the result according to the evaluated optimal execution plan. The optimization module will continuously monitor the execution situation of the query and make adjustments as needed to improve the query performance.

[0012] Furthermore, the concepts in the business system include entities, value objects, domain services, events, attributes, and relationships.

[0013] Furthermore, in order to improve the query execution efficiency, the optimization module can automatically identify the parameters in the query statement and replace them with placeholders. This can avoid repeated parsing of the same query statement. For query optimization, a distributed task method is adopted. By decomposing a single query operation into multiple subtasks and executing them in parallel on multiple threads, the execution efficiency is improved.

[0014] Furthermore, when the optimization module generates multiple possible execution plans according to the statistical information and cost model and selects the best one, the following factors will be considered: access path, connection method, and sorting method.

[0015] Furthermore, the factors considered by the optimization module when evaluating the generated execution plan include data distribution, index usage, and disk I / O.

[0016] Compared with the prior art, the present application provides an adapter device that simplifies the interaction between the application program and the database. This device is modeled based on domain-driven and realizes the logical encapsulation of different types of databases, and uses object-relational mapping to implement a unified service interface on the application side, greatly simplifying the process of replacing and integrating the underlying database during the information technology application innovation transformation of the application system, improving the development efficiency, and saving R & D manpower. At the same time, an automatic query optimization function is provided, which can generate efficient SQL statements and appropriate indexes according to the actual database structure and data volume, effectively improving the performance of the application program. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] Figure 1 It is the database architecture of the embodiment of the present invention. Detailed implementation manners

[0018] The embodiments of the present invention will be described in detail below. Examples of the embodiments are shown in the accompanying drawings, where the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below by referring to the accompanying drawings are exemplary and are only used to explain the present invention and should not be construed as a limitation to the present invention.

[0019] In addition, the terms "first" and "second" are only used for descriptive purposes and should not be construed as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features. Thus, the features defined with "first" and "second" may explicitly or implicitly include one or more of such features. In the description of the present invention, "a plurality" means two or more unless otherwise specifically defined.

[0020] In the present invention, unless otherwise clearly specified and defined, the terms "installed", "connected", "connected to", "fixed", etc. should be understood in a broad sense. For example, it may be a fixed connection, a detachable connection, or integrated; it may be a mechanical connection or an electrical connection; it may be directly connected or indirectly connected through an intermediate medium, and it may be the communication inside two elements or the interaction relationship between two elements. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0021] The implementation of the present invention will be described in detail below in combination with specific embodiments.

[0022] Referring to Figure 1 as shown, a preferred embodiment is provided by the present invention.

[0023] A database adapter based on domain-driven design and object-relational mapping technology includes:

[0024] A business domain model, which is used to analyze and model the business domain, clarify the concepts in the business system, and facilitate the horizontal promotion and application on the business side. The business domain model divides the objects in the business system into a group of related objects, and such a group of objects can be independently operated and can be created, read, updated, and deleted separately;

[0025] An interface layer, which defines the basic operation functions of this group of related objects and realizes the robustness of the interface, so that even if the business requirements change, the interface does not need to be modified;

[0026] Service logic, which is encapsulated by the following method: Prepare and organize the configuration information such as the database connection information and driver program of the domestic database, and construct a configured data source for the adapter connection process; Then use the object-relational mapping technology framework to define ordinary Java objects, establish a mapping relationship between ordinary JAVA objects and data tables of various domestic databases through configuration files and annotations, and automatically generate SQL statements for specific domestic database objects according to the definition of entity classes; Convert the query results into corresponding entity class objects and feedback them to the user layer or application program through the interface layer.

[0027] Further, the interface layer has an optimization module, and the optimization module has an automatic query optimization function. The optimization module can analyze the generated unified query statements that are adapted to multiple databases to determine the information of the tables, fields, and condition ranges to be queried; Query the table and index statistical information of the database docked based on the adapter to generate a more efficient equivalent query; The optimization module can generate an execution plan according to the analysis results of the query statements. This plan describes how to execute the query and which indexes to access; At the same time, generate multiple possible execution plans according to the statistical information and cost model and select the best one; The optimization module will evaluate the generated execution plan, considering various factors to determine the optimal execution plan; The optimization module can execute the query and return the results according to the evaluated optimal execution plan; The optimization module will continuously monitor the execution situation of the query and make adjustments as needed to improve the query performance.

[0028] Further, the concepts in the business system include entities, value objects, domain services, events, attributes, and relationships.

[0029] Further, in order to improve the query execution efficiency, the optimization module can automatically identify the parameters in the query statements and replace them with placeholders; This can avoid repeated parsing of the same query statements; For query optimization, a distributed task method is adopted, by decomposing a single query operation into multiple subtasks and executing them in parallel on multiple threads to improve the execution efficiency.

[0030] Further, when the optimization module generates multiple possible execution plans according to the statistical information and cost model and selects the best one, the following factors will be considered: access path, connection method, and sorting method.

[0031] Further, the factors considered by the optimization module when evaluating the generated execution plan include data distribution, index usage, and disk I / O.

[0032] As a specific implementation, with the in-depth transformation of the business system towards domestic information technology innovation, when introducing new domestic information technology innovation systems, it is inevitable to integrate with existing legacy systems. How to adapt the interfaces of the new system to the interfaces expected by the legacy system to achieve compatibility between the two systems needs to be solved. Therefore, at the beginning of the design, we used the idea of domain-driven design to implement the design and implementation of the software system and closely integrate it with the knowledge and rules of the business domain. During the implementation process, we first designed the business domain model. By analyzing and modeling the business domain, we clarified concepts in the business system such as entities, value objects, domain services, events, attributes, relationships, etc., which is convenient for the business side to promote the application horizontally. Then, in this model, we divided the system objects into a group of related objects. Such a group of objects can be operated independently, that is, operations such as creation, reading, updating, and deletion can be performed separately. On this basis, an interface layer was designed and implemented. The interface layer defines the basic operation functions of this group of related objects and realizes the robustness of the interface. Even if the business requirements change, the interface does not need to be modified. Here, it can be considered that a group of related objects actually correspond to a database table in the database layer.

[0033] How to achieve data persistence and transaction management after the interface is ready? At the same time, how to uniformly dock and map for easy docking between the business side and the database side in the face of technologies such as Java Naming and Directory Interface (JNDI for short), Java Database Connectivity (JDBC), Open Database Connectivity (ODBC), etc.? Here, we borrowed the object-relational mapping technology to abstractly complete the construction of the database connection management layer to achieve unified connection to the database side, and at the same time, through the connector pattern, we achieved unified interfaces for the business side. Why not directly use the open-source object-relational mapping technology framework but build a new one? The main reason is that traditional object-relational mapping technology frameworks only support a limited number of database types, and these databases are all foreign products. Then, in the process of domestic information technology innovation transformation of the business, databases such as Gauss Database, Alibaba OceanBase Database, Yashan Database, etc. cannot have unified interfaces.

[0034] Therefore, referring to the existing object-relational mapping technology framework, we encapsulate the service logic by combining the characteristics of various domestic databases on top of it. First, we prepare and organize the configuration information such as database connection information and driver programs for domestic databases such as Gauss Database, Alibaba OceanBase Database, and Yashan Database, and construct a configuration data source for the adapter connection process. Then, we use the object-relational mapping technology framework to define ordinary Java objects (POJOs), and establish a mapping relationship between ordinary Java objects and data tables of various domestic databases through configuration files and annotations, and automatically generate SQL statements for specific domestic database objects according to the definition of entity classes. For example, if a record needs to be inserted, the framework will automatically generate an insert statement; if data that meets the conditions needs to be queried, the framework will automatically generate a query statement. Then, the query results are converted into corresponding entity class objects and fed back to the user layer or application through the service interface layer. In this way, when the application is undergoing the transformation of the information and communication technology (ICT) innovation database, only decoupling and docking adaptation need to be carried out on the adapter side, and limited coding transformation can achieve full-stack ICT innovation of the application. The database operation logic, data fetching logic, etc. on the application side do not need to be modified and adapted, which greatly improves the development efficiency in the ICT innovation transformation of the application, and also improves the maintainability and readability of the code.

[0035] In addition, in actual use, we also found the performance defects of the object-relational mapping technology. Therefore, we designed and implemented an automatic query optimization function. An optimization module is built on the unified service interface layer to achieve engineering implementation. The optimization module has the following functions:

[0036] Analyze the query statement: The optimization module will first analyze the generated unified query statement that adapts to multiple databases to determine the range information such as the tables, fields, and conditions to be queried. By reusing the statistical information of the tables and indexes of the database docked by the adapter, a more efficient equivalent query is generated. For example, multiple subqueries can be merged into a nested query, or a join operation can be converted into a more efficient hash join. At the same time, this ability is also the summary and sublimation of operation and maintenance knowledge. An optimization system is constructed through the data dictionary method, making the automatically optimized statements more suitable for specific application scenarios.

[0037] Generate an execution plan: According to the analysis results of the query statement, the optimization module will generate an execution plan that describes how to execute the query and which indexes to access, etc. At the same time, multiple possible execution plans are generated according to the statistical information and cost model, and the best one is selected. It will consider various factors, such as access paths, connection methods, sorting methods, etc.

[0038] Evaluate the execution plan: The optimization module evaluates the generated execution plan, considering various factors such as data distribution, index usage, disk I / O, etc., to determine the optimal execution plan.

[0039] Execute the query: Based on the evaluated optimal execution plan, the optimization module executes the query and returns the results. To improve the query execution efficiency, the module can automatically identify the parameters in the query statement and replace them with placeholders. This can avoid repeated parsing of the same query statement. Here, a distributed task approach is also adopted for query optimization. By decomposing a single query operation into multiple subtasks and executing them in parallel on multiple threads, the execution efficiency can be improved.

[0040] Monitor and adjust: The optimization module continuously monitors the execution of the query and makes adjustments as needed to improve query performance. For example, if it is found that the usage rate of a certain index is low, the index can be considered for optimization or the query statement can be modified. Here, we combine the ANSI-standard DML syntax supported by domestic and foreign data, as well as the parsing of other SQL languages. Through the syntax analysis of SQL statements, combined with the table structure definition information and statistical information, appropriate indexes can be recommended for all possible syntax combinations to improve the database query performance.

[0041] The recommended index mechanism of the present invention has a variety of comprehensive recommendation strategies, such as equality conditions, range conditions, grouping, covering indexes, multi-condition syntax combinations, multi-table associations, logical subqueries, transitive closure rewriting, etc. Overall, index recommendation is based on query blocks. Some rewrite optimization algorithms can deduce or push down the parts related to index recommendation into the query blocks, so that the index recommendation engine can recommend appropriate indexes.

[0042] The indexes provided by the traditional simple analysis of query blocks can only be used for index range scans. By integrating multiple strategies and enabling rewrite optimization under filtering conditions, the present patent has a higher index screening rate for the recommended indexes and can avoid sorting, with better efficiency.

[0043] Similarly, the rewrite optimization algorithms for the present invention to recommend more effective indexes also include: LIMIT clause push-down rewrite optimization, outer join conversion to inner join optimization, projection push-down optimization, SATTC optimization, etc. Based on the above functions, the present invention can generate efficient SQL statements and efficient indexes according to the actual database structure and data volume and feedback them to application users, effectively improving the performance of the application program and simplifying the docking and transformation difficulty on the application side.

[0044] This application provides an adapter device that simplifies the interaction between application programs and databases. This device is modeled based on domain-driven design and realizes the logical encapsulation of different types of databases, and uses object-relational mapping to implement a unified service interface on the application side, greatly simplifying the process of replacing and integrating underlying databases during the information technology application innovation transformation of application systems, improving development efficiency, and saving R & D manpower. At the same time, it provides an automatic query optimization function that can generate efficient SQL statements and appropriate indexes according to the actual database structure and data volume, effectively improving the performance of application programs.

[0045] In the description of this specification, the descriptions referring to terms such as "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. mean that the specific features, structures, materials, or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representations of the above terms are not necessarily directed to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, without contradiction, those skilled in the art can combine and combine the different embodiments or examples described in this specification and the features of different embodiments or examples.

[0046] As mentioned above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the various embodiments of the present invention.

Claims

1. Database adapter based on domain-driven design and object-relational mapping technology, characterized by: include: Business domain model: The business domain model is used to analyze and model the business domain, clarify the concepts in the business system, and facilitate horizontal promotion and application on the business side. The business domain model divides the objects of the business system into a group of related objects. Such a group of objects can be operated independently and can be created, read, updated, and deleted separately; The interface layer defines the basic operation functions of this group of related objects and implements the robustness of the interface, so that the interface does not need to be modified even if the business requirements change; The service logic is encapsulated by the following methods: preparing and organizing the database connection information, driver program and other configuration information of the domestic database, and building the configuration data source of the adapter connection process; then using the object-relational mapping technology framework to define ordinary java objects, and establishing mapping relationships between ordinary JAVA objects and data tables of various domestic databases through configuration files and annotations, and automatically generating SQL statements for specific domestic database objects according to the definition of entity classes; converting query results into corresponding entity class objects, and feeding back to the user layer or application through the interface layer.

2. The database adapter based on domain driven design and object relational mapping technology according to claim 1, characterized in that: The interface layer has an optimization module, which has an automatic query optimization function. The optimization module can analyze the generated unified query statements that are adapted to multiple databases and determine the query table, field, and condition range information; Query statements are performed based on the statistical information of tables and indexes of the database connected to the adapter to produce more efficient equivalent queries; the optimization module can generate an execution plan based on the analysis results of the query statements, which describes how to execute the query and which indexes to access; at the same time, multiple possible execution plans are generated based on the statistical information and cost model, and the best one is selected; the optimization module will evaluate the generated execution plan, considering various factors to determine the optimal execution plan; the optimization module can execute the query and return the result based on the evaluated optimal execution plan; the optimization module will continuously monitor the execution of the query and make adjustments as needed to improve query performance.

3. The database adapter based on domain driven design and object relational mapping technology according to claim 1, characterized in that: The concepts in the business system include entities, value objects, domain services, events, attributes and relationships.

4. The database adapter based on domain driven design and object relational mapping technology according to claim 1, characterized in that: In order to improve the query execution efficiency, the optimization module can automatically identify the parameters in the query statement and replace them with placeholders; this can avoid repeated parsing of the same query statement; a distributed task method is adopted for query optimization, by breaking down a single query operation into multiple subtasks and executing them in parallel on multiple threads to improve execution efficiency.

5. The database adapter based on domain driven design and object relational mapping technology according to claim 1, characterized in that: The optimization module generates multiple possible execution plans based on statistics and cost models, and selects the best one taking into account the following factors: Access path, connection method, and sorting method.

6. The database adapter based on domain driven design and object relational mapping technology according to claim 1, characterized in that: The optimization module considers factors such as data distribution, index usage, and disk IO when evaluating the generated execution plan.