Data persistence layer design method and system, storage medium and electronic equipment
Through the ontology-based data persistence layer design method, the construction of conceptual models and the creation of SQL syntax are solved, and the traditional persistence layer design method is ineffective in development and maintenance difficulties are achieved, and more efficient object-relational data storage and applications are achieved.
Patent Information
- Application Number
- CN202411919850.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-25
- Publication Date
- 2025-05-27
AI Technical Summary
Traditional persistent layer design methods have problems with inefficient development and difficulty in maintaining persistent layer code.
Using the ontology-based data persistence layer design method, by building a conceptual model and creating a SQL syntax, SQL statements of object data are generated, and the object data is stored in the database. At the same time, class objects are generated through deserialization and class object data are assembled.
It improves development efficiency, reduces the difficulty of maintaining persistent layer code, and realizes the storage and application of object-relational data through meta-model modeling, which is more convenient and efficient.
Smart Images

Figure CN120045544A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of electronic digital data processing, and in particular, to a data persistence layer design method, a design system, a storage medium, and an electronic device. Background Art
[0002] The traditional persistence layer design method is to form an ORM (Object-Relational Mapping) mapping through XML (eXtensible Markup Language) configuration, that is, an object-relational data mapping component. It is necessary to develop using both object-oriented and relational data at the same time. During collaborative team development, problems are likely to occur due to untimely communication and coordination or insufficient understanding, and it is difficult to maintain the persistence layer code.
[0003] Therefore, how to propose a new data persistence layer design method to improve development efficiency and reduce the maintenance difficulty of the persistence layer code has become a technical problem to be solved urgently at present. Summary of the Invention
[0004] In view of this, the present invention aims to solve the problems of low development efficiency and difficult maintenance of the persistence layer code existing in the traditional persistence layer design method.
[0005] Specifically, the present invention is implemented through the following technical solutions:
[0006] According to a first aspect of the present invention, there is provided a data persistence layer design method based on ontology, including: constructing a concept model based on ontology, and creating an SQL syntax analyzer in combination with an SQL (Structured Query Language) semantic graph; obtaining object data; generating an SQL statement for the object data according to the definition of the ontology and the SQL syntax analyzer; executing the SQL statement and storing the object data in a database; deserializing the SQL statement to generate a class object, and assembling the class object according to the object data to generate class object data.
[0007] Optionally, in some technical solutions, the step of generating an SQL statement for the object data according to the definition of the ontology and the SQL syntax analyzer includes: generating a first SQL statement according to the SQL syntax analyzer; generating a second SQL statement according to the object data, and using the first SQL statement and the second SQL statement as the SQL statement for the object data.
[0008] Optionally, in some technical solutions, the steps of generating an SQL statement for object data according to the definition of the ontology and the SQL syntax parser include: obtaining the type of object data, its own attributes, and the data types corresponding to each attribute according to the definition of the ontology; determining the corresponding database table according to the type of object data; determining the corresponding database table fields according to the own attributes; determining the data types corresponding to the database table fields according to the data types corresponding to each attribute; and generating an SQL statement for object data according to the database table, the database table fields, the data types corresponding to the database table fields, the object data, and the SQL syntax parser.
[0009] Optionally, in some technical solutions, the types of object data include department objects and user objects, and the data types corresponding to each attribute include string type, numerical type, boolean type, and text type.
[0010] Optionally, in some technical solutions, the steps of deserializing the SQL statement to generate a class object and assembling the class object according to the object data to generate class object data include: querying the database according to the SQL statement to obtain a query result set; parsing the metadata in the query result set and obtaining table field information; creating a class object according to the table field information and the definition of the ontology; and looping through each piece of metadata to assemble object data for the class object to generate class object data.
[0011] Optionally, in some technical solutions, when deserializing to generate a class object, a custom translation method is used to translate data of boolean data type and date type.
[0012] Optionally, in some technical solutions, the SQL syntax parser is applicable to database management systems of multiple platforms.
[0013] According to a second aspect of the present invention, there is provided a data persistence layer design system based on ontology, including: a construction unit for constructing a concept model based on the ontology and creating an SQL syntax parser in combination with an SQL semantic graph; an acquisition unit for acquiring object data; a generation unit for generating an SQL statement for object data according to the definition of the ontology and the SQL syntax parser; an execution unit for executing the SQL statement and storing the object data in a database; and the generation unit is further configured to deserialize the SQL statement to generate a class object and assemble the class object according to the object data to generate class object data.
[0014] According to a third aspect of the present invention, there is provided a storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of the data persistence layer design method based on ontology in the first aspect or any possible implementation manner of the first aspect of the present invention are implemented.
[0015] According to a fourth aspect of the present invention, there is provided an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the steps of the data persistence layer design method based on ontology in the first aspect of the present invention or any possible implementation manner of the first aspect are implemented.
[0016] The technical solution provided by the present invention at least brings the following beneficial effects:
[0017] The present invention provides a data persistence layer design method based on ontology.
[0018] The data persistence layer design method based on ontology provided by the present invention obtains the attributes and relationships of object classes through an ontology meta-model, and can deserialize objects from a database, that is, generate database SQL statements through this meta-model information to persist data. Implementing the storage and application of object-relational data through meta-model modeling is more convenient and efficient. Developers can also more easily understand the logical relationships between object-relational data, improving development efficiency. And by generating SQL statements through an SQL syntax parser, the amount of code is reduced, and the maintenance difficulty of the persistence layer code is lowered. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The accompanying drawings here are incorporated into the specification and constitute a part of this specification, showing embodiments consistent with the present invention, and are used together with the specification to explain the principles of the present invention.
[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the accompanying drawings required for use in the description of the embodiments or related technologies. Obviously, for those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0021] Figure 1 It is a schematic flowchart of a data persistence layer design method based on ontology provided by an embodiment of the present invention;
[0022] Figure 2 It is a schematic flowchart of another data persistence layer design method based on ontology provided by an embodiment of the present invention;
[0023] Figure 3 It is a block diagram of a data persistence layer design system based on ontology provided by an embodiment of the present invention;
[0024] Figure 4 It is a block diagram of an electronic device provided by an embodiment of the present invention;
[0025] Figure 5 It is a schematic diagram of an SQL syntax parser provided by an embodiment of the present invention;
[0026] Figure 6 Schematic diagram of another SQL syntax parser provided by an embodiment of the present invention;
[0027] Figure 7 Schematic diagram of data serialization taking HCUser as an example provided by an embodiment of the present invention;
[0028] Figure 8 Schematic diagram of data deserialization taking HCUser as an example provided by an embodiment of the present invention;
[0029] Figure 9 Schematic diagram of database storage provided by an embodiment of the present invention. Detailed implementation manners
[0030] To make the objectives, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are some but not all of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0031] As Figure 1 shown, the present invention provides a method for designing an ontology-based data persistence layer, including:
[0032] S101: Construct a concept model based on the ontology and create an SQL syntax parser in combination with the SQL semantic graph;
[0033] S102: Obtain object data;
[0034] S103: Generate an SQL statement for the object data according to the definition of the ontology and the SQL syntax parser;
[0035] S104: Execute the SQL statement and store the object data in the database;
[0036] S105: Deserialize the SQL statement to generate a class object and assemble the class object according to the object data to generate class object data.
[0037] The data persistence layer design method based on ontology provided by the present invention. First, a conceptual model is constructed based on ontology, and an SQL syntax generator is created in combination with an SQL semantic graph. Here, ontology is a formal framework used to define and classify entities and the relationships between entities. SQL is a standard programming language for managing and processing relational databases, capable of performing queries, inserts, updates, and deletes on data in the database, as well as defining and managing the structure of the database. At the same time, the SQL syntax generator is an application tool that can describe the mapping relationship between object data and the database. Then, object data is obtained. Object data is the specific data unit generated by class instantiation in object-oriented programming. Each object has its own attributes and methods. Object data is the specific data representation in the program, used to store and operate on actual information. Ontology is an abstract description of object data. Combining the definition of ontology and the SQL syntax generator can generate SQL statements for object data. While executing the SQL statements, the object data is stored in the database, that is, the object data is serialized, and at the same time, the object data is stored in the database. Finally, the SQL statements are deserialized to generate class objects, and the class objects are assembled according to the object data to generate class object data. The attributes and relationships of the object classes are obtained through the ontology meta-model, and objects can be deserialized from the database, that is, database SQL statements are generated through this meta-model information to persist data. Through meta-model modeling, the storage and application of object-relational data are more convenient and efficient. Developers can also more easily understand the logical relationship between object-relational data, improving development efficiency. And by generating SQL statements through the SQL syntax generator, the amount of code is reduced, and the maintenance difficulty of the persistence layer code is lowered.
[0038] Optionally, in some embodiments, the step of generating SQL statements for object data according to the definition of ontology and the SQL syntax generator includes: generating a first SQL statement according to the SQL syntax generator; generating a second SQL statement according to the object data, and using the first SQL statement and the second SQL statement as the SQL statements for object data.
[0039] In this embodiment, the first SQL statement generated by the SQL syntax generator and the second SQL statement generated by the object data are combined to form the SQL statements for object data. When the code part that needs to use the SQL statements is reached, the previously defined SQL syntax generator is used to generate the required SQL statements configurably according to the current code, thus avoiding the use of traditional string concatenation. When generating long or difficult SQL statements, it can also be efficiently completed and the error rate can be reduced. It can be understood that directly using string concatenation to construct SQL statements in current application development is not only error-prone but also difficult to maintain. As the application programs become more and more complex, the SQL statements may also become very long and difficult to manage. By using the SQL syntax generator to generate SQL statements, the error rate and maintenance difficulty are reduced.
[0040] Optionally, in some embodiments, the step of generating an SQL statement for object data according to the ontology definition and the SQL syntax parser includes: obtaining the type of the object data, its own attributes, and the data types corresponding to each attribute according to the ontology definition; determining the corresponding database table according to the type of the object data; determining the corresponding database table fields according to the own attributes; determining the data types corresponding to the database table fields according to the data types corresponding to each attribute; and generating an SQL statement for the object data according to the database table, the database table fields, the data types corresponding to the database table fields, the object data, and the SQL syntax parser.
[0041] In this embodiment, the ontology definition of the object data based on the ontology is obtained. The ontology definition includes the type of its own object class, its own attributes, and the data types corresponding to each attribute. According to the type of its own object class, the corresponding database table can be found. According to its own attributes, the corresponding database table fields can be found. According to the data types corresponding to each attribute, information such as strings, texts, binaries, booleans, and dates can be found correspondingly. Finally, according to information such as the database table, the database table fields, and the data types corresponding to the database fields, as well as the SQL syntax parser and the data values of the object data itself, the corresponding SQL statement is generated. Eventually, with the execution of the SQL statement, the data is stored in the database. That is, by serializing the object data and storing it in the database, the data storage volume can be reduced. For complex object data, the object data can be serialized to avoid creating too many associated tables and also reduce the query difficulty.
[0042] Optionally, in some embodiments, the types of object data include department objects and user objects, and the data types corresponding to each attribute include string type, numerical type, boolean type, and text type.
[0043] In this embodiment, when serializing data, the data types corresponding to each attribute field can be obtained based on the ontology definition of the object, including string type, numerical type, boolean type, text type, etc. At the same time, the type of object data can also be other object type data defined by the ontology, including department objects and user objects, etc. By clarifying the data types in this embodiment, the consistency and correctness of the data are ensured, errors are avoided, and different types of data can be stored more efficiently for storage and query.
[0044] Optionally, in some embodiments, the steps of deserializing an SQL statement to generate a class object and assembling the class object according to the object data to generate class object data include: querying the database according to the SQL statement to obtain a query result set; parsing the metadata in the query result set and obtaining table field information; creating a class object according to the table field information and the ontology definition; and looping through each piece of metadata to assemble object data for the class object to generate class object data.
[0045] In this embodiment, deserializing the data in the database to generate an object specifically includes: First, query the database according to the SQL statement to obtain the query result set. The query result set includes metadata. Parse the metadata to obtain the table field information. Then, create a class object according to the table field information and the definition of the ontology. Loop through each row of metadata and assemble the data of the class object according to the object data. Finally, generate the complete class object data. That is, through deserialization, the data stored in the database can be restored to an object, which enables developers to more easily understand the structure and relationships of the data, reduces errors and misunderstandings, improves development efficiency, and reduces the difficulty of maintenance.
[0046] Optionally, in some embodiments, when deserializing to generate a class object, a custom translation method is used to translate the data of the boolean data type and the date type.
[0047] In this embodiment, when deserializing to generate a class object, using a custom translation method to translate the data of the boolean data type and the date type can not only solve specific data format problems, but also improve the flexibility and accuracy of data processing.
[0048] Among them, taking the boolean data type as an example, if the database stores 0 or 1 in the Number(1) format, then when deserialized to an object, it is false and true; for the date type, the database stores 28-Jul-2303.51.39.101000 PM in the TimeStamp(6) format, and when deserializing, a new date object newDate() will be newly created. Taking the date type as an example, the database stores 28-Jul-2303.51.39.101000 PM in the TimeStamp(6) format, and when deserializing, a new date object newDate() will be newly created.
[0049] Optionally, in some embodiments, the SQL syntax parser is applicable to the database management systems of multiple platforms.
[0050] In this embodiment, when interacting with the database for information, corresponding SQL statements can be generated through the SQL syntax parser defined by different models. The SQL syntax parser is applicable to the database management systems of multiple platforms, which improves the compatibility of the SQL syntax parser.
[0051] As Figure 2 shown, the present invention provides another ontology-based data persistence layer design method, including:
[0052] S201: Construct a concept model based on the ontology and create an SQL syntax parser in combination with the SQL semantic graph;
[0053] S202: Obtain object data;
[0054] S203: Obtain the type of object data, its own attributes, and the data types corresponding to each attribute according to the definition of the ontology;
[0055] S204: Determine the corresponding database table according to the type of object data;
[0056] S205: Determine the corresponding database table fields according to its own attributes;
[0057] S206: Determine the data types corresponding to the database table fields according to the data types corresponding to each attribute;
[0058] S207: Generate the SQL statement of the object data according to the database table, the database table fields, the data types corresponding to the database table fields, the object data, and the SQL syntax parser;
[0059] S208: Execute the SQL statement and store the object data in the database;
[0060] S209: Query the database according to the SQL statement to obtain the query result set;
[0061] S210: Analyze the metadata in the query result set and obtain the table field information;
[0062] S211: Create a class object according to the table field information and the definition of the ontology;
[0063] S212: Loop through each metadata and assemble the object data for the class object to generate the class object data.
[0064] As Figure 3 shown, the present invention provides a data persistence layer design system 10 based on ontology, including: a construction unit 11 for constructing a concept model based on ontology and creating an SQL syntax parser in combination with an SQL semantic graph; an acquisition unit 12 for acquiring object data; a generation unit 13 for generating an SQL statement of the object data according to the definition of the ontology and the SQL syntax parser; an execution unit 14 for executing the SQL statement and storing the object data in the database; the generation unit 13 is further configured to deserialize the SQL statement to generate a class object and assemble the class object according to the object data to generate the class object data.
[0065] The ontology-based data persistence layer design system 10 provided by the present invention includes a construction unit 11, an acquisition unit 12, a generation unit 13, and an execution unit 14. The construction unit 11 is used to construct a concept model based on the ontology and create an SQL syntax parser in combination with the SQL semantic graph. Herein, the ontology is a formal framework for defining and classifying entities and the relationships between entities. SQL is a standard programming language for managing and processing relational databases, capable of executing queries, inserting, updating, and deleting data in the database, as well as defining and managing the structure of the database. Meanwhile, the SQL syntax parser is an application tool that can describe the object data and database mapping relationship. The acquisition unit 12 is used to acquire object data. Object data is the specific data unit generated by class instantiation in object-oriented programming. Each object has its own attributes and methods. Object data is the specific data representation in the program, used to store and operate on actual information. The ontology is an abstract description of the object data. Combining the definition of the ontology and the SQL syntax parser can generate SQL statements for the object data. While the execution unit 14 executes the SQL statements, the object data is stored in the database, that is, the object data is serialized, and at the same time, the object data is stored in the database. Finally, the generation unit 13 is used to deserialize the SQL statements to generate class objects, and assemble the class objects according to the object data to generate class object data. The attributes and relationships of the object classes are obtained through the ontology meta-model, and objects can be deserialized from the database, that is, database SQL statements are generated through this meta-model information to persist the data. Through meta-model modeling, the storage and application of object-relational data are more convenient and efficient. Developers can also more easily understand the logical relationship between object-relational data, improving the development efficiency. And by generating SQL statements through the SQL syntax parser, the amount of code is reduced, and the maintenance difficulty of the persistence layer code is lowered.
[0066] The present invention provides a storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the meta-model construction method based on the prototype chain in the first aspect of the present invention or any possible implementation manner of the first aspect are realized.
[0067] As Figure 4 shown, the present invention provides an electronic device 20, including a memory 21, a processor 22, and a computer program stored on the memory 21 and executable on the processor 22. When the processor 22 executes the computer program, the steps of the meta-model construction method based on the prototype chain in the first aspect of the present invention or any possible implementation manner of the first aspect are realized.
[0068] For the specific implementation process of the functions and roles of each unit in the above system, refer to the implementation process of the corresponding steps in the above method in detail, which will not be elaborated here.
[0069] In a specific application, taking the HCUser object as an example, the design method of the ontology-based data persistence layer is further described, including:
[0070] Step 1: Design and develop an application for the SQL syntax parser. As Figure 5 shown, based on the ontology definition and modeled according to the SQL semantic graph, the design and application of the SQL syntax parser model are completed. When interacting with the database, the corresponding SQL statements can be generated through the SQL syntax parsers defined by different models. As Figure 6 shown, the query SQL for HCUser is "var select = newModel.svc.odb.sql.Select({tables:['MODEL_ORG_HCUSER']});".
[0071] Step 2: As Figure 7 and Figure 9 shown, object data serialization and storage into the database. For the object data based on the ontology, obtain its ontology definition, and according to the types corresponding to the class fields, obtain the corresponding object classes at the backend. For example, if there is a class field record of Model.org.HCUser on the front-end HCUser object, there is a unique class object Model.org.HCUser corresponding to it at the backend. Including the type of its own object class Model.org.HCUser, the corresponding database table MODEL_ORG_HCUSER can be found; its own attributes, that is, the corresponding database table fields such as name, sn, and sex; the data types corresponding to each attribute, such as name–StringType–VarChar(1000), etc. According to the information such as the database table, database table fields, and data types corresponding to the database fields, as well as the application of the SQL syntax parser tool, plus the data values of the object itself, the corresponding SQL statement 'INSERT INTO MODEL_ORG_HCUSER(oid,classClass,name,description,path,seq,s…:userExpandClassClass,:departmentOid,:departmentClassClass)' can be generated. Finally, with the execution of the SQL statement, the data is stored in the database. As Figure 9 shown, the Row1 column represents the database table fields, and the Fields column represents the data values of the object itself.
[0072] Step 3: As Figure 8 and Figure 9As shown, the database data is deserialized to generate an object. For the result set queried according to the SQL statement, its metadata corresponds to the table fields, which are the data corresponding to the database table fields. According to the ontology-based definition corresponding to the class field Model.org.HCUser, a new class object is constructed, and information such as attribute fields and field data types is obtained according to the ontology class definition in the first step. For example, var o = new Model.org.HCUser(); Loop through each row of data and assemble the class object data according to the data information. For example, o.name = 'Zhang San'. This includes translating some data type fields that require special processing, such as boolean and date data types. For example, o.disableFlag = value == 0? false : true. Finally, the complete class object data is generated.
[0073] It should be noted that in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variation thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, article or device comprising the element.
[0074] The above are only specific embodiments of the present invention, enabling those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to these embodiments shown herein, but rather to the broadest scope consistent with the principles and novel features claimed herein.
Claims
1. A data persistence layer design method based on ontology, characterized in that: include: Build a conceptual model based on the ontology and create a SQL grammar based on the SQL semantic graph; Get object data; Generate an SQL statement for the object data according to the definition of the ontology and the SQL grammar; Execute the SQL statement and store the object data in the database; The SQL statement is deserialized to generate a class object, and the class object is assembled according to the object data to generate class object data.
2. The ontology-based data persistence layer design method according to claim 1, characterized in that: The step of generating the SQL statement of the object data according to the definition of the ontology and the SQL grammar comprises: Generate a first SQL statement according to the SQL grammar; A second SQL statement is generated according to the object data, and the first SQL statement and the second SQL statement are used as SQL statements for the object data.
3. The ontology-based data persistence layer design method according to claim 1, characterized in that: The step of generating the SQL statement of the object data according to the definition of the ontology and the SQL grammar comprises: According to the definition of the ontology, the type of the object data, its own attributes and the data types corresponding to each attribute are obtained; Determine a corresponding database table according to the type of the object data; Determine the corresponding database table field according to the own attribute; Determine the data type corresponding to the database table field according to the data type corresponding to each attribute; An SQL statement for the object data is generated according to the database table, the database table fields, the data types corresponding to the database table fields, the object data and the SQL grammar.
4. The ontology-based data persistence layer design method according to claim 3 is characterized in that: The types of the object data include department objects and user objects, and the data types corresponding to the various attributes include string type, numerical type, Boolean type and text type.
5. The ontology-based data persistence layer design method according to claim 1 is characterized in that: The step of deserializing the SQL statement to generate a class object, and assembling the class object according to the object data to generate class object data comprises: Query the database according to the SQL statement to obtain a query result set; Parsing metadata in the query result set and obtaining table field information; Create the class object according to the table field information and the definition of the ontology; Loop through each of the metadata, assemble the object data for the class object to generate the class object data.
6. The ontology-based data persistence layer design method according to claim 1, characterized in that: When deserializing to generate the class object, a custom translation method is used to translate the Boolean data type and the date type data.
7. The ontology-based data persistence layer design method according to any one of claims 1 to 6, characterized in that: The SQL grammar is applicable to database management systems of multiple platforms.
8. A data persistence layer design system based on ontology, characterized in that: include: The construction unit is used to build a conceptual model based on the ontology and create an SQL grammar in combination with the SQL semantic graph; An acquisition unit, used for acquiring object data; A generating unit, configured to generate an SQL statement for the object data according to the definition of the ontology and the SQL grammar; An execution unit, used for executing the SQL statement and storing the object data in a database; The generating unit is further used for deserializing the SQL statement to generate a class object, and assembling the class object according to the object data to generate class object data.
9. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the ontology-based data persistence layer design method according to any one of claims 1 to 7 are implemented.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the ontology-based data persistence layer design method according to any one of claims 1 to 7 are implemented.