CN110765187A - Data source route management method and device - Google Patents

Data source route management method and device Download PDF

Info

Publication number
CN110765187A
CN110765187A CN201810743523.3A CN201810743523A CN110765187A CN 110765187 A CN110765187 A CN 110765187A CN 201810743523 A CN201810743523 A CN 201810743523A CN 110765187 A CN110765187 A CN 110765187A
Authority
CN
China
Prior art keywords
data source
annotation
identification
business method
thread context
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201810743523.3A
Other languages
Chinese (zh)
Inventor
隋红华
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201810743523.3A priority Critical patent/CN110765187A/en
Publication of CN110765187A publication Critical patent/CN110765187A/en
Pending legal-status Critical Current

Links

Images

Abstract

The invention discloses a data source route management method and device, and relates to the technical field of computers. One embodiment of the method comprises: adding an annotation on a business method needing to select a data source, and specifying a data source identifier in an attribute of the annotation; intercepting a business method with annotations through a section, and obtaining a thread context environment variable corresponding to a data source identifier by executing a data source selection logic in the section; and the business method selects a data source corresponding to the business method according to the thread context environment variable. The implementation mode can reduce repeated data source selection logic codes, reduce intrusion to business codes, reduce the coupling degree of the data source selection codes and the business codes, flexibly configure dynamic data source selection, realize dynamic switching of uniformly managed data sources, determine the data sources according to specified strategies, meet basic management requirements, meet expansion requirements, reduce integration cost and improve development efficiency.

Description

