Summary of the invention
In order to solve the above-mentioned technical problems, the present invention provides a kind of method and devices for realizing multi-tenant system, can
Existing single Tenant system is converted into multi-tenant system by less workload.
In order to reach the object of the invention, what the technical solution of the embodiment of the present invention was realized in:
The embodiment of the invention provides a kind of methods for realizing multi-tenant system, including:
Before system operation, multi-tenant referenced classes are pre-defined, and using in multi-tenant referenced classes replacement operational processor
Single tenant's referenced classes of introducing, the multi-tenant referenced classes are used to connect single tenant folder access interface, single tenant's internal storage access
Mouth is packaged into multi-tenant file access interface, multi-tenant memory access interface respectively;
After system operation, the business processing request of user is received, is called at business corresponding with business processing request
It manages device and carries out business processing;
The database access request that operational processor issues is intercepted and captured, obtains tenant's information belonging to user, and by database
Access request is converted into the access request of database corresponding with acquired tenant's information, obtains the number of tenant belonging to user
According to library data and it is back to operational processor.
Further, before the step of business processing for receiving user is requested, the method also includes:
It receives and verifies the logging request of user, create session object, generate session identification, and by tenant belonging to user
Information preservation is in session object;
In described the step of calling operational processor corresponding with business processing request to be handled, the method is also
Including:
According to business processing request in session identification, tenant's information belonging to the user is obtained from session object,
And it stores it in storage region;
In the step of tenant's information belonging to the acquisition user, the letter of tenant belonging to user is obtained from storage region
Breath.
Further, the storage region includes local thread, memory cache or database.
Further, it described the step of intercepting and capturing the database access request that operational processor issues, specifically includes:Pass through prison
It listens the interface of operating system layer, monitor Java database connection JDBC interface or setting TCP agent intercepting and capturing operational processor sending
Database access request.
The embodiment of the invention provides a kind of device for realizing multi-tenant system, including encapsulation unit, request Dispatching Unit,
Service Processing Unit intercepts and captures unit, wherein
Encapsulation unit, for pre-defining multi-tenant referenced classes, and replace using multi-tenant referenced classes before system operation
The single tenant's referenced classes introduced in Service Processing Unit, the multi-tenant referenced classes are used for single tenant folder access interface, list
Tenant's memory access interface is packaged into multi-tenant file access interface, multi-tenant memory access interface respectively;
Dispatching Unit is requested, for after system operation, receiving the business processing request of user, calling is asked with business processing
Corresponding Service Processing Unit is asked to carry out business processing;
Service Processing Unit issues database access for carrying out business processing, and during carrying out business processing
Request, file access request or memory access request;
Unit is intercepted and captured, for the database access being intercepted and captured and being asked when Service Processing Unit issues database access request
It asks, obtains tenant's information belonging to user, and database access request is converted into number corresponding with acquired tenant's information
According to the access request in library, obtains the database data of tenant belonging to user and be back to Service Processing Unit.
Further, the request Dispatching Unit is also used to, and before receiving the business processing request of user, is received and is verified
The logging request of user creates session object, generates session identification, and by tenant's information preservation belonging to user in session object
In;
Receive user business processing request when, according to business processing request in session identification, from session object
Tenant's information belonging to the user is obtained, and is stored it in storage region;
The intercepting and capturing unit is specifically used for, and tenant's information belonging to user is obtained from storage region.
Further, the storage region includes local thread, memory cache or database.
Further, the intercepting and capturing unit is specifically used for, and by the interface of snoop-operations system layer, monitors Java database
It connects JDBC interface or TCP agent is set and intercept and capture the database access request that Service Processing Unit issues.
Technical solution of the present invention has the advantages that:
The method and device provided by the invention for realizing multi-tenant system, using a kind of implicit way transmitting tenant's letter
Single tenant folder access interface, single tenant's memory access interface are packaged into more rents by defining multi-tenant referenced classes by breath respectively
Family file access interface, multi-tenant memory access interface and data interception library access request, obtain corresponding tenant's information, root
Access different data fields respectively according to tenant's information, in this way, Service Processing Unit just completely without concern tenant's information, in the past
The code that single tenant can only be handled only needs a small amount of modification that can be transformed into multi-tenant version, considerably reduces and was transformed
Workload in journey, and the business development process of multi-tenant is simplified, enable developer to be absorbed in business development, drops
The cost of low exploitation.
Specific embodiment
To make the objectives, technical solutions, and advantages of the present invention clearer, below in conjunction with attached drawing to the present invention
Embodiment be described in detail.It should be noted that in the absence of conflict, in the embodiment and embodiment in the application
Feature can mutual any combination.
As shown in Fig. 2, a kind of method for realizing multi-tenant system according to the present invention, includes the following steps:
Step 201:Before system operation, multi-tenant referenced classes are pre-defined, and replace business using multi-tenant referenced classes
The single tenant's referenced classes introduced in processor, the multi-tenant referenced classes are used for will be in single tenant folder access interface, single tenant
It deposits access interface and is packaged into multi-tenant file access interface, multi-tenant memory access interface respectively;
It is worth noting that the list tenant folder access interface, single tenant's memory access interface are single tenant's reference
Method in class, the multi-tenant file access interface, multi-tenant memory access interface are the method in multi-tenant referenced classes;
By the way that the single tenant's referenced classes introduced in operational processor are simply replaced with multi-tenant referenced classes, so that it may in business processing
It is automatic to call multi-tenant file access interface or multi-tenant internal storage access when device issues file access request or memory access request
Interface obtains the file data or internal storage data of tenant belonging to user.
Step 202:After system operation, the business processing request of user is received, is called corresponding with business processing request
Operational processor carry out business processing;
Further, before the step 202, the method also includes:The logging request of user is received and verified, is created
Session (Session) object is built, is generated session identification (Session ID), and by tenant's information preservation belonging to user in session
In object.
It should be noted that the action time of the session object in the present invention opens browser from user, login successfully out
Begin, exiting or close browser to the user terminates.Due to not transmitting session mark during operational processor processing business
Know, therefore in order to obtain tenant's information belonging to user, needs that tenant's information belonging to user is individually stored in a storage
In region.
Further, in described the step of calling operational processor corresponding with business processing request to carry out business processing
In, the method also includes:
According to business processing request in session identification, tenant's information belonging to the user is obtained from session object,
And it stores it in storage region.
Further, the storage region includes local thread, memory cache or database.
It should be noted that operational processor carry out business procession in, it will usually issue database access request,
The request of at least one of file access request or memory access request;If operational processor issues file access request or interior
Access request is deposited, operational processor will call multi-tenant file access interface or multi-tenant memory access interface automatically, obtain
The file data or internal storage data of tenant belonging to user.
Step 203:The database access request that operational processor issues is intercepted and captured, tenant's information belonging to user is obtained, and
Database access request is converted into the access request of database corresponding with acquired tenant's information, is obtained belonging to user
The database data of tenant is simultaneously back to operational processor.
Further, in the step of tenant's information belonging to the acquisition user in step 203, from storage region
Obtain tenant's information belonging to user.
Specifically, as shown in figure 3, tenant 1 access database it is requested come when, intercept the request.In intercept process
Tenant's information is got, the relationship of tenant and database are inquired, initiates access request to the corresponding database of the tenant.In this way,
For operational processor just completely without concern tenant's information, the code for being formerly only available the single tenant of processing only needs a small amount of modification
(i.e. pre-defined multi-tenant referenced classes, and replace single tenant's referenced classes with multi-tenant referenced classes) can be transformed into multi-tenant system
System.
Further, the step of database access request that the intercepting and capturing operational processor in step 203 issues, specifically
Including:By the interface of snoop-operations system layer, monitor Java database connection (JDBC) interface or setting transmission control protocol
(TCP) it acts on behalf of, intercepts and captures the database access request that operational processor issues.
As shown in figure 4, the embodiment of the invention also provides a kind of device for realizing multi-tenant system, including encapsulation unit
401, it requests Dispatching Unit 402, Service Processing Unit 403, intercept and capture unit 404, wherein
Encapsulation unit 401, for pre-defining multi-tenant referenced classes, and use multi-tenant referenced classes before system operation
The single tenant's referenced classes introduced in replacement Service Processing Unit 403, the multi-tenant referenced classes are for accessing single tenant folder
Interface, single tenant's memory access interface are packaged into multi-tenant file access interface, multi-tenant memory access interface respectively;
Request Dispatching Unit 402, for after system operation, the business processing for receiving user to be requested, at calling and business
Reason requests corresponding Service Processing Unit 403 to carry out business processing;
Service Processing Unit 403 issues database for carrying out business processing, and during carrying out business processing
Access request, file access request or memory access request;
Unit 404 is intercepted and captured, for intercepting and capturing the database when Service Processing Unit 403 issues database access request
Access request obtains tenant's information belonging to user, and database access request is converted into and acquired tenant's information pair
The access request for the database answered obtains the database data of tenant belonging to user and is back to Service Processing Unit 403.
It is worth noting that the list tenant folder access interface, single tenant's memory access interface are single tenant's reference
Method in class, the multi-tenant file access interface, multi-tenant memory access interface are the method in multi-tenant referenced classes;
By the way that the single tenant's referenced classes introduced in Service Processing Unit 403 are simply replaced with multi-tenant referenced classes, so that it may in industry
It is automatic to call multi-tenant file access interface or more when the sending file access request of processing unit 403 or the memory access request of being engaged in
Tenant's memory access interface obtains the file data or internal storage data of tenant belonging to user.
Further, as shown in figure 4, the request Dispatching Unit 402 is also used to, in the business processing request for receiving user
Before, it receives and verifies the logging request of user, create session object, generate session identification, and by tenant's information belonging to user
It is stored in session object;
Receive user business processing request when, according to business processing request in session identification, from session object
Tenant's information belonging to the user is obtained, and is stored it in storage region;
The intercepting and capturing unit 404 is specifically used for, and tenant's information belonging to user is obtained from storage region.
It should be noted that the action time of the session object in the present invention opens browser from user, login successfully out
Begin, exiting or close browser to the user terminates.Due to not transmitting session mark during operational processor processing business
Know, therefore in order to obtain tenant's information belonging to user, needs that tenant's information belonging to user is individually stored in a storage
In region.
Further, the storage region includes local thread, memory cache or database.
Further, the intercepting and capturing unit 404 is specifically used for, and by the interface of snoop-operations system layer, monitors Java number
(JDBC) interface, which is connected, according to library or TCP agent is set intercepts and captures the database access request that Service Processing Unit issues.
Below with reference to a preferred embodiment, the present invention is further expalined, it will be appreciated that the preferred reality
It applies example to be intended merely to preferably describe the present invention, does not constitute and the present invention is improperly limited.
Before system operation, encapsulation unit pre-defines multi-tenant referenced classes, and replaces business using multi-tenant referenced classes
The single tenant's referenced classes introduced in processing unit, the multi-tenant referenced classes are used for single tenant folder access interface, single tenant
Memory access interface is packaged into multi-tenant file access interface, multi-tenant memory access interface respectively.
After system operation, as shown in figure 5, primary complete tenant's information process includes the following steps:
Step 501:User logs on a web browser, inputs user name password;
Step 502:According to username information find out the user belonging to tenant, verifying user name password it is whether correct;
Step 503:It is verified, establishes the session information of the user, in a session by affiliated tenant's information storage;
Step 504:User initiates the request of an acquisition business datum, and the data obtained herein should be corresponding tenant
Data cannot get the data of other tenants;
Step 505:Server receives service request, and tenant's information is got from session, and local thread is arrived in setting
In (Thread Local);
Step 506:The request of server calls Service Processing Unit processing business;
Step 507:Business datum is obtained during Service Processing Unit processing business, calls the interface of access data;
Step 508:If the interface for accessing data is file access interface or memory access interface, multi-tenant is called directly
File access interface or multi-tenant memory access interface;If the interface of access data is database access interface, system is intercepted and captured
Database access request takes out tenant's information from Thread Local, finds the corresponding number of this tenant according to tenant's information
According to library name;
Step 509:This file access catalogue, memory cache or database for storing corresponding tenant data is accessed, is obtained
Access evidence;
Step 510:It gets correct data and returns to browser end all the way later.
The present invention transmits tenant's information using a kind of implicit way, by defining multi-tenant referenced classes for single tenant folder
Access interface, single tenant's memory access interface are packaged into multi-tenant file access interface, multi-tenant memory access interface respectively, with
And data interception library access request, corresponding tenant's information is obtained, accesses different data fields respectively according to tenant's information, in this way
For Service Processing Unit just completely without concern tenant's information, the code for being formerly only available the single tenant of processing only needs a small amount of modification
It can be transformed into SaaS multi-tenant version, the workload in transformation process can greatly be reduced, and can simplify more rents
The business development process at family, enables developer to be absorbed in business development, reduces the cost of exploitation.
Those of ordinary skill in the art will appreciate that all or part of the steps in the above method can be instructed by program
Related hardware is completed, and described program can store in computer readable storage medium, such as read-only memory, disk or CD
Deng.Optionally, one or more integrated circuits also can be used to realize, accordingly in all or part of the steps of above-described embodiment
Ground, each module/unit in above-described embodiment can take the form of hardware realization, can also use the shape of software function module
Formula is realized.The present invention is not limited to the combinations of the hardware and software of any particular form.
The foregoing is only a preferred embodiment of the present invention, is not intended to restrict the invention, for the skill of this field
For art personnel, the invention may be variously modified and varied.All within the spirits and principles of the present invention, made any to repair
Change, equivalent replacement, improvement etc., should all be included in the protection scope of the present invention.