CN114096956A - Method and device for representing database operation layer - Google Patents

Method and device for representing database operation layer Download PDF

Info

Publication number
CN114096956A
CN114096956A CN201980096445.5A CN201980096445A CN114096956A CN 114096956 A CN114096956 A CN 114096956A CN 201980096445 A CN201980096445 A CN 201980096445A CN 114096956 A CN114096956 A CN 114096956A
Authority
CN
China
Prior art keywords
class
entity
operation layer
database
type
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201980096445.5A
Other languages
Chinese (zh)
Inventor
张卫平
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Global Digital Group Co Ltd
Original Assignee
Global Digital Group Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Global Digital Group Co Ltd filed Critical Global Digital Group Co Ltd
Publication of CN114096956A publication Critical patent/CN114096956A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor

Abstract

A method and a device for representing a database operation layer are provided, the method comprises the following steps: configuring the mapping relation of the entity class, and specifying the mapping relation between the entity class and the table; identifying the transmitted parameter type by the class method of the operation layer through configuration, and taking out the SQL statement of the method from the template according to the transmitted parameter type or the configuration to obtain a required result; and according to the input parameters or the configuration in the template, assembling the generated result into the required class object and returning. According to the method, the JPA mechanism is used in the MyBatis framework to make up the defects of MyBatis reusability and the defects of query statements during operation, so that the system is easy to develop and reuse, and the characteristic that the MyBatis flexibly configures the SQL aiming at complex business logic is reserved.

Description