Data source route management method and device
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a data source route management method and apparatus.
Background
The internet is widely applied in real life, users can quickly extract and exchange information on the internet, and big data becomes the development trend of the internet. MySQL (a relational database management system) is used as the most widely used free database in the world at present, but in an actual production environment, a single MySQL is used as an independent database which can not meet the actual requirements at all, no matter in various aspects of safety, high availability, high concurrency and the like. When MySQL is used, except for considering the scheme of database division and table division, master-slave databases can exert larger energy, so that the slave provides convenient and quick read-only service and the read-write separation is realized elegantly. At present, a hard coding mode is adopted to realize the separation of database reading and writing, namely, the selection of a data source is realized in a business logic through an API (application programming interface) calling mode.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art:
the code selected by the data source and the service code have high coupling degree, and the service is relatively high in invasion;
lack of uniform management of dynamic switching of data sources;
the data source switching design scheme is not perfect enough and only solves the basic management requirement.
Disclosure of Invention
In view of this, embodiments of the present invention provide a data source route management method and apparatus, which can reduce repeated data source selection logic codes, reduce intrusion to service codes, reduce the coupling degree between data source selection codes and service codes, flexibly configure dynamic data source selection, implement dynamic switching of unified management data sources, determine data sources according to a specified policy, meet not only basic management requirements, but also expansion requirements, reduce integration cost, and improve development efficiency.
To achieve the above object, according to an aspect of an embodiment of the present invention, a data source route management method is provided.
A data source route management method, comprising: adding an annotation on a business method needing to select a data source, and specifying a data source identifier in the attribute of the annotation; intercepting a business method with the annotation through a section, and executing a data source selection logic in the section to obtain a thread context environment variable corresponding to the data source identification; and the business method selects a data source corresponding to the business method according to the thread context environment variable.
Optionally, the annotation is added at a signature of the business method.
Optionally, the step of obtaining a thread context variable corresponding to the data source identifier by executing a data source selection logic in the tangent plane includes: and analyzing the data source identification appointed in the annotated attribute, and storing the analyzed data source identification value into the thread context environment variable corresponding to the data source identification.
Optionally, an identifier of a business method to which the annotation belongs is further specified in the attribute of the annotation, the priority of the identifier of the business method to which the annotation belongs is higher than that of the data source identifier specified in the attribute of the annotation, and the step of obtaining the thread context variable corresponding to the data source identifier by executing the data source selection logic in the section includes: analyzing the mark of the affiliated business method in the attribute of the annotation, and inquiring the latest data source configuration according to the mark of the affiliated business method; storing the data source identification in the latest data source configuration into a thread context environment variable corresponding to the data source identification; and the latest data source configuration comprises a corresponding relation between a dynamically configured service method and a data source identifier.
Optionally, an execution policy is further specified in the attribute of the annotation, where the execution policy includes a correspondence between a query parameter and a data source identifier, and a step of obtaining a thread context variable corresponding to the data source identifier by executing a data source selection logic in the section includes: analyzing an execution strategy in the annotated attribute to determine a corresponding data source identifier according to the query parameter; and storing the data source identification corresponding to the query parameter into the thread context environment variable corresponding to the data source identification.
According to another aspect of the embodiments of the present invention, a data source route management device is provided.
A data source route management device, comprising: the annotation adding module is used for adding annotations on a business method needing to select a data source and appointing a data source identifier in the attribute of the annotations; the section interception module is used for intercepting the business method with the annotation through a section so as to obtain a thread context environment variable corresponding to the data source identification by executing the data source selection logic in the section; and the data source selection module is used for selecting the data source corresponding to the service method according to the thread context environment variable by the service method.
Optionally, the annotation is added at a signature of the business method.
Optionally, the section intercepting module includes a first data source selection logic executing module, configured to: and analyzing the data source identification appointed in the annotated attribute, and storing the analyzed data source identification value into the thread context environment variable corresponding to the data source identification.
Optionally, the annotation adding module further specifies, in the attribute of the annotation, an identifier of a business method to which the annotation belongs, where the priority of the identifier of the business method to which the annotation belongs is higher than that of the data source identifier specified in the attribute of the annotation, and the cut plane intercepting module includes a second data source selection logic execution module configured to: analyzing the mark of the affiliated business method in the attribute of the annotation, and inquiring the latest data source configuration according to the mark of the affiliated business method; storing the data source identification in the latest data source configuration into a thread context environment variable corresponding to the data source identification; and the latest data source configuration comprises a corresponding relation between a dynamically configured service method and a data source identifier.
Optionally, the annotation adding module further specifies an execution policy in the attribute of the annotation, where the execution policy includes a correspondence between a query parameter and a data source identifier, and the tangent plane intercepting module includes a third data source selection logic execution module, configured to: analyzing an execution strategy in the annotated attribute to determine a corresponding data source identifier according to the query parameter; and storing the data source identification corresponding to the query parameter into the thread context environment variable corresponding to the data source identification.
According to yet another aspect of an embodiment of the present invention, an electronic device is provided.
An electronic device, comprising: one or more processors; a memory for storing one or more programs which, when executed by the one or more processors, cause the one or more processors to implement the data source route management method provided by the present invention.
According to yet another aspect of an embodiment of the present invention, a computer-readable medium is provided.
A computer-readable medium, on which a computer program is stored, which, when executed by a processor, implements the data source route management method provided by the present invention.
One embodiment of the above invention has the following advantages or benefits: adding an annotation on a business method needing to select a data source, and specifying a data source identifier in an attribute of the annotation; intercepting a business method with annotations through a section, and obtaining a thread context environment variable corresponding to a data source identifier by executing a data source selection logic in the section; the business method selects a data source according to the thread context environment variable. Repeated data source selection logic codes can be reduced, invasion to service codes is reduced, and the coupling degree of the data source selection codes and the service codes is reduced. The attribute of the annotation can also be assigned with the identification of the business method to which the annotation belongs, and the latest data source configuration is inquired according to the identification of the business method to which the annotation belongs, so that the selection of the dynamic data source can be flexibly configured, and the dynamic switching of the unified management data source is realized. An execution policy may also be specified in the annotated attributes, such that data sources may be determined according to the specified policy, satisfying not only basic management requirements, but also extended requirements. The invention can reduce the integration cost and improve the development efficiency.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
fig. 1 is a schematic diagram illustrating the main steps of a data source route management method according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of a system architecture according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of the main modules of a data source route management device according to an embodiment of the present invention;
FIG. 4 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
FIG. 5 is a schematic block diagram of a computer system suitable for use with a server implementing an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Fig. 1 is a schematic diagram illustrating the main steps of a data source route management method according to an embodiment of the present invention.
As shown in fig. 1, the data source routing management method according to the embodiment of the present invention mainly includes the following steps S101 to S103.
Step S101: adding annotation on the business method needing to select the data source, and specifying the data source identification in the attribute of the annotation.
Specifically, a line of annotation "@ DataSource" may be added at the signature of the business method, and the attribute of the annotation is set, such as a unique identification key specifying the data source. key is a necessary configuration attribute of the comment "@ DataSource", the type is string, the attribute indicates a data source key, and the data source key required to be used is filled in, namely the corresponding data source can be accessed.
Step S102: and intercepting a business method with annotations through the section, and obtaining a thread context environment variable corresponding to the data source identification by executing the data source selection logic in the section.
Section interception can be realized by using the AOP (abstract ordered Programming, meaning section-Oriented Programming, which is a technology for realizing uniform maintenance of program functions by means of a pre-compiling mode and a runtime dynamic agent) of Spring (an open source Java platform).
The step of obtaining the thread context environment variable corresponding to the data source identifier by executing the data source selection logic in the section may specifically include: and analyzing the data source identification appointed in the annotated attribute, and storing the analyzed data source identification value into the thread context environment variable corresponding to the data source identification.
Analyzing the key value through the step, determining the data source needed to be used at this time, and storing the key value into the context variable in the thread environment, so that data can be obtained according to the key value when the data source is finally obtained, and the routing management of the data source is realized.
And the identifier configKey of the business method to which the annotation belongs can be also specified in the attribute of the annotation, the configKey is an optional configuration attribute of the annotation @ DataSource, the type of the optional configuration attribute is string, the attribute indicates the configuration of the data source, and the configuration of the data source to be used can be obtained according to the configKey to realize the dynamic switching of the data source.
And the priority of the identifier configKey of the business method to which the annotation belongs is higher than the data source identifier key specified in the attribute of the annotation. When the attribute configKey is configured, the step of obtaining the thread context environment variable corresponding to the data source identifier by executing the data source selection logic in the section may specifically include: analyzing the mark of the business method in the attribute of the annotation, and inquiring the latest data source configuration according to the mark of the business method to which the annotation belongs; and storing the data source identification in the latest data source configuration into the thread context environment variable corresponding to the data source identification.
The latest data source configuration comprises a corresponding relation between a dynamically configurable service method and a data source identifier. The corresponding relation between the service method and the data source identification can be dynamically modified and effective in real time, so that the dynamic switching of the data source can be realized, for example, when the originally configured A data source is down, the configuration can be modified and switched to the B data source.
An execution policy, string, may also be specified in the annotated attributes, the execution policy including a correspondence of query parameters to data source identifications. The stream is an optional configuration attribute for the annotation @ DataSource, the type is string, and the execution policy stream can be self-defined as required. The data source selection logic in the section may be fully controlled by configuring this attribute. When the attribute of string is configured, the step of obtaining the thread context environment variable corresponding to the data source identifier by executing the data source selection logic in the section may specifically include: analyzing an execution strategy in the annotated attribute to determine a corresponding data source identifier according to the query parameter; and storing the data source identification corresponding to the query parameter into the thread context environment variable corresponding to the data source identification. For example, by configuring the attribute of the execution policy, which data source is selected can be determined according to a certain query parameter "single number" to realize the function of database hashing (sub-base and sub-table).
Wherein, the external parameters (such as query parameters) required for executing the policy stream are obtained by configuring the stream Args attribute of the annotation @ DataSource. StrategArgs is an optional configuration attribute for the annotation @ DataSource, and is of type string, used to describe the parameters of the execution policy.
A disable attribute can also be configured in the annotation, the attribute type is coolean, and is an optional configuration attribute of the annotation @ DataSource, the default value is false, and the value of disable is used for indicating whether to disable the processing logic of the cut surface. When the value of disable is true, equivalent to annotating @ DataSource, all processing logic is turned off, i.e.: after the business method is intercepted by the tangent plane, the tangent plane does not execute any data source selection logic.
Step S103: and the business method selects a data source corresponding to the business method according to the thread context environment variable.
The embodiment of the invention is realized under a Spring frame, and is implemented according to the following implementation steps: xml by MAVEN (a project management tool) introduces dependent jar packages; setting a configuration file of the DataSource and a section definition of a DataSource aspect cache layer; and adding data source annotation on the business method, and selecting a specific data source according to the requirement. A pom, i.e. a project object model, is a basic work unit of Maven, which is an XML file containing detailed information about projects and configurations used by Maven to build a project, and which contains default values for most projects, some configurations that can be specified in the pom are project dependencies, executable plug-ins or objects, build configuration files, etc., and other information such as project versions, descriptions, developers, mailing lists, etc. can also be specified. Xml of the embodiment of the present invention is an engineering file of MAVEN, and is mainly used for managing dependent jar packages. Configuration files for setting the DataSource include, for example, configurations of a dynamic data source selector, a production library data source, a read-only library data source, a transaction manager, and a tagged transaction.
The embodiment of the invention provides a perfect data source management layer architecture design support, realizes non-invasive design, reduces the degree of coupling with business logic, has highly flexible data source component configuration, can realize perfect data source management function by adding annotation marks, and has clear layers.
Fig. 2 is a schematic diagram of a system architecture according to an embodiment of the present invention.
As shown in FIG. 2, the system architecture of the embodiment of the present invention includes a plurality of Web servers (three Web servers: WebServer-1, WebServer-2, WebServer-3 are exemplarily shown in the figure), a data source management plane, and a plurality of MySQL databases (three slave databases are exemplarily shown in the figure). The Web server sends out a database reading and writing request and reads and writes data from the MySQL database. The MySQL DB Master in the MySQL database is used as a Master database for writing data, and the MySQL DB Slave1, MySQL DB Slave2 and MySQL DB Slave3 are Slave databases for reading data. The data source management section comprises an @ DateSource data source section selection processor which is used for intercepting the section of the service method and executing data source selection logic in the data source management section to obtain a thread context environment variable corresponding to the data source identification. When executing the service logic of the Web server, the service method in the Web server refers to the data source identification (variable in the thread context environment) and finally selects the data source.
The data source identification is determined through the tangent plane, the data source identification is stored in the thread context environment, the bottom layer data source is packaged and realized, the final data source is selected according to the data source identification when the data source is obtained, the data source selection logic can be separated from the service logic and belongs to the bottom layer realization, the service logic does not need to pay attention to the selection logic of the data source, the coupling of the service logic and the data source selection logic is reduced, and the development cost is reduced.
Fig. 3 is a schematic diagram of main modules of a data source routing management apparatus according to an embodiment of the present invention.
As shown in fig. 3, the data source routing management apparatus 300 according to the embodiment of the present invention mainly includes: an annotation adding module 301, a tangent plane intercepting module 302 and a data source selecting module 303.
The annotation adding module 301 is configured to add an annotation to a business method that needs to select a data source, and specify a data source identifier in an attribute of the annotation.
Annotations are added at the signature of the business method.
A section intercepting module 302, configured to intercept, through a section, the business method with the annotation, so as to obtain, by executing a data source selection logic in the section, a thread context environment variable corresponding to the data source identifier.
And the data source selection module 303 is configured to select, by the service method, a data source corresponding to the service method according to the thread context environment variable.
In one embodiment, the cutting plane intercepting module 302 includes a first data source selection logic executing module configured to: and analyzing the data source identification appointed in the annotated attribute, and storing the analyzed data source identification value into the thread context environment variable corresponding to the data source identification.
In the second embodiment, the annotation adding module 301 further specifies an identifier of the business method to which the annotation belongs in the attribute of the annotation, and the priority of the identifier of the business method to which the annotation belongs is higher than that of the identifier of the data source specified in the attribute of the annotation. In this embodiment, the cut plane intercepting module 302 may include a second data source selection logic execution module to: analyzing the mark of the business method in the attribute of the annotation, and inquiring the latest data source configuration according to the mark of the business method; storing the data source identification in the latest data source configuration into the thread context environment variable corresponding to the data source identification; the latest data source configuration comprises a corresponding relation between a dynamically configured service method and a data source identifier.
In a third embodiment, the annotation adding module further specifies an execution policy in the attribute of the annotation, where the execution policy includes a correspondence between the query parameter and the data source identifier, and in this embodiment, the section intercepting module includes a third data source selection logic execution module, configured to: analyzing an execution strategy in the annotated attribute to determine a corresponding data source identifier according to the query parameter; and storing the data source identification corresponding to the query parameter into the thread context environment variable corresponding to the data source identification.
In addition, in the embodiment of the present invention, the detailed implementation content of the data source route management device has been described in detail in the above data source route management method, so that the repeated content is not described again.
Fig. 4 illustrates an exemplary system architecture 400 of a data source route management method or data source route management apparatus to which embodiments of the present invention may be applied.
As shown in fig. 4, the system architecture 400 may include terminal devices 401, 402, 403, a network 404, and a server 405. The network 404 serves as a medium for providing communication links between the terminal devices 401, 402, 403 and the server 405. Network 404 may include various types of connections, such as wire, wireless communication links, or fiber optic cables, to name a few.
A user may use terminal devices 401, 402, 403 to interact with a server 405 over a network 404 to receive or send messages or the like. The terminal devices 401, 402, 403 may have various communication client applications installed thereon, such as shopping applications, web browser applications, search applications, instant messaging tools, mailbox clients, social platform software, and the like.
The terminal devices 401, 402, 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 405 may be a server that provides various services, such as a background management server that supports shopping websites browsed by users using the terminal devices 401, 402, and 403. The background management server may analyze and perform other processing on the received data such as the information query request, and feed back a processing result (e.g., the queried information) to the terminal device.
It should be noted that the data source route management method provided by the embodiment of the present invention is generally executed by the server 405, and accordingly, the data source route management apparatus is generally disposed in the server 405.
It should be understood that the number of terminal devices, networks, and servers in fig. 4 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 5, a block diagram of a computer system 500 suitable for use in implementing a server according to embodiments of the present application is shown. The server shown in fig. 5 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present application.
As shown in fig. 5, the computer system 500 includes a Central Processing Unit (CPU)501 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)502 or a program loaded from a storage section 508 into a Random Access Memory (RAM) 503. In the RAM 503, various programs and data necessary for the operation of the system 500 are also stored. The CPU 501, ROM 502, and RAM 503 are connected to each other via a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
The following components are connected to the I/O interface 505: an input portion 506 including a keyboard, a mouse, and the like; an output portion 507 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 508 including a hard disk and the like; and a communication section 509 including a network interface card such as a LAN card, a modem, or the like. The communication section 509 performs communication processing via a network such as the internet. The driver 510 is also connected to the I/O interface 505 as necessary. A removable medium 511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 510 as necessary, so that a computer program read out therefrom is mounted into the storage section 508 as necessary.
In particular, according to embodiments of the present disclosure, the processes described above with reference to the main step schematic may be implemented as computer software programs. For example, the disclosed embodiments of the invention include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method shown in the main step diagram. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 509, and/or installed from the removable medium 511. The above-described functions defined in the system of the present application are executed when the computer program is executed by the Central Processing Unit (CPU) 501.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present application, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In this application, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The principal step diagrams and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present application. In this regard, each block in the main step diagrams or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or block diagrams, and combinations of blocks in the block diagrams or block diagrams, can be implemented by special purpose hardware-based systems that perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes an annotation adding module 301, a cut plane intercepting module 302, a data source selection module 303. The names of these modules do not constitute a definition of the module itself in some cases, for example, the annotation adding module 301 may also be described as "a module for adding an annotation on a business method that needs to select a data source and specifying the data source identification in the attribute of the annotation".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: adding an annotation on a business method needing to select a data source, and specifying a data source identifier in the attribute of the annotation; intercepting a business method with the annotation through a section, and executing a data source selection logic in the section to obtain a thread context environment variable corresponding to the data source identification; and the business method selects a data source corresponding to the business method according to the thread context environment variable.
According to the technical scheme of the embodiment of the invention, an annotation is added to a business method needing to select a data source, and a data source identifier is specified in the attribute of the annotation; intercepting a business method with annotations through a section, and obtaining a thread context environment variable corresponding to a data source identifier by executing a data source selection logic in the section; the business method selects a data source according to the thread context environment variable. Repeated data source selection logic codes can be reduced, invasion to service codes is reduced, and the coupling degree of the data source selection codes and the service codes is reduced. The attribute of the annotation can also be assigned with the identification of the business method to which the annotation belongs, and the latest data source configuration is inquired according to the identification of the business method to which the annotation belongs, so that the selection of the dynamic data source can be flexibly configured, and the dynamic switching of the unified management data source is realized. An execution policy may also be specified in the annotated attributes, such that data sources may be determined according to the specified policy, satisfying not only basic management requirements, but also extended requirements. The invention can reduce the integration cost and improve the development efficiency.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (12)

