Summary of the invention
Optimistic locking (Optimistic Lock) is suitable for the application type more read, and helps to improve handling up for database table
Amount.But the realization of current optimistic locking solution is mostly dependent on the Rule of judgment added manually, due in optimistic locking solution
Rule of judgment is set in core logic sentence, so that the realization logic of optimistic locking is coupled in service code completely, is caused at present
The problems such as optimistic locking solution, which exists, realizes that logic is complicated, and maintenance difficulties are big, and versatility is low, and pluggable property is poor.Further, since
The database table quantity that Rule of judgment is related in optimistic locking solution at present is more, further also results in opening for optimistic locking
The problem of degree of raising difficult questions and maintenance difficulties increase.
In the present context, embodiments of the present invention be intended to provide a kind of program code conversion method, device, medium and
Equipment is calculated, to solve the above problem existing for current optimistic locking solution.
In the first aspect of embodiment of the present invention, a kind of program code conversion method is provided, comprising: read sentence by sentence
The source code of program;Judge whether the program statement currently read is particular statement;If so, program statement is converted into centre
Code;It explains and executes intermediate code;Program statement is executed if it is not, directly explaining.
In one embodiment of the invention, it is different from execution program statement is explained to explain that execution intermediate code can be realized
Function.
In another embodiment of the invention, the step of whether program statement that judgement is currently read is particular statement packet
It includes: obtaining preset critical field in configuration file;It whether is particular statement according to critical field determining program sentence.
In yet another embodiment of the present invention, the step of whether being particular statement according to critical field determining program sentence
It include: to judge whether critical field matches with each field in program statement;According to matching result determining program sentence whether
For particular statement.
In yet another embodiment of the present invention, the step of particular statement in recognize program code includes: to obtain configuration
Preset unique identification in file;It whether is particular statement according to unique identification determining program sentence.
In another embodiment of the present invention, the step of according to unique identification determining program sentence whether being particular statement
It include: the unique identification for obtaining program statement;Judge whether preset unique identification matches with the unique identification of program statement;Root
It whether is particular statement according to matching result determining program sentence.
In one embodiment of the invention, the step of program statement being converted into intermediate code includes: to obtain configuration text
Preset intermediate code create-rule in part;It is rule-based that program statement is converted into intermediate code.
In one embodiment of the invention, preset intermediate code create-rule includes preset field and corresponding behaviour
Make type, rule-based the step of program statement is converted into intermediate code includes: to splice preset field to program statement
Designated position is to generate intermediate code;Or preset field is deleted from the designated position of program statement to generate intermediate code.
In one embodiment of the invention, preset field includes that can be realized the field of version control function.
In one embodiment of the invention, configuration file is stored in local or decentralized configuration management platform.
In the second aspect of embodiment of the present invention, a kind of program code conversion apparatus is provided, comprising: source code is read
Modulus block is configured as sentence by sentence the source code of reading program;
Particular statement judgment module, is configured as whether the program statement that judgement is currently read is particular statement;
Intermediate code generation module, is configured as if the determination result is YES, and program statement is converted into intermediate code;
It explains execution module, is configured as explaining executing intermediate code;And
If judging result be it is no, directly explain execute program statement.
In one embodiment of the invention, it is different from execution program statement is explained to explain that execution intermediate code can be realized
Function.
In one embodiment of the invention, particular statement judgment module is specifically used for: obtaining preset in configuration file
Critical field;It whether is particular statement according to critical field determining program sentence.
In one embodiment of the invention, particular statement judgment module according to critical field determining program sentence whether
When for particular statement, it is specifically used for: judges whether critical field matches with each field in program statement;According to matching result
Whether determining program sentence is particular statement.
In one embodiment of the invention, particular statement judgment module is specifically used for: obtaining preset in configuration file
Unique identification;It whether is particular statement according to unique identification determining program sentence.
In one embodiment of the invention, particular statement judgment module according to unique identification determining program sentence whether
When for particular statement, it is specifically used for: obtains the unique identification of program statement;Judge preset unique identification and program statement only
One identifies whether to match;It whether is particular statement according to matching result determining program sentence.
In one embodiment of the invention, intermediate code generation module is specifically used for: obtaining preset in configuration file
Intermediate code create-rule;It is rule-based that program statement is converted into intermediate code.
In one embodiment of the invention, preset intermediate code create-rule includes preset field and corresponding behaviour
Make type, intermediate code generation module it is rule-based program statement is converted into intermediate code when, be specifically used for: by predetermined word
Section splicing is to the designated position of program statement to generate intermediate code;Or preset field is deleted from the designated position of program statement
To generate intermediate code.
In one embodiment of the invention, preset field includes that can be realized the field of version control function.
In one embodiment of the invention, configuration file is stored in local or decentralized configuration management platform.
In the third aspect of embodiment of the present invention, a kind of medium is provided, which has computer executable
Instruction, the method that computer executable instructions are used to that computer to be made to execute any embodiment in first aspect.
In the fourth aspect of embodiment of the present invention, provide a kind of calculating equipment, including processing unit, memory with
And input/output (In/Out, I/O) interface;Memory, the program or instruction executed for storage processing unit;Processing unit,
Program or instruction for being stored according to memory, the method for executing any embodiment in first aspect;I/O interface is used for
Data are received or sent under the control of processing unit.
The technical solution that embodiments of the present invention provide, can reading program sentence by sentence source code, judge current read
To program statement whether be particular statement;If program statement is then converted into intermediate code, and explain execution intermediate code;
If otherwise directly explaining and executing program statement.Technical solution provided by the invention, by judging whether present procedure sentence is special
Attribute sentence, and execution program statement is explained according to judging result, to realize that automatic identification and dynamic to program statement are modified,
The modification for facilitating simplified program statement, reduces the realization logical complexity and maintenance difficulties of program statement, improves program
The versatility of sentence.
Summary of the invention
Optimistic locking is suitable for the application type more read, and helps to improve the handling capacity of database table.The inventors discovered that existing
The realization of some optimistic locking solutions mostly realizes logic dependent on the optimistic locking added manually, but due to optimistic locking solution
Middle optimistic locking realizes that logic needs to be set in core logic sentence, so that the realization logic of optimistic locking is coupled in business generation completely
Code causes existing optimistic locking solution to exist and realizes that logic is complicated, and maintenance difficulties are big, and versatility is low, pluggable property difference etc.
Problem.By taking SQL statement as an example, it is assumed that the SQL statement before addition optimistic locking is update lottery_table set
Lottery_num=*where activity_id=*, then after adding optimistic locking using existing optimistic locking solution,
SQL statement is update lottery_table set lottery_num=*where activity_id=*and
Version=*.Also, optimistic locking realizes that logic can also be related to a fairly large number of database table in optimistic locking solution, into
One step causes the problem of development difficulty and maintenance difficulties increase of optimistic locking.For example added using existing optimistic locking solution
Add the increments logical that can increase version when optimistic locking in processing business logic.Therefore, existing optimistic locking solution is deposited
Realizing that logic is complicated, the problems such as maintenance difficulties are big, and versatility is low, and pluggable property is poor.
It is of the existing technology in order to overcome the problems, such as, a kind of program code conversion method, device, Jie are proposed in the present invention
Matter and calculating equipment.This method comprises: whether the source code of reading program, the program statement that judgement is currently read are special sentence by sentence
Attribute sentence;If program statement is then converted into intermediate code, and explain execution intermediate code;If otherwise directly explaining and executing journey
Sequence sentence.Method provided by the invention is solved by judging whether present procedure sentence is particular statement according to judging result
Execution program statement is released, to realize that automatic identification and dynamic to program statement are modified, facilitates the modification for simplifying program statement
Scheme reduces the realization logical complexity and maintenance difficulties of program statement, improves the versatility of program statement.
After introduced the basic principles of the present invention, lower mask body introduces various non-limiting embodiment party of the invention
Formula.
Application scenarios overview
The embodiment of the present invention can be applied to the modification scene of the modification scene of program statement, especially SQL statement.This hair
The program statement that bright embodiment is related to be not limited to inquiry (query) SQL statement for realizing query logic, for realizing
One of update (update) SQL statement of more new logic or combination, can also be the program statement of other grammers or format.
Technical solution provided by the embodiment of the present invention be suitable for any server or service platform, be also applied for equipped with
The electronic equipment of any software systems.The present embodiments relate to electronic equipment, can be directed to user provide image and/or
The equipment of data connectivity has the handheld device of wireless connecting function or is connected to its elsewhere of radio modem
Manage equipment.Wireless terminal device can be through wireless access network (Radio Access Network, RAN) and one or more cores
Net is communicated, and wireless user equipment can be mobile terminal device, such as mobile phone and with the calculating of mobile terminal device
Machine, for example, it may be portable, pocket, hand-held, built-in computer or vehicle-mounted mobile device.
Illustrative methods
Below with reference to above-mentioned application scenarios, it is described with reference to Figure 1 the program code of illustrative embodiments according to the present invention
Conversion method.It should be noted which is shown only for the purpose of facilitating an understanding of the spirit and principles of the present invention for above-mentioned application scenarios, this
The embodiment of invention is unrestricted in this regard.On the contrary, embodiments of the present invention can be applied to it is applicable any
Scene.
The embodiment of the invention provides a kind of program code conversion methods, as shown in Figure 1, the program code conversion method packet
It includes:
S101: the source code of reading program sentence by sentence.
S102: whether the program statement that judgement is currently read is particular statement.
S103: if so, program statement is converted into intermediate code.
S104: it explains and executes intermediate code.
S105: program statement is executed if it is not, directly explaining.
The source code of method shown in FIG. 1 reading program sentence by sentence judges whether the program statement currently read is specific
Sentence;If program statement is then converted into intermediate code, and explain execution intermediate code;If otherwise directly explaining and executing program
Sentence.Method provided by the invention is explained by judging whether present procedure sentence is particular statement according to judging result
Program statement is executed, to realize that automatic identification and dynamic to program statement are modified, facilitates the modification side for simplifying program statement
Case reduces the realization logical complexity and maintenance difficulties of program statement, improves the versatility of program statement.
In the embodiment of the present invention, particular statement refers to the program statement that can be realized certain logic, or can be realized spy
Determine the program statement of function.For the modification scene of distinct program sentence, particular statement can be different sentences.With SQL statement
Modification scene for, particular statement can be query SQL sentence and/or update SQL statement.
In the embodiment of the present invention, configuration file is at least stored with one of following configuration information or combines: unique identification,
Critical field, intermediate code create-rule.It should be noted that unique identification, critical field and intermediate code herein is raw
It will be described below at rule, being described in detail can be found in hereafter.The configuration information stored in configuration file is dynamic
It can match, it is to be understood that can be realized pair in program code operational process by the configuration information in modification configuration file
The modification of program code, to realize the pluggable of program code modification by the configuration file independently of source code
Property.
Configuration file is stored in local or decentralized configuration management platform.By taking program statement is SQL statement as an example, configuration text
Part can store inner in decentralized configuration service (disconf);Configuration file is stored in local, is using in the case of this
It needs for the configuration file to be loaded into memory from local before configuration file, the configuration in scanning memory can be passed through so as to subsequent
File monitors the modification of configuration file.
Judge in S102 the program statement currently read whether be particular statement method include it is a variety of, the present invention implement
It is not limited in example.A kind of implementation method is preset critical field in configuration file to be obtained, according to the preset critical field
Whether determining program sentence is particular statement.Wherein, preset critical field refers to field or energy with specific syntax meaning
Enough realize that the field of specific function, such as critical field can be update or query.Specifically, obtaining pre- in configuration file
If critical field, and program statement is divided to obtain each field in program statement, judges preset keyword
Whether whether section matches with each field in program statement, be afterwards particular statement according to matching result determining program sentence.
If matching result is the presence of the field that matches with preset critical field in program statement, illustrate preset critical field with
Each field in program statement matches, and program statement is particular statement in the case of this;If matching result is program statement
In there is no the fields that match with preset critical field, then illustrate each word in preset critical field and program statement
Section mismatches, and program statement is not particular statement in the case of this.
Before S102, handled using source code of the encoding tool to the program using corresponding coded format, it will
Source code is converted to the program statement that can be read.
By taking program statement shown in Fig. 2 modifies scene as an example, it is assumed that program statement is SQL statement.Before S102, pass through
Mybatis tool is handled the SQL statement that can be read to using the pseudo- SQL statement of mybatis grammatical tagging.In S102
In, the blocker characteristic according to mybatis creates SQL statement blocker (Intercerpetor), configures SQL statement interception
The type (Type) of device is Executor, according to critical field update and query preset in configuration file come to the SQL language
The method (Method) of sentence blocker is configured;The SQL statement blocker completed using configuration judges the SQL language currently read
With the presence or absence of the field to match with update or query in sentence, if then intercepting the SQL statement currently read, to pass through
The automatic interception of SQL statement is realized to query SQL sentence and updated to SQL statement blocker.
By above-mentioned implementation method, can be realized based on the preset configuration information of configuration file to program code whether be
The judgement of particular statement helps to reduce optimistic locking solution to realize the automatic acquisition to particular statement in source code
Realization difficulty.
Further, in S102 according to the matching result of each field in preset critical field and program statement come
After whether determining program sentence is particular statement, the particular statement in program code can also be identified.It identifies specific
The implementation method of sentence is as follows: preset unique identification in configuration file is obtained, according to the preset unique identification determining program
Whether sentence is particular statement.Unique identification includes but is not limited to the mark of the corresponding database table of program statement, program statement
Mark, such as the mark of SQL statement.Specifically, obtaining preset unique identification in configuration file, and obtain program statement
Unique identification, to judge whether the preset unique identification matches with the unique identification of the program statement, according to matching result
Whether determining program sentence is particular statement.If matching result is the unique identification of the preset unique identification and the program statement
Unanimously, then illustrate that the preset unique identification and the unique identification of the program statement match, program statement is in the case of this
Particular statement;If matching result is that the preset unique identification and the unique identification of the program statement are inconsistent, illustrate that this is pre-
If unique identification and the program statement unique identification mismatch, program statement is not particular statement in the case of this.It needs
It is noted that being directed to the modification scene of same program sentence, the unique identification of preset unique identification and program statement can be same
Belong to the mark of a type;For the modification scene of distinct program sentence, the type of preset unique identification can be identical, in advance
If the type of unique identification can also be different, do not limit herein.Above-mentioned detailed process does not limit when judging matching result
Used implementation is canonical matching or other modes.
By taking program statement shown in Fig. 2 modifies scene as an example, it is assumed that program statement is SQL statement.Intercepting current read
SQL statement after, scan and read preset database table title and SQL statement Id in configuration file, and pass through Mapped
The tools such as Statement and Bound SQL obtain database belonging to the SQL statement Id and the SQL statement that currently read
Table name;Preset database table title and database belonging to the SQL statement currently read are judged using canonical matching respectively
Whether table name consistent and whether the Id of the preset SQL statement and SQL statement Id that currently reads is consistent;According to canonical
Whether the SQL statement currently read with result judgement is identified as particular statement.
By above-mentioned implementation method, the particular statement in program code can be known based on preset unique identification
Not, to realize the automatic identification to particular statement in program code.
If it is determined that the program statement currently read is particular statement in S103, then program statement is converted into intermediate code
Specific steps include: to obtain preset intermediate code create-rule in configuration file, based on the rule by the program statement turn
Change intermediate code into.
By taking program statement shown in Fig. 2 modifies scene as an example, it is assumed that program statement is SQL statement, if it is determined that working as in S103
Before the SQL statement that reads be particular statement, then obtain preset intermediate code create-rule in configuration file, replaced by canonical
It changes and the program statement is converted by intermediate code based on the rule.
Wherein, intermediate code create-rule be dependent on program statement modification scene modification demand be arranged, intermediate generation
Code is the program code with the certain logic for meeting modification demand obtained after modifying.To add optimistic locking in program statement
For the scene for realizing logic, intermediate code is that the program statement of logic is realized added with optimistic locking.In addition to optimistic locking is realized
The certain logic for meeting modification demand is not limited except logic, in the embodiment of the present invention as other logics.
In the embodiment of the present invention, intermediate code create-rule includes at least preset field and corresponding action type.It should
Preset field include but is not limited to can be realized the field of version control function, such as preset field can be that by it is incremental
The field of logic and the field that can be realized decision logic.Preferably, preset field is the VO in database table, and the VO
Including version field.According to the difference of action type, S103 can be mainly divided into following situation:
Situation one: action type is splicing SQL statement.
In the case, preset preset field and corresponding action type in configuration file are first obtained in S103, then
The preset field is spliced to the designated position of program statement to generate intermediate code.
With program statement be update SQL statement, applicable scene be in SQL statement add optimistic locking realize logic for,
Assuming that the SQL statement currently read is to update SQL statement, i.e. update tablename set num=# { num } where
Id=# { id }, preset field be the first field ", version=version+1 " and the second field " and version=#
{ version } ", preset action type be splicing SQL statement, then in S103 obtain configuration file in preset first field and
Second field and corresponding action type are spliced the first field and the second field to currently reading by canonical replacement
The designated position of SQL statement is updated, so that intermediate code update tablename set num=# { num } is generated,
Version=version+1where id=# { id } and version=# { version }.
It is query SQL sentence with program statement, applicable scene is to add in SQL statement for optimistic locking realizes logic,
Assuming that the SQL statement currently read is query SQL sentence, i.e. select id, num from tablename where id
=# { id }, preset field be field ", version ", preset action type be splicing SQL statement, then in S103 obtain configuration
Preset first field and the second field and corresponding action type in file are replaced by canonical and splice field to current
The query result of the query SQL sentence read is concentrated, to generate intermediate code: select id, num, version from
Tablename where id=# { id }.
Situation two: action type is to delete SQL statement.
In the case, preset preset field and corresponding action type in configuration file are first obtained in S103, it will
The preset field is deleted from the designated position of program statement to generate intermediate code.It is understood that specific in the case of this
Example can be two exemplary reverse process in situation one above, and details are not described herein again.
It should be noted that the designated position of restricted program sentence is not head, the tail portion of the program statement in S103
Or it is intermediate;The quantity of designated position is not limited in S103 yet.
It is generated by the automation that S103 realizes intermediate code, facilitates the modification process for simplifying program statement, help
In the realization difficulty for reducing optimistic locking solution.Especially, the scene of logic is realized for addition optimistic locking, S103 can be with
The unfriendly code in service code is removed by integrating the increments logical of version in program statement, reduces optimistic locking
The degree of coupling for realizing logical AND service code, further decreases the realization difficulty and maintenance difficulties of optimistic locking solution.Equally,
Above-mentioned solution can also put off in other program statement modification scenes, to reduce the modified code degree of coupling, drop
The modification difficulty and maintenance difficulties of low program statement.
There is the certain logic different from original program sentence by the intermediate code that S103 is generated, it is seen that explain and hold in S104
Row intermediate code can be realized the function different from execution program statement is explained.
With program statement be update SQL statement, applicable scene be in SQL statement add optimistic locking realize logic for,
In S103 by preset field splice to currently read update SQL statement designated position to generate intermediate code after,
It is explained in S104 and executes the intermediate code, realize the optimistic lock function for being different from former SQL statement afterwards.
If it is determined that the program statement currently read is not particular statement in S105, then directly explains and executes program statement,
To avoid influencing the normal execution of service code.
By taking program statement shown in Fig. 2 modifies scene as an example, it is assumed that program statement is SQL statement, if it is determined that working as in S105
Before the SQL statement that reads be not particular statement, then directly explain and execute program statement.
Method provided by the invention, can reading program sentence by sentence source code, judge that the program statement currently read is
No is particular statement, if program statement is then converted into intermediate code, and explains execution intermediate code, if otherwise directly explaining
Execute program statement.Method provided by the invention is tied by judging whether present procedure sentence is particular statement, and according to judgement
Fruit explains execution program statement, to realize that automatic identification and dynamic to program statement are modified, helps to simplify program statement
Modification, reduce the realization logical complexity and maintenance difficulties of program statement, improve the versatility of program statement.
Exemplary means
After describing the method for exemplary embodiment of the invention, next, introducing, the present invention provides exemplary
The device of implementation.Program code conversion apparatus provided by the invention may be implemented to appoint in the method that the corresponding embodiment of Fig. 1 provides
The method of one execution.Referring to Fig. 3, which is included at least:
Source code read module is configured as sentence by sentence the source code of reading program;
Particular statement judgment module, is configured as whether the program statement that judgement is currently read is particular statement;
Intermediate code generation module, is configured as if the determination result is YES, and program statement is converted into intermediate code;
It explains execution module, is configured as explaining executing intermediate code;And
If judging result be it is no, directly explain execute program statement.
Optionally, explain that executing intermediate code can be realized the function different from execution program statement is explained.
Optionally, particular statement judgment module is specifically used for: obtaining preset critical field in configuration file;According to key
Whether field determining program sentence is particular statement.
Optionally, whether particular statement judgment module is when being particular statement according to critical field determining program sentence, tool
Body is used for: judging whether critical field matches with each field in program statement;It is according to matching result determining program sentence
No is particular statement.
Optionally, particular statement judgment module is specifically used for: obtaining preset unique identification in configuration file;According to unique
Identify whether determining program sentence is particular statement.
Optionally, whether particular statement judgment module is when being particular statement according to unique identification determining program sentence, tool
Body is used for: obtaining the unique identification of program statement;Judge whether preset unique identification matches with the unique identification of program statement;
It whether is particular statement according to matching result determining program sentence.
Optionally, intermediate code generation module is specifically used for: obtaining preset intermediate code create-rule in configuration file;
It is rule-based that program statement is converted into intermediate code.
Optionally, preset intermediate code create-rule includes preset field and corresponding action type, intermediate code
Generation module it is rule-based program statement is converted into intermediate code when, be specifically used for: preset field spliced to program word
The designated position of sentence is to generate intermediate code;Or preset field is deleted from the designated position of program statement to generate intermediate generation
Code.
Optionally, preset field includes that can be realized the field of version control function.
Optionally, configuration file is stored in local or decentralized configuration management platform.
Exemplary media
After describing the method and apparatus of exemplary embodiment of the invention, next, the present invention mentions with reference to Fig. 4
A kind of exemplary media is supplied, which there are computer executable instructions, which can be used for making institute
It states computer and executes method described in any one of corresponding exemplary embodiment of the invention of Fig. 1.
Exemplary computer device
After method, medium and the device for describing exemplary embodiment of the invention, next, being introduced with reference to Fig. 5
A kind of exemplary computer device 50 provided by the invention, the calculating equipment 50 include processing unit 501, memory 502, bus
503, external equipment 504, I/O interface 505 and network adapter 506, the memory 502 include random access memory
(random access memory, RAM) 5021, cache memory 5022, read-only memory (Read-Only
Memory, ROM) 5023 and at least memory cell array 5025 that constitutes of a piece of storage unit 5024.The wherein memory
502, the program or instruction executed for storage processing unit 501;The processing unit 501, for being stored according to the memory 502
Program or instruction, execute method described in any one of corresponding exemplary embodiment of the invention of Fig. 1;The I/O interface
505, for receiving or sending data under the control of the processing unit 501.
It should be noted that although be referred in the above detailed description program code conversion apparatus several units/modules or
Subelement/module, but it is this division be only exemplary it is not enforceable.In fact, embodiment party according to the present invention
The feature and function of formula, two or more above-described units/modules can embody in a units/modules.Conversely,
The feature and function of an above-described units/modules can be to be embodied by multiple units/modules with further division.
In addition, although describing the operation of the method for the present invention in the accompanying drawings with particular order, this do not require that or
Hint must execute these operations in this particular order, or have to carry out shown in whole operation be just able to achieve it is desired
As a result.Additionally or alternatively, it is convenient to omit multiple steps are merged into a step and executed by certain steps, and/or by one
Step is decomposed into execution of multiple steps.
Although detailed description of the preferred embodimentsthe spirit and principles of the present invention are described by reference to several, it should be appreciated that, this
It is not limited to the specific embodiments disclosed for invention, does not also mean that the feature in these aspects cannot to the division of various aspects
Combination is benefited to carry out, this to divide the convenience merely to statement.The present invention is directed to cover appended claims spirit and
Included various modifications and equivalent arrangements in range.