Seamless adaptation method, device and equipment from single tenant to multiple tenants

By automatically generating SQL statements and using interceptors, the high cost and low accuracy of manually updating database tables in the prior art is solved, and seamless adaptation between single-tenant databases to multi-tenant databases is achieved, reducing labor costs and improving operational efficiency.

CN119603014AActive Publication Date: 2025-03-11CHINA CONSTRUCTION BANK +1
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202411675435.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-21
Publication Date
2025-03-11
Estimated Expiration
2044-11-21

AI Technical Summary

Technical Problem

In the prior art, it is necessary to manually update the database table, add tenant ID data items, and manually set the tenant ID every time it is added, modified, or query, resulting in high labor costs and low accuracy.

Method used

By automatically generating SQL statements and using interceptors, the database table automatically adds tenant ID data items, and automatically sets and querys tenant IDs in database operations, reducing labor costs and improving accuracy.

Benefits of technology

It realizes seamless adaptation from single-tenant database to multi-tenant database, reduces labor costs, and improves operational accuracy and efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119603014A_ABST
    Figure CN119603014A_ABST
Patent Text Reader

Abstract

The embodiment of the invention relates to the technical field of communication, in particular to a single-tenant to multi-tenant seamless adaptation method, device and equipment. According to the scheme, data in a plurality of single-tenant databases are merged into one multi-tenant database, and each data item in the multi-tenant database is generated by tenant information and user information in the single-tenant database, so that all tenants can complete data interaction in the same database; and then the multi-tenant database intercepts user information of a login user in the service system, so that matching is performed according to the user information to obtain data items of the multi-tenant database corresponding to tenants where the user is located, and then updating can be performed in the database by utilizing SQL statements corresponding to the generated data items. Therefore, an independent user can be fully automatically and quickly adapted to a shared user scene, a corresponding user ID information logic code does not need to be added, modified and inquired at each position, the labor cost is reduced, and the accuracy is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present specification relate to the field of communication technology, and in particular to a method, device and equipment for seamless adaptation from a single tenant to multiple tenants. Background Art

[0002] With the development of Internet technology, the existing single-tenant model can no longer meet business needs. In the existing large-scale projects, most of them are based on the single-tenant model implemented by mybatis-plus, but due to business needs, it is necessary to support a multi-tenant SAAS version. A single tenant is a tenant that deploys a set of services separately, but after becoming multi-tenant, multiple tenants share a set of services. This paper proposes a solution based on mybatis-plus to quickly adapt from a single tenant to a multi-tenant. The main thing is that each database table needs to add a tenant ID data item to distinguish different tenants, and then insert the corresponding tenant ID when inserting the database when adding, and add the tenant ID data item to the database SQL condition when modifying and querying. The existing method is mainly to manually add tenant ID data items to distinguish different tenants in each database table. In each new operation, you need to write code to set the tenant ID, and when modifying and querying, you need to write code to add the tenant ID data item. Brush selection conditions. It is necessary to add the corresponding tenant ID information logic code when adding, modifying, and querying at each place, which has high labor costs and cannot guarantee accuracy.

[0003] At present, 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 difficult maintenance of routing to the specified module through code or manual means through automatically generated modification statements and interceptors. Summary of the invention

[0004] In order to solve the problem that the existing technology needs to update the database table by pure manual means, the embodiments of this specification provide a method, device and equipment for seamless adaptation from a single tenant to multiple tenants. Through SQL statements and interceptors, a multi-tenant database can seamlessly replace multiple single-tenant databases. At the same time, the modification statement for adding tenant ID data items to the database table is automatically generated. At the same time, only the interceptor needs to be written to automatically implement database tenant ID related operations, thereby reducing labor costs and improving accuracy. The specific technical solutions of the embodiments of this specification are as follows:

[0005] On the one hand, the embodiments of this specification provide a method for seamless adaptation from a single tenant to multiple tenants, including:

[0006] Merging data in multiple single-tenant databases to generate a multi-tenant database; wherein the multi-tenant database includes multiple data items, each of which includes tenant information and user information in a single-tenant database;

[0007] Generate an SQL statement for updating corresponding data items in the multi-tenant database according to the data in each of the single-tenant databases;