1. A data source route management method, comprising:
adding an annotation on a business method needing to select a data source, and specifying a data source identifier in the attribute of the annotation;
intercepting a business method with the annotation through a section, and executing a data source selection logic in the section to obtain a thread context environment variable corresponding to the data source identification;
and the business method selects a data source corresponding to the business method according to the thread context environment variable.
2. The method of claim 1, wherein the annotation is added at a signature of the business method.
3. The method of claim 1, wherein the step of obtaining a thread context variable corresponding to the data source identification by executing data source selection logic in the section comprises:
and analyzing the data source identification appointed in the annotated attribute, and storing the analyzed data source identification value into the thread context environment variable corresponding to the data source identification.
4. The method according to claim 1, characterized in that an identification of a business method to which an annotation belongs is also specified in the attributes of the annotation, said identification of the business method belonging having a higher priority than the identification of the data source specified in the attributes of the annotation,
obtaining a thread context variable corresponding to the data source identification by executing the data source selection logic in the section, wherein the step comprises the following steps:
analyzing the mark of the affiliated business method in the attribute of the annotation, and inquiring the latest data source configuration according to the mark of the affiliated business method;
storing the data source identification in the latest data source configuration into a thread context environment variable corresponding to the data source identification;
and the latest data source configuration comprises a corresponding relation between a dynamically configured service method and a data source identifier.
5. The method according to claim 1, characterized in that an execution policy is further specified in the annotated attributes, the execution policy comprising a correspondence of query parameters to data source identifications,
obtaining a thread context variable corresponding to the data source identification by executing the data source selection logic in the section, wherein the step comprises the following steps:
analyzing an execution strategy in the annotated attribute to determine a corresponding data source identifier according to the query parameter;
and storing the data source identification corresponding to the query parameter into the thread context environment variable corresponding to the data source identification.
6. A data source route management device, comprising:
the annotation adding module is used for adding annotations on a business method needing to select a data source and appointing a data source identifier in the attribute of the annotations;
the section interception module is used for intercepting the business method with the annotation through a section so as to obtain a thread context environment variable corresponding to the data source identification by executing the data source selection logic in the section;
and the data source selection module is used for selecting the data source corresponding to the service method according to the thread context environment variable by the service method.
7. The apparatus of claim 6, wherein the annotation is added at a signature of the business method.
8. The apparatus of claim 6, wherein the cut plane intercepting module comprises a first data source selection logic execution module to:
and analyzing the data source identification appointed in the annotated attribute, and storing the analyzed data source identification value into the thread context environment variable corresponding to the data source identification.
9. The apparatus of claim 6, wherein the annotation addition module further specifies in the attributes of the annotation an identification of a business method to which the annotation belongs, the identification of the business method having a higher priority than the data source identification specified in the attributes of the annotation,
the section intercepting module comprises a second data source selection logic execution module used for:
analyzing the mark of the affiliated business method in the attribute of the annotation, and inquiring the latest data source configuration according to the mark of the affiliated business method;
storing the data source identification in the latest data source configuration into a thread context environment variable corresponding to the data source identification;
and the latest data source configuration comprises a corresponding relation between a dynamically configured service method and a data source identifier.
10. The apparatus of claim 6, wherein the annotation addition module further specifies an execution policy in attributes of the annotation, the execution policy comprising a correspondence of query parameters to data source identifications,
the section intercepting module comprises a third data source selection logic execution module used for:
analyzing an execution strategy in the annotated attribute to determine a corresponding data source identifier according to the query parameter;
and storing the data source identification corresponding to the query parameter into the thread context environment variable corresponding to the data source identification.
11. An electronic device, comprising:
one or more processors;
a memory for storing one or more programs,
the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the method recited in any of claims 1-5.
12. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-5.
CN201810743523.3A 2018-07-09 2018-07-09 Data source route management method and device Pending CN110765187A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810743523.3A CN110765187A (en) 2018-07-09 2018-07-09 Data source route management method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810743523.3A CN110765187A (en) 2018-07-09 2018-07-09 Data source route management method and device

