CN115309389A - Code file updating method and device, electronic equipment and storage medium - Google Patents

Code file updating method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN115309389A
CN115309389A CN202210937150.XA CN202210937150A CN115309389A CN 115309389 A CN115309389 A CN 115309389A CN 202210937150 A CN202210937150 A CN 202210937150A CN 115309389 A CN115309389 A CN 115309389A
Authority
CN
China
Prior art keywords
file
code file
target
mapper
program
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
CN202210937150.XA
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 Dajia Internet Information Technology Co Ltd
Original Assignee
Beijing Dajia Internet 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 Dajia Internet Information Technology Co Ltd filed Critical Beijing Dajia Internet Information Technology Co Ltd
Priority to CN202210937150.XA priority Critical patent/CN115309389A/en
Publication of CN115309389A publication Critical patent/CN115309389A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/35Creation or generation of source code model driven
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/72Code refactoring

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The present disclosure relates to a method, an apparatus, an electronic device and a storage medium for updating a code file, the method comprising: monitoring whether the content of a target code file under a target file path changes or not in the running process of a target program; under the condition that the content of the target code file is monitored to change, analyzing the target code file with the changed content by utilizing analysis software to obtain mapper information; and storing the mapper information corresponding to the object code file with the changed content and the object code file with the changed content into a configuration module of the analysis software. In the method and the device, a developer is allowed to modify the code file in the program running process, and the code file with changed content can be automatically re-analyzed in a monitoring mode. When the code file is modified, the program does not need to be closed or restarted, so that a developer is prevented from wasting a large amount of time on waiting for the program to be restarted, and the development efficiency of the program can be improved.

Description