[0008] The multi-tenant database intercepts user information of a user who logs in to the business system, and matches corresponding data items of the multi-tenant database according to the user information;

[0009] Using the SQL statement corresponding to the data item to update the user information in the multi-tenant database;

[0010] The updated user information is stored in the multi-tenant database using thread local variables, and an independent variable copy is provided for each thread using the variable;

[0011] Replacing the reference class of tenant information and user information in the single-tenant database with a multi-tenant reference class, wherein the multi-tenant reference class is used to call a multi-tenant file access interface or a multi-tenant memory access interface;

[0012] Login information is generated according to the tenant information included in the data item in the multi-tenant database and returned to the business system.

[0013] Furthermore, the multi-tenant database includes multiple data items further including:

[0014] Each single-tenant database contains tenant information of a single tenant, and each tenant contains at least one user;

[0015] The single-tenant database includes tenant information of the tenant and user information of multiple users in the tenant.

[0016] Furthermore, the multi-tenant database intercepts user information of business system login users and further includes:

[0017] Intercepting a user registration request of the business system, wherein the user registration request includes user information and a configuration file;

[0018] Parse the configuration file to generate configuration information, and match the data items of the multi-tenant database corresponding to the user information according to the configuration information;

[0019] The user information and configuration information are added to the multi-tenant database using the SQL statement corresponding to the data item.

[0020] Furthermore, generating an SQL statement for updating a corresponding data item in the multi-tenant database according to the data in each of the single-tenant databases further includes:

[0021] Generate a modification statement used when updating the single-tenant database according to the database table name of the single-tenant database;

[0022] The single-tenant database corresponds to the multi-tenant database data items one by one, and the SQL statement is set according to the single-tenant database corresponding to the data item of each multi-tenant database and its modification statement.

[0023] Furthermore, the multi-tenant database intercepts user information of business system login users and further includes:

[0024] The tenant information tenant permissions;

[0025] The user information includes user ID, user name and tenant ID;

[0026] The tenant ID is stored as a thread variable in a corresponding data item of the multi-tenant database.

[0027] Furthermore, matching the data items of the multi-tenant database corresponding to the user information further includes:

[0028] If the user information does not exist in the data item of the multi-tenant database, the user's login request is rejected.

[0029] On the other hand, the embodiment of this specification also provides a single-tenant to multi-tenant seamless adaptation device, the device comprising:

[0030] A database merging module, used to merge data in multiple single-tenant databases to generate a multi-tenant database; wherein the multi-tenant database includes multiple data items, each of which includes tenant information and user information in a single-tenant database;

[0031] A statement generation module, used to generate an SQL statement for updating corresponding data items in the multi-tenant database according to the data in each of the single-tenant databases;

[0032] An information interception module, used for the multi-tenant database to intercept user information of a user logging into the business system, and match corresponding data items of the multi-tenant database according to the user information;

[0033] A data updating module, used to update the user information in the multi-tenant database using the SQL statement corresponding to the data item;

[0034] A thread variable module, used to store the updated user information in the multi-tenant database using thread local variables, and provide an independent variable copy for each thread using the variable;

[0035] A reference class replacement module, used to replace the reference class of tenant information and user information in the single-tenant database with a multi-tenant reference class, wherein the multi-tenant reference class is used to call a multi-tenant file access interface or a multi-tenant memory access interface;

[0036] An information feedback module is used to generate login information based on the tenant information contained in the data item in the multi-tenant database and return it to the business system.

[0037] On the other hand, an embodiment of the present specification further provides a computer device, including 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] On the other hand, an embodiment of the present specification further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and the computer program implements the above method when executed by a processor.

[0039] Finally, the embodiments of this specification also provide a computer program product, wherein the computer program product includes a computer program, and the computer program implements the above method when executed by a processor.