Publications (1)

Publication Number Publication Date
CN110765187A true CN110765187A (en) 2020-02-07

Family

ID=69326783

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810743523.3A Pending CN110765187A (en) 2018-07-09 2018-07-09 Data source route management method and device

Country Status (1)

Country Link
CN (1) CN110765187A (en)

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111737228A (en) * 2020-06-23 2020-10-02 平安医疗健康管理股份有限公司 Database and table dividing method and device
CN112000738A (en) * 2020-08-18 2020-11-27 中国建设银行股份有限公司 Database connection switching method, device, equipment and medium
CN113434582A (en) * 2021-06-24 2021-09-24 平安国际智慧城市科技股份有限公司 Service data processing method and device, computer equipment and storage medium
CN113448679A (en) * 2020-03-25 2021-09-28 北京沃东天骏信息技术有限公司 Method and device for processing call request
CN113448588A (en) * 2021-07-09 2021-09-28 天津狮拓信息技术有限公司 Data security processing method and device, electronic equipment and storage medium
CN113722733A (en) * 2021-08-27 2021-11-30 北京航天云路有限公司 Data access authority control method based on Java annotation
CN113763094A (en) * 2020-11-23 2021-12-07 北京沃东天骏信息技术有限公司 Service information processing method, device, server, medium and system

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2012092325A1 (en) * 2010-12-30 2012-07-05 Verisign, Inc. Method and system for implementing business logic
CN103530427A (en) * 2013-11-04 2014-01-22 北京京东尚科信息技术有限公司 Dynamic switching method and device based on multiple databases
CN106529331A (en) * 2016-10-31 2017-03-22 用友网络科技股份有限公司 Multi-tenant data isolation scheme applied to PaaS (Platform-as-a-Service) platform
CN106940695A (en) * 2016-01-05 2017-07-11 阿里巴巴集团控股有限公司 The method of calibration and device of data source information
CN107480302A (en) * 2017-09-05 2017-12-15 四川中电启明星信息技术有限公司 A kind of loose coupling data integration synchronization realizing method based on enterprise-level application scene

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2012092325A1 (en) * 2010-12-30 2012-07-05 Verisign, Inc. Method and system for implementing business logic
CN103530427A (en) * 2013-11-04 2014-01-22 北京京东尚科信息技术有限公司 Dynamic switching method and device based on multiple databases
CN106940695A (en) * 2016-01-05 2017-07-11 阿里巴巴集团控股有限公司 The method of calibration and device of data source information
CN106529331A (en) * 2016-10-31 2017-03-22 用友网络科技股份有限公司 Multi-tenant data isolation scheme applied to PaaS (Platform-as-a-Service) platform
CN107480302A (en) * 2017-09-05 2017-12-15 四川中电启明星信息技术有限公司 A kind of loose coupling data integration synchronization realizing method based on enterprise-level application scene

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
HKENJOY: "基于自定义注解和AOP的Spring多数据源配置和使用", pages 1 - 4, Retrieved from the Internet <URL:《https://www.cnblogs.com/niehaikuo/p/8627007.html》> *

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113448679A (en) * 2020-03-25 2021-09-28 北京沃东天骏信息技术有限公司 Method and device for processing call request
CN111737228A (en) * 2020-06-23 2020-10-02 平安医疗健康管理股份有限公司 Database and table dividing method and device
CN111737228B (en) * 2020-06-23 2022-11-15 深圳平安医疗健康科技服务有限公司 Database and table dividing method and device
CN112000738A (en) * 2020-08-18 2020-11-27 中国建设银行股份有限公司 Database connection switching method, device, equipment and medium
CN112000738B (en) * 2020-08-18 2023-06-02 建信金融科技有限责任公司 Database connection switching method, device, equipment and medium
CN113763094A (en) * 2020-11-23 2021-12-07 北京沃东天骏信息技术有限公司 Service information processing method, device, server, medium and system
CN113434582A (en) * 2021-06-24 2021-09-24 平安国际智慧城市科技股份有限公司 Service data processing method and device, computer equipment and storage medium
CN113448588A (en) * 2021-07-09 2021-09-28 天津狮拓信息技术有限公司 Data security processing method and device, electronic equipment and storage medium
CN113448588B (en) * 2021-07-09 2024-04-16 天津狮拓信息技术有限公司 Data security processing method and device, electronic equipment and storage medium
CN113722733A (en) * 2021-08-27 2021-11-30 北京航天云路有限公司 Data access authority control method based on Java annotation