Code file updating method and device, electronic equipment and storage medium
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a method and an apparatus for updating a code file, an electronic device, and a storage medium.
Background
The persistent layer framework (mybatis) is a database access framework commonly used in Java development, and the (mapping extensible markup language) mapper xml file is a configuration file written by a developer for accessing a database. After the developer writes the mapper xml file and runs the developed program, if the mapper xml file is found to have a writing error, the error mapper xml file needs to be modified.
In the related art, when a developer wants to modify a mapper xml file, the running program needs to be closed. After the mapper xml file is modified, the program needs to be restarted, and then mybatis is loaded and continues to test the developed program by using the modified mapper xml file. However, the closing and restarting of the program takes a long time, and the program needs to be restarted every time the mapper xml file is modified, so that a great amount of time of a developer is wasted on waiting for the program to be restarted, and the development efficiency of the program is low.
Disclosure of Invention
The disclosure provides a code file updating method, a code file updating device, an electronic device and a storage medium, so as to at least solve the problem that in the related art, a program needs to be restarted every time a mapper xml file is modified, which results in low program development efficiency.
According to a first aspect of the embodiments of the present disclosure, there is provided a method for updating a code file, including: monitoring whether the content of an object code file under an object file path changes or not in the running process of an object program, wherein the object code file is a code file for forming the object program, the object file path is a file path which is added into a file path configuration directory of analysis software in advance, and the analysis software is software which is quoted by the object program and is used for analyzing the code file; under the condition that the content of the object code file is monitored to be changed, analyzing the object code file with the changed content by utilizing the analysis software to obtain mapper information corresponding to the object code file with the changed content; and storing the mapper information corresponding to the object code file with the changed content and the object code file with the changed content into a configuration module of the analysis software.
Optionally, before monitoring whether the content of the target code file in the target file path changes, the method further includes: adding the target file path of the target code file into a monitoring list of a monitor; the monitoring whether the content of the target code file under the target file path changes includes: and monitoring whether the content of the target code file under the target file path changes or not through the listener.
Optionally, before adding the target file path of the target code file into the snoop list of the listener, the method further includes: starting the target program; in the process of starting the target program, adding a file path registration function in an analysis module in the analysis software by using a byte code enhancement technology, wherein the file path registration function is used for adding a file path of the analyzed code file into a monitoring list of the monitor; adding the target file path of the target code file into a monitoring list of a listener includes: and adding the target file path of the target code file into the monitoring list of the monitor by using the file path registration function of the analysis module of the analysis software.
Optionally, after adding a file path registration function in a parsing module in the parsing software by using a bytecode enhancement technology, the method further includes: analyzing an unmodified target code file under the target file path by utilizing an analysis module added with a file path registration function to obtain mapper information corresponding to the unmodified target code file; and storing the mapper information corresponding to the unmodified object code file and the unmodified object code file into a configuration module of the analysis software.
Optionally, the storing the mapper information corresponding to the object code file with the changed content and the object code file with the changed content into a configuration module of the parsing software includes: and on the basis of the mapper information corresponding to the unmodified object code file and the unmodified object code file, overwriting and storing the mapper information corresponding to the object code file with the changed content and the object code file with the changed content into a configuration module of the analysis software.
Optionally, before starting the target program, the method further includes: and adding the target file path of the target code file into a file path configuration directory of the analysis software.
According to a second aspect of the embodiments of the present disclosure, there is provided an apparatus for updating a code file, including: the monitoring module is configured to monitor whether the content of a target code file under a target file path changes or not in the running process of a target program, wherein the target code file is a code file for forming the target program, the target file path is a file path which is added into a file path configuration directory of analysis software in advance, and the analysis software is software which is quoted by the target program and is used for analyzing the code file; the first analysis module is configured to analyze the object code file with the changed content by using the analysis software under the condition that the change of the content of the object code file is monitored, and obtain the mapper information corresponding to the object code file with the changed content; the first storage module is configured to store the mapper information corresponding to the object code file with the changed content and the object code file with the changed content into the configuration module of the analysis software.
Optionally, the apparatus for updating the code file further includes:
a first adding module configured to add a target file path of the target code file into a listening list of a listener;
the monitoring module is configured to monitor whether the content of the target code file in the target file path changes through the monitor.
Optionally, the updating apparatus of the code file further includes a starting module and a second adding module;
the starting module is configured to start the target program;
the second adding module is configured to add a file path registration function in an analysis module in the analysis software by using a byte code enhancement technology in the process of starting the target program, wherein the file path registration function is used for adding a file path of the analyzed code file into a monitoring list of the listener;
the first adding module is configured to:
and adding the target file path of the target code file into the monitoring list of the monitor by using the file path registration function of the analysis module of the analysis software.
Optionally, the updating apparatus for the code file further includes a second parsing module and a second storage module;
the second analysis module is configured to analyze the unmodified target code file under the target file path by using the analysis module with the added file path registration function, and obtain mapper information corresponding to the unmodified target code file;
the second storage module is configured to store the mapper information corresponding to the unmodified object code file and the unmodified object code file into a configuration module of the parsing software.
Optionally, the first storage module is configured to:
and on the basis of the mapper information corresponding to the unmodified object code file and the unmodified object code file, overwriting and storing the mapper information corresponding to the object code file with the changed content and the object code file with the changed content into a configuration module of the analysis software.
Optionally, the updating apparatus of the code file further includes a third adding module;
the third adding module is configured to add the target file path of the target code file into the file path configuration directory of the analysis software.
According to a third aspect of the embodiments of the present disclosure, there is provided an electronic apparatus including: a processor; a memory for storing the processor-executable instructions; wherein the processor is configured to execute the instructions to implement a method of updating a code file according to the present disclosure.
According to a fourth aspect of embodiments of the present disclosure, there is provided a computer-readable storage medium in which instructions, when executed by a processor of an electronic device, enable the electronic device to perform a method of updating a code file according to the present disclosure.
According to a fifth aspect of embodiments of the present disclosure, there is provided a computer program product comprising a computer program which, when executed by a processor, implements a method of updating a code file according to the present disclosure.
The technical scheme provided by the embodiment of the disclosure at least brings the following beneficial effects:
in the method and the device, a developer is allowed to modify the code file in the program running process, and the code file with changed content can be automatically re-analyzed in a monitoring mode. When the code file is modified, the program does not need to be closed or restarted, so that a developer is prevented from wasting a large amount of time on waiting for the program to be restarted, and the development efficiency of the program can be improved.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the disclosure and are not to be construed as limiting the disclosure.
FIG. 1 is a flowchart illustrating a method of updating a code file according to an exemplary embodiment of the present disclosure;
FIG. 2 is a flowchart illustrating a specific implementation of a method for updating a mapper xml file according to an exemplary embodiment of the present disclosure;
FIG. 3 is a block diagram illustrating an apparatus for updating a code file according to an exemplary embodiment of the present disclosure;
fig. 4 is a block diagram illustrating an electronic device according to an exemplary embodiment of the present disclosure.
Detailed Description
In order to make the technical solutions of the present disclosure better understood, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings.
It should be noted that the terms "first," "second," and the like in the description and claims of the present disclosure and in the foregoing drawings are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the disclosure described herein are capable of operation in sequences other than those illustrated or otherwise described herein. The embodiments described in the following examples do not represent all embodiments consistent with the present disclosure. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the disclosure, as detailed in the appended claims.
In this case, the expression "at least one of the items" in the present disclosure means a case where three types of parallel expressions "any one of the items", "a combination of any plural ones of the items", and "the entirety of the items" are included. For example, "include at least one of a and B" includes the following three cases in parallel: (1) comprises A; (2) comprises B; and (3) comprises A and B. For another example, "at least one of step one and step two is performed", which means the following three parallel cases: (1) executing the step one; (2) executing the step two; and (3) executing the step one and the step two.
Hot updates are the ability to dynamically cause code, file changes, and enable running programs to recognize such changes. mybatis is a database access framework commonly used for Java development, and the mapper xml file is a configuration file written by a developer for accessing a database. Wherein, the mapper xml file is exemplified as follows:
Figure BDA0003783914990000051
the above is a segment of SQL statement, which belongs to the standard writing method of mybatis, and is used for querying a piece of data from a database table. I.e. the mapper xml file mentioned above is used to look up data with ID as the incoming ID parameter from the Blog table and then convert the result into the form of org.
In the related art, when a developer wants to modify a mapper xml file, the running program needs to be closed. After the mapper xml file is modified, the program needs to be restarted, and then mybatis is loaded and continues to test the developed program by using the modified mapper xml file. However, the closing and restarting of the program takes a long time, and the program needs to be restarted every time the mapper xml file is modified according to the size of the program, which causes a lot of time waste for developers to wait for the program to be restarted, and thus the development efficiency of the program is low.
In order to solve the above problems in the related art, the present disclosure provides a method for updating a code file, which allows a developer to modify the code file during the running of a program, and can automatically parse the code file with changed content again in a monitoring manner. When the code file is modified, the program does not need to be closed or restarted, so that a developer is prevented from wasting a large amount of time on waiting for the program to be restarted, and the development efficiency of the program can be improved.
Fig. 1 is a flowchart illustrating an update method of a code file according to an exemplary embodiment of the present disclosure.
Referring to fig. 1, in step 101, during the running of the target program, it may be monitored whether the content of the target code file in the target file path changes. The object code file is a code file for composing the object program, that is, the object code file is one of a plurality of code files written by a developer for composing the object program, and the code file may be a mapping extensible markup language (mapper xml) file.
The target file path is a file path which is added to a file path configuration directory of the analysis software in advance, and the target file path is used for indicating the storage position of the target code file. The analysis software is the software which is referenced by the target program and is used for analyzing the code file. The parsing software may be a dependency package, which is a reusable component, the object program may refer to the dependency package, i.e., the object program and the parsing software are in a reference relationship, and the parsing software may be a persistent layer framework (mybatis).
In step 102, when it is monitored that the content of the object code file changes, the object code file with the changed content may be analyzed by using analysis software, so as to obtain Mapper (Mapper) information corresponding to the object code file with the changed content. For example, when it is monitored that the content of the target Mapper xml file changes, mybatis may be used to analyze the target Mapper xml file with changed content, and obtain Mapper information corresponding to the target Mapper xml file with changed content.
In step 103, the mapper information corresponding to the object code file with changed content and the object code file with changed content may be stored in a Configuration module of the parsing software. For example, the Mapper information corresponding to the target Mapper xml file with changed content and the target Mapper xml file with changed content may be stored in the Configuration class of mybatis. In the subsequent use process of the mybatis, the constructed Mapper information can be directly obtained from the cache information in the Configuration class of the mybatis, and the parsing process of the code file does not need to be executed again.
It should be noted that, if a developer modifies a plurality of code files constituting a target program, mybatis may be used to analyze the plurality of code files with changed content, so as to obtain a plurality of Mapper information corresponding to the plurality of code files one to one. Then, the plurality of Mapper information and the plurality of code files may be cached into a Configuration class of mybatis.
According to an example embodiment of the present disclosure, a target file path of a target code file may be added to a snoop list of a listener, which may be a hot-update xml file listener, before listening for whether the content of the target code file under the target file path has changed. Then, whether the content of the target code file added to the target file path in the snoop list is changed or not can be snooped by the snooper. In this way, the target file path of the target code file is added into the monitoring list of the listener, so that whether the content of the target code file changes or not can be monitored by the listener in real time, and the state of the target code file can be acquired in time conveniently.
According to an example embodiment of the present disclosure, a developer may launch a target program before adding a target file path of a target code file into a snoop list of a listener. Then, in the process of starting the target program, a file path registration function can be added in a parsing module in the parsing software by using a byte code enhancement technology, wherein the file path registration function is used for adding a file path of the parsed code file into a monitoring list of the listener.
For example, in the process of starting the object program, bytecode enhancement technologies such as a Java bytecode manipulation framework (asm) and a class library (javasist) for creating Java bytecode may be used to modify the Java bytecode when an extensible markup language mapping builder (XML Mapper holder) class is loaded, that is, some logic may be added to the XML Mapper holder class in mybatis, and the added logic functions as: "when parsing an xml file, register the file path of the parsed xml file in the listening list of the listener".
Next, the file path registration function of the parsing module of the parsing software may be utilized to add the target file path of the target code file into the listening list of the listener. For example, the target file path of the parsed target Mapper XML file may be registered in the listener's snoop list using bytecode-modified XML Mapper. Therefore, by adding the file path registration function in the analysis module in the analysis software by using the byte code enhancement technology, the file path of the analyzed code file can be automatically added into the monitoring list of the monitor by using the file path registration function when the code file is analyzed, so that the monitor can monitor the code file under the file path in the monitoring list in time.
According to the exemplary embodiment of the disclosure, as described above, the code file in the disclosure may be a Mapper XML file, the parsing software may be mybatis, and the parsing module of the parsing software may be an XML Mapper holder class in the mybatis.
According to an exemplary embodiment of the present disclosure, after a file path registration function is added in a parsing module in parsing software by using a bytecode enhancement technology, an unmodified object code file in an object file path may be parsed by using the parsing module to which the file path registration function is added, so as to obtain mapper information corresponding to the unmodified object code file. For example, the unmodified target mappers XML file in the target file path may be parsed by using the XML Mapper type to which the file path registration function is added, so as to obtain the Mapper information corresponding to the unmodified target mappers XML file. The mapper information corresponding to the unmodified object code file and the unmodified object code file may then be stored within a configuration module of the parsing software. For example, the Mapper information corresponding to the unmodified target Mapper xml file and the unmodified target Mapper xml file may be stored in the Configuration class of mybatis.
According to the exemplary embodiment of the disclosure, on the basis of the mapper information corresponding to the unmodified object code file and the unmodified object code file, the mapper information corresponding to the object code file with changed content and the object code file with changed content are stored in the configuration module of the analysis software in an overlaying manner.
For example, when the listener monitors that the content of the target Mapper XML file changes, the listener calls the XML Mapper folder class of mybatis to re-parse the target Mapper XML file with the changed content, and re-registers the re-parsed Mapper information and the target Mapper XML file with the changed content into the Configuration class of mybatis, and the re-parsed Mapper information and the target Mapper XML file with the changed content may cover the Mapper information corresponding to the unmodified target Mapper XML file and the unmodified target Mapper XML file which are cached in the Configuration class before.
Further, if the developer modifies the same Mapper xml file for multiple times, the Mapper information corresponding to the Mapper xml file cached in the Configuration class before the modification and the Mapper xml file may be covered by the Mapper information obtained by parsing the Mapper xml file after each modification and the Mapper xml file after the modification. The mybatis uses the latest Mapper information cached in the Configuration class in the subsequent process, so that the dynamic updating capability of the mybatis Mapper xml is realized. Moreover, because the newly analyzed Mapper information and the modified Mapper xml file are stored in a covering manner on the basis of the previously cached Mapper information and the Mapper xml file, the Mapper information and the corresponding Mapper xml file which are cached in the Configuration class of mybatis can be deleted, the useless information can be prevented from occupying the Configuration class of mybatis too much, and the cache resource is saved.
According to the exemplary embodiment of the disclosure, before starting the target program, the target file path of the target code file may be added to the file path configuration directory of the parsing software, that is, the developer may add the storage location of the code file to be parsed to the file path configuration directory of mybatis in advance. After the target program is started, the XML Mapper files in the mybatis can read and analyze the content of the Mapper XML files from the file path according to the file path of the Mapper XML files configured by developers in advance, and then the Mapper type information corresponding to the analyzed Mapper XML files can be obtained. Next, the Mapper class information obtained by parsing and the corresponding Mapper xml file may be cached in the Configuration class of mybatis.
It should be noted that, after the content of the mapper xml file is modified each time, the file path of the mapper xml file may be maintained unchanged, that is, when it is monitored that the content of the mapper xml file changes, the modified mapper xml file may be read from the same file path and parsed again, where the "same file path" is the file path that is added to the mybatis file path configuration directory by the developer at first. Therefore, after the developer writes the mapper xml file, the file path, that is, the storage position corresponding to the written mapper xml file can be added into the file path configuration directory of the analysis software, and then the analysis of the specified mapper xml file under the specified file path can be realized.
Fig. 2 is a flowchart illustrating a specific implementation of a method for updating a mapper xml file according to an exemplary embodiment of the present disclosure.
In step 201, the developer adds the file path of the mapper xml file to be parsed into the file path configuration directory of mybatis. Wherein, the mapper xml file to be analyzed is at least one mapper xml file composing the developed program.
In step 202, the program is started. For example, a developer may manually initiate a program to place the program in a running state.
In step 203, during program startup, bytecode modification is performed on the XML Mapper folder class of mybatis when the XML Mapper folder class is loaded by using a bytecode enhancement technology. For example, some logic may be added in the XML Mapper holder class in mybatis, the added logic acting as: "when parsing an xml file, register the file path of the parsed xml file in the listening list of the listener". As described in the previous embodiment, mybatis is the software referenced by the developed program and used to parse the mapper xml file.
In step 204, the bytecode-modified XML Mapper based on the file path that is added to the mybatis file path configuration directory by the developer in advance reads the Mapper XML file under the file path and parses the Mapper XML file to obtain the original Mapper information.
In step 205, the parsed original Mapper information and the corresponding Mapper xml file are stored into the Configuration class of mybatis. It should be noted that, if there are multiple mapper xml files to be parsed, for example, n mapper xml files are: mapper xml file 1, mapper xml file 2, …, and mapper xml file n. Each of the n Mapper xml files may obtain corresponding Mapper information through parsing, for example, a Mapper xml file 1 may obtain corresponding Mapper information 1 through parsing, a Mapper xml file 2 may obtain corresponding Mapper information 2, … through parsing, a Mapper xml file n may obtain corresponding Mapper information n through parsing, and the like. Then, each Mapper xml file and its corresponding Mapper information may be cached in the Configuration class of mybatis.
In step 206, while reading the Mapper XML file in the file path configuration directory of mybatis, the bytecode-modified XML type registers the file path corresponding to the read Mapper XML file in the snoop list of the listener, where the listener may be a hot update XML file listener.
In step 207, the listener listens to the mapper xml file in each file path in at least one file path included in the listening list, that is, the listener listens to whether the content of the mapper xml file in each file path in the at least one file path changes.
In step 208, when it is monitored that the content of the Mapper XML file in a certain file path included in the monitoring list changes, the listener sends a notification message to the XML Mapper holder class of mybatis, where the notification message is used to prompt that the content of a certain Mapper XML file has changed and needs to be parsed again, and the notification message may include the file path of the Mapper XML file whose content has changed.
In step 209, based on the notification message sent by the listener, the XML Mapper holder class of mybatis rereads the modified mappers XML file from the file path of the mappers XML file whose content is changed, and parses the modified mappers XML file to obtain the Mapper information corresponding to the modified mappers XML file.
In step 2010, the Mapper information corresponding to the modified Mapper xml file and the modified Mapper xml file are cached in the Configuration class of mybatis. Moreover, the Mapper information corresponding to the modified Mapper xml file and the modified Mapper xml file may overwrite the original Mapper information and the unmodified Mapper xml file cached in the Configuration class of mybatis before.
Further, as described in the previous embodiment, if the developer modifies the same Mapper xml file multiple times, the Mapper information corresponding to the Mapper xml file cached in the Configuration class before the modification and the Mapper xml file obtained by parsing the Mapper xml file after each modification and the Mapper xml file after the modification may be overwritten. The mybatis uses the latest Mapper information cached in the Configuration class in the subsequent process, so that the dynamic updating capability of the mybatis Mapper xml is realized.
According to the code file updating method provided by the disclosure, the file path of the analyzed code file can be registered in the monitoring list of the monitor by enhancing the XMLMapperBuilder class of mybatis; by adding the monitoring mechanism, the code files registered in the file path in the monitoring list can be monitored in real time through the monitor. Therefore, a developer can be allowed to modify the code file in the program running process, and the code file with changed content can be automatically re-analyzed in a monitoring mode, namely the effect of dynamically updating the mybatis mapper xml file is realized. When a developer runs a program to test the mapper xml file, if the written mapper xml file is found to have errors, the program does not need to be closed or restarted, the program can be continuously tested, the restarting time of the program is saved, and the program development efficiency is improved.
Fig. 3 is a block diagram illustrating an updating apparatus of a code file according to an exemplary embodiment of the present disclosure.
Referring to fig. 3, the apparatus 300 may include a listening module 301, a first parsing module 302, and a first storing module 303.
In the running process of the target program, the monitoring module 301 may monitor whether the content of the target code file in the target file path changes. The object code file is a code file for composing the object program, that is, the object code file is one of a plurality of code files written by a developer for composing the object program, and the code file may be a mapping extensible markup language (mapper xml) file.
The target file path is a file path which is added to a file path configuration directory of the analysis software in advance, and the target file path is used for indicating the storage position of the target code file. The analysis software is the software which is referenced by the target program and is used for analyzing the code file. The parsing software may be a dependency package, which is a reusable component, the target program may refer to the dependency package, i.e., the target program is in a reference relationship with the parsing software, and the parsing software may be a persistent layer framework (mybatis).
When the monitoring module 301 monitors that the content of the object code file changes, the first parsing module 302 may parse the object code file with the changed content by using parsing software, and obtain Mapper (Mapper) information corresponding to the object code file with the changed content. For example, when it is monitored that the content of the target Mapper xml file changes, mybatis may be used to analyze the target Mapper xml file with changed content, and obtain Mapper information corresponding to the target Mapper xml file with changed content.
The first storage module 303 may store the mapper information corresponding to the object code file with the changed content and the object code file with the changed content into a Configuration module of the parsing software. For example, the Mapper information corresponding to the target Mapper xml file with changed content and the target Mapper xml file with changed content may be stored in the Configuration class of mybatis. In the subsequent use process of mybatis, the constructed Mapper information can be directly obtained from the cache information in the Configuration class of mybatis, and the parsing process for the code file does not need to be executed again.
It should be noted that, if a developer modifies a plurality of code files constituting the target program, the plurality of code files with changed contents may be analyzed by mybatis, so as to obtain a plurality of Mapper information corresponding to the plurality of code files one to one. Then, the plurality of Mapper information and the plurality of code files may be cached into a Configuration class of mybatis.
According to an exemplary embodiment of the present disclosure, the apparatus 300 for updating a code file may further include a first adding module. Before monitoring whether the content of the target code file under the target file path changes or not, the first adding module may add the target file path of the target code file into a monitoring list of a listener, and the listener may be a hot update xml file listener. Then, the snooping module 301 may snoop whether the content of the object code file added to the object file path in the snoop list changes through the snooper. In this way, the target file path of the target code file is added into the monitoring list of the monitor, so that whether the content of the target code file changes or not can be monitored in real time by the monitor, and the state of the target code file can be acquired in time conveniently.
According to an exemplary embodiment of the present disclosure, the apparatus for updating a code file may further include a start module and a second adding module.
The start module may start the target program before adding the target file path of the target code file to the snoop list of the listener. Then, during the starting process of the target program, the second adding module may add a file path registration function in a parsing module in the parsing software by using a bytecode enhancement technology, where the file path registration function is used to add a file path of the parsed code file into a listening list of the listener.
For example, during the starting process of the target program, the second adding module may modify the XML Mapper holder class by using the bytecode enhancement technology such as asm, javasist and the like when loading the XML Mapper holder class, that is, the second adding module may add some logic in the XML Mapper holder class in mybatis, and the added logic has the functions of: "when parsing an xml file, register the file path of the parsed xml file in the listening list of the listener".
Next, the first adding module may add the target file path of the target code file to the listening list of the listener by using a file path registration function of the parsing module of the parsing software. For example, the target file path of the parsed target Mapper XML file may be registered in the listener's snoop list using bytecode-modified XML Mapper. Therefore, by adding the file path registration function in the analysis module in the analysis software by using the byte code enhancement technology, the file path of the analyzed code file can be automatically added into the monitoring list of the monitor by using the file path registration function when the code file is analyzed, so that the monitor can monitor the code file under the file path in the monitoring list in time.
According to an exemplary embodiment of the present disclosure, the apparatus for updating a code file may further include a second parsing module and a second storage module.
After a file path registration function is added to an analysis module in analysis software by using a byte code enhancement technology, the second analysis module can also analyze an unmodified target code file under a target file path by using the analysis module added with the file path registration function to obtain mapper information corresponding to the unmodified target code file. For example, the second parsing module may parse the unmodified target Mapper XML file in the target file path by using the XML Mapper holder class to which the file path registration function is added, and obtain Mapper information corresponding to the unmodified target Mapper XML file. The second storage module may then store the mapper information corresponding to the unmodified object code file and the unmodified object code file into a configuration module of the parsing software. For example, the second storage module may store Mapper information corresponding to the unmodified target Mapper xml file and the unmodified target Mapper xml file into the Configuration class of mybatis.
According to an exemplary embodiment of the disclosure, the first storage module 303 may store the mapper information corresponding to the object code file with changed content and the object code file with changed content into the configuration module of the parsing software in an overlay manner based on the mapper information corresponding to the object code file without being modified and the object code file without being modified.
For example, when the listener monitors that the content of the target Mapper XML file changes, the listener calls the XML Mapper folder class of mybatis to re-parse the target Mapper XML file with the changed content, and re-registers the re-parsed Mapper information and the target Mapper XML file with the changed content into the Configuration class of mybatis, and the re-parsed Mapper information and the target Mapper XML file with the changed content may cover the Mapper information corresponding to the unmodified target Mapper XML file and the unmodified target Mapper XML file which are cached in the Configuration class before.
Further, if the developer modifies the same Mapper xml file for multiple times, the Mapper information corresponding to the Mapper xml file cached in the Configuration class before the modification and the Mapper xml file may be covered by the Mapper information obtained by parsing the Mapper xml file after each modification and the Mapper xml file after the modification. The mybatis uses the latest Mapper information cached in the Configuration class in the subsequent process, so that the dynamic updating capability of the mybatis Mapper xml is realized. Moreover, because the newly analyzed Mapper information and the modified Mapper xml file are stored in an overlaying manner on the basis of the previously cached Mapper information and the Mapper xml file, the Mapper information and the corresponding Mapper xml file which are cached in the Configuration class of mybatis can be deleted, excessive occupation of useless information on the Configuration class of mybatis can be avoided, and cache resources are saved.
According to an exemplary embodiment of the present disclosure, the apparatus for updating a code file may further include a third adding module.
Before starting the target program, the third adding module may add the target file path of the target code file into the file path configuration directory of the parsing software, that is, the developer may add the storage location of the code file to be parsed into the file path configuration directory of mybatis in advance. After the target program is started, the XML Mapper files in the mybatis can read and analyze the content of the Mapper XML files from the file path according to the file path of the Mapper XML files configured by developers in advance, and then the Mapper type information corresponding to the analyzed Mapper XML files can be obtained. Next, the parsed Mapper class information and the corresponding Mapper xml file may be cached in the Configuration class of mybatis.
It should be noted that, after the content of the mapper xml file is modified each time, the file path of the mapper xml file may be maintained unchanged, that is, when it is monitored that the content of the mapper xml file changes, the modified mapper xml file may be read from the same file path and parsed again, where the "same file path" is the file path that is added to the mybatis file path configuration directory by the developer at first. Therefore, after the developer writes the mapper xml file, the file path, that is, the storage position corresponding to the written mapper xml file can be added into the file path configuration directory of the analysis software, and then the analysis of the specified mapper xml file under the specified file path can be realized.
Fig. 4 is a block diagram illustrating an electronic device 400 according to an exemplary embodiment of the present disclosure.
Referring to fig. 4, the electronic device 400 includes at least one memory 401 and at least one processor 402, the at least one memory 401 having stored therein instructions that, when executed by the at least one processor 402, perform a method of updating a code file according to an exemplary embodiment of the present disclosure.
By way of example, the electronic device 400 may be a PC computer, tablet device, personal digital assistant, smartphone, or other device capable of executing the instructions described above. Here, the electronic device 400 need not be a single electronic device, but can be any collection of devices or circuits that can execute the above instructions (or sets of instructions) individually or in combination. The electronic device 400 may also be part of an integrated control system or system manager, or may be configured as a portable electronic device that interfaces with local or remote (e.g., via wireless transmission).
In the electronic device 400, the processor 402 may include a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), a programmable logic device, a special purpose processor system, a microcontroller, or a microprocessor. By way of example, and not limitation, processors may also include analog processors, digital processors, microprocessors, multi-core processors, processor arrays, network processors, and the like.
The processor 402 may execute instructions or code stored in the memory 401, wherein the memory 401 may also store data. The instructions and data may also be transmitted or received over a network via a network interface device, which may employ any known transmission protocol.
The memory 401 may be integrated with the processor 402, for example, by having RAM or flash memory disposed within an integrated circuit microprocessor or the like. Further, memory 401 may comprise a stand-alone device, such as an external disk drive, storage array, or any other storage device usable by a database system. The memory 401 and the processor 402 may be operatively coupled or may communicate with each other, such as through I/O ports, network connections, etc., so that the processor 402 can read files stored in the memory.
In addition, the electronic device 400 may also include a video display (such as a liquid crystal display) and a user interaction interface (such as a keyboard, mouse, touch input device, etc.). All components of electronic device 400 may be connected to each other via a bus and/or a network.
According to an exemplary embodiment of the present disclosure, there may also be provided a computer-readable storage medium, in which instructions, when executed by a processor of an electronic device, enable the electronic device to perform the above-described method of updating a code file. Examples of the computer-readable storage medium herein include: read-only memory (ROM), random-access programmable read-only memory (PROM), electrically erasable programmable read-only memory (EEPROM), random-access memory (RAM), dynamic random-access memory (DRAM), static random-access memory (SRAM), flash memory, non-volatile memory, CD-ROM, CD-R, CD + R, CD-RW, CD + RW, DVD-ROM, DVD-R, DVD + R, DVD-RW, DVD + RW, DVD-RAM, BD-ROM, BD-R, BD-R LTH, BD-RE, blu-ray or optical disk memory, hard Disk Drives (HDDs), solid-state hard disks (SSDs), card-type memory (such as a multimedia card, a Secure Digital (SD) card, or an extreme digital (XD) card), magnetic tape, floppy disk, magneto-optical data storage, hard disk, solid-state disk, and any other device configured to store and to enable a computer program and any associated data file, data processing structure and to be executed by a computer. The computer program in the computer-readable storage medium described above can be run in an environment deployed in a computer device, such as a client, a host, a proxy appliance, a server, or the like, and further, in one example, the computer program and any associated data, data files, and data structures are distributed across networked computer systems such that the computer program and any associated data, data files, and data structures are stored, accessed, and executed in a distributed fashion by one or more processors or computers.
According to an exemplary embodiment of the present disclosure, a computer program product may also be provided, comprising a computer program which, when executed by a processor, implements a method of updating a code file according to the present disclosure.
According to the updating method, the updating device, the electronic equipment and the storage medium of the code file, the file path of the analyzed code file can be registered in a monitoring list of a monitor by enhancing the XMLMappBuilder class of mybatis; by adding a monitoring mechanism, the code file registered in the file path in the monitoring list can be monitored in real time through the monitor. Therefore, a developer can be allowed to modify the code file in the program running process, and the code file with changed content can be automatically re-analyzed in a monitoring mode, namely the effect of dynamically updating the mybatis mapper xml file is realized. When a developer runs a program to test the mapper xml file, if the written mapper xml file is found to have errors, the program does not need to be closed or restarted, the program can be continuously tested, the restarting time of the program is saved, and the program development efficiency is improved.
Furthermore, the target file path of the target code file is added into the monitoring list of the monitor, so that whether the content of the target code file changes or not can be monitored in real time by the monitor, and the state of the target code file can be acquired in time conveniently.
Furthermore, by adding a file path registration function in an analysis module in analysis software by using a byte code enhancement technology, the file path of the analyzed code file can be automatically added into a monitoring list of the monitor by using the file path registration function when the code file is analyzed, so that the monitor can monitor the code file under the file path in the monitoring list in time.
Further, because the newly parsed Mapper information and the modified Mapper xml file are stored in an overlaying manner on the basis of the previously cached Mapper information and the Mapper xml file, the Mapper information and the corresponding Mapper xml file which are previously cached in the Configuration class of mybatis can be deleted, excessive occupation of useless information on the Configuration class of mybatis can be avoided, and cache resources are saved.
Furthermore, after the developer writes the mapper xml file, the file path, that is, the storage location corresponding to the written mapper xml file may be added to the file path configuration directory of the analysis software, so that the specified mapper xml file under the specified file path may be analyzed.
Other embodiments of the disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the disclosure disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of the disclosure following, in general, the principles of the disclosure and including such departures from the present disclosure as come within known or customary practice within the art to which the disclosure pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the disclosure being indicated by the following claims.
It will be understood that the present disclosure is not limited to the precise arrangements described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims (10)

