Embodiment
Below with reference to accompanying drawings exemplary embodiment of the present disclosure is described in more detail.Although show exemplary embodiment of the present disclosure in accompanying drawing, however should be appreciated that can realize the disclosure in a variety of manners and not should limit by the embodiment set forth here.On the contrary, provide these embodiments to be in order to more thoroughly the disclosure can be understood, and complete for the scope of the present disclosure can be conveyed to those skilled in the art.
Fig. 1 schematically illustrates the process flow diagram of the method for process database operations request according to an embodiment of the invention, and Fig. 2 schematically illustrates the process flow diagram of each step of method of process database operations request according to an embodiment of the invention.Below index map 1 and Fig. 2 are described in detail the present invention.
According to embodiments of the invention, database can be such as MySQL database.Hereinafter, for MySQL database, principle of the present invention is described, but this is just in order to the object of example, and scope of the present invention is not limited to this, principle of the present invention is equally applicable to the database of other type, the databases such as such as IBMDB2, Oracle10.
As shown in Figure 1, the method 100 of process database operations request is according to an embodiment of the invention suitable for step S101, wherein, receives the operation requests for database.One or more application server should be such as come from for the operation requests of database.
See also Fig. 2, first, the submeter information from such as one or more database server can be stored.According to embodiments of the invention, this submeter information can comprise the data table name that will carry out the tables of data of submeter and the submeter field be associated with this tables of data name.
Next, in step S101, receive the operation requests for database from one or more application server, if do not received, then continue to wait for; If received, then enter next step, the step S103 namely shown in Fig. 1.
According to embodiments of the invention, this operation requests can comprise database program language statement.Alternatively, this database program language statement can be SQL(StructuredQueryLanguage, Structured Query Language (SQL)) statement.But sql like language and SQL statement are only example, for helping reader understanding's principle of the present invention, scope of the present invention is not limited to this, but is equally applicable to other suitable database program language and corresponding statement.
In step s 103, resolve this operation requests, to obtain the first data table name (such as table) in this operation requests.Now, if there is not the first data table name (such as there is not table) in this operation requests, then illustrate that this operation requests is not the operation for certain table, so just operation requests directly can be sent to database server.
And if there is the first data table name in operation requests, then perform step S105 as shown in Figure 1, wherein, according to this operation requests of submeter information analysis, to obtain the submeter field and the field value corresponding with this submeter field that are associated with the first tables of data name in this operation requests.
Such as, suppose tables of data table to be split as 100 sublists, be called table_0, table_1 ..., table_99, integer type field id is set to submeter field.Now, if SQL statement included in operation requests is SELECT*FROMtableWHEREname=" zhangsan " ANDid=123, the submeter field be then associated with the first data table name table in operation requests is id, and the field value corresponding with this submeter field is 123.
In step S105, if the first data table name is not in submeter information, then illustrates that the tables of data representated by the first data table name is not split as multiple submeters, so just directly operation requests can be sent to database server.And if the first data table name does not parse the field value corresponding with the submeter field that the first tables of data name is associated and this submeter field in this submeter information from operation requests, then cannot judge that this operation requests for which sublist operates, just miscue can be returned, such as, the miscue of " operation requests mistake does not comprise submeter field " is returned to application server.
Next, perform step S107, wherein, the field value corresponding with obtained submeter field according to submeter information, is revised as the second data table name by the first data table name in operation requests.
According to embodiments of the invention, submeter information can also comprise the sublist quantity will carrying out the tables of data of submeter, in step s 107, according to the sublist quantity of the field value corresponding with submeter field and tables of data, the first data table name can be revised as the second data table name.According to embodiments of the invention, one of multiple second tables of data that the second data table name generates after corresponding to the first tables of data submeter, it comprises the first data table name and the second tables of data mark.
Such as, be still described for above-mentioned SQL statement SELECT*FROMtableWHEREname=" zhangsan " ANDid=123.According to the sublist quantity 100 of the field value 123 corresponding with submeter field and tables of data, the submeter strategy asking mould mode can be adopted, namely, ask mould for 123 pairs 100, obtain 23, then illustrate this SQL statement actual be will operate sublist table_23, second data table name is table_23, comprise the first data table name table and the second tables of data mark 23, thus the SQL statement in operation requests can be revised as SELECT*FROMtable_23WHEREname=" zhangsan " ANDid=123, namely, from sublist table_23, select " zhangsan " field to operate.
Afterwards, as shown in Figure 1, perform step S109, amended operation requests is sent to database server.Such as, the operation requests comprising amended SQL statement SELECT*FROMtable_23WHEREname=" zhangsan " ANDid=123 is sent to database server.
According to embodiments of the invention, as shown in Figure 2, method 100 can also comprise the following steps: check whether submeter information upgrades (such as, sublist number change, has newly split some table etc.), if upgraded, then before above-mentioned steps S101, submeter information after storage update, and in step S105, carry out parse operation request according to the submeter information after upgrading.
Below, in order to help reader understanding the present invention, in conjunction with a concrete example, principle of the present invention is described.
Suppose that the tables of data that the first tables of data is called person is divided into 10 sublists, submeter field is pid, the tables of data that first tables of data is called student is divided into 100 sublists, submeter field is no, then submeter information can be as follows: table [1]={ person, 10, pid}, table [2]={ student, 100, no}.
Suppose that the SQL statement that operation requests comprises is SELECT*FROMpersonWHEREpid=123.First, parse operation request, obtains the first data table name person, then obtains submeter field pid and the field value 123 corresponding with submeter field according to submeter information analysis, asks mould, obtain result 3 by 123 to 10.So, just the first data table name person in former SQL statement can be revised as the second data table name person_3, then the operation requests comprising amended SQL statement SELECT*FROMperson_3WHEREpid=123 be sent to database server to perform.
In addition, suppose that the SQL statement that operation requests comprises is INSERTINTOstudent (`no`, `name`) VALUES (246, ' zhangsan ').First, parse operation request, obtains the first data table name student, then obtains submeter field no and the field value corresponding with submeter field according to submeter information analysis, by 246 to 100 deliverys, obtain result 46.So, just the first data table name student in former SQL statement can be revised as the second data table name student_46, then amended SQL statement INSERTINTOstudent_46 (`no` will be comprised, `name`) operation requests of VALUES (246, ' zhangsan ') sends to database server to perform.
The invention discloses a kind of method of process database operations request.According to embodiments of the invention, according to the submeter information from database server, resolve the operation requests of application server for database, to obtain the first data table name, submeter field associated with it and field value, and according to submeter information and field value, the first data table name is revised as the second data table name, and amended operation requests is sent to database server.Thus, make the process of Score Lists to application transparence, application writer no longer needs the corresponding relation between control data and concrete sublist, no matter physically there are how many Zhang Zibiao, application writer faced by be a table in logic all the time, what application writer no longer needed to be concerned about database submeter strategy realizes details, can be absorbed in and write concrete service code, only need comprise the value of submeter field in for the operation requests of database.In addition, according to embodiments of the invention, by upgrading submeter information, the change of the submeter information such as sublist quantity can be avoided the impact of application, application only needs exploitation once, no longer needs due to the adjustment of database submeter information and revises application itself, significantly reducing maintenance cost.
Corresponding with said method 100, present invention also offers a kind of equipment 200 of process database operations request.Fig. 3 schematically illustrates the equipment 200 of process database operations request according to an embodiment of the invention.See Fig. 3, equipment 200 mainly comprises application programming interfaces 201, resolver 203, operation requests modifier 205 and database interface 207.
According to embodiments of the invention, application interface 201 receives the operation requests for database from application server 300-1 to 300-n.Then the operation requests that resolver 203 pairs of application interfaces 201 receive is resolved, to obtain the first data table name in operation requests, and according to submeter information analysis operation requests, to obtain the submeter field and the field value corresponding with this submeter field that are associated with the first tables of data name in operation requests.
Submeter information comprises the data table name that will carry out the tables of data of submeter and the submeter field be associated with this tables of data name.Such as, suppose that the tables of data that the first tables of data is called person is divided into 10 sublists, submeter field is pid, and the tables of data that the first tables of data is called student is divided into 100 sublists, and submeter field is no, then submeter information can be as follows: table [1]={ person, 10, pid}, table [2]={ student, 100, no}.
The field value that operation requests modifier 205 is corresponding with the submeter field that resolver 203 obtains according to submeter information, is revised as the second data table name by the first data table name in operation requests.
Suppose that the SQL statement that operation requests comprises is SELECT*FROMpersonWHEREpid=123.The first tables of data that resolver 203 obtains is called person, the field value 123 corresponding with submeter field pid.Operation requests modifier 205 asks mould by 123 to 10, obtains result 3.So the first data table name person in former SQL statement just can be revised as the second data table name person_3 by operation requests modifier 205.
Amended for operation requests modifier 205 operation requests is sent to database server by database interface 207.Application interface 201 may be used for the step S101 performed in the method 100 of above-mentioned process database operations request, resolver 203 may be used for performing step S103 and S105, operation requests modifier 205 may be used for performing step S107, and database interface may be used for performing step S109.
According to embodiments of the invention, operation requests can comprise database program language statement.Alternatively, database program language statement can be SQL statement, and database can be MySQL database.As mentioned above, SQL statement and MySQL database are only example of the present invention, are not intended to limit the present invention.
According to embodiments of the invention, if during resolver 203 parse operation request, there is not the first data table name in operation requests, then illustrate that this operation requests is not the operation for certain table, so operation requests just directly can be sent to database server by database interface 207.
And when resolver 203 is according to submeter information analysis operation requests, if the first data table name is not in submeter information, then illustrate that the tables of data representated by the first data table name is not split as multiple submeters, so operation requests just can be sent to database server by database interface 207.
If the first data table name is in submeter information but resolver 203 does not parse the field value corresponding with the submeter field that the first tables of data name is associated and this submeter field from operation requests, then return miscue, such as, the miscue of " operation requests mistake does not comprise submeter field " is returned to application server 300-1 to 300-n.
According to embodiments of the invention, submeter information also comprises the sublist quantity will carrying out the tables of data of submeter, operation requests modifier 205 is according to the sublist quantity of the field value corresponding with submeter field and tables of data, first data table name is revised as the second data table name, one of multiple second tables of data that second data table name generates after corresponding to the first tables of data submeter, it comprises the first data table name and the second tables of data mark.Still for above for method 100 describe SQL statement, first data table name table can be revised as the second data table name table_23, then the operation requests comprising amended SQL statement SELECT*FROMtable_23WHEREname=" zhangsan " ANDid=123 be sent to database server.
According to embodiments of the invention, (such as, sublist number change that database interface 207 can also check whether submeter information upgrades, new split some table etc.), if upgraded, then the submeter information after storage update, is used for parse operation request for resolver 203.
Because above-mentioned each apparatus embodiments is corresponding with aforementioned approaches method embodiment, therefore no longer each apparatus embodiments is described in detail.
According to another aspect of the invention, a kind of system 1000 of allocation database operation requests is additionally provided.See Fig. 3, system 1000 comprises the said equipment 200; One or more application server 300-1 ..., 300-n, is suitable for sending operation requests for database to equipment 200; And database server 400-1 ..., 400-n, is suitable for providing submeter information to equipment 200, and the amended operation requests that receiving equipment 200 sends.
Intrinsic not relevant to any certain computer, virtual system or miscellaneous equipment with display at this algorithm provided.Various general-purpose system also can with use based on together with this teaching.According to description above, the structure constructed required by this type systematic is apparent.In addition, the present invention is not also for any certain programmed language.It should be understood that and various programming language can be utilized to realize content of the present invention described here, and the description done language-specific is above to disclose preferred forms of the present invention.
In instructions provided herein, describe a large amount of detail.But can understand, embodiments of the invention can be put into practice when not having these details.In some instances, be not shown specifically known method, structure and technology, so that not fuzzy understanding of this description.
Similarly, be to be understood that, in order to simplify the disclosure and to help to understand in each inventive aspect one or more, in the description above to exemplary embodiment of the present invention, each feature of the present invention is grouped together in single embodiment, figure or the description to it sometimes.But, the method for the disclosure should be construed to the following intention of reflection: namely the present invention for required protection requires feature more more than the feature clearly recorded in each claim.Or rather, as claims below reflect, all features of disclosed single embodiment before inventive aspect is to be less than.Therefore, the claims following embodiment are incorporated to this embodiment thus clearly, and wherein each claim itself is as independent embodiment of the present invention.
Those skilled in the art are appreciated that and adaptively can change the module in the device in embodiment and they are arranged in one or more devices different from this embodiment.Some block combiner in embodiment can be become a module or unit or assembly, and multiple submodule or subelement or sub-component can be put them in addition.Except at least some in such feature and/or process or module be mutually repel except, any combination can be adopted to combine all processes of all features disclosed in this instructions (comprising adjoint claim, summary and accompanying drawing) and so disclosed any method or equipment or unit.Unless expressly stated otherwise, each feature disclosed in this instructions (comprising adjoint claim, summary and accompanying drawing) can by providing identical, equivalent or similar object alternative features replaces.
In addition, those skilled in the art can understand, although embodiments more described herein to comprise in other embodiment some included feature instead of further feature, the combination of the feature of different embodiment means and to be within scope of the present invention and to form different embodiments.Such as, in detail in the claims, the one of any of embodiment required for protection can use with arbitrary array mode.
Each device embodiment of the present invention with hardware implementing, or can realize with the software module run on one or more processor, or realizes with their combination.It will be understood by those of skill in the art that the some or all functions that microprocessor or digital signal processor (DSP) can be used in practice to realize according to the some or all modules in the system of the embodiment of the present invention.The present invention can also be embodied as part or all the device program (such as, computer program and computer program) for performing method as described herein.Realizing program of the present invention and can store on a computer-readable medium like this, or the form of one or more signal can be had.Such signal can be downloaded from internet website and obtain, or provides on carrier signal, or provides with any other form.
The present invention will be described instead of limit the invention to it should be noted above-described embodiment, and those skilled in the art can design alternative embodiment when not departing from the scope of claims.In the claims, any reference symbol between bracket should be configured to limitations on claims.Word " comprises " not to be got rid of existence and does not arrange element in the claims or step.Word "a" or "an" before being positioned at element is not got rid of and be there is multiple such element.The present invention can by means of including the hardware of some different elements and realizing by means of the computing machine of suitably programming.In the unit claim listing some devices, several in these devices can be carry out imbody by same hardware branch.Word first, second and third-class use do not represent any order.Can be title by these word explanations.