[0040] By using the embodiments of this specification, a method capable of seamlessly adapting a single-tenant database to a multi-tenant database is provided. This solution merges the data in multiple single-tenant databases into a multi-tenant database, and generates each data item in the multi-tenant database from the tenant information and user information in the single-tenant database, so that all tenants can complete data interaction in the same database; at the same time, an SQL statement for updating the corresponding data item in the multi-tenant database is generated according to the data in each single-tenant database, so that the data item in the multi-tenant database can be automatically updated, and then the multi-tenant database intercepts the user information of the logged-in user in the business system, so as to obtain the data item of the multi-tenant database corresponding to the tenant where the user is located according to the user information, and then the user information can be updated in this multi-tenant database using the SQL statement corresponding to the generated data item; finally, the login information required by the user is generated according to the tenant information contained in the data item and returned to the business system. Thus, the newly received message is automatically distributed through the routing configuration rules, and the message is automatically routed to different processing modules for parsing and processing through flexible configuration, thereby improving the efficiency of message processing. At the same time, the accuracy of message routing is improved by automatically processing messages through routing configuration rules. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] In order to more clearly illustrate the embodiments of this specification 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 embodiments of this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0042] Figure 1 The figure shows a schematic diagram of a system for implementing a method for seamless adaptation from a single tenant to multiple tenants in an embodiment of the present specification;

[0043] Figure 2 The figure is a flow chart of a method for seamless adaptation from a single tenant to multiple tenants in an embodiment of the present specification;

[0044] Figure 3 The figure is a schematic diagram of the process of intercepting user information of a user who logs in to a business system by a multi-tenant database in an embodiment of this specification;

[0045] Figure 4 The figure is a schematic diagram of a process of generating SQL statements according to the data in each single-tenant database in an embodiment of this specification;

[0046] Figure 5 The figure is a schematic diagram of the process of automatically adding tenant ID information to perform database operations in an embodiment of this specification;

[0047] Figure 6 The figure is a flow chart of updating the user information in the multi-tenant database by using the SQL statement corresponding to the data item in the embodiment of this specification;

[0048] Figure 7 The figure shows a specific structural diagram of the device for seamless adaptation from a single tenant to multiple tenants in this embodiment;

[0049] Figure 8 The figure is a schematic diagram of the structure of a computer device in an embodiment of the present specification.

[0050]

Description of reference numerals

[0051] 101. Business system;

[0052] 102. Single tenant database;

[0053] 103. Multi-tenant database;

[0054] 701. Database merging module;

[0055] 702, sentence 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 equipment;

[0062] 804. Processing equipment;

[0063] 806. Storage resources;

[0064] 808, drive system;

[0065] 810, input / output module;

[0066] 812. Input device;

[0067] 814. Output device;

[0068] 816. Presentation equipment;

[0069] 818. Graphical user interface;

[0070] 820, network interface;

[0071] 822, communication link;

[0072] 824. Communication bus. DETAILED DESCRIPTION

[0073] The following will be combined with the drawings in the embodiments of this specification to clearly and completely describe the technical solutions in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of them. Based on the embodiments in the embodiments of this specification, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the embodiments of this specification.

[0074] It should be noted that the terms "first", "second", etc. in the description and claims of the embodiments of this specification and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the embodiments of this specification described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, device, product or equipment that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or equipment.

[0075] It should be noted that the acquisition, storage, use, and processing of data in the technical solutions of the embodiments of this specification comply with the relevant provisions of national laws and regulations.

[0076] It should be noted that in the embodiments of this specification, certain software, components, models and other existing solutions in the industry may be mentioned, and they should be regarded as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of this application, but it does not mean that the applicant has or will necessarily use the solution.

[0077] like Figure 1 The diagram shows a system diagram of a method for seamlessly adapting from a single tenant to multiple tenants in an embodiment of the specification, including 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 with each other through a network, and the network can include a local area network (LAN), a wide area network (WAN), the Internet, or a combination thereof, and is connected to a website, a user device (such as a computing device), and a back-end system. Optionally, 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 obtains a user login request and sends the customer information to the single-tenant database 102. During the sending process, the multi-tenant database 103 intercepts the customer information. The multi-tenant database 103 is established by merging the data in multiple single-tenant databases 102. The multi-tenant database 103 then 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 1What is shown is only one application environment provided by the embodiment of this specification. In actual application, other application environments may also be included, and this specification does not limit it.