1. A method for updating a code file, comprising:
monitoring whether the content of an object code file under an object file path changes or not in the running process of an object program, wherein the object code file is a code file for forming the object program, the object file path is a file path which is added into a file path configuration directory of analysis software in advance, and the analysis software is software which is quoted by the object program and is used for analyzing the code file;
under the condition that the content of the object code file is monitored to be changed, analyzing the object code file with the changed content by utilizing the analysis software to obtain mapper information corresponding to the object code file with the changed content;
and storing the mapper information corresponding to the object code file with the changed content and the object code file with the changed content into a configuration module of the analysis software.
2. The updating method according to claim 1, wherein before monitoring whether the content of the target code file under the target file path changes, further comprising:
adding the target file path of the target code file into a monitoring list of a monitor;
the monitoring whether the content of the target code file under the target file path changes includes:
and monitoring whether the content of the target code file under the target file path changes or not through the listener.
3. The update method of claim 2, prior to adding the target file path of the target code file to the snoop list of a listener, further comprising:
starting the target program;
in the process of starting the target program, adding a file path registration function in an analysis module in the analysis software by using a byte code enhancement technology, wherein the file path registration function is used for adding a file path of the analyzed code file into a monitoring list of the monitor;
adding the target file path of the target code file into a monitoring list of a listener includes:
and adding the target file path of the target code file into the monitoring list of the monitor by using the file path registration function of the analysis module of the analysis software.
4. The updating method of claim 3, after adding a file path registration function in a parsing module in the parsing software using a bytecode enhancement technique, further comprising:
analyzing the unmodified target code file under the target file path by utilizing an analysis module added with a file path registration function to obtain mapper information corresponding to the unmodified target code file;
and storing the mapper information corresponding to the unmodified object code file and the unmodified object code file into a configuration module of the analysis software.
5. The updating method of claim 4, wherein the storing the mapper information corresponding to the object code file with the changed content and the object code file with the changed content into the configuration module of the parsing software comprises:
and on the basis of the mapper information corresponding to the unmodified object code file and the unmodified object code file, overwriting and storing the mapper information corresponding to the object code file with the changed content and the object code file with the changed content into a configuration module of the analysis software.
6. The updating method of claim 5, prior to starting the target program, further comprising:
and adding the target file path of the target code file into a file path configuration directory of the analysis software.
7. An apparatus for updating a code file, comprising:
the monitoring module is configured to monitor whether the content of a target code file under a target file path changes or not in the running process of a target program, wherein the target code file is a code file for forming the target program, the target file path is a file path which is added into a file path configuration directory of analysis software in advance, and the analysis software is software which is quoted by the target program and is used for analyzing the code file;
the first analysis module is configured to analyze the object code file with the changed content by using the analysis software under the condition that the change of the content of the object code file is monitored, and obtain the mapper information corresponding to the object code file with the changed content;
the first storage module is configured to store the mapper information corresponding to the object code file with the changed content and the object code file with the changed content into the configuration module of the analysis software.
8. An electronic device, comprising:
a processor;
a memory for storing the processor-executable instructions;
wherein the processor is configured to execute the instructions to implement the method of updating a code file of any of claims 1 to 6.
9. A computer-readable storage medium, wherein instructions in the computer-readable storage medium, when executed by a processor of an electronic device, enable the electronic device to perform the method of updating a code file of any of claims 1 to 6.
10. A computer program product comprising a computer program, characterized in that the computer program, when being executed by a processor, implements a method of updating a code file according to any one of claims 1 to 6.
CN202210937150.XA 2022-08-05 2022-08-05 Code file updating method and device, electronic equipment and storage medium Pending CN115309389A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210937150.XA CN115309389A (en) 2022-08-05 2022-08-05 Code file updating method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210937150.XA CN115309389A (en) 2022-08-05 2022-08-05 Code file updating method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN115309389A true CN115309389A (en) 2022-11-08