Method and device for representing database operation layer Technical Field
The invention relates to the technical field of databases, in particular to a method and a device for representing a database operation layer.
Background
The requirement at the data operation (DAO) level is to operate on entity classes/objects or SQL statements via the data operation class DAO.
The common representation mode of the entity class/object is a JPA/ORM mode, wherein ORM is object relational mapping, the object is associated with a table of a database, the corresponding relation between an entity object and the table and between an entity object attribute and a table column is specified, and JPA provides the specification of the relational mapping but does not provide the implementation mode of the relational mapping; an entity object refers to an object that corresponds to and represents a table in a database, and is an associative bridge of classes and tables.
The mainstream framework for implementing the ORM currently has many but not two implementation manners, and earlier frameworks including hibernate, castor, etc. provide a base (data operation) class to operate the database, where the class includes a limited number of methods for performing incremental and destructive inspection on entity classes and objects, and a limited number of methods for performing incremental and destructive inspection through incoming SQL statements, and the database can only be implemented by calling the methods of the base class to operate in a program, which has the advantages of high code reusability, but has the disadvantages that: 1. the code flexibility is poor, the requirements are diversified, and sometimes, the method is not convenient to call; 2. if complex SQL sentences are needed in a complex business scene, the sentences are spliced in codes by hard coding, and the hard coding is difficult to understand and poor in maintainability.
Another implementation is MyBatis, configuring the methods in ORM and DAO through SQL template, belonging to the type of add-delete-modify-Check (CUID), SQL statement, and object type return, ORM is only used for object return type assembly. MyBatis relatively increases business flexibility and code intelligibility because developers can define DAO layer operation methods at will and correspond to SQL templates; the disadvantages are that: 1. the ORM of the MyBatis mode only does ORM when the DAO layer method returns data, the program can not simply add, delete, modify and check the table through the entity class/object, each method of MyBatis needs to write SQL codes in the template, 2, MyBatis can not be reused, and the maintainability is influenced.
Technical problem
The technical problem to be solved by the invention is that the prior art cannot have the characteristics of high reusability and strong code flexibility and the code has poor maintainability.
Technical solution
The present invention is directed to solve the above problems, and provides a method and an apparatus for representing a database operation layer with high code flexibility and strong reusability.
In order to solve the above technical problem, a technical solution adopted by the present application is to provide a method for representing an operation layer of a database, the method including: the class method of the operation layer identifies the input parameter type through configuration, and extracts the SQL statement of the method from the template according to the input parameter type or configuration, generates a dynamic SQL statement or further generates the required dynamic SQL statement after extracting the SQL statement of the method; executing the SQL statement to obtain a required result; and according to the input parameters or the configuration in the template, assembling the generated result into the required class object and returning.
In order to solve the above technical problem, the present application adopts a technical solution of providing a database operating apparatus, the apparatus including: the system comprises an operation layer, a realization framework, a service layer and a service layer, wherein the operation layer comprises a class of the operation layer and a class method of the operation layer, the class method of the operation layer specifies an incoming parameter type by configuration, the incoming parameter type comprises an entity class and/or an entity object and/or a main key and/or SQL (structured query language) statement and/or paging information, and if the parameter comprises the entity class, the entity class analyzes a JPA (Java native application platform) mapping relation between the entity class and a table; the entity class is used for defining an ORM mapping relation between the entity class and the table; the SQL template is used for realizing the data adding, deleting, modifying, checking and flexible configuration.
In order to solve the above technical problem, a technical solution adopted by the present application is to provide a database entity class configuration method, including: and (3) checking a null value of the bound property/column during addition, deletion or modification when the column property of the entity class is configured, and if the check is the null value, triggering corresponding operation, otherwise, not operating.
In order to solve the above technical problem, a technical solution adopted by the present application is to provide a column attribute generating method, including: the column attribute generation is defined to be composed of a first generation selection, a second alternative generation selection and a plurality of alternative generation selections, and if the first generation fails, the column attribute value is obtained through the second alternative generation.
In order to solve the above technical problem, a technical solution adopted in the present application is to provide a cache mechanism, where the apparatus includes: the caching strategy of the class is stated in the configuration of the entity class, the caching strategy of the class comprises a whole-table memory cache, a whole-table external memory cache and a non-cache, the memory cache is stored in a whole-table memory, and the external cache is cached in other programs or equipment according to a removal strategy.
In order to solve the above technical problem, the present application adopts a technical solution of providing a MyBatis database caching device, which includes: and configuring the caching strategies in the entity class into an internal memory cache, a whole-table external memory cache and a non-cache, preferentially using the internal cache and the external cache of the entity class, and if the entity class is not configured with the cache, using a cache mechanism of MyBatis according to the generated SQL statement.
Advantageous effects
The JPA mechanism is used in the MyBatis framework to make up the defects of MyBatis reusability and query statements during operation, so that the system has easy development and reusability, and the characteristic of flexibly configuring the SQL of MyBatis is reserved for complex business logic.
Drawings
Fig. 1 is a flowchart illustrating a method for representing a database operation layer according to an embodiment of the present invention.
Modes for carrying out the invention
In order to make the objects, technical solutions and advantages of the present application clearer, the technical solutions of the present application will be described in more detail below with reference to the accompanying drawings in the embodiments of the present application. The following examples are further illustrative and supplementary to the present invention and do not limit the present invention in any way.
Fig. 1 is a schematic flow chart of a method for representing a database operation layer according to an embodiment of the present invention, where the method includes the following steps:
step S01: and configuring the mapping relation of the entity class, and specifying the mapping relation between the entity class and the table.
Specifically, the entity class or entity object may be an input parameter type of the operation layer, but the input parameter type is not limited to the above two types.
Step S02: identifying the transmitted parameter type by the class method of the operation layer through configuration, taking out the SQL statement of the method from the template according to the transmitted parameter type or configuration, generating a dynamic SQL statement or further generating the required dynamic SQL statement after taking out the SQL statement of the method;
specifically, the class of the operation layer comprises a basic class and an extended class, the basic class realizes a standard method of the JPA basic operation class, the data is added, deleted, modified and checked by transmitting parameters such as an entity class, a main key, an entity object, SQL (structured query language), query conditions and the like, and the extended class realizes the extension of the Mybatis basic operation class and realizes the multiplexing.
Step S03: the SQL statement is executed to obtain the desired result.
Specifically, the type of the return is directly determined by the operation layer parameter type specification, the SQL template specification or the return type of the method, the return type is determined by the method return value priority, the type is determined by the method return value priority, if the return type cannot be judged by the method return value, the type is determined to be priority, if the type is not determined, the return is performed through the type specified by the template, otherwise, the collection of the key value pairs is returned.
Step S04: and according to the input parameters or the configuration in the template, assembling the generated result into the required class object and returning.
In particular embodiments, a specific reserved word may be specified in the operation layer method to represent the object type required by the JPA, and the framework identifies the object type represented by the reserved word from the configuration of the operation layer method, thereby implementing the JPA conversion.
In a specific embodiment, a reserved word specifying operation can be specified to return an object type, and a query result is converted into the returned object type according to JPA mapping, so that result dynamic conversion is realized.
In a specific embodiment, the operation layer framework learns the type of the incoming parameter by a reserved word comprising: class reserved words, entity object reserved words, id main key reserved words, dynamic import SQL reserved words, SQL additional parameter reserved words, return type reserved words, reserved words meeting query conditions, page reserved words for queries or modifications, and paging information reserved words.
In particular embodiments, if a paging information retention word is incoming, a paging statement may be further generated again from the generated SQL statement.
In a specific embodiment, when the SQL statement is generated, the condition of the SQL statement is written into the MyBatis environment according to the JPA specification.
In a specific embodiment, the SQL statement is executed, a result parameter is returned according to the operation of the data access layer, the ORM is modified when returning, and if the return of the data access layer is a column, the result parameter is mapped as a return value according to the transmitted parameter.
In the specific embodiment, an ORM mechanism is used to perform object association mapping on the relationship between each object mark table name and the object, the operation class is multiplexed, and the methods of checking, adding, deleting, modifying and paging are added to the object association writing.
In a specific embodiment, a JPA mechanism is used in a MyBatis framework to make up for the defects of MyBatis reusability and the defects of query statements in operation, and the system has easy development and reusability and can flexibly configure SQL.
An embodiment of the present invention further provides a database operating apparatus, where the apparatus includes: operation layer, implementation frame, entity class and SQL template.
The operation layer comprises classes and methods of the classes of the operation layer, the methods of the classes of the operation layer specify the types of the input parameters through configuration, the types of the input parameters comprise entity classes and/or entity objects and/or main keys and/or SQL statements and/or paging information, and if the parameters comprise the entity classes, the entity classes analyze JPA mapping relations between the entity classes and the tables on behalf of the entity classes.
The class of the operation layer is the operation class, and the method of the class of the operation layer is the method of the operation layer.
Implementation frameworks include the launch and run mechanisms of the MyBatis framework itself and the MyBatis plug-ins.
Intercepting the data access layer operation of the Mybatis by utilizing a Mybatis plug-in mechanism, converting the input parameters into SQL according to the specific increasing, deleting, modifying and checking operation of the basic class, and returning a correct result to realize the functions of JPA and ORM similar to hibernate of the data operation class of the Mybatis data access layer.
And the entity class is used for defining an ORM mapping relation between the entity class and the table.
The SQL template is used for realizing the data adding, deleting, modifying, checking and flexible configuration.
In a specific embodiment, the device specifies an entity class, an entity object, a primary key, returned or modified fields or attributes, and other query conditions, and if the template SQL corresponding to the basic class or method is empty, the MyBatis plug-in intercepts the attributes to realize the generation of the statement by the framework.
In a specific embodiment, the device specifies paging, total number of query and maximum value query as parameter types, and the MyBatis plug-in intercepts the attributes, so that the framework generates paging statements, total number query statements and maximum value query statements again according to a template or generated statements.
In a specific embodiment, the specified return type is used as a parameter type, the MyBatis plug-in intercepts the attribute, and after the query is executed, JPA mapping is performed according to the specified data type to assemble a return value.
The embodiment of the invention also provides a configuration method of the entity class of the database, which is characterized in that when the column property of the entity class is configured, the null value check of the column property during the addition, deletion or modification is bound, if the check is the null value, the corresponding operation is triggered, otherwise, the operation is not carried out.
In a specific embodiment, the operation triggered by the null value includes: generating column attributes, throwing errors, printing messages, ignoring.
The embodiment of the invention also provides a column attribute generation method, which specifies that the column attribute generation is composed of a first generation selection case, a second alternative generation selection case and a plurality of alternative generation selection cases, and if the first generation fails, the column attribute value is obtained through the second alternative generation.
In a specific embodiment, one generation solution comprises a plurality of generation sequences, and the generation solutions are spliced according to the front-back sequence after being generated by the generation sequences.
In a specific embodiment, the generation order rule of the generation order includes: constants and/or variables, classes and methods, objects and methods.
The embodiment of the invention also provides a caching mechanism, which declares the caching strategy of the class in the configuration of the entity class, wherein the caching strategy of the class comprises whole-table memory caching, whole-table external caching and no caching, the memory caching means that the whole table is stored in the memory, and the external caching means that the external caching is cached in other programs or equipment according to the elimination strategy.
The embodiment of the invention also provides a MyBatis database caching device, wherein the caching strategies are configured in the entity class as memory caching, whole-table external memory caching and no caching, the entity class internal caching and external caching are preferentially used, and if the entity class is not configured with caching, the MyBatis caching mechanism is used according to the generated SQL statement.