[0080] In view of the problems existing in the prior art, the embodiments of this specification provide a method for seamless adaptation from a single tenant to multiple tenants. In the embodiments of this specification, Figure 2 The figure shows a flow chart of the method for seamless adaptation from a single tenant to multiple tenants in the embodiment of this specification. The figure describes the seamless adaptation process from a single tenant to multiple tenants. The order of steps listed in the embodiment is only one way of executing the steps among many, and does not represent the only execution order. When the actual system or device product is executed, it can be executed in the order or in parallel according to the method shown in the embodiment or the accompanying drawings. Specifically, Figure 2 As shown, the method may include:

[0081] Step 201: Merge data in multiple single-tenant databases to generate a multi-tenant database; wherein the multi-tenant database includes multiple data items, each of which includes tenant information and user information in a single-tenant database;

[0082] Step 202: Generate an SQL statement for updating corresponding data items in the multi-tenant database according to the data in each of the single-tenant databases;

[0083] Step 203: the multi-tenant database intercepts user information of the business system login user, and matches the corresponding data item of the multi-tenant database according to the user information;

[0084] Step 204: using the SQL statement corresponding to the data item to update the user information in the multi-tenant database;

[0085] Step 205: Store the updated user information in the multi-tenant database using thread local variables, and provide an independent variable copy for each thread using the variable;

[0086] Step 206: replacing the reference class of the tenant information and user information in the single-tenant database with a multi-tenant reference class, where the multi-tenant reference class is used to call a multi-tenant file access interface or a multi-tenant memory access interface;

[0087] Step 207: Generate login information based on the tenant information included in the data item in the multi-tenant database and return it to the business system.

[0088] By using the embodiments of this specification, a method capable of seamlessly adapting a single-tenant database to a multi-tenant database is provided. This solution merges the data in multiple single-tenant databases into a multi-tenant database, and generates each data item in the multi-tenant database from the tenant information and user information in the single-tenant database, so that all tenants can complete data interaction in the same database; at the same time, an SQL statement for updating the corresponding data item in the multi-tenant database is generated according to the data in each single-tenant database, so that the data item in the multi-tenant database can be automatically updated, and then the multi-tenant database intercepts the user information of the logged-in user in the business system, so as to obtain the data item of the multi-tenant database corresponding to the tenant where the user is located according to the user information, and then the user information can be updated in this multi-tenant database using the SQL statement corresponding to the generated data item; finally, the login information required by the user is generated according to the tenant information contained in the data item and returned to the business system. Thus, the newly received message is automatically distributed through the routing configuration rules, and the message is automatically routed to different processing modules for parsing and processing through flexible configuration, thereby improving the efficiency of message processing. At the same time, the accuracy of message routing is improved by automatically processing messages through routing configuration rules.

[0089] In the embodiments of this specification, a single-tenant database is replaced by a multi-tenant database. Since one tenant uses one environment, the database only stores the data of one tenant, so a large amount of resources are consumed; therefore, the scale cost and security of the multi-tenant database are achieved by sharing hardware or software. In a multi-tenant environment, multiple tenants and applications directly and securely share IT resources. The more resources are shared between tenants, the higher the utilization rate of basic resources and the lower the unit resource cost. At the same time, thread-local variables are used for storage in the multi-tenant database, and an independent copy of the variable is provided for each thread that uses the variable. Therefore, each thread can independently change its copy without affecting the copies of other threads, ensuring that sharing variable data in a multi-threaded environment becomes easier and safer.

[0090] According to one embodiment of the present specification, in order to replace a single-tenant database with a multi-tenant database and ensure that data therein is not lost, the multi-tenant database includes multiple data items further including:

[0091] Each single-tenant database contains tenant information of a single tenant, and each tenant contains at least one user;

[0092] The single-tenant database includes tenant information of the tenant and user information of multiple users in the tenant.

[0093] Specifically, the single-tenant file access interface and the single-tenant memory access interface are both methods in the single-tenant reference class, and the multi-tenant file access interface and the multi-tenant memory access interface are both methods in the multi-tenant reference class; by replacing the reference class of the tenant information and user information in the single-tenant database introduced in the business processor with the multi-tenant reference class, 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 user information of the multi-tenant database data item to which the user belongs.

