Method, device and equipment for directly transmitting context parameters into SQL (Structured Query Language) statements
By obtaining user-defined entity and context parameter keys, using an interceptor to intercept user requests and inject user information, the complex and cross-platform compatibility problems of SQL statement processing in the prior art are solved, dynamic database query and operation are realized, and business flexibility and security are improved.
Patent Information
- Application Number
- CN202510245394.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-04
- Publication Date
- 2025-04-01
- Estimated Expiration
- 2045-03-04
AI Technical Summary
In existing database query and operation techniques, when passing context parameters using placeholders or bound variables, SQL statements are complicated to process and are limited by database support, resulting in cross-platform compatibility issues.
By obtaining user-defined entities, context parameter keys, and methods used to implement user-related information incoming, use an interceptor to intercept user requests, parse user unique identifiers, access the database to obtain user information, and store it in the inheritableThreadLocals variable. Rewrite the Intercept method based on a custom interceptor and inject context parameters directly into SQL statements.
It realizes dynamic database query and operation, simplifies SQL statement processing, improves business flexibility and security, and avoids compatibility issues across database platforms.
Smart Images

Figure CN119739737A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of database query and operation, and in particular relates to a method, a device and equipment for directly transmitting context parameters to SQL statements. Background Art
[0002] At present, in the existing database query and operation technologies, the common way to pass context parameters to SQL (Structured Query Language, a database query and programming language used to access data and query, update and manage relational database systems) statements is to use placeholders or bind variables. Although these placeholders can be specified in SQL statements and replaced by parameters during execution, there are also the following problems: (1) SQL statement processing is complex, that is, if complex SQL logic is involved, the use of placeholders or bind variables may require more work to handle parameter passing and replacement; (2) It is limited by database support, that is, different database management systems have different levels of support for placeholders and bind variables, so you may need to pay attention to compatibility issues when crossing database platforms. Summary of the invention
[0003] The purpose of the present invention is to provide a method, apparatus, computer device, computer readable storage medium and computer program product for directly transmitting context parameters to SQL statements, so as to solve the problems of complex SQL statement processing and limitation of database support in existing context parameter transmission schemes.
[0004] In order to achieve the above object, the present invention adopts the following technical solutions: In a first aspect, a method for directly passing context parameters to an SQL statement is provided, comprising: Get the user-defined entity, context parameter key and method for implementing the user-related information input, where the entity contains the attribute of the inheritableThreadLocals variable and the method for setting and getting the context parameter key; Use the UserInterceptorHandler interceptor to intercept all user requests, parse the interception results to obtain the user's unique identifier, then access the database according to the user's unique identifier to obtain the user's related information pre-stored in the database and bound to the user's unique identifier, and finally call the method in the entity for setting the context parameter key to store the user's related information into the inheritableThreadLocals variable; Rewrite the Intercept method based on the user-defined interceptor MybatisSqlParamInterceptor; In all SQL statements involving context parameters, the method for implementing the input of user-related information is used to obtain any user-related information and input it into the SQL statement.
[0005] Based on the above invention content, a new solution is provided for directly passing context parameters into SQL statements to realize dynamic database query and operation, that is, after obtaining the user-defined entity, context parameter key and the method for realizing the user-related information input, an interceptor is used to intercept all user requests, and the interception result is parsed to obtain the user's unique identifier, and then the database is accessed according to the identifier to obtain the user's related information, and the setting method is called to store the user-related information into a variable, and then the Intercept method is rewritten based on the user-defined interceptor, and finally in all SQL statements involving context parameters, the input method is used to obtain any user-related information and pass it into the SQL statement, which can meet the demand for dynamically passing context parameters in database query and operation, simplify SQL statement processing and no longer be restricted by the database, improve the flexibility and security of the business, and facilitate practical application and promotion.
[0006] In a possible design, before accessing the database according to the user unique identifier to obtain user related information pre-stored in the database and stored in binding with the user unique identifier, the method further includes: After the user logs in, all information related to the user is stored in the database, wherein all the information includes the user's name, user account, user gender and / or user authority.
[0007] In a possible design, the database adopts a Redis database.
[0008] In a possible design, the Intercept method is rewritten based on the user-defined interceptor MybatisSqlParamInterceptor, including: Get the parameter array in the target method intercepted by the user-defined interceptor MybatisSqlParamInterceptor, where the parameter array contains all the parameters required by the target method; Extracting the first parameter from the parameter array and converting it into a MappedStatement object, wherein the MappedStatement object contains relevant information required to execute the SQL statement; Extract the second parameter from the parameter array and convert it into a Map type, and inject the user information into the SQL statement being compiled; The second parameter in the parameter array is modified to the Map type, and then the subsequent interceptor chain and SQL operation are continued.
[0009] In one possible design, user information is injected into the SQL statement being compiled, including: Inject common context parameters into the SQL statement being compiled; The method in the entity for obtaining the context parameter key is called to store the user information into the Map type.
[0010] In one possible design, injecting user information into the SQL statement being compiled also includes: The creation time, modification time and / or operator information are maintained in the Map type.
[0011] In a second aspect, a device for directly transmitting context parameters to SQL statements is provided, comprising a definition content acquisition unit, a request interception processing unit, a method rewriting processing unit, and a user information input unit which are sequentially connected in communication; The definition content acquisition unit is used to obtain a user-defined entity, a context parameter key, and a method for implementing the input of user-related information, wherein the entity includes an attribute of an inheritableThreadLocals variable and a method for setting and obtaining the context parameter key; The request interception processing unit is used to intercept all requests of the user using the UserInterceptorHandler interceptor, and parse the interception result to obtain the user unique identifier, and then access the database according to the user unique identifier to obtain the user related information pre-stored in the database and bound to the user unique identifier, and finally call the method in the entity and used to set the context parameter key to store the user related information into the inheritableThreadLocals variable; The method rewriting processing unit is used to rewrite the Intercept method based on the user-defined interceptor MybatisSqlParamInterceptor; The user information input unit is used to obtain any user-related information and input it into the SQL statement using the method for implementing user-related information input in all SQL statements involving context parameters.
[0012] In a third aspect, the present invention provides a computer device comprising a memory, a processor and a transceiver which are communicatively connected in sequence, wherein the memory is used to store a computer program, the transceiver is used to send and receive messages, and the processor is used to read the computer program and execute the method for implementing the direct passing of context parameters into an SQL statement as described in the first aspect or any possible design of the first aspect.
[0013] In a fourth aspect, the present invention provides a computer-readable storage medium having instructions stored thereon, which, when executed on a computer, executes a method for implementing direct passing of context parameters into an SQL statement as described in the first aspect or any possible design of the first aspect.
[0014] In a fifth aspect, the present invention provides a computer program product, including a computer program or instructions, which, when executed by a computer, implement the method of directly passing context parameters into a SQL statement as described in the first aspect or any possible design of the first aspect.
[0015] Beneficial effects of the above scheme: (1) The present invention creatively provides a new solution for directly passing context parameters into SQL statements to realize dynamic database query and operation. That is, after obtaining the user-defined entity, context parameter key and the method for implementing the user-related information input, an interceptor is used to intercept all user requests, and the interception result is parsed to obtain the user's unique identifier. Then, the database is accessed according to the identifier to obtain the user's related information, and the setting method is called to store the user-related information into a variable. Then, the Intercept method is rewritten based on the user-defined interceptor. Finally, in all SQL statements involving context parameters, the input method is used to obtain any user-related information and input it into the SQL statement. In this way, the demand for dynamically passing context parameters in database query and operation can be met, SQL statement processing can be simplified and no longer restricted by the database, the flexibility and security of the business can be improved, and practical application and promotion can be facilitated. (2) Using custom interceptors to inject context parameters can provide greater flexibility and code maintainability, making the parameter passing process more concise and convenient; (3) It has higher flexibility. That is, through custom interceptors, the parameter injection process can be flexibly controlled according to specific business needs to adapt to different scenarios and needs; (4) Reduce code intrusion, that is, encapsulate the parameter injection logic in a custom interceptor, which can reduce redundant code related to parameter passing in the business code; (5) It can avoid manually passing context data every time a MyBatis method is called, simplifying code writing; (6) Ensure data consistency. That is, since the context data is directly passed to the SQL statement, data consistency is guaranteed, avoiding the risk of data inconsistency caused by manual parameter passing. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0017] Figure 1 A flowchart of a method for implementing direct transfer of context parameters to SQL statements provided in an embodiment of the present application.
[0018] Figure 2 A flowchart of rewriting and implementing the Intercept method provided in an embodiment of the present application.
[0019] Figure 3 A flowchart of the user information injection SQL statement provided in an embodiment of the present application.
[0020] Figure 4 A schematic diagram of the structure of an apparatus for implementing direct transmission of context parameters to SQL statements provided in an embodiment of the present application.
[0021] Figure 5 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0022] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the present invention will be briefly introduced below in combination with the drawings and the description of the embodiments or the prior art. Obviously, the following description of the structures of the drawings is only some embodiments of the present invention. For ordinary technicians in this field, other embodiments can be obtained based on these embodiments without creative work. It should be noted that the description of these embodiments is used to help understand the present invention, but does not constitute a limitation of the present invention.
[0023] It should be understood that although the terms first and second, etc. may be used herein to describe various objects, these objects should not be limited by these terms. These terms are only used to distinguish one object from another object. For example, a first object can be referred to as a second object, and similarly, a second object can be referred to as a first object without departing from the scope of the exemplary embodiments of the present invention.
[0024] It should be understood that the term "and / or" that may appear in this document is merely a description of the association relationship between associated objects, indicating that there may be three relationships. For example, A and / or B can indicate three situations: A exists alone, B exists alone, or A and B exist at the same time. For another example, A, B and / or C can indicate the existence of any one of A, B and C or any combination of them. The term " / and" that may appear in this document describes another type of association object relationship, indicating that there may be two relationships. For example, A / and B can indicate two situations: A exists alone or A and B exist at the same time. In addition, the character " / " that may appear in this document generally indicates that the previous and next associated objects are in an "or" relationship.
[0025] Example like Figure 1 As shown, the method for directly transferring context parameters to SQL statements provided in the first aspect of this embodiment can be, but is not limited to, executed by a computer device with certain computing resources, such as a cloud server, a personal computer (PC, which refers to a multi-purpose computer with a size, price and performance suitable for personal use; desktops, laptops, small laptops, tablets and ultrabooks are all personal computers), a smart phone, a personal digital assistant (PDA) or a wearable device. Figure 1 As shown, the method for implementing direct transmission of context parameters to SQL statements may include, but is not limited to, the following steps S1 to S4.
[0026] S1. Obtain user-defined entities, context parameter keys, and methods for implementing user-related information input, wherein the entities include but are not limited to attributes of inheritableThreadLocals variables and methods for setting and obtaining context parameter keys.
[0027] In step S1, the entity (Context) refers to one of the main components used to manage entity objects when accessing data using Entity Framework (i.e., Entity Framework, which is an object-relational mapping tool launched by Microsoft that allows developers to operate databases in an object-oriented manner; context is one of the core concepts in Entity Framework, which provides a simple and powerful way to access data by mapping the relationship between entity classes and database tables). It acts as a bridge between the application and the database, responsible for tracking the status of entity objects, performing database operations, and managing data changes. In the entity, the inheritableThreadLocals variable is an existing term, which is specifically represented by InheritableThreadLocal <Map<String,Object> >, where Map<String,Object> It is a generic type that represents a collection of key-value pairs. Its key is a string type (String), and its value can be any object type (Object).<String,Object> ) is saved in the inheritableThreadLocals variable of Thread. At the same time, if a new thread needs to be opened under the current main thread, and the main thread has an inheritableThreadLocals variable, the new thread will copy the value held by the inheritableThreadLocals variable in the main thread to the inheritableThreadLocals variable of the new thread, similar to the child thread inheriting the inheritableThreadLocals variable of the parent thread. In addition, the entity, the context parameter key and the method for implementing the user-related information input can be specifically defined by the user through conventional human-computer interaction methods, wherein the context parameter key is used for subsequent acquisition of specified information through this key in the context, for example, all user information can be uniformly placed in the environment variable $User, and this environment variable $User is a key that can be customized by the user in advance; the user-related information includes but is not limited to user name, user account, user gender and / or user authority, etc.
[0028] S2. Use the UserInterceptorHandler interceptor to intercept all user requests, parse the interception results to obtain the user's unique identifier, and then access the database based on the user's unique identifier to obtain user-related information pre-stored in the database and bound to the user's unique identifier. Finally, call the method in the entity for setting the context parameter key to store the user-related information into the inheritableThreadLocals variable.
[0029] In the step S2, the UserInterceptorHandler interceptor is a custom interceptor processor for intercepting user-related requests and processing them; in the Spring framework, you can create your own interceptor by implementing the HandlerInterceptor interface. The user unique identifier may specifically include, but is not limited to, the user name and / or user account, etc. The database may specifically include, but is not limited to, Redis (RemoteDictionary Server, i.e., remote dictionary service, is an open source log-type, Key-Value database written in ANSI C language, supporting the network, memory-based and persistent, and providing APIs in multiple languages) database. The method for setting the context parameter key is specifically used to set the context parameter key, and then the context parameter key and the user-related information used as the context parameter (which is also used as the value) are stored as a pair of key values in the Map<String,Object> In addition, before accessing the database according to the user unique identifier to obtain user-related information pre-stored in the database and stored in conjunction with the user unique identifier, the method also includes but is not limited to: storing all information related to the user in the database after the user logs in, wherein all information includes but is not limited to user name, user account, user gender and / or user authority, etc. (of course, it can also be customized according to the actual situation of the login system).
[0030] S3. Rewrite the Intercept method based on the user-defined interceptor MybatisSqlParamInterceptor.
[0031] In the step S3, the user-defined interceptor MybatisSqlParamInterceptor is used to intercept the target method in the database query and operation process, so as to obtain the parameter array of the target method and rewrite the Intercept method according to the parameter array. It can be based on the Mybatis (which is an open source persistence layer framework that can simply encapsulate jdbc, but it is not a complete object-relational mapping and cannot be adapted without the database) persistence layer framework and the conventional definition of the human-computer delivery method. The Intercept method is mainly used for aspect-oriented programming (AOP), which can enhance the program without modifying the source code. It is mainly implemented in Java by implementing the Interceptor interface and can be applied to a variety of scenarios, including security checks, logging and transaction management; in this embodiment, the rewritten Intercept method will be called before executing the SQL statement, that is, if the parameter information (such as the user information mentioned above) is to be used in the SQL statement, the user information can be assigned to the SQL statement in advance through the rewritten Intercept method, so that the user information can be used in the SQL statement later. Specifically, Figure 2 As shown, the Intercept method is rewritten based on the user-defined interceptor MybatisSqlParamInterceptor, including but not limited to the following steps S31 to S34.
[0032] S31. Obtain a parameter array in the target method intercepted by the user-defined interceptor MybatisSqlParamInterceptor, wherein the parameter array includes but is not limited to all parameters required by the target method.
[0033] In the step S31, the actual parameters of the target method when it is called can be obtained through the line of code "Object[] args = invocation.getArgs()" (the string in the code means the existing knowledge, such as the invocation object and the getArgs method), and various custom processing can be performed based on these parameters later; for example, unified format verification or encryption processing of the incoming parameters, or judging whether the parameters meet the expected business rules, etc. The following is a simple example: recording the parameters when intercepting the Executor to execute the query method (i.e. as the target method) (this is just a demonstration, and the actual use needs to be configured in the MyBatis interceptor chain and other related environments).
[0034] S32. Extract the first parameter from the parameter array and convert it into a MappedStatement object, wherein the MappedStatement object includes but is not limited to relevant information required to execute the SQL statement.
[0035] In the step S32, the extraction of the first parameter and the object conversion can be implemented specifically through the line of code "MappedStatement ms=(MappedStatement) args[0]".
[0036] S33. Extract the second parameter from the parameter array and convert it into a Map type, and inject the user information into the SQL statement being compiled.
[0037] In step S33, the second parameter can be extracted by the line of code "Object parameter = args[1]". The Map type is a key-value pair type, so that the value can be accessed by key, that is, the Map in the inheritableThreadLocals variable<String,Object> In programming, the Map type is often called an associative array or dictionary, whose elements consist of unique keys and related values, and the corresponding values can be quickly found, inserted, and deleted through the key. Specifically, such as Figure 3 As shown, injecting user information into the SQL statement being compiled includes but is not limited to the following steps S331 to S332.
[0038] S331. Inject common context parameters into the SQL statement being compiled.
[0039] In the step S331, the common context parameters specifically include but are not limited to user information customized by the user in the environment variable $User (after the user logs into the system, the user information can be queried and stored in the environment variable $User. All context parameters are as described above. When the user needs certain information, the user can customize the corresponding parameters).
[0040] S332. Call the method in the entity for obtaining the context parameter key to store the user information into the Map type.
[0041] After step S332, information such as creation time, modification time and / or operator information may also be maintained in the Map type.
[0042] S34. Modify the second parameter in the parameter array to the Map type, and then continue to execute subsequent interceptor chains and SQL operations.
[0043] In step S34, the second parameter can be modified by the line of code "args[1]=parameter", so that these parameters can be used directly in subsequent SQL statements without writing these common parameters again each time when writing SQL statements. And the subsequent interceptor chain and SQL operations can be continued by "invocation.proceed()".
[0044] S4. In all SQL statements involving context parameters, use the method for implementing the user-related information input to obtain any user-related information and input it into the SQL statement.
[0045] In step S4, since the parameter object has been modified before, after obtaining data from this object, the required information can be directly obtained in the SQL statement through the #{$User.} method.
[0046] Therefore, based on the method of directly passing context parameters to SQL statements described in the aforementioned steps S1 to S4, a new solution is provided for directly passing context parameters to SQL statements to realize dynamic database queries and operations, that is, after obtaining the user-defined entity, context parameter key and the method for implementing the user-related information input, an interceptor is used to intercept all user requests, and the interception result is parsed to obtain the user's unique identifier, and then the database is accessed according to the identifier to obtain the user's related information, and the setting method is called to store the user-related information into a variable, and then the Intercept method is rewritten based on the user-defined interceptor, and finally, in all SQL statements involving context parameters, the input method is used to obtain any user-related information and pass it into the SQL statement, which can meet the demand for dynamic transmission of context parameters in database queries and operations, simplify SQL statement processing and no longer be restricted by the database, improve business flexibility and security, and facilitate practical application and promotion.
[0047] like Figure 4 As shown, the second aspect of this embodiment provides a virtual device for implementing the method of directly transferring context parameters to SQL statements described in the first aspect, comprising a definition content acquisition unit, a request interception processing unit, a method rewriting processing unit and a user information input unit which are sequentially connected in communication; The definition content acquisition unit is used to obtain a user-defined entity, a context parameter key, and a method for implementing the input of user-related information, wherein the entity includes an attribute of an inheritableThreadLocals variable and a method for setting and obtaining the context parameter key; The request interception processing unit is used to intercept all requests of the user using the UserInterceptorHandler interceptor, and parse the interception result to obtain the user unique identifier, and then access the database according to the user unique identifier to obtain the user related information pre-stored in the database and bound to the user unique identifier, and finally call the method in the entity and used to set the context parameter key to store the user related information into the inheritableThreadLocals variable; The method rewriting processing unit is used to rewrite the Intercept method based on the user-defined interceptor MybatisSqlParamInterceptor; The user information input unit is used to obtain any user-related information and input it into the SQL statement using the method for implementing user-related information input in all SQL statements involving context parameters.
[0048] The working process, working details and technical effects of the aforementioned device provided in the second aspect of this embodiment can be referred to the method for implementing direct transmission of context parameters to SQL statements described in the first aspect, and will not be repeated here.
[0049] like Figure 5 As shown, the third aspect of this embodiment provides a computer device for executing the method for directly transferring context parameters to SQL statements as described in the first aspect, including a memory, a processor and a transceiver that are sequentially connected in communication, wherein the memory is used to store a computer program, the transceiver is used to send and receive messages, and the processor is used to read the computer program to execute the method for directly transferring context parameters to SQL statements as described in the first aspect. For example, the memory may include, but is not limited to, a random access memory (Random-Access Memory, RAM), a read-only memory (Read-Only Memory, ROM), a flash memory (Flash Memory), a first-in-first-out memory (First Input First Output, FIFO) and / or a first-in-last-out memory (First Input Last Output, FILO), etc.; the processor may include, but is not limited to, a microprocessor of the STM32F105 series. In addition, the computer device may also include, but is not limited to, a power module, a display screen and other necessary components.
[0050] The working process, working details and technical effects of the aforementioned computer device provided in the third aspect of this embodiment can be referred to the method for implementing direct transmission of context parameters to SQL statements described in the first aspect, and will not be repeated here.
[0051] In a fourth aspect of this embodiment, there is provided a computer-readable storage medium storing instructions including the method for implementing the method of directly transferring context parameters to SQL statements as described in the first aspect, that is, the computer-readable storage medium stores instructions, and when the instructions are executed on a computer, the method for implementing the method of directly transferring context parameters to SQL statements as described in the first aspect is executed. The computer-readable storage medium refers to a carrier for storing data, which may include but is not limited to computer-readable storage media such as floppy disks, optical disks, hard disks, flash memories, USB flash drives, and / or memory sticks, and the computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices.
[0052] The working process, working details and technical effects of the aforementioned computer-readable storage medium provided in the fourth aspect of this embodiment can be referred to the method for implementing direct transmission of context parameters to SQL statements as described in the first aspect, and will not be repeated here.
[0053] In a fifth aspect, the present embodiment provides a computer program product, including a computer program or an instruction, wherein the computer program or the instruction, when executed by a computer, implements the method for directly passing context parameters to SQL statements as described in the first aspect. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device.
[0054] Finally, it should be noted that the above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for directly transferring context parameters to SQL statements, characterized in that: include: Get the user-defined entity, context parameter key and method for implementing the user-related information input, where the entity contains the attribute of the inheritableThreadLocals variable and the method for setting and getting the context parameter key; Use the UserInterceptorHandler interceptor to intercept all user requests, parse the interception results to obtain the user's unique identifier, then access the database according to the user's unique identifier to obtain the user's related information pre-stored in the database and bound to the user's unique identifier, and finally call the method in the entity for setting the context parameter key to store the user's related information into the inheritableThreadLocals variable; Rewrite the Intercept method based on the user-defined interceptor MybatisSqlParamInterceptor; In all SQL statements involving context parameters, the method for implementing the input of user-related information is used to obtain any user-related information and input it into the SQL statement.
2. The method for implementing direct transfer of context parameters to SQL statements according to claim 1, characterized in that: Before accessing the database according to the user unique identifier to obtain user related information pre-stored in the database and stored in binding with the user unique identifier, the method further includes: After the user logs in, all information related to the user is stored in the database, wherein all the information includes the user's name, user account, user gender and / or user authority.
3. The method for implementing direct transfer of context parameters to SQL statements according to claim 1, characterized in that: The database adopts Redis database.
4. The method for implementing direct transfer of context parameters to SQL statements according to claim 1, characterized in that: Rewrite the Intercept method based on the user-defined interceptor MybatisSqlParamInterceptor, including: Get the parameter array in the target method intercepted by the user-defined interceptor MybatisSqlParamInterceptor, where the parameter array contains all the parameters required by the target method; Extracting the first parameter from the parameter array and converting it into a MappedStatement object, wherein the MappedStatement object contains relevant information required to execute the SQL statement; Extract the second parameter from the parameter array and convert it into a Map type, and inject the user information into the SQL statement being compiled; The second parameter in the parameter array is modified to the Map type, and then the subsequent interceptor chain and SQL operation are continued.
5. The method for implementing direct transfer of context parameters to SQL statements according to claim 4, characterized in that: Inject user information into the SQL statement being compiled, including: Inject common context parameters into the SQL statement being compiled; The method in the entity for obtaining the context parameter key is called to store the user information into the Map type.
6. The method for implementing direct transfer of context parameters to SQL statements according to claim 5, characterized in that: Inject user information into the SQL statement being compiled, including: The creation time, modification time and / or operator information are maintained in the Map type.
7. A device for directly transferring context parameters to SQL statements, characterized in that: It includes a definition content acquisition unit, a request interception processing unit, a method rewriting processing unit and a user information input unit which are sequentially connected in communication; The definition content acquisition unit is used to obtain a user-defined entity, a context parameter key, and a method for implementing the input of user-related information, wherein the entity includes an attribute of an inheritableThreadLocals variable and a method for setting and obtaining the context parameter key; The request interception processing unit is used to intercept all requests of the user using the UserInterceptorHandler interceptor, and parse the interception result to obtain the user unique identifier, and then access the database according to the user unique identifier to obtain the user related information pre-stored in the database and bound to the user unique identifier, and finally call the method in the entity and used to set the context parameter key to store the user related information into the inheritableThreadLocals variable; The method rewriting processing unit is used to rewrite the Intercept method based on the user-defined interceptor MybatisSqlParamInterceptor; The user information input unit is used to obtain any user-related information and input it into the SQL statement using the method for implementing user-related information input in all SQL statements involving context parameters.
8. A computer device, characterized in that: It includes a memory, a processor and a transceiver which are communicatively connected in sequence, wherein the memory is used to store a computer program, the transceiver is used to send and receive messages, and the processor is used to read the computer program and execute the method for directly transferring context parameters to SQL statements as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores instructions, and when the instructions are executed on the computer, the method for directly transferring context parameters to SQL statements as described in any one of claims 1 to 6 is executed.
10. A computer program product comprising a computer program or instructions, characterized in that When the computer program or the instruction is executed by a computer, the method for directly transferring context parameters to SQL statements as claimed in any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Data correlation method based on J2EE platform and correlation plug-in
CN103647794A
A data processing method and device
CN109815284A
Database data processing method and device, computer equipment and storage medium
CN112988787A
Tenant data access management method and device, equipment and storage medium
CN113965383A
Method and system for obtaining user information accessing SQL database and storage medium
CN114547697A