Family

ID=83860893

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210937150.XA Pending CN115309389A (en) 2022-08-05 2022-08-05 Code file updating method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN115309389A (en)

Similar Documents

Publication Publication Date Title
US9934005B2 (en) Dynamically building locale objects or subsections of locale objects based on historical data
US9558214B1 (en) Secondary mappings to enable code changes without schema updates
US8126859B2 (en) Updating a local version of a file based on a rule
US20100235321A1 (en) Programming model for synchronizing browser caches across devices and web services
US9652220B2 (en) Zero down-time deployment of new application versions
MX2008011058A (en) Rss data-processing object.
CN106648569B (en) Target serialization realization method and device
WO2020010725A1 (en) Method and apparatus for automatically synchronously refreshing browser, and computer device
US7721278B2 (en) Modular server architecture for multi-environment HTTP request processing
US10579502B2 (en) Resuming applications using pass-through servers and trace data
US10216553B2 (en) Message oriented middleware with integrated rules engine
US8191041B2 (en) Javascript pre-processing framework
EP2440997A2 (en) Software extension analysis
CN114116505A (en) Code testing method and device
CN114048415A (en) Form generation method and device, electronic equipment and computer readable storage medium
CN111177089B (en) Log processing code generation method and device, computer system and storage medium
WO2011157105A2 (en) Method and device for component expansion
CN115309389A (en) Code file updating method and device, electronic equipment and storage medium
US8793663B2 (en) Smart cache for a server test environment in an application development tool
CN113591000A (en) Browser engine switching method, device and equipment
TWI444824B (en) Method for identifying memory of virtual machine and computer system using the same
CN112528273B (en) Medical data detection method, device, medium and electronic equipment
JP2009122985A (en) System and program for sub-process execution
WO2021223544A1 (en) Application starting method and related device
US11726776B2 (en) Super-app extension discovery and configuration via source code management platform comments

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