[0094] According to an embodiment of the present specification, in order to meet different business needs, the tenant may add new users, such as Figure 3 As shown, the multi-tenant database intercepts the user information of the business system login user and further includes:

[0095] Step 301: intercepting a user registration request of the business system, wherein the user registration request includes user information and a configuration file;

[0096] Step 302: Parse the configuration file to generate configuration information, and match the data items of the multi-tenant database corresponding to the user information according to the configuration information;

[0097] Step 303: Use the SQL statement corresponding to the data item to add the user information and configuration information to the multi-tenant database.

[0098] According to an embodiment of the present specification, in order to obtain a SQL statement for updating a corresponding data item in the multi-tenant database, such as Figure 4 As shown, generating an SQL statement for updating a corresponding data item in the multi-tenant database according to the data in each of the single-tenant databases further includes:

[0099] Step 401: Generate 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 multi-tenant database data items one by one, and the SQL statement is set according to the single-tenant database corresponding to each multi-tenant database data item and its modification statement.

[0101] Specifically, the table names of all data tables are automatically obtained; the modification statements for adding tenant ID data items corresponding to each database table are automatically generated; that is, the freemarker module engine is used to generate corresponding SQL statements according to the obtained database table names, that is, the corresponding text is automatically generated based on the module and the data to be modified.

[0102] According to an 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 intercepts the user information of the user who logs in to the business system, further comprising:

[0103] The tenant information tenant permissions;

[0104] The user information includes user ID, user name and tenant ID;

[0105] The tenant ID is stored as a thread variable in a corresponding data item of the multi-tenant database.

[0106] Specifically, in each request, an interceptor is used to obtain the user information UserInfo of the currently logged-in user, including the user ID, user name, tenant ID, etc., and the UserInfo is stored in the form of a thread variable ThreadLocal; the specific steps of the interceptor are:

[0107] Get the user information userJson stored in string JSON format from the request header;

[0108] Convert the userJson data item into the userInfo object of user information UserInfo, where the UserInfo class includes user ID, user name, and tenant ID;

[0109] The userInfo object is then stored in the UserInfoContext context object used to store user thread variables, thereby obtaining the user information of the logged-in user.

[0110] Among them, UserInfoContext: indicates the class name used to store user thread variables, which contains only one thread variable field of user type (UserInfo). Thread variables (threadlocal) belong only to the current thread and are isolated from other threads.

[0111] Furthermore, an interceptor is used to automatically add tenant ID information for database operations, such as Figure 5 As shown, specifically:

[0112] Step 501: Get the currently executed SQL and its related attributes to determine whether it is a query statement;

[0113] Step 502: If it is not a query statement, that is, it is not SqlCommandType.SELECT, then the process ends;

[0114] Among them, SqlCommandType is an enumeration class for database operation types provided by Mybatis-plus, mainly including: add, delete, modify, check, etc.

[0115] Step 503: If it is a query statement, that is, the SQL type is SqlCommandType.SELECT, then obtain the tenant information thread variable and obtain 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, add the variable condition of the tenant ID.

[0119] According to an embodiment of the present specification, it is also necessary to confirm the identity information of the user, and matching the corresponding data items of the multi-tenant database according to the user information further includes:

[0120] If the user information does not exist in the data item of the multi-tenant database, the user's login request is rejected.

[0121] According to an embodiment of the present specification, the user information is updated in the multi-tenant database using the SQL statement corresponding to the data item, the database operation object base class BasePo adds the tenantId field data item, and rewrites the insertFull function, such as Figure 6 As shown, 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 value of the tenant ID field in the current operation object is empty, the tenant ID information of the current operation user is set to the tenantId data item in the BasePo object;

[0124] Step 603: MetaObjectHandler needs to be implemented in the configuration file to automatically fill in the tenant ID information for subsequent SQL queries.

[0125] Among them, the object base class BasePo is the parent class of all database operation entity object classes in the application. This class defines the common fields of all database operation entity objects. Because the tenant ID (tenantId) is a common field of all database operation entity objects, this field is added to the base class BasePo class so that all database operation entity classes in the application have the tenant ID (tenantId) field.