Similar Documents

Publication Publication Date Title
CN110765187A (en) Data source route management method and device
EP3408745B1 (en) Automatically updating a hybrid application
CN111708749B (en) Operation log recording method and device, computer equipment and storage medium
US20140195514A1 (en) Unified interface for querying data in legacy databases and current databases
US11036560B1 (en) Determining isolation types for executing code portions
CN111400061A (en) Data processing method and system
CN110795315A (en) Method and device for monitoring service
CN110928912A (en) Method and device for generating unique identifier
CN109960212B (en) Task sending method and device
CN114817146A (en) Method and device for processing data
CN112947992A (en) Method and device for managing code version
CN112463251A (en) Method and device for configuring hot publishing by uliweb framework
CN113779122B (en) Method and device for exporting data
CN114489674A (en) Data verification method and device of dynamic data model
US10114864B1 (en) List element query support and processing
CN113760861A (en) Data migration method and device
CN112416865A (en) File processing method and device based on big data
CN113127416A (en) Data query method and device
CN111984686A (en) Data processing method and device
CN112711572A (en) Online capacity expansion method and device suitable for sub-warehouse and sub-meter
CN110851192A (en) Method and device for responding to configuration of degraded switch
CN111797110B (en) Method, device, computer equipment and storage medium for generating scheduling model
CN113495747B (en) Gray scale release method and device
CN113065042A (en) Management method and device of terminal equipment
CN114356873A (en) Data sharing system and method

Legal Events

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