Claims (21)

  1. A method for representing an operation layer of a database, comprising:
    configuring the mapping relation of the entity class, and specifying the mapping relation between the entity class and the table;
    identifying the transmitted parameter type by the class method of the operation layer through configuration, taking out the SQL statement of the method from the template according to the transmitted parameter type or configuration, generating a dynamic SQL statement or further generating the required dynamic SQL statement after taking out the SQL statement of the method;
    executing the SQL statement to obtain a required result;
    and according to the input parameters or the configuration in the template, assembling the generated result into the required class object and returning.
  2. The database operation layer representation method of claim 1, wherein an entity class or an entity object can be used as a parameter type introduced by the operation layer.
  3. The database operation layer representation method according to claim 1, wherein the type of the return is directly determined by operation layer parameter type specification, SQL template specification or return type of the method, the method return value determines the return type preferentially, the type is determined preferentially if the return type cannot be judged from the method return value, if no type is specified, the return is performed by the type specified by the template, otherwise, the collection of key value pairs is returned.
  4. The database operation layer representation method of claim 1, wherein specific reserved words are specified in the operation layer method for representing object types required by the JPA, and the framework identifies the object types represented by the reserved words from the configuration of the method of the operation layer, thereby implementing the JPA conversion.
  5. The database operation layer representation method as claimed in claim 4, wherein the reserved word specifying operation is specified to return an object type, and the query result is converted into the returned object type according to JPA mapping, thereby realizing dynamic conversion of the result.
  6. The database operation layer representation method of claim 4, wherein the operation layer framework is aware of the incoming parameter type through a reserved word comprising: class reserved words, entity object reserved words, id main key reserved words, dynamic import SQL reserved words, SQL additional parameter reserved words, return type reserved words, reserved words meeting query conditions, page reserved words for queries or modifications, and paging information reserved words.
  7. The database operation layer representation method according to claim 4, wherein if a paging information retention word is introduced, a paging statement can be further generated again from the generated SQL statement.
  8. The method for representing the database operation layer according to any one of claims 1 to 7, wherein the classes of the operation layer comprise a basic class and an extension class, the basic class realizes a standard method of a JPA basic operation class, the addition and deletion of data is realized by transmitting parameters such as an entity class, a main key, an entity object, SQL, query conditions and the like, and the extension class realizes the implementation of an extension MyBatis basic operation class and realizes multiplexing.
  9. The database operation layer representation method according to any one of claims 1 to 7, wherein the condition of the SQL statement is written into a MyBatis environment according to the JPA specification when the SQL statement is generated.
  10. The database operation layer representation method according to any one of claims 1 to 7, wherein a result parameter is returned according to a data access layer operation when the SQL statement is executed, the ORM when returned is modified, and if the data access layer return is a column, mapping as a return value according to an incoming parameter.
  11. A database operating apparatus, comprising:
    the operation layer comprises classes of the operation layer and methods of the classes of the operation layer, the methods of the classes of the operation layer specify the types of the transmitted parameters through configuration, the types of the parameters comprise entity classes and/or entity objects and/or main keys and/or SQL statements and/or paging information, and if the parameters comprise the entity classes, the entity classes analyze JPA mapping relations between the entity classes and the tables;
    the implementation framework comprises a starting and running mechanism of the MyBatis framework and a MyBatis plug-in;
    the entity class is used for defining an ORM mapping relation between the entity class and the table;
    the SQL template is used for realizing the data adding, deleting, modifying, checking and flexible configuration.
  12. The database operating apparatus according to claim 11, wherein the apparatus specifies an entity class, an entity object, a primary key, a returned or modified field or attribute, and other query conditions, and if the template SQL corresponding to the basic class or method is empty, the MyBatis plug-in intercepts the attributes to implement the framework generation statement.
  13. The database operating apparatus of claim 11, wherein the apparatus specifies paging, total number of query, and maximum value as parameter types, and the MyBatis plug-in intercepts these attributes, so that the implementation framework regenerates paging statements, total number of query statements, and maximum value query statements according to the template or the generated statements.
  14. The apparatus of claim 11, wherein the specified return type is used as a parameter type, and if the MyBatis plug-in intercepts the attribute, the JPA mapping is performed according to the specified data type after the query is executed, so as to assemble the return value.
  15. A configuration method for database entity class is characterized in that when the column property of the entity class is configured, the null value check of the column property during addition, deletion or modification is bound, if the check is null value, the corresponding operation is triggered, otherwise, the operation is not carried out.
  16. The database entity class configuration method of claim 15, wherein the null-triggered operation comprises: generating column attributes, throwing errors, printing messages, ignoring.
  17. A column attribute generation method is characterized in that the column attribute generation is defined to be composed of a first generation selection case, a second alternative generation selection case and a plurality of alternative generation selection cases, and if the first generation fails, a column attribute value is obtained through the second alternative generation.
  18. The method according to claim 17, wherein the one generation scenario includes a plurality of generation sequences, and the generation scenarios are generated by sequentially concatenating the generation sequences.
  19. The column attribute generation method according to claim 18, wherein the generation order rule of the generation order includes: constants and/or variables, classes and methods, objects and methods.
  20. A cache mechanism is characterized in that a cache policy of a class is declared in configuration of an entity class, the cache policy of the class comprises a whole-table memory cache, a whole-table external memory cache and no cache, the memory cache is a whole-table memory cache, and the external cache is cached in other programs or equipment according to a removal policy.
  21. A MyBatis database caching device is characterized in that caching strategies of memory caching, whole-table memory caching and no caching are configured in an entity class, the entity class memory caching and the entity class memory caching are preferentially used, and if the entity class is not configured with caching, a MyBatis caching mechanism is used according to a generated SQL statement.