[0126] As an example of this specification, please refer to Figure 7 The figure shows a specific structural diagram of the device for seamless adaptation from a single tenant to multiple tenants in this embodiment.

[0127] A database merging module 701 is used to merge data in multiple single-tenant databases to generate a multi-tenant database; wherein the multi-tenant database includes multiple data items, each of which includes tenant information and user information in a single-tenant database;

[0128] A statement generation module 702, configured to generate, based on the data in each of the single-tenant databases, an SQL statement for updating corresponding data items in the multi-tenant database;

[0129] An information interception module 703 is used for the multi-tenant database to intercept user information of a user who logs into the business system, and match the corresponding data item of the multi-tenant database according to the user information;

[0130] A data updating module 704 is used to update the user information in the multi-tenant database using the SQL statement corresponding to the data item;

[0131] A thread variable module 705, used to store the updated user information in the multi-tenant database using thread local variables, and provide an independent variable copy for each thread using the variable;

[0132] A reference class replacement module 706, used to replace the reference class of the tenant information and the user information in the single-tenant database with a multi-tenant reference class, wherein the multi-tenant reference class is used to call a multi-tenant file access interface or a multi-tenant memory access interface;

[0133] The information feedback module 707 is used to generate login information based on the tenant information included in the data item in the multi-tenant database and return it to the business system.

[0134] Since the principle of solving the problem by the above device is similar to that of 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 repeated.

[0135] like Figure 8The figure is a schematic diagram of the structure of a computer device according to an embodiment of the present specification. The computer device according to the embodiment of the present specification can run the method according to the embodiment of the present specification.

[0136] The computer device 802 may include one or more processing devices 804, such as one or more central processing units (CPUs), each of which may implement one or more hardware threads. The computer device 802 may also include any storage resources 806 for storing any type of information such as code, settings, data, etc. Without limitation, for example, the storage resources 806 may include any one or more combinations 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 may use any technology to store information.

[0137] Further, any storage resource may provide volatile or non-volatile retention of information.

[0138] Further, any storage resource may represent a fixed or removable component of the computer device 802. In one case, when the processing device 804 executes the associated instructions stored in any storage resource or combination of storage resources, the computer device 802 may perform any operation of the associated instructions. 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 may 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). A specific output mechanism may include a presentation device 816 and an associated graphical user interface 818 (GUI). In other embodiments, the input / output module 810 (I / O), input device 812, and output device 814 may not be included, and the computer device 802 may be used as a computer device in a network. The computer device 802 may 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 components described above together.

[0140] The communication link 822 may 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 link 822 may include any combination of hardwired links, wireless links, routers, gateway functions, name servers, etc. governed by any protocol or combination of protocols.

[0141] The embodiments of the present specification also provide a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and the computer program implements the above method when executed by a processor.

[0142] The embodiments of the present specification also provide a computer-readable instruction, wherein when a processor executes the instruction, the program therein causes the processor to execute the above method.

[0143] It should be understood that in the various embodiments of the present specification, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present specification.

[0144] It should also be understood that in the embodiments of this specification, the term "and / or" is only a description of the association relationship of the associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in the embodiments of this specification generally indicates that the associated objects before and after are in an "or" relationship.

[0145] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed in the embodiments of this specification can be implemented with electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the embodiments of this specification.

[0146] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0147] In the several embodiments provided in the embodiments of this specification, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, or it can be an electrical, mechanical or other form of connection.

[0148] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiments of this specification.

[0149] In addition, each functional unit in each embodiment of the present specification can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above integrated unit can be implemented in the form of hardware or in the form of software functional units.

[0150] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of this specification is essentially or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the embodiment of this specification. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program code.

[0151] The embodiments of this specification use specific embodiments to illustrate the principles and implementation methods of the embodiments of this specification. The description of the above embodiments is only used to help understand the methods and core ideas of the embodiments of this specification. At the same time, for those skilled in the art, according to the ideas of the embodiments of this specification, there will be changes in the specific implementation methods and application scopes. In summary, the content of this specification should not be understood as a limitation on the embodiments of this specification.

Claims

