Dynamic mapping method, device and equipment from database to API (Application Program Interface) based on Java and medium
Through the Java-based dynamic database to API mapping method, the API interface is dynamically generated and registered in the application context, solving the problems of high development costs, low development efficiency and insufficient flexibility in the integration process of database and API in the prior art, and achieving efficient and flexible database and API integration.
Patent Information
- Application Number
- CN202411817166.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-11
- Publication Date
- 2025-03-14
AI Technical Summary
The prior art has problems such as high development costs, low development efficiency, insufficient flexibility and inability to effectively utilize existing stored procedures in the database in the database.
Through the Java-based dynamic database to API mapping method, the Java reflection mechanism and Javassist bytecode technology are used to dynamically generate API interfaces and register them in the application context, realizing the automated integration of database and API.
It significantly reduces coding requirements, improves development efficiency, supports multiple database types, enhances flexibility, simplifies the call of stored procedures, reduces system maintenance costs, and achieves rapid iteration and efficient integration.
Smart Images

Figure CN119621828A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of database technology, and in particular to a Java-based database to API dynamic mapping method, device, equipment and medium. Background Art
[0002] In modern applications, the interaction between databases and APIs is becoming increasingly important. Currently, many companies face the following technical issues when integrating with databases:
[0003] 1. High cost of connecting to traditional systems: When enterprises connect to existing old systems or third-party services, they usually need to spend a lot of time and manpower to manually write interface codes, which greatly increases development costs.
[0004] 2. Low development efficiency: Existing development methods often require repetitive writing of a large amount of similar code, especially in the process of mapping databases to APIs. This not only consumes developers’ time, but also easily leads to human errors and increases the difficulty of system maintenance.
[0005] 3. Lack of flexibility: Existing solutions often have a strong dependence on specific database types or API modes, which means that redevelopment must be done when the database needs to be replaced or the API needs to be modified, increasing the complexity and cost of system maintenance.
[0006] 4. Insufficient support for stored procedures: Many companies already have a large number of stored procedures in their databases, but existing technologies often cannot effectively map these stored procedures to APIs, making it impossible for companies to fully utilize existing resources. Summary of the invention
[0007] The present invention provides a Java-based database to API dynamic mapping method, device, equipment and medium to significantly improve the integration efficiency between the database and the API.
[0008] According to one aspect of the present invention, a Java-based dynamic database to API mapping method is provided, comprising:
[0009] Determine and store the database driver of the target database, and obtain connection information of the target database;
[0010] Based on the database driver and the connection information, a data source object corresponding to the target database is created using a Java reflection mechanism, and the data source object is registered in a connection pool;
[0011] Obtain the interface information corresponding to the target API interface, wherein the interface information includes the API request path, request method, data source object, and database operation;
[0012] A controller class corresponding to the target API interface is generated according to the interface information, so as to process the target API request based on the controller class.
[0013] In a possible implementation, determining and storing a database driver of a target database includes:
[0014] Based on the user's operation on the front-end setting interface, the database driver uploaded by the user is determined, and the database driver is persistently stored.
[0015] In a possible implementation, obtaining the connection information of the target database includes: obtaining the connection information of the target database based on a configuration operation performed by a user in a front-end page, wherein the configuration operation includes: inputting the connection information of the database, and the connection information includes a URL, a user name, and a password.
[0016] In one possible implementation, the connection pool includes a data source object corresponding to at least one type of database; the database is Oracle, SQL Server, MySQL, PostGresql or DAMO database.
[0017] In one possible implementation, obtaining interface information corresponding to the target API interface includes: obtaining an API request path, request method, target data source object, and database operation corresponding to the target API interface defined by a user on a front-end page; and determining the API request path, request method, data source object, and database operation as the interface information.
[0018] In a possible implementation, generating a controller class corresponding to the target API interface according to the interface information includes: dynamically generating a controller class corresponding to the target API interface through javassist bytecode technology according to the interface information; and automatically registering the controller class into the application context through Spring Framework.
[0019] In a possible implementation, the processing of the target API request based on the controller class includes: performing an operation on the target database according to a URL and HTTP interface corresponding to the target API request, and returning the result.
[0020] According to another aspect of the present invention, there is provided a Java-based dynamic database to API mapping device, comprising:
[0021] A database information determination module is used to determine and store the database driver of the target database and obtain the connection information of the target database;
[0022] A data source object registration module, used to create a data source object corresponding to the target database using a Java reflection mechanism based on the database driver and the connection information, and register the data source object in a connection pool;
[0023] An interface information determination module is used to obtain interface information corresponding to the target API interface, wherein the interface information includes API request path, request method, data source object and database operation;
[0024] The target API request processing module is used to generate a controller class corresponding to the target API interface according to the interface information, so as to process the target API request based on the controller class.
[0025] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0026] at least one processor;
[0027] and a memory communicatively connected to the at least one processor; wherein,
[0028] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the Java-based dynamic database to API mapping method described in any embodiment of the present invention.
[0029] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the Java-based dynamic database to API mapping method described in any embodiment of the present invention when executed.
[0030] The technical solution of the embodiment of the present invention includes: determining and storing the database driver of the target database, obtaining the connection information of the target database; based on the database driver and the connection information, using the Java reflection mechanism to create the data source object corresponding to the target database, and registering the data source object in the connection pool; obtaining the interface information corresponding to the target API interface, wherein the interface information includes the API request path, the request method, the data source object and the database operation; generating the controller class corresponding to the target API interface according to the interface information, so as to process the target API request based on the controller class. The technical solution solves the problems that the dynamic mapping of Java database to API in the prior art requires writing a large amount of code, the development efficiency is low, the flexibility is insufficient, and the existing stored procedures in the database cannot be effectively utilized. By automatically generating the corresponding API, the coding requirements are significantly reduced and the development efficiency is improved. Supporting multiple database types, it can quickly adapt to different database environments and enhance flexibility. Simplifying the stored procedure call, the system automatically handles the mapping of the stored procedure, and reduces the complexity of using the stored procedure. Rapid iteration and efficient integration, through dynamic generation of API and registration, enterprises can quickly respond to business changes, achieve rapid iteration and efficient integration, and promote the digital transformation of enterprises.
[0031] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0033] Figure 1 A flowchart of a Java-based dynamic database to API mapping method provided in Embodiment 1 of the present invention;
[0034] Figure 2 An architecture diagram of a Java-based dynamic database to API mapping system provided in Embodiment 2 of the present invention;
[0035] Figure 3 It is a structural schematic diagram of a Java-based dynamic database to API mapping device provided according to Embodiment 3 of the present invention;
[0036] Figure 4 This is a schematic diagram of the structure of an electronic device provided in Embodiment 4 of the present invention. DETAILED DESCRIPTION
[0037] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0038] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0039] Embodiment 1
[0040] Figure 1 This is a flowchart of a Java-based dynamic database to API mapping method provided in Embodiment 1 of the present invention. This embodiment can be applied to simplify the integration process between database and API. The method can be executed by a Java-based dynamic database to API mapping device / system. The device can be implemented in the form of hardware and / or software, and the device can be configured in a computer device. Figure 1 As shown, the method specifically comprises the following steps:
[0041] S110: Determine and store a database driver of a target database, and obtain connection information of the target database.
[0042] The target database may be a database that needs to map an API; the database driver may be a database driver of the target database; and the connection information may be understood as information required to connect to the target database. For example, the connection information may include but is not limited to the URL of the target database.
[0043] In a possible implementation, determining and storing a database driver of a target database includes: based on an operation of a user in a front-end setting interface, determining a database driver uploaded by the user, and persistently storing the database driver.
[0044] In an embodiment of the present invention, a Java-based dynamic database to API mapping device / system (hereinafter referred to as mapping system) can provide a front-end page, on which multiple database driver names and corresponding database versions can be displayed.
[0045] The user can select the driver name and version through the front-end page. After selecting and confirming, the database driver that matches the driver name and version can be automatically uploaded to the database of the mapping system, that is, the database driver is persistently stored.
[0046] In a possible implementation, obtaining the connection information of the target database includes: obtaining the connection information of the target database based on a configuration operation performed by a user in a front-end page.
[0047] The configuration operation includes inputting the connection information of the database, and the connection information includes the URL, user name and password.
[0048] Specifically, the mapping system can provide a front-end page, and the user can perform configuration operations through the front-end page. The configuration operation can be to enter the connection information of the target database on the front-end page, so that the connection with the target database can be established later. The connection information includes the URL of the target database and the user name and password required to log in to the target database.
[0049] S120. Based on the database driver and the connection information, create a data source object corresponding to the target database using a Java reflection mechanism, and register the data source object in a connection pool.
[0050] Specifically, based on the database driver and connection information, the mapping system can use the Java reflection mechanism to dynamically create a data source object and register it in the connection pool. In this way, the mapping system can flexibly switch between different data source environments according to needs, enhancing scalability.
[0051] For example, when connecting to a SQL Server database, the user can enter the database connection information through the front-end page, and the mapping system can use this connection information to dynamically create a SQL Server data source and register it in the connection pool. After that, the data source can be used to interact with the SQL Server database.
[0052] In one possible implementation, the connection pool includes a data source object corresponding to at least one type of database; the database is Oracle, SQL Server, MySQL, PostGresql or DAMO database.
[0053] It should be noted that data source objects of different types of databases can be registered in the connection pool, which can quickly adapt to different database environments and enhance flexibility.
[0054] S130: Obtain interface information corresponding to the target API interface.
[0055] The target API interface may be a generated API interface, based on which the target database may be accessed to perform corresponding database operations. The interface information includes the API request path, request method, data source object, and database operation.
[0056] In one possible implementation, obtaining interface information corresponding to the target API interface may include: obtaining the API request path, request method, data source object, and database operation corresponding to the target API interface defined by the user on the front-end page; and determining the API request path, request method, target data source object, and database operation as the interface information.
[0057] The target data source object may be a user-defined data source object. It is understandable that multiple data source objects are registered in the connection pool, and the user selects one of them to achieve the connection between the database and the API.
[0058] Specifically, users can define API request paths and methods on the front-end page, and specify database operations corresponding to these APIs, such as query, insert, update, etc.
[0059] S140. Generate a controller class corresponding to the target API interface according to the interface information, so as to process the target API request based on the controller class.
[0060] In a possible implementation, generating a controller class corresponding to the target API interface according to the interface information includes: dynamically generating a controller class corresponding to the target API interface through javassist bytecode technology according to the interface information; and automatically registering the controller class into the application context through Spring Framework.
[0061] Specifically, the user defines the API request method path and method on the front-end page, and specifies the corresponding database operation. The mapping system uses Javassist bytecode technology to dynamically generate controller classes based on user-defined information, and the controller classes are automatically registered in the context of the mapping system through the Spring Framework. In this way, users can access data in the database through the defined API interface path. In this way, the mapping system can quickly generate API interfaces based on user needs without having to manually write a lot of controller code.
[0062] For example, a user wants to create an API interface that can query user information. The API request method path (such as / users / {id}) can be defined on the front-end page, and the database operation corresponding to this path is to query user information, and the data source object is specified. The mapping system dynamically generates a controller class based on this information. The class contains a method for processing GET requests. This method can query user information in the database and return the result to the client, that is, processing the target API request.
[0063] In a possible implementation, processing the target API request based on the controller class may include: performing an operation on the target database according to the URL and HTTP interface corresponding to the target API request, and returning the result.
[0064] Specifically, when a request arrives, the mapping system performs corresponding database operations according to the URL and HTTP method, and returns the results to the client.
[0065] For example, when a user sends a GET request to / users / {id} through a browser or client, the system will find the corresponding controller class and method based on the URL and HTTP method (GET), and execute the method to query user information. The query result will be encapsulated into a response object and returned to the client.
[0066] The technical solution of the embodiment of the present invention includes: determining and storing the database driver of the target database, obtaining the connection information of the target database; based on the database driver and the connection information, using the Java reflection mechanism to create the data source object corresponding to the target database, and registering the data source object in the connection pool; obtaining the interface information corresponding to the target API interface, wherein the interface information includes the API request path, the request method, the data source object and the database operation; generating the controller class corresponding to the target API interface according to the interface information, so as to process the target API request based on the controller class. The technical solution solves the problems that the dynamic mapping of Java database to API in the prior art requires writing a large amount of code, the development efficiency is low, the flexibility is insufficient, and the existing stored procedures in the database cannot be effectively utilized. By automatically generating the corresponding API, the coding requirements are significantly reduced and the development efficiency is improved. Supporting multiple database types, it can quickly adapt to different database environments and enhance flexibility. Simplifying the stored procedure call, the system automatically handles the mapping of the stored procedure, and reduces the complexity of using the stored procedure. Rapid iteration and efficient integration, through dynamic generation of API and registration, enterprises can quickly respond to business changes, achieve rapid iteration and efficient integration, and promote the digital transformation of enterprises.
[0067] Embodiment 2
[0068] Figure 2 The following is an architecture diagram of a Java-based dynamic database to API mapping system provided in Embodiment 2 of the present invention. This embodiment is a preferred embodiment of the above embodiment, and its specific implementation method can refer to the technical solution of this embodiment. Among them, the technical terms that are the same or corresponding to the above embodiment are not repeated here.
[0069] The embodiment of the present invention provides a Java-based dynamic database to API mapping system. Through an automated approach, the present invention aims to simplify the integration process between the database and the API, reduce the need for manual coding, and improve development efficiency. The present invention realizes the function of automatically generating a RESTful API by utilizing the Java reflection mechanism java ssist bytecode. Developers only need to define the database model to automatically generate the corresponding API interface, covering common operations such as GET, POST, PUT, and DELETE. In addition, the present invention also supports multiple database types (such as Oracle, SQL Server, MySQL, PostGresql, and Dameng databases), and can effectively handle the mapping of (Orac le, SQL Server) stored procedures. This method can dynamically register data sources and APIs, help enterprises quickly adapt to business changes, and reduce system maintenance costs.
[0070] The present invention realizes dynamic mapping from database to API in an automated way. The core function utilizes Java reflection mechanism, annotation and Javassist bytecode technology, which simplifies the integration process between database and API, reduces the need for manual coding and improves development efficiency.
[0071] The execution process of the mapping system of this method includes the following steps:
[0072] Dynamically define database drivers: Users select and upload database drivers on the front-end page. The system persists the information of the database driver selected by the user for subsequent database operations.
[0073] Dynamically define data sources: Configure the required data source on the user front-end page, and enter the connection information (such as URL, user name, password, etc.) and database driver. The system uses the Java reflection mechanism to dynamically create a data source object and register it in the connection pool. This process ensures that the system can flexibly switch between different data source environments and enhance scalability.
[0074] Dynamically define the API interface path: define the API request path and request method on the user page, and specify the corresponding database operation. The system uses javassist bytecode technology to dynamically generate the controller class based on the user-defined information (request path, request method, data source, database operation) and store it in the system running memory.
[0075] Register as an API interface: When the generated API interface is automatically registered with the application context through the Spring Framework, dynamic request routing is implemented. When a request arrives, the system executes the corresponding database based on the URL and HTTP interface.
[0076] This paper can significantly improve the integration efficiency between database and API through a JAVA-based dynamic database to API mapping method. The specific effects include:
[0077] Developers only need to define the database model to automatically generate the corresponding RESTful API, significantly reducing the need for coding and improving development efficiency.
[0078] This method supports multiple database types (such as Oracle, SQL Server, Mysql, Postgresql and DAMO database) and can quickly adapt to different database environments to enhance flexibility.
[0079] Simplify stored procedure calls. The system automatically handles the mapping of stored procedures, reducing the complexity of using stored procedures.
[0080] Rapid iteration and efficient integration. By dynamically generating APIs and registrations, enterprises can quickly respond to business changes, achieve rapid iteration and efficient integration, and promote enterprise digital transformation.
[0081] Embodiment 3
[0082] Figure 3 This is a schematic diagram of a Java-based dynamic database to API mapping device provided in Embodiment 3 of the present invention. Figure 3 As shown, the device comprises:
[0083] The database information determination module 310 is used to determine and store the database driver information of the target database and obtain the connection information of the target database;
[0084] A data source object registration module 320 is used to create a data source object corresponding to the target database using a Java reflection mechanism based on the database driver and the connection information, and register the data source object in a connection pool;
[0085] The interface information determination module 330 is used to obtain the interface information corresponding to the target API interface, wherein the interface information includes the API request path, request method, data source object and database operation;
[0086] The target API request processing module 340 is used to generate a controller class corresponding to the target API interface according to the interface information, so as to process the target API request based on the controller class.
[0087] The technical solution of the embodiment of the present invention includes: determining and storing the database driver of the target database, obtaining the connection information of the target database; based on the database driver and the connection information, using the Java reflection mechanism to create the data source object corresponding to the target database, and registering the data source object in the connection pool; obtaining the interface information corresponding to the target API interface, wherein the interface information includes the API request path, the request method, the data source object and the database operation; generating the controller class corresponding to the target API interface according to the interface information, so as to process the target API request based on the controller class. The technical solution solves the problems that the dynamic mapping of Java database to API in the prior art requires writing a large amount of code, the development efficiency is low, the flexibility is insufficient, and the existing stored procedures in the database cannot be effectively utilized. By automatically generating the corresponding API, the coding requirements are significantly reduced and the development efficiency is improved. Supporting multiple database types, it can quickly adapt to different database environments and enhance flexibility. Simplifying the stored procedure call, the system automatically handles the mapping of the stored procedure, and reduces the complexity of using the stored procedure. Rapid iteration and efficient integration, through dynamic generation of API and registration, enterprises can quickly respond to business changes, achieve rapid iteration and efficient integration, and promote the digital transformation of enterprises.
[0088] Based on the above technical solution, the database information determination module 310 includes:
[0089] The database driver upload submodule is used to determine the database driver uploaded by the user based on the user's operation in the front-end setting interface, and to store the database driver persistently.
[0090] Based on the above technical solution, the database information determination module 310 includes:
[0091] The connection information acquisition submodule is used to acquire the connection information of the target database based on the configuration operation performed by the user in the front-end page, wherein the configuration operation includes: inputting the connection information of the database, and the connection information includes the URL, user name and password.
[0092] On the basis of the above technical solution, the connection pool includes a data source object corresponding to at least one type of database;
[0093] The database is Oracle, SQL Server, MySQL, PostGresql or DAMO database.
[0094] Based on the above technical solution, the interface information determination module 330 is specifically used to:
[0095] Obtain the API request path, request method, target data source object and database operation corresponding to the target API interface defined by the user on the front-end page;
[0096] The API request path, request method, data source object and database operation are determined as the interface information.
[0097] Based on the above technical solution, the target API request processing module 340 includes:
[0098] A controller class generation submodule is used to dynamically generate a controller class corresponding to the target API interface through javassist bytecode technology according to the interface information;
[0099] The controller class is automatically registered into the application context through Spring Framework.
[0100] Based on the above technical solution, the target API request processing module 340 includes:
[0101] The request processing submodule is used to perform operations on the target database according to the URL and HTTP interface corresponding to the target API request and return the results.
[0102] The Java-based dynamic database to API mapping device provided in the embodiment of the present invention can execute the Java-based dynamic database to API mapping method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0103] Embodiment 4
[0104] Figure 4 A schematic diagram of the structure of an electronic device provided for Embodiment 4 of the present invention. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0105] like Figure 4 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0106] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0107] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as a Java-based dynamic database to API mapping method.
[0108] In some embodiments, the Java-based dynamic database to API mapping may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the Java-based dynamic database to API mapping described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to perform the Java-based dynamic database to API mapping in any other appropriate manner (e.g., by means of firmware).
[0109] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0110] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0111] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0112] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0113] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0114] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0115] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0116] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A Java-based dynamic database to API mapping method, characterized in that: include: Determine and store the database driver of the target database, and obtain connection information of the target database; Based on the database driver and the connection information, a data source object corresponding to the target database is created using a Java reflection mechanism, and the data source object is registered in a connection pool; Obtain the interface information corresponding to the target API interface, wherein the interface information includes the API request path, request method, data source object, and database operation; A controller class corresponding to the target API interface is generated according to the interface information, so as to process the target API request based on the controller class.
2. The method according to claim 1, characterized in that The step of determining and storing the database driver of the target database includes: Based on the user's operation on the front-end setting interface, the database driver uploaded by the user is determined, and the database driver is persistently stored.
3. The method according to claim 2, characterized in that The obtaining the connection information of the target database includes: Based on the configuration operation performed by the user in the front-end page, the connection information of the target database is obtained, wherein the configuration operation includes: inputting the connection information of the database, and the connection information includes a URL, a user name and a password.
4. The method according to claim 1, characterized in that The connection pool includes at least one type of data source object corresponding to the database; The database is Oracle, SQL Server, MySQL, PostGresql or DAMO database.
5. The method according to claim 1, characterized in that The obtaining of interface information corresponding to the target API interface includes: Obtain the API request path, request method, target data source object and database operation corresponding to the target API interface defined by the user on the front-end page; The API request path, request method, data source object and database operation are determined as the interface information.
6. The method according to claim 1, characterized in that The generating a controller class corresponding to the target API interface according to the interface information includes: According to the interface information, dynamically generate a controller class corresponding to the target API interface through javassist bytecode technology; The controller class is automatically registered into the application context through Spring Framework.
7. The method according to claim 1, characterized in that The processing of the target API request based on the controller class includes: According to the URL and HTTP interface corresponding to the target API request, the operation on the target database is performed and the result is returned.
8. A Java-based dynamic database to API mapping device, characterized in that: include: A database information determination module is used to determine and store the database driver of the target database and obtain the connection information of the target database; A data source object registration module, used to create a data source object corresponding to the target database using a Java reflection mechanism based on the database driver and the connection information, and register the data source object in a connection pool; An interface information determination module is used to obtain interface information corresponding to the target API interface, wherein the interface information includes API request path, request method, data source object and database operation; The target API request processing module is used to generate a controller class corresponding to the target API interface according to the interface information, so as to process the target API request based on the controller class.
9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the Java-based dynamic database to API mapping method described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the Java-based dynamic database to API mapping method described in any one of claims 1 to 7 when executed.
Citation Information
Patent Citations
Data service mapping API interface method and system, storage medium and terminal
CN112328672A
JDBC-based multi-database access method and device, and electronic equipment
CN113641741A
Method, system and equipment for realizing connection of multiple data sources and readable medium
CN114490849A
Database information comparison method and device, electronic equipment and storage medium
CN117171214A
Cross-database query method and device, equipment, medium and computer program product
CN118796911A