CN201980096445.5A 2019-05-17 2019-05-17 Method and device for representing database operation layer Pending CN114096956A (en)

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2019/087386 WO2020232569A1 (en) 2019-05-17 2019-05-17 Database access layer representation method and device

Publications (1)

Publication Number Publication Date
CN114096956A true CN114096956A (en) 2022-02-25

Family

ID=73459226

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201980096445.5A Pending CN114096956A (en) 2019-05-17 2019-05-17 Method and device for representing database operation layer

Country Status (2)

Country Link
CN (1) CN114096956A (en)
WO (1) WO2020232569A1 (en)

Families Citing this family (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112685435A (en) * 2020-12-21 2021-04-20 福建新大陆软件工程有限公司 Table query method and system based on Vue and Mybatis
CN112905630A (en) * 2021-03-31 2021-06-04 浙江太美医疗科技股份有限公司 Data manipulation method, server, and computer-readable medium
CN112905636A (en) * 2021-03-31 2021-06-04 浙江太美医疗科技股份有限公司 Data manipulation method, server, and computer-readable medium
CN112905617B (en) * 2021-03-31 2023-01-24 浙江太美医疗科技股份有限公司 Data writing method, server and computer readable storage medium
CN113239009A (en) * 2021-04-08 2021-08-10 大唐软件技术股份有限公司 Database operation method, device, equipment and storage medium
CN113190264B (en) * 2021-04-29 2024-02-23 上海天好信息技术股份有限公司 JPA-based automatic data version generation and application device and method
CN113656433B (en) * 2021-08-16 2023-09-05 北京京东振世信息技术有限公司 Entity object expansion method, entity object expansion device, electronic equipment and storage medium
CN113608724B (en) * 2021-08-24 2023-12-15 上海德拓信息技术股份有限公司 Offline warehouse real-time interaction method and system based on model cache implementation
CN114356438B (en) * 2021-12-14 2023-08-18 海尔优家智能科技(北京)有限公司 Intelligent scene starting method and device, electronic equipment and storage medium
CN114519582A (en) * 2022-02-21 2022-05-20 中国邮政储蓄银行股份有限公司 Service preheating method, preheating device and service system
CN114356302B (en) * 2022-03-15 2022-06-21 江苏数兑科技有限公司 Gremlin language-based persistence layer optimization method
CN114756554B (en) * 2022-06-13 2022-09-30 中建电子商务有限责任公司 Data query processing method based on MyBatis framework
CN116107585B (en) * 2023-02-17 2024-03-08 广东保伦电子股份有限公司 Method and device for generating xml in compiling period of server side

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103116622B (en) * 2013-01-30 2016-03-09 深圳联友科技有限公司 A kind of sequence value generation method for Ibatis scheme and device
US9389934B1 (en) * 2014-12-18 2016-07-12 Sap Se Centralized and distributed notification handling system for software applications
CN106682042B (en) * 2015-11-11 2019-11-22 杭州海康威视数字技术股份有限公司 A kind of relation data caching and querying method and device
CN108090063A (en) * 2016-11-21 2018-05-29 深圳联友科技有限公司 A kind of configurable module data access method and device
CN107392053A (en) * 2017-08-11 2017-11-24 四川长虹电器股份有限公司 A kind of data permission control method in enterprise staff information database

Also Published As

Publication number Publication date
WO2020232569A1 (en) 2020-11-26

Similar Documents

Publication Publication Date Title
CN114096956A (en) Method and device for representing database operation layer
KR100995199B1 (en) Reflection-based processing of input parameters for commands
US10331425B2 (en) Automated source code adaption to inject features between platform versions
US20040015822A1 (en) Method and apparatus for dynamic assembly and verification of software components into flexible applications
US20080098037A1 (en) Markup language based database upgrades
CN109947422B (en) Business entity implementation method and system based on domain-driven design
US10437564B1 (en) Object mapping and conversion system
JPH1040087A (en) Method for handling data model to be used for software engineering
CN107330014B (en) Data table creating method and device
US11893367B2 (en) Source code conversion from application program interface to policy document
CN110727482B (en) Interface updating method and device
WO2018233673A1 (en) Method and apparatus for configuring model code in controller, and storage medium
CN111240772A (en) Data processing method and device based on block chain and storage medium
US20130297755A1 (en) Network element configuration management
US7657869B2 (en) Integration of external tools into an existing design environment
US20050021686A1 (en) Automated transformation of specifications for devices into executable modules
CN110347416B (en) Script updating method and device
US10540157B2 (en) Systems to remove object relational mappings from a software project
CN108845793B (en) ORM design method and device
CN113608748B (en) Data processing method, device and equipment for converting C language into Java language
CN112783573A (en) SELinux strategy configuration system and method for multiple user-defined services
CN116627390B (en) ICD file substitution method and device in aviation software development
CN116756727B (en) Data authority control method and device, electronic equipment and storage medium
CN116737162A (en) Code compiling method and device, electronic equipment and medium
CN117971863A (en) Data source connection method for realizing micro-service merging deployment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination