A seamless adaptation method, device and equipment from single-tenant to multi-tenant
By automating the generation of SQL statements and interceptors, the adaptation problem from single-tenant database to multi-tenant database was solved, enabling efficient and accurate updates of tenant ID data items and reducing labor costs.
Patent Information
- Application Number
- CN202411675435.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-21
- Publication Date
- 2025-12-09
- Estimated Expiration
- 2044-11-21
AI Technical Summary
In existing technologies, the single-tenant model cannot meet the business needs of multi-tenant SaaS versions. It requires manually adding tenant ID data items to each database table, resulting in high labor costs, low accuracy, and low efficiency.
The system automatically generates tenant ID data item modification statements for database tables using SQL statements and interceptors. The interceptors intercept user login information from business systems and use multi-tenant reference classes for data updates and storage, achieving seamless adaptation.
It reduced labor costs, improved accuracy and efficiency, and achieved seamless adaptation from single-tenant databases to multi-tenant databases.
Smart Images

Figure CN119603014B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present specification relate to the technical field of communication, and in particular to a seamless adaptation method, device and equipment from single-tenant to multi-tenant. BACKGROUND
[0002] With the development of Internet technology, the existing single-tenant mode has been unable to meet the business needs. In the existing large projects, the single-tenant mode is mostly implemented based on mybatis-plus, but due to business needs, it is necessary to support multi-tenant SAAS version. Single-tenant is a single deployment of a set of services for a tenant, but after becoming multi-tenant, multiple tenants share a set of services. This paper proposes a scheme for quickly adapting multi-tenant from single-tenant based on mybatis-plus, which mainly adds a tenant ID data item to distinguish different tenants in each database table, and then inserts the corresponding tenant ID when inserting the database, and adds the tenant ID data item screening condition in the database SQL condition when modifying and querying. The existing method mainly manually adds a tenant ID data item to distinguish different tenants in each database table, and needs to write code to set the tenant ID in each new operation, and needs to write code to add the tenant ID data item screening condition when modifying and querying. The corresponding tenant ID information logic code needs to be added at each new, modification and query, which is high in labor cost and cannot guarantee accuracy.
[0003] There is an urgent need for a seamless adaptation method from single-tenant to multi-tenant, so as to solve the problems of low efficiency, low accuracy and not easy to maintain by automatically generating modification statements and interceptors, and routing to the specified module through code or manually. SUMMARY
[0004] To solve the problem of updating the database table by pure manual method in the prior art, the embodiments of the present specification provide a seamless adaptation method, device and equipment from single-tenant to multi-tenant, which enables the multi-tenant database to seamlessly replace multiple single-tenant databases through SQL statements and interceptors. At the same time, the modification statement for adding the tenant ID data item of the database table is automatically generated, and only the interceptor needs to be written, so that the database tenant ID related operations can be automatically implemented, reducing labor costs while improving accuracy. The specific technical solutions of the embodiments of the present specification are as follows:
[0005] In one aspect, the embodiments of the present specification provide a seamless adaptation method from single-tenant to multi-tenant, comprising:
[0006] merging data in multiple single-tenant databases to generate a multi-tenant database; wherein the multi-tenant database includes multiple data items, and each data item includes tenant information and user information in a single-tenant database;
[0007] generating SQL statements for updating corresponding data items in the multi-tenant database according to data in each of the single-tenant databases;
[0008] The multi-tenant database intercepts user information of a user logging in a business system, and matches a data item of the multi-tenant database according to the user information;
[0009] The user information is updated in the multi-tenant database by using the SQL statement corresponding to the data item;
[0010] The updated user information is stored in the multi-tenant database by using a thread local variable, and an independent variable copy is provided for each thread using the variable;
[0011] The single-tenant database includes a multi-tenant reference class for calling a multi-tenant file access interface or a multi-tenant memory access interface;
[0012] Login information is returned to the business system according to tenant information contained in the data item in the multi-tenant database.
[0013] Further, the multi-tenant database includes a plurality of data items, which further include,
[0014] Each single-tenant database includes tenant information of a single tenant, and each tenant includes at least one user;
[0015] The single-tenant database includes tenant information of the tenant and user information of a plurality of users in the tenant.
[0016] Further, the multi-tenant database intercepts user information of a user logging in a business system, which further includes,
[0017] The user registration request of the business system is intercepted, and the user registration request includes user information and a configuration file;
[0018] The configuration information is generated by parsing the configuration file, and a data item of the multi-tenant database corresponding to the user information is matched according to the configuration information;
[0019] The user information and the configuration information are added to the multi-tenant database by using the SQL statement corresponding to the data item.
[0020] Further, generating SQL statements for updating corresponding data items in the multi-tenant database according to data in each of the single-tenant databases further includes,
[0021] generating a modification statement used for updating the single-tenant database according to a database table name of the single-tenant database;
[0022] The single-tenant database corresponds to the multi-tenant database data item one by one, and the SQL statement is set according to the single-tenant database corresponding to each multi-tenant database data item and the modification statement of the single-tenant database.
[0023] Further, the multi-tenant database intercepts user information of a user logging in a business system, and the method further comprises:
[0024] The tenant information tenant permission;
[0025] The user information includes a user ID, a user name, and a tenant ID.
[0026] The tenant ID is stored as a thread variable in the data item corresponding to the multi-tenant database.
[0027] Further, the multi-tenant database intercepts user information of a user logging in a business system, and the method further comprises:
[0028] If the user information does not exist in the data item of the multi-tenant database, the login request of the user is rejected.
[0029] On the other hand, the embodiment of the present specification also provides a seamless adaptation device from single-tenant to multi-tenant, and the device comprises:
[0030] A database merging module is configured to merge data in a plurality of single-tenant databases to generate a multi-tenant database; wherein the multi-tenant database comprises a plurality of data items, and each data item comprises tenant information and user information in a single-tenant database.
[0031] A statement generation module is configured to generate a SQL statement for updating a corresponding data item in the multi-tenant database according to data in each single-tenant database.
[0032] An information interception module is configured to intercept user information of a user logging in a business system by the multi-tenant database, and match a corresponding data item of the multi-tenant database according to the user information.
[0033] A data updating module is configured to update the user information in the multi-tenant database by using the SQL statement corresponding to the data item.
[0034] A thread variable module is configured to store the updated user information in the multi-tenant database by using a thread local variable, and provide an independent variable copy for each thread using the variable.
[0035] The reference class replacement module is configured to replace reference classes of tenant information and user information in the single-tenant database with multi-tenant reference classes, the multi-tenant reference classes being configured to invoke a multi-tenant file access interface or a multi-tenant memory access interface;
[0036] The information feedback module is configured to generate login information according to tenant information contained in the data item in the multi-tenant database, and return the login information to the business system.
[0037] In another aspect, the embodiments of the present specification also provide a computer device, comprising a memory, a processor, and a computer program stored in the memory, and the processor implements the above method when executing the computer program.
[0038] In another aspect, the embodiments of the present specification also provide a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the above method.
[0039] Finally, the embodiments of the present specification also provide a computer program product, which comprises a computer program, and the computer program is executed by a processor to implement the above method.
[0040] By using the embodiments of the present specification, a method capable of seamlessly adapting a single-tenant database to a multi-tenant database is provided. The present solution combines data in multiple single-tenant databases into one multi-tenant database, and generates each data item in the multi-tenant database from tenant information and user information in the single-tenant database, so that all tenants can complete data interaction in the same database. Meanwhile, SQL statements for updating corresponding data items in the multi-tenant database are generated according to data in each single-tenant database, so that the data items in the multi-tenant database can be automatically updated. Then, the multi-tenant database intercepts user information of a logged-in user in the business system, and matches the user information according to the user information to obtain a data item of the multi-tenant database corresponding to the tenant where the user is located. Then, the user information can be updated in the multi-tenant database by using the generated SQL statement corresponding to the data item. Finally, login information required by the user is generated according to tenant information contained in the data item, and the login information is returned to the business system. Thus, new received packets are automatically distributed by routing configuration rules, and the packets are automatically routed to different processing modules for analysis and processing by flexible configuration, thereby improving the efficiency of packet processing. Meanwhile, the routing configuration rules automatically process the packets, thereby improving the accuracy of packet routing. BRIEF DESCRIPTION OF DRAWINGS
[0041] In order to more clearly illustrate the technical solutions in the embodiments of the present specification or the prior art, the accompanying drawings needed to be used in the embodiments or prior art description will be briefly introduced. Obviously, the accompanying drawings in the following description are only some embodiments of the present specification, and for those skilled in the art, other drawings can also be obtained without creative labor based on these drawings.
[0042] Figure 1 An embodiment system schematic diagram of a seamless adaptation method from single-tenant to multi-tenant in the embodiments of the present specification is shown.
[0043] Figure 2 A flowchart of a seamless adaptation method from single-tenant to multi-tenant in the embodiments of the present specification is shown.
[0044] Figure 3 A flowchart of a multi-tenant database intercepting user information of a login user in a business system in the embodiments of the present specification is shown.
[0045] Figure 4 A flowchart of generating a SQL statement according to data in each single-tenant database in the embodiments of the present specification is shown.
[0046] Figure 5 A flowchart of automatically adding tenant ID information for database operation in the embodiments of the present specification is shown.
[0047] Figure 6 A flowchart of updating the user information in the multi-tenant database by using the SQL statement corresponding to the data item in the embodiments of the present specification is shown.
[0048] Figure 7 A specific structure schematic diagram of a seamless adaptation device from single-tenant to multi-tenant in the embodiments of the present specification is shown.
[0049] Figure 8 A structure schematic diagram of a computer device in the embodiments of the present specification is shown.
[0050]
Explanation of reference numerals
[0051] 101, business system;
[0052] 102, single-tenant database;
[0053] 103, multi-tenant database;
[0054] 701, database merging module;
[0055] 702, statement generation module;
[0056] 703, information interception module;
[0057] 704, data update module;
[0058] 705, thread variable module;
[0059] 706, reference class replacement module;
[0060] 707, information feedback module;
[0061] 802, computer device;
[0062] 804, processing device;
[0063] 806, storage resource;
[0064] 808, drive system;
[0065] 810, input / output module;
[0066] 812, input device;
[0067] 814, output device;
[0068] 816, presentation device;
[0069] 818, graphical user interface;
[0070] 820, network interface;
[0071] 822, communication link;
[0072] 824, communication bus. DETAILED DESCRIPTION
[0073] The technical solutions in the embodiments of the present specification will be described clearly and completely in the following combined with the drawings in the embodiments of the present specification. Obviously, the described embodiments are only part of the embodiments of the present specification, rather than all the embodiments. Based on the embodiments in the embodiments of the present specification, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of protection of the embodiments of the present specification.
[0074] It should be noted that the terms "first", "second" and the like in the description and in the claims of the embodiments of the present specification and the above-described figures are used to distinguish similar objects, and do not necessarily indicate a specific order or a chronological sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present specification described herein can be implemented in other than the order illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof, are intended to cover non-exclusive inclusion, for example, a process, method, device, product or apparatus that includes a list of steps or units is not necessarily limited to those steps or units clearly listed, but can include other steps or units not clearly listed or inherent to such processes, methods, products or apparatuses.
[0075] It should be noted that the acquisition, storage, use, processing and the like of data in the technical solutions of the embodiments of the present specification comply with the relevant provisions of national laws and regulations.
[0076] It should be noted that in the embodiments of the present specification, some industry existing solutions of software, components, models and the like may be mentioned, which should be considered as exemplary, and the purpose is only to illustrate the feasibility in the implementation of the technical solutions of the present application, but does not mean that the applicant has or will necessarily use the solution.
[0077] As Figure 1 shown is an implementation system schematic diagram of a seamless adaptation method from single-tenant to multi-tenant in the embodiments of the present specification, which includes a business system 101, a single-tenant database 102 and a multi-tenant database 103. The business system 101, the single-tenant database 102 and the multi-tenant database 103 can communicate through a network, which can include a local area network (Local Area Network, LAN for short), a wide area network (Wide Area Network, WAN for short), the Internet or a combination thereof, and is connected to a website, a user device (such as a computing device) and a backend system. Alternatively, the single-tenant database 102 and the multi-tenant database 103 can be nodes of a cloud computing system, or each server can be a separate cloud computing system, including multiple computers interconnected by a network and working as a distributed processing system.
[0078] The business system 101 acquires a request for user login and sends customer information to the single-tenant database 102. In the sending process, the multi-tenant database 103 intercepts the customer information, the multi-tenant database 103 is established according to the data merging in multiple single-tenant databases 102, and then the multi-tenant database 103 processes the customer information and returns the login information required by the business system 101 to the business system 101.
[0079] In addition, it should be noted that Figure 1The shown is only one application environment provided by the embodiment of the present specification, and other application environments can be included in actual application, which is not limited by the present specification.
[0080] In view of the problems in the prior art, the embodiment of the present specification provides a seamless adaptation method from single-tenant to multi-tenant, in the embodiment of the present specification, Figure 2 The shown is a flowchart of the seamless adaptation method from single-tenant to multi-tenant in the embodiment of the present specification. The seamless adaptation process from single-tenant to multi-tenant is described in the figure. The step sequence listed in the embodiment is only one of the many step execution sequences, and does not represent the only execution sequence. In actual system or device product execution, the method sequence shown in the embodiment or the figure can be executed in sequence or in parallel. Specifically, as Figure 2 As shown, the method can include:
[0081] Step 201: merging data in multiple single-tenant databases to generate a multi-tenant database; wherein the multi-tenant database includes multiple data items, and each data item includes tenant information and user information in a single-tenant database;
[0082] Step 202: generating an SQL statement for updating a corresponding data item in the multi-tenant database according to data in each single-tenant database;
[0083] Step 203: the multi-tenant database intercepts user information of a user logged in by a business system, and matches a corresponding data item of the multi-tenant database according to the user information;
[0084] Step 204: updating the user information in the multi-tenant database by using the SQL statement corresponding to the data item;
[0085] Step 205: storing the updated user information in the multi-tenant database by using a thread local variable, and providing an independent variable copy for each thread using the variable;
[0086] Step 206: replacing a reference class of tenant information and user information in the single-tenant database with a multi-tenant reference class, the multi-tenant reference class being used to call a multi-tenant file access interface or a multi-tenant memory access interface;
[0087] Step 207: generating login information according to tenant information contained in the data item in the multi-tenant database and returning the login information to the business system.
[0088] This specification provides a method for seamlessly adapting from a single-tenant database to a multi-tenant database. This solution merges data from multiple single-tenant databases into a single multi-tenant database, and generates each data item in the multi-tenant database from tenant and user information in the single-tenant databases, enabling all tenants to interact within the same database. Simultaneously, it generates SQL statements to update corresponding data items in the multi-tenant database based on data from each single-tenant database, allowing for automatic updates. The multi-tenant database then intercepts user information from logged-in users in the business system, matching this information to obtain the corresponding multi-tenant database data item for the user's tenant. The generated SQL statement for each data item is then used to update the user information in the multi-tenant database. Finally, the required login information for the user is generated based on the tenant information contained in the data item and returned to the business system. Furthermore, routing configuration rules automatically allocate newly received packets, flexibly routing packets to different processing modules for parsing and processing, improving packet processing efficiency. Simultaneously, automatic packet processing through routing configuration rules improves the accuracy of packet routing.
[0089] In the embodiments described in this specification, a multi-tenant database replaces the single-tenant database. Since a single tenant uses only one environment and the database stores only one tenant's data, it consumes significant resources. Therefore, sharing hardware or software is used to achieve scalability, cost-effectiveness, and security improvements in multi-tenant databases. In a multi-tenant environment, multiple tenants and applications directly and securely share IT resources. The more resources shared among tenants, the higher the utilization rate of basic resources and the lower the unit resource cost. Furthermore, thread-local variables are used for storage in the multi-tenant database, providing each thread using the variable with an independent copy. Therefore, each thread can independently modify its copy without affecting the copies of other threads, making it easier and safer to share mutable data in a multi-threaded environment.
[0090] According to one embodiment of this specification, in order to replace a single-tenant database with a multi-tenant database and ensure that no data is missing, the multi-tenant database further includes multiple data items,
[0091] Each single-tenant database contains tenant information for a single tenant, and each tenant contains at least one user;
[0092] The single-tenant database includes the tenant information of the tenant and the user information of multiple users within the tenant.
[0093] Specifically, the single-tenant file access interface and the single-tenant memory access interface are methods in a single-tenant reference class, and the multi-tenant file access interface and the multi-tenant memory access interface are methods in a multi-tenant reference class; by replacing the reference classes of the tenant information and the user information in the single-tenant database introduced in the business processor with the multi-tenant reference classes, when the business processor issues a file access request or a memory access request, the multi-tenant file access interface or the multi-tenant memory access interface can be automatically called to obtain the tenant information or the user information of the data item of the multi-tenant database to which the user belongs.
[0094] According to one embodiment of the present specification, in order to meet different business needs, tenants may add new users, such as Figure 3 As shown in the figure, the multi-tenant database intercepts the user information of the user logging in the business system further includes,
[0095] Step 301: Intercepting a user registration request of the business system, the user registration request including user information and a configuration file;
[0096] Step 302: Parsing the configuration file to generate configuration information, and matching the data item of the multi-tenant database corresponding to the user information according to the configuration information;
[0097] Step 303: Adding the user information and the configuration information to the multi-tenant database by using the SQL statement corresponding to the data item.
[0098] According to one embodiment of the present specification, in order to obtain the SQL statement for updating the corresponding data item in the multi-tenant database, such as Figure 4 As shown in the figure, generating the SQL statement for updating the corresponding data item in the multi-tenant database according to the data in each single-tenant database further includes,
[0099] Step 401: Generating a modification statement used when updating the single-tenant database according to the database table name of the single-tenant database;
[0100] Step 402: The single-tenant database corresponds to the data item of the multi-tenant database one by one, and the SQL statement is set according to the single-tenant database corresponding to each data item of the multi-tenant database and the modification statement thereof.
[0101] Specifically, the table name of all data tables is automatically obtained; the modification statement of adding a tenant ID data item corresponding to each database table is automatically generated; that is, in the form of a freemarker module engine, the corresponding SQL statement is generated according to the obtained database table name, that is, the corresponding text is automatically generated based on the module and the data to be changed.
[0102] According to one embodiment of the present specification, in order to enable the multi-tenant database to seamlessly replace the single-tenant database during the operation of the system, the multi-tenant database intercepting the user information of the business system login user further comprises,
[0103] The tenant information tenant permission;
[0104] The user information includes a user ID, a user name, and a tenant ID;
[0105] The tenant ID is stored as a thread variable in the data item corresponding to the multi-tenant database.
[0106] Specifically, in each request, the user information UserInfo of the current login user is obtained by using an interceptor, including a user ID, a user name, a tenant ID, etc. The UserInfo is stored in the form of a thread variable ThreadLocal. The steps of the interceptor interception are specifically:
[0107] The user information userJson stored in the form of a string JSON is obtained from the request header;
[0108] The userJson data item is converted into the user information UserInfo object userInfo, wherein the UserInfo class includes a user ID, a user name, and a tenant ID;
[0109] Then the userInfo object is stored in the UserInfoContext context object for storing user thread variables, thereby obtaining the user information of the login user.
[0110] Wherein, UserInfoContext: represents the class name for storing user thread variables, and only has a thread variable field of user type (UserInfo). The thread variable (threadlocal) belongs to the current thread only, and is isolated from other threads.
[0111] Further, the interceptor is used to automatically add tenant ID information for database operation, such as Figure 5 As shown in the figure, specifically:
[0112] Step 501: Obtain the current execution SQL and its related attributes, and judge whether it is a query statement;
[0113] Step 502: If it is not a query statement, i.e. not SqlCommandType.SELECT, end the process;
[0114] SqlCommandType is an enumeration class provided by Mybatis-plus for database operation types, mainly including: add, delete, modify, query, and other types;
[0115] Step 503: If it is a query statement, that is, the SQL type is SqlCommandType.SELECT, get the tenant information thread variable and get the tenant id;
[0116] Step 504: Get the query statement and determine whether there is a where condition;
[0117] Step 505: If there is no where condition, directly add the variable condition of the tenant ID;
[0118] Step 506: If there is a where condition, append the variable condition of the tenant ID.
[0119] According to one embodiment of the present specification, it is also necessary to confirm the user's identity information, and further comprising,
[0120] If the user information does not exist in the data item of the multi-tenant database, the login request of the user is rejected.
[0121] According to one embodiment of the present specification, the user information is updated in the multi-tenant database by using the SQL statement corresponding to the data item, the database operation object base class BasePo adds a tenantId field data item, and the insertFull function is rewritten, as shown in Figure 6 , specifically:
[0122] Step 601: Get the tenant information thread variable and get the tenant id, that is, String currTenantId = UserInfoContext.getUserInfo().getTenantId();
[0123] Step 602: If the tenantId field value in the current object is empty, set the tenant ID information of the current operation user to the tenantId data item in the BasePo object;
[0124] Step 603: It is necessary to automatically fill in the tenant ID information in the configuration file by implementing MetaObjectHandler for subsequent SQL queries.
[0125] The object base class BasePo is a parent class of all database operation entity object classes in the application, and the class defines common fields of all database operation entity objects.
[0126] As one embodiment of the present specification, reference can also be made to as shown in Figure 7 The specific structure diagram of the seamless adaptation device from single-tenant to multi-tenant is shown.
[0127] The database merging module 701 is configured to merge data in multiple single-tenant databases to generate a multi-tenant database; wherein the multi-tenant database includes multiple data items, and each data item includes tenant information and user information in a single-tenant database.
[0128] The statement generation module 702 is configured to generate an SQL statement for updating a corresponding data item in the multi-tenant database according to data in each single-tenant database.
[0129] The information interception module 703 is configured to intercept user information of a user logging in a business system in the multi-tenant database, and match a corresponding data item of the multi-tenant database according to the user information.
[0130] The data updating module 704 is configured to update the user information in the multi-tenant database by using the SQL statement corresponding to the data item.
[0131] The thread variable module 705 is configured to store the updated user information in the multi-tenant database by using a thread local variable, and provide an independent variable copy for each thread using the variable.
[0132] The reference class replacement module 706 is configured to replace a reference class of the tenant information and the user information in the single-tenant database with a multi-tenant reference class, and the multi-tenant reference class is configured to call a multi-tenant file access interface or a multi-tenant memory access interface.
[0133] The information feedback module 707 is configured to generate login information according to tenant information contained in the data item in the multi-tenant database, and return the login information to the business system.
[0134] Since the principle of solving the problem of the above device is similar to the above method, the implementation of the above system can refer to the implementation of the above method, and the repeated parts will not be described.
[0135] As shown in Figure 8Fig. 1 shows a schematic diagram of a computer device according to an embodiment of the present specification.
[0136] The computer device 802 can include one or more processing devices 804, such as one or more central processing units (CPUs), each of which can implement one or more hardware threads. The computer device 802 can also include any storage resources 806 for storing any kind of information, such as code, settings, data, etc. Without limitation, for example, the storage resources 806 can include any one or combination of the following: any type of RAM, any type of ROM, a flash memory device, a hard disk, an optical disk, etc. More generally, any storage resource can store information using any technology.
[0137] Further, any storage resource can provide volatile or non-volatile retention of information.
[0138] Further, any storage resource can represent a fixed or removable component of the computer device 802. In one case, the computer device 802 can perform any operation of the associated instructions when the processing device 804 executes the associated instructions stored in any storage resource or combination of storage resources. The computer device 802 also includes one or more drive systems 808 for interacting with any storage resource, such as a hard disk drive system, an optical disk drive system, etc.
[0139] The computer device 802 can also include an input / output module 810 (I / O) for receiving various inputs (via input devices 812) and for providing various outputs (via output devices 814). One particular output mechanism can include a presentation device 816 and an associated graphical user interface 818 (GUI). In other embodiments, the input / output module 810 (I / O), the input devices 812, and the output devices 814 can also not be included, just as a computer device in a network. The computer device 802 can also include one or more network interfaces 820 for exchanging data with other devices via one or more communication links 822. One or more communication buses 824 couple the above-described components together.
[0140] The communication links 822 can be implemented in any manner, for example, through a local area network, a wide area network (e.g., the Internet), a point-to-point connection, etc., or any combination thereof. The communication links 822 can include any combination of hardwired links, wireless links, routers, gateway functionality, name servers, etc., governed by any protocol or combination of protocols.
[0141] The embodiment of the present specification further provides a computer readable storage medium storing a computer program, the computer program being executed by a processor to implement the above method.
[0142] The embodiment of the present specification further provides a computer readable instruction, wherein when the processor executes the instruction, the program therein causes the processor to execute the above method.
[0143] It should be understood that, in various embodiments of the embodiment of the present specification, the size of the sequence number of the above processes does not mean the order of execution, and the execution order of the processes should be determined according to its function and inherent logic, and should not constitute any limitation on the implementation process of the embodiment of the present specification.
[0144] It should also be understood that, in the embodiment of the present specification, the term "and / or" is only a description of the association relationship of the associated objects, which means that there can be three relationships. For example, A and / or B can represent three cases of A alone, A and B together, and B alone. In addition, the character " / " in the embodiment of the present specification generally represents an "or" relationship between the front and rear associated objects.
[0145] Those skilled in the art can realize that the units and algorithm steps of the examples described in combination with the disclosed embodiments in the embodiment of the present specification can be realized by electronic hardware, computer software or a combination of both. In order to clearly illustrate the interchangeability of hardware and software, the components and steps of the examples have been described in general in the above description. Whether the functions are executed in hardware or software depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the embodiment of the present specification.
[0146] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above described system, device and unit can refer to the corresponding process in the foregoing method embodiment, which will not be repeated here.
[0147] In several embodiments provided by the embodiment of the present specification, it should be understood that the disclosed system, device and method can be implemented in other ways. For example, the above described device embodiments are only schematic, for example, the division of the units is only a logical function division, and actual implementation can have another division manner, for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the shown or discussed mutualities can be indirect coupling or communication connection through some interfaces, devices or units, and can also be electrical, mechanical or other forms of connection.
[0148] The units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, i.e., may be located in one place, or may be distributed on multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment of the present specification.
[0149] In addition, each functional unit in each embodiment of the present specification can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.
[0150] The integrated unit, if realized in the form of a software functional unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the embodiments of the present specification essentially or say the part that contributes to the prior art, or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, including a number of instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the method described in each embodiment of the present specification. The foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various program code storage media.
[0151] The principles and implementation manners of the embodiments of the present specification are described in the specific embodiments in the present specification, and the above embodiment description is only used to help understand the method and its core idea of the present specification; meanwhile, for those skilled in the art, according to the idea of the present specification, the specific implementation manner and application range will be changed, and the above description should not be understood as a limitation of the present specification.
Claims
1. A method for seamless adaptation of single tenancy to multi tenancy, characterized in that, The method comprises: merging data in a plurality of single-tenant databases to generate a multi-tenant database; wherein the multi-tenant database comprises a plurality of data items, each of the data items comprising tenant information and user information in a single-tenant database; generating an SQL statement for updating a corresponding data item in the multi-tenant database according to data in each single-tenant database; generating a modification statement for the single-tenant database according to a database table name of the single-tenant database, the modification statement being used when the single-tenant database is updated; the single-tenant database corresponds to a data item in the multi-tenant database, the SQL statement is set according to the single-tenant database corresponding to each data item in the multi-tenant database and the modification statement of the single-tenant database; the multi-tenant database intercepts user information of a user logging in a business system, and matches a corresponding data item in the multi-tenant database according to the user information; updating the user information in the multi-tenant database by using the SQL statement corresponding to the data item; storing the updated user information in the multi-tenant database by using a thread local variable, and providing an independent variable copy for each thread using the variable; replacing a reference class of the tenant information and the user information in the single-tenant database with a multi-tenant reference class, the multi-tenant reference class being used to call a multi-tenant file access interface or a multi-tenant memory access interface; generating login information according to the tenant information contained in the data item in the multi-tenant database, and returning the login information to the business system.
2. The method for seamless adaptation of single tenancy to multi tenancy as claimed in claim 1 wherein, The multi-tenant database comprises a plurality of data items, which further comprises: each single-tenant database comprises tenant information of a single tenant, and each tenant comprises at least one user; the single-tenant database comprises the tenant information of the tenant and user information of a plurality of users in the tenant.
3. The method for seamless adaptation of single tenancy to multi tenancy as claimed in claim 1 wherein, The multi-tenant database intercepts user information of a user logging in a business system, which further comprises: intercepting a user registration request of the business system, the user registration request comprising user information and a configuration file; parsing the configuration file to generate configuration information, and matching a data item in the multi-tenant database corresponding to the user information according to the configuration information; adding the user information and the configuration information to the multi-tenant database by using the SQL statement corresponding to the data item.
4. The method for seamless adaptation of single tenancy to multi tenancy as claimed in claim 1, wherein, The multi-tenant database intercepts user information of a user logging in a business system, which further comprises: the tenant information comprises tenant permissions; the user information comprises a user ID, a user name, and a tenant ID; the tenant ID is stored in the data item in the corresponding multi-tenant database as a thread variable.
5. The method for seamless adaptation of single tenancy to multi tenancy as claimed in claim 1, wherein, The multi-tenant database intercepts user information of a user logging in a business system, which further comprises: if the user information does not exist in the data item in the multi-tenant database, the login request of the user is rejected.
6. An apparatus for seamless adaptation of single tenancy to multi tenancy, characterized in that, The apparatus comprises: a database merging module configured to merge data in a plurality of single-tenant databases to generate a multi-tenant database; wherein the multi-tenant database comprises a plurality of data items, each of the data items comprising tenant information and user information in a single-tenant database; The SQL statement generation module is configured to generate an SQL statement for updating a corresponding data item in the multi-tenant database according to data in each single-tenant database. The modification statement generation module is configured to generate a modification statement for updating the single-tenant database according to a database table name of the single-tenant database; The single-tenant database corresponds to a data item in the multi-tenant database one-to-one, and the SQL statement is set according to the single-tenant database corresponding to each data item in the multi-tenant database and the modification statement of the single-tenant database; The information interception module is configured to intercept user information of a user logging in the business system in the multi-tenant database, and match a corresponding data item in the multi-tenant database according to the user information; The data update module is configured to update the user information in the multi-tenant database by using the SQL statement corresponding to the data item; The thread variable module is configured to store the updated user information in the multi-tenant database by using a thread local variable, and provide an independent variable copy for each thread using the variable; The reference class replacement module is configured to replace a reference class of tenant information and user information in the single-tenant database into a multi-tenant reference class, and the multi-tenant reference class is configured to call a multi-tenant file access interface or a multi-tenant memory access interface; The information feedback module is configured to generate login information according to tenant information contained in the data item in the multi-tenant database, and return the login information to the business system.
7. A computer device comprising a memory, a processor, and a computer program stored on the memory, wherein, The processor executes the computer program to implement the method in any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a computer program, and the computer program is executed by the processor to implement the method in any one of claims 1 to 5.
9. A computer program product, characterised in that, The computer program product includes a computer program, and the computer program is executed by the processor to implement the method in any one of claims 1 to 5.
Citation Information
Patent Citations
Method and device for implementing multi-tenant system
CN108881111A
Multi-tenant database isolation method and system, electronic equipment and computer storage medium
CN110765489A