1. A method for seamless adaptation from a single tenant to multiple tenants, characterized in that: The method comprises, Merging data in multiple single-tenant databases to generate a multi-tenant database; wherein the multi-tenant database includes multiple data items, each of which includes tenant information and user information in a single-tenant database; Generate an SQL statement for updating corresponding data items in the multi-tenant database according to the data in each of the single-tenant databases; The multi-tenant database intercepts user information of a user who logs in to the business system, and matches corresponding data items of the multi-tenant database according to the user information; Using the SQL statement corresponding to the data item to update the user information in the multi-tenant database; The updated user information is stored in the multi-tenant database using thread local variables, and an independent variable copy is provided for each thread using the variable; Replacing the reference class of tenant information and user information in the single-tenant database with a multi-tenant reference class, wherein the multi-tenant reference class is used to call a multi-tenant file access interface or a multi-tenant memory access interface; Login information is generated according to the tenant information included in the data item in the multi-tenant database and returned to the business system.

2. The method for seamless adaptation from a single tenant to multiple tenants according to claim 1, characterized in that: The multi-tenant database includes multiple data items further including: Each single-tenant database contains tenant information of a single tenant, and each tenant contains at least one user; The single-tenant database includes tenant information of the tenant and user information of multiple users in the tenant.

3. The method for seamless adaptation from a single tenant to multiple tenants according to claim 1, characterized in that: The multi-tenant database intercepts user information of business system login users further including: Intercepting a user registration request of the business system, wherein the user registration request includes user information and a configuration file; Parse the configuration file to generate configuration information, and match the data items of the multi-tenant database corresponding to the user information according to the configuration information; The user information and configuration information are added to the multi-tenant database using the SQL statement corresponding to the data item.

4. The method for seamless adaptation from a single tenant to multiple tenants according to claim 1, characterized in that: Generating an SQL statement for updating a corresponding data item in the multi-tenant database according to the data in each of the single-tenant databases further includes: Generate a modification statement used when updating the single-tenant database according to the database table name of the single-tenant database; The single-tenant database corresponds to the data items of the multi-tenant database one by one, and the SQL statement is set according to the single-tenant database corresponding to the data item of each multi-tenant database and its modification statement.

5. The method for seamless adaptation from a single tenant to multiple tenants according to claim 1, characterized in that: The multi-tenant database intercepts user information of business system login users further including: The tenant information includes tenant permissions; The user information includes user ID, user name and tenant ID; The tenant ID is stored as a thread variable in a corresponding data item of the multi-tenant database.

6. The method for seamless adaptation from a single tenant to multiple tenants according to claim 1, characterized in that: Matching the corresponding data items of the multi-tenant database according to the user information further includes: If the user information does not exist in the data item of the multi-tenant database, the user's login request is rejected.

7. A seamless adaptation device from a single tenant to multiple tenants, characterized in that: The device comprises: A database merging module, used to merge data in multiple single-tenant databases to generate a multi-tenant database; wherein the multi-tenant database includes multiple data items, each of which includes tenant information and user information in a single-tenant database; A statement generation module, used to generate an SQL statement for updating corresponding data items in the multi-tenant database according to the data in each of the single-tenant databases; An information interception module, used for the multi-tenant database to intercept user information of a user logging into the business system, and match corresponding data items of the multi-tenant database according to the user information; A data updating module, used to update the user information in the multi-tenant database using the SQL statement corresponding to the data item; A thread variable module, used to store the updated user information in the multi-tenant database using thread local variables, and provide an independent variable copy for each thread using the variable; A reference class replacement module, used to replace the reference class of tenant information and user information in the single-tenant database with a multi-tenant reference class, wherein the multi-tenant reference class is used to call a multi-tenant file access interface or a multi-tenant memory access interface; An information feedback module is used to generate login information based on the tenant information contained in the data item in the multi-tenant database and return it to the business system.

8. A computer device comprising a memory, a processor, and a computer program stored in the memory, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 6 is implemented.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.

10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.

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

  • Multi-tenant database management and control method and system and storage medium

    CN113535723A

  • Multi-tenant service implementation method and system

    CN115480914A

  • Dynamically provisioning instances of a single-tenant application for multi-tenant use

    US20180278675A1