Dynamic agent driven NebulaGraph graph database operation device and method
Through the dynamic proxy-driven NebulaGraph graph database operation device, the proxy classes are automatically generated and parameters and result sets are automatically processed, which solves the problem of developers writing complex Cypher statements and managing database connections, improving development efficiency and performance.
Patent Information
- Application Number
- CN202411358737.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-27
- Publication Date
- 2025-02-07
AI Technical Summary
In the prior art When using NebulaGraph graph databases, developers need to write complex Cypher statements and manually manage database connections, resulting in inefficient development and performance problems.
The NebulaGraph graph database operation device driven by dynamic proxy is automatically generated by dynamic proxy generation module, and the parameter analysis and result processing module automatically realizes the conversion of parameters to Cypher statements and the mapping of result sets, and uses performance optimization modules such as connection pool management. , paging query and batch operations improve performance.
It greatly reduces the workload of developers in writing code, improves development efficiency and code maintainability, simplifies graph data processing, and improves the access efficiency of NebulaGraph database through performance optimization measures.
Smart Images

Figure CN119397061A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of NebulaGraph graph database operation, and in particular to a dynamic proxy-driven NebulaGraph graph database operation device and method. Background Art
[0002] NebulaGraph is a powerful open source graph database management system. Its distributed architecture enables it to perform well in processing complex graph data structures and relationship queries. However, in practical applications, developers face the following challenges:
[0003] First, they need to directly write Cypher statements to operate data, which undoubtedly increases the learning cost and requires a lot of time and energy to become familiar with and master this query language.
[0004] Secondly, for each type of label and connection, developers have to write a large number of similar query statements, which not only leads to code redundancy but also makes code maintenance more difficult.
[0005] In addition, when dealing with complex data models, developers need to write a lot of configuration information, which further increases the difficulty and complexity of development.
[0006] More importantly, some existing devices have obvious performance problems when implementing graph data operations. For example, frequently creating and destroying connections will lead to a waste of resources and reduce system performance; returning too much data at one time may cause excessive memory usage or network delays, affecting user experience; inefficient data writing will lead to slow system response; improper result set processing will affect data accuracy and integrity. These problems have seriously restricted the improvement of development efficiency and system performance in practical applications, so an effective solution is urgently needed to improve them. Summary of the invention
[0007] In order to solve the above problems existing in the prior art, the present invention provides a NebulaGraph graph database operation device and method driven by a dynamic proxy to improve development efficiency and performance.
[0008] To achieve the above purpose, the present invention adopts the following technical solutions:
[0009] In one embodiment of the present invention, a dynamic proxy-driven NebulaGraph graph database operation device is proposed, the device comprising:
[0010] Dynamic proxy generation module, which is used to automatically generate corresponding dynamic proxy classes based on the DAO interface defined by the developer. These proxy classes encapsulate the interaction logic with NebulaGraph.
[0011] The parameter parsing and result processing module is used to automatically convert parameters to Cypher statements and map database return results to Java objects based on the parameter types and return value types of the DAO method declared by the developer;
[0012] The graph data operation module is used to provide common single-table CRUD operations and a series of graph data-specific operations;
[0013] Performance optimization module, used to manage NebulaGraph connections using session pool; support paging query; provide batch insert and batch update functions; select the appropriate result set processor according to the return value type of the DAO method, and different result set processors are optimized for basic types and collection types;
[0014] Extensibility modules are used to customize or extend specific functions according to requirements and are registered to the device.
[0015] Furthermore, when customizing methods in the DAO interface, you need to create a XXXDao.xml resource in the specified resource directory; when the application starts, the resource loader reads and parses the XXXDao.xml resource, obtains the method information and Cypher statement templates, and stores this information in the mapping context object in memory.
[0016] Furthermore, a dynamic proxy class is generated for the DAO interface using JDK dynamic proxy technology. The dynamic proxy class implements all methods of the DAO interface, including methods inherited from NebulaDaoBasic and custom methods. The implementation logic of the dynamic proxy class is as follows:
[0017] Parse the signature information of each method in the DAO interface and generate the corresponding Cypher statement template;
[0018] Implement a proxy method for each method in the DAO interface and complete the following operations in the proxy method:
[0019] Get the DAO method parameter value and convert it into the parameter required by the Cypher statement;
[0020] Get a Session instance from the session pool;
[0021] Use the Session instance to execute the generated Cypher statement and obtain the result set;
[0022] Map the result set to the return value type of the DAO method and return it.
[0023] In one embodiment of the present invention, a dynamic proxy-driven NebulaGraph graph database operation method is also proposed, the method comprising:
[0024] Automatically generate corresponding dynamic proxy classes based on the DAO interface defined by the developer. These proxy classes encapsulate the interaction logic with NebulaGraph.
[0025] According to the parameter types and return value types of the DAO methods declared by the developer, the conversion of parameters to Cypher statements and the mapping of database return results to Java objects are automatically implemented;
[0026] Provides common single-table CRUD operations and a series of graph data-specific operations;
[0027] Use session pool to manage NebulaGraph connections; support paging query; provide batch insert and batch update functions; select the appropriate result set processor according to the return value type of the DAO method, and different result set processors are optimized for basic types and collection types;
[0028] Customize or expand specific functions as required and register.
[0029] Furthermore, when customizing methods in the DAO interface, you need to create a XXXDao.xml resource in the specified resource directory; when the application starts, the resource loader reads and parses the XXXDao.xml resource, obtains the method information and Cypher statement templates, and stores this information in the mapping context object in memory.
[0030] Furthermore, a dynamic proxy class is generated for the DAO interface using JDK dynamic proxy technology. The dynamic proxy class implements all methods of the DAO interface, including methods inherited from NebulaDaoBasic and custom methods. The implementation logic of the dynamic proxy class is as follows:
[0031] Parse the signature information of each method in the DAO interface and generate the corresponding Cypher statement template;
[0032] Implement a proxy method for each method in the DAO interface and complete the following operations in the proxy method:
[0033] Get the DAO method parameter value and convert it into the parameter required by the Cypher statement;
[0034] Get a Session instance from the session pool;
[0035] Use the Session instance to execute the generated Cypher statement and obtain the result set;
[0036] Map the result set to the return value type of the DAO method and return it.
[0037] In one embodiment of the present invention, a computer device is also proposed, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the aforementioned dynamic proxy-driven NebulaGraph graph database operation method is designed.
[0038] In one embodiment of the present invention, a computer-readable storage medium is also proposed, which stores a computer program for executing a dynamic proxy-driven NebulaGraph graph database operation method.
[0039] Beneficial effects:
[0040] 1. The present invention provides functions such as dynamic proxy generation, parameter parsing and result processing, so developers do not need to write cumbersome Cypher statements and manually manage underlying details such as database connections, which greatly reduces the development workload and improves development efficiency.
[0041] 2. The present invention provides a clear interface and encapsulation, enabling developers to operate graph data in an object-oriented manner, making the code structure more concise, easy to read, and convenient for maintenance and expansion.
[0042] 3. The present invention provides a series of operations specific to graph data, such as obtaining associated nodes based on node IDs, which greatly simplifies developers' processing of graph data and enables them to focus on the development of business logic.
[0043] 4. The present invention effectively improves the access efficiency of the NebulaGraph database through connection pool management, paging query, batch operation and result set processing optimization, and can meet the needs of various complex application scenarios.
[0044] 5. The present invention adopts a modular design, and developers can customize or expand specific functions according to needs, such as custom parameter parsers, result processors, etc., which improves the adaptability of the device. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] Figure 1 This is a diagram of the architecture of the NebulaGraph graph database operation device driven by a dynamic proxy of the present invention;
[0046] Figure 2 It is a schematic diagram of the process flow of the NebulaGraph graph database operation method driven by a dynamic proxy of the present invention;
[0047] Figure 3 It is a schematic diagram of the computer device structure of the present invention. DETAILED DESCRIPTION
[0048] The principles and spirit of the present invention will be described below with reference to several exemplary embodiments. It should be understood that these embodiments are provided only to enable those skilled in the art to better understand and design the present invention, and are not intended to limit the scope of the present invention in any way. On the contrary, these embodiments are provided to make the present disclosure more thorough and complete, and to fully convey the scope of the present disclosure to those skilled in the art.
[0049] Those skilled in the art will appreciate that the embodiments of the present invention may be designed as a device, apparatus, equipment, method or computer program product. Therefore, the present disclosure may be specifically designed in the following forms, namely: complete hardware, complete software (including firmware, resident software, microcode, etc.), or a combination of hardware and software.
[0050] According to an embodiment of the present invention, a dynamic proxy-driven NebulaGraph graph database operation device is proposed. Through the collaborative operation of functional modules such as dynamic proxy generation, parameter parsing and result processing, graph data operation, performance optimization and scalability, it can effectively solve the problems existing in the prior art and improve development efficiency and performance.
[0051] The principle and spirit of the present invention are explained in detail below with reference to several representative embodiments of the present invention.
[0052] Figure 1 This is a diagram of the architecture of the NebulaGraph graph database operation device driven by a dynamic proxy of the present invention. Figure 1 As shown, the device mainly includes the following functional modules:
[0053] 1. Dynamic proxy generation module: According to the DAO interface defined by the developer, the corresponding dynamic proxy class is automatically generated; these proxy classes encapsulate the interaction logic with NebulaGraph. Developers only need to define the DAO interface method to complete various operations on NebulaGraph. The DAO interface (Data Access Object Interface) here refers to the interface defined by the developer to interact with the NebulaGraph graph database. The DAO interface is used to encapsulate the access logic to the database, and it usually contains some method declarations for operations such as query, update, and delete.
[0054] 2. Parameter parsing and result processing module: Provides a flexible parameter parsing and result processing mechanism. Developers can declare the parameter type and return value type of the DAO method through annotations or XML configuration. The device will automatically convert parameters to Cypher statements and map the database return results to Java objects.
[0055] 3. Graph data operation module: In addition to the common single-table CRUD operations, it also provides a series of operations unique to graph data, such as obtaining related nodes based on node IDs, obtaining starting nodes based on relationship types, etc., which greatly simplifies developers' processing of graph data. CRUD here is an abbreviation of the first letters of the four English words Create, Read, Update, and Delete, which are usually used to describe the four most basic operations in database operations. In a graph database, CRUD operations can be understood as basic operations on graph data: Create: create new nodes or edges; Read: query or retrieve information about existing nodes or edges; Update: modify the properties of existing nodes or edges; Delete: remove nodes or edges.
[0056] 4. Performance optimization module:
[0057] (1) Connection pool management: Use session pool to manage NebulaGraph connections to avoid frequent creation and destruction of connections and improve connection utilization. The session pool implements a strategy of regular inspection and automatic release of expired sessions to ensure connection availability.
[0058] (2) Paginated query: Paginated query is supported. Developers can pass pagination parameters in the DAO method. The device will automatically add SKIP and LIMIT clauses in the Cypher statement to reduce the problem of returning too much data at one time.
[0059] (3) Batch operations: Batch insert and batch update functions are provided. After the developer passes in the entity list, the device will generate a single INSERT or UPDATE statement, which greatly improves the efficiency of data writing. The entity here is a node or an edge. For example, in a social network application, the entity list may be a group of users (nodes) or a group of relationships between users (edges). Batch insert and batch update operations allow developers to process multiple entities at once, rather than one by one. This means that you can insert a group of user data (for example, 1,000 users) into the database as a whole, rather than sending an insert statement for each user. Similarly, batch updates also allow you to update the status of a group of entities at once, rather than updating them one by one. The benefit of this batch processing method is that it can significantly improve the efficiency of data writing because the number of interactions with the database is reduced. For example, without batch operations, inserting 1,000 pieces of data may require sending 1,000 separate insert requests, but when using batch operations, these data can be inserted with a single request, which can greatly reduce network communication and database processing time.
[0060] (4) Result set processing optimization: Select the appropriate result set processor according to the return value type of the DAO method. Different result set processors are optimized for basic types and collection types to avoid unnecessary data conversion and improve processing efficiency.
[0061] (5) Extensibility module. The device adopts a modular design. Each functional module is relatively independent. Developers can customize or expand specific functions according to their needs, such as custom parameter parsers, result processors, etc., and register them in the device.
[0062] The term "module" used above may be a combination of software and / or hardware designed to implement a predetermined function. Although the devices described in the following embodiments are preferably designed with software, hardware, or a combination of software and hardware, is also possible and contemplated.
[0063] It should be noted that although several modules of the dynamic proxy-driven NebulaGraph graph database operation device are mentioned in the above detailed description, this division is only exemplary and not mandatory. In fact, according to an embodiment of the present invention, the features and functions of two or more modules described above can be concretized in one module. Conversely, the features and functions of one module described above can be further divided into multiple modules for concretization.
[0064] In order to explain the above-mentioned dynamic proxy-driven NebulaGraph graph database operation device more clearly, a specific embodiment is used for illustration below. However, it should be noted that this embodiment is only for better illustrating the present invention and does not constitute an improper limitation to the present invention.
[0065] Example:
[0066] 1. Dynamic proxy generation
[0067] Dynamic proxy is one of the core functions of this device. The device will automatically generate the corresponding dynamic proxy class according to the DAO interface defined by the developer. These proxy classes are responsible for interacting with the NebulaGraph database, including parameter parsing, Cypher statement generation, result set processing and other logic.
[0068] First, the developer defines a DAO interface. This interface can inherit the NebulaDaoBasic interface provided by the present invention to obtain basic CRUD methods. It can also customize methods in the DAO interface. When customizing methods, XXXDao.xml resources must be created in the specified resource directory. When the application starts, the present invention will read and parse the developer's self-built XXXDao.xml resource through the resource loader (MapperResourceLoader), obtain the method information and Cypher statement templates therein, and store this information in the mapping context object (MapperContext) in the memory for subsequent dynamic proxy use. Use JDK dynamic proxy technology to generate a dynamic proxy class for the DAO interface. This dynamic proxy class will implement all methods of the DAO interface, including methods inherited from NebulaDaoBasic and customized methods.
[0069] The implementation logic of the dynamic proxy class is as follows:
[0070] (1) Parse the signature information of each method in the DAO interface, including method name, parameter type, return value type, etc.
[0071] (2) Generate the corresponding Cypher statement template according to the signature information of each method in the parsed DAO interface. For the selectById method, a Cypher statement similar to MATCH(n: entity name) WHERE id(n) == $id RETURN n may be generated.
[0072] (3) Implement a proxy method for each method in the DAO interface and complete the following operations in the proxy method:
[0073] Get the DAO method parameter value and convert it into the parameter required by the Cypher statement.
[0074] Get a Session instance from the session pool.
[0075] Use the Session instance to execute the generated Cypher statement and obtain the result set.
[0076] Map the result set to the return value type of the DAO method, such as List <user>.
[0077] Returns the mapped result.
[0078] The advantage of dynamic proxy is that developers only need to define DAO interface without writing any Cypher statements or manually managing database connection and other underlying details. The device will automatically generate proxy class, shielding these complex operations, greatly improving development efficiency. At the same time, the proxy class can be flexibly extended, such as adding paging query, batch operation and other functions, enhancing the scalability of the device.
[0079] The following example illustrates the principle of dynamic proxy:
[0080] Assume that the developer defines a PlayerDao interface as follows:
[0081] public interface PlayerDao extends NebulaDaoBasic <player>{
[0082] List <player>list(Player player);
[0083] void create(Player player);
[0084] }
[0085] This interface inherits the NebulaDaoBasic interface provided by the present invention and defines two custom methods.
[0086] When we call playerDao.list({age: 21}) in the code, the following process occurs:
[0087] (1) The JDK dynamic proxy mechanism will be used to generate a dynamic proxy class for the PlayerDao interface.
[0088] (2) The dynamic proxy class implements all methods of the PlayerDao interface, such as the list(Player player) method.
[0089] (3) When the list method is called, the method of the dynamic proxy class is actually called.
[0090] (4) The list method of the dynamic proxy class does the following:
[0091] a. Parse the method signature, including method name, parameter type, etc. b. Generate the corresponding Cypher statement based on the method signature. In this example, a Cypher statement similar to this is generated:
[0092] MATCH(n:Player)WHERE n.age==21RETURN n
[0093] c. Get a Session instance from the session pool. d. Use the Session instance to execute the generated Cypher statement and get the result set. e. Map the result set to a List <player>object and returns it.
[0094] (5) Finally, the caller of the playerDao.list({age: 21}) method will receive the List returned by the dynamic proxy class. <user>result.
[0095] The calling process for the create method is similar:
[0096] (1) The dynamic proxy class parses the signature of the create(Player player) method.
[0097] (2) Generate the corresponding INSERT Cypher statement based on the method name and parameter information.
[0098] (3) Obtain the Session instance, execute the INSERT statement, and insert the Player object into the graph database.
[0099] (4) The method call returns, and no result needs to be returned.
[0100] Through this dynamic proxy method, the encapsulation of graph database operations is realized. Developers only need to define a clean and concise DAO interface without writing cumbersome Cypher statements and result mapping codes. The dynamic proxy class will automatically generate and execute the corresponding Cypher statement based on the DAO interface method information, and finally return the result.
[0101] This dynamic proxy mechanism greatly improves development efficiency and also enhances the flexibility and scalability of the device. Developers can customize SQL statement generation, result mapping and other functions according to their needs to meet various complex business needs.
[0102] 2. Parameter parsing and result processing
[0103] Parameter parsing and result processing is another key module of the device. Developers can declare the parameter type and return value type of the DAO method through annotations, and the device will automatically complete the conversion of parameters to Cypher statements and the mapping of database return results to Java objects.
[0104] The implementation logic of parameter parsing is as follows:
[0105] (1) When a method in the DAO interface is called, the device will obtain the parameter information of the method, including the number and type of parameters.
[0106] (2) Based on the method signature and configured parameter mapping rules, the device determines the corresponding placeholder (such as ${parameter name}) for each parameter in the SQL statement.
[0107] (3) Traverse the parameter type array and process each parameter:
[0108] If the parameter is modified by the @Param annotation, the name specified by the annotation is used as the parameter name.
[0109] If the parameter is not modified by an annotation, the format of "p{index}" is used as the parameter name.
[0110] Convert parameter values to a format that can be used by Cypher statements, such as converting a Java object to a Map.
[0111] (4) Assemble all parameters into a parameter map for use in Cypher statement rendering.
[0112] The implementation logic of result processing is as follows:
[0113] (1) Select the appropriate result set handler according to the return value type of the method. The device has built-in multiple common handlers, such as NumberResultHandler, StringResultHandler, CollectionMapResultHandler, etc. Developers can also customize handlers. (2) Call the selected handler to convert the ResultSet returned by the database into a Java object. The processing process includes:
[0114] Check the status of the ResultSet to ensure that the query was successful.
[0115] Create an appropriate container object (List, Map, etc.) based on the return value type.
[0116] Iterate over the ResultSet, convert each record into a Java object, and add it to the container.
[0117] (3) Return the processed Java object.
[0118] The advantage of parameter parsing and result processing is that developers do not need to write tedious parameter binding and result mapping code, and the device will automatically complete these tasks according to the method signature. At the same time, the device provides a flexible extension mechanism, and developers can customize parameter parsers and result processors according to their needs, further improving development efficiency.
[0119] For example, suppose we have a PlayerDao interface that defines a method findByName(Stringname), and the following query statement is configured in the corresponding XML mapping file:
[0120] <select id="findbyname"parametertype="string"resulttype="player">
[0121] MATCH(n:Play)WHERE n.name==$name RETURN n
[0122] < / select>
[0123] When calling playerDao.findByName("Jack"), the device will parse the parameter "Jack", replace it in the Cypher statement to generate MATCH(n:Play)WHERE n.name==$name RETURN n, and then execute the statement. After the execution result is returned, each row of data in the result set will be mapped to the attribute value of the Player object according to the configuration of resultType, and finally a Player object will be returned.
[0124] 3. Graph Data Operation
[0125] The present invention provides a base class NebulaDaoBasic, which is a powerful graph database operation base class. It provides developers with a series of out-of-the-box methods, greatly simplifying the development process of graph data applications. This class is an abstract class. The base class encapsulates common single-table CRUD operations, such as querying based on primary keys, batch insertion, etc. These methods can meet the needs of most single-table operations. Developers only need to inherit the base class in a custom DAO interface, and the device will automatically generate the corresponding implementation. In addition to common single-table CRUD operations, this class also provides a wealth of graph data-specific functions, such as inserting edges, querying related nodes, calculating the shortest path, etc., allowing developers to operate complex graph data structures in an object-oriented manner without paying too much attention to the underlying Cypher statement writing. The device will automatically generate Cypher statements for accessing graph data. These operations greatly simplify the developer's processing of graph data, allowing developers to focus on the development of business logic without paying too much attention to the underlying graph database operations.
[0126] Taking obtaining the associated nodes according to the node ID as an example, the implementation logic is as follows:
[0127] (1) The developer defines the following method in the DAO interface:
[0128] List <t>listStartNodes(Class<?>edgeType, I endId);
[0129] Where T represents the entity type of the starting node, and I represents the type of the node ID.
[0130] (2) When the device parses the DAO interface, it extracts the method information, including the method name, parameter types, return value type, etc., and constructs a MethodModel object. The MethodModel object here is a model object used to represent the method in the DAO interface. It contains key information about the method, such as the method name, parameter types, return value type, etc. When the device parses the DAO interface, it extracts this information for each method and creates a MethodModel object to save this data.
[0131] (3) In the invoke method of the dynamic proxy, the invoke method refers to a core method implemented by the dynamically generated proxy class in the Java dynamic proxy. When the method in the DAO interface is called through the proxy object, the invoke method of the dynamic proxy is actually called. This method is part of the java.lang.reflect.InvocationHandler.invoke() method in the Java reflection API. It is the key to implementing dynamic proxy. The device will dynamically generate query statements based on the Cypher statement template in the MethodModel:
[0132] MATCH(n:`$startVertexName`)-[r:`$edgeName`]->(n2)WHERE id(n2)=$endId
[0133] RETURN
[0134] Among them, $startVertexName and $edgeName are the entity name and relationship name extracted from the parameter type.
[0135] (4) The device calls the parameter parser to convert the method parameters into the parameter map required by the Cypher statement, then executes the query and returns the result.
[0136] (5) Finally, the device calls the result processor to convert the query results into a list of Java entity objects.
[0137] This implementation of graph data operations greatly simplifies the work of developers. Developers only need to define the corresponding methods in the DAO interface, and the device can automatically generate Cypher statements to access graph data and complete the mapping of results to Java objects. At the same time, the device also provides other graph data operations, such as obtaining the starting node according to the relationship type, shortest path query, etc., so that developers can process graph data efficiently.
[0138] 4. Performance optimization
[0139] In order to improve the performance of the device, the present invention also makes the following optimizations:
[0140] (1) Connection pool management: The device uses a session pool to manage NebulaGraph connections, avoiding frequent creation and destruction of connections and improving connection utilization. The implementation of the session pool adopts a strategy of regular inspection and automatic release of expired sessions to ensure the availability of connections.
[0141] Suppose there are a large number of frequent database operation requests in the system. Without connection pool management, each operation needs to create a new connection, and then destroy the connection after the operation is completed, which will lead to a lot of resource consumption and time waste. After using the session pool to manage NebulaGraph connections, the session pool will pre-create a certain number of connections and keep these connections active. When there is a database operation request, the available connection is directly obtained from the session pool, and the connection is returned to the session pool after use for other requests. This avoids the overhead of frequent creation and destruction of connections, improves connection utilization, and thus improves system performance.
[0142] (2) Paginated query: The device supports paginated query. Developers can pass in pagination parameters (such as page number and page size) in the DAO method. The device will automatically add SKIP and LIMIT clauses to the Cypher statement to reduce the problem of returning too much data at one time.
[0143] For example, there is a query requirement to obtain a large amount of data, but returning all the data at once may cause excessive memory usage or network transmission delays. At this time, the developer can pass in paging parameters in the DAO method, such as the page number is 2 and the page size is 50. The device will automatically add SKIP and LIMIT clauses to the Cypher statement and generate a query statement similar to "MATCH...RETURN n SKIP 50LIMIT 50". In this way, data can be obtained in batches, reducing the problem of returning too much data at one time, and improving the efficiency and response speed of the query.
[0144] (3) Batch operations: The device provides batch insert and batch update functions. Developers can pass in a list of entities, and the device will generate a single INSERT or UPDATE statement, greatly improving data writing efficiency.
[0145] Suppose you need to insert 1,000 entity data. Without the batch operation function, you may need to execute 1,000 separate insert statements, which will bring great performance overhead. After using the batch insert function provided by the device, developers can pass in a list of 1,000 entities, and the device will generate a single INSERT statement, such as "INSERT...(values1), (values2), ...(values1000)", which greatly improves the efficiency of data writing.
[0146] (4) Result set processing optimization: The device will select the appropriate result set processor according to the return value type of the DAO method. Different result set processors are optimized for basic types, collection types, etc., avoiding unnecessary data conversion and improving processing efficiency.
[0147] For example, for basic types (such as integers and strings), the result set processor will directly extract the corresponding values, avoiding unnecessary data conversion and object creation. For collection types (such as lists and maps), the result set processor will efficiently traverse the ResultSet (the result set returned after the database query operation), convert each record into a corresponding Java object and add it to the collection, improving processing efficiency.
[0148] Through the above performance optimization measures, the device can effectively improve the access efficiency of the NebulaGraph database and meet the needs of various complex application scenarios.
[0149] 5. Scalability
[0150] The device adopts a modular design, and each functional module is relatively independent. Developers can customize or expand specific functions according to needs, such as custom parameter parsers, result processors, etc.
[0151] For example, if the developer needs to support a special data type, he can implement a new ResultHandler and register it with the device. When the device processes the result set of this type, it will call the custom ResultHandler for conversion.
[0152] Alternatively, if the developer needs to perform special formatting on the parameters, they can implement a new ArgNameFormatter (parameter name formatter) and register it with the device. When the device parses the parameters, it will use the custom ArgNameFormatter for conversion.
[0153] This scalability not only improves the adaptability of the device, but also reduces the learning cost for developers. Developers only need to focus on their business needs without having to deeply understand the internal implementation details of the device.
[0154] Based on the same inventive concept, the present invention also proposes a dynamic proxy-driven NebulaGraph graph database operation method. The implementation of the method can refer to the implementation of the above-mentioned device, and the repeated parts will not be repeated.
[0155] Figure 2 The following is a schematic diagram of the process flow of the NebulaGraph graph database operation method driven by a dynamic proxy of the present invention. Figure 2 As shown, the method includes:
[0156] When developers define DAO interfaces and customize methods in DAO interfaces, they need to create XXXDao.xml resources in the specified resource directory. When the application starts, the resource loader reads and parses the XXXDao.xml resources, obtains the method information and Cypher statement templates, and stores this information in the mapping context object in memory.
[0157] Use JDK dynamic proxy technology to generate a dynamic proxy class for the DAO interface and call the DAO interface method; the proxy method of the dynamic proxy class is executed as follows:
[0158] Parse the signature information of each method in the DAO interface and generate the corresponding Cypher statement template;
[0159] Implement a proxy method for each method in the DAO interface and complete the following operations in the proxy method:
[0160] Get the DAO method parameter value and convert it into the parameter required by the Cypher statement;
[0161] Get a Session instance from the session pool;
[0162] Use the Session instance to execute the generated Cypher statement and obtain the result set;
[0163] Map the result set to the return value type of the DAO method and return it.
[0164] It should be noted that, although the operations of the method of the present invention are described in a specific order in the above embodiments and the accompanying drawings, this does not require or imply that the operations must be performed in the specific order, or that all the operations shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps.
[0165] Based on the above invention concept, Figure 3 As shown, the present invention also proposes a computer device 200, including a memory 210, a processor 220, and a computer program 230 stored in the memory 210 and executable on the processor 220. When the processor 220 executes the computer program 230, the aforementioned dynamic proxy-driven NebulaGraph graph database operation method is designed.
[0166] Based on the aforementioned inventive concept, the present invention further proposes a computer-readable storage medium, which stores a computer program for executing the aforementioned dynamic proxy-driven NebulaGraph graph database operation method.
[0167] The highlights of the dynamic proxy-driven NebulaGraph graph database operation device and method proposed in the present invention are:
[0168] 1. Improve development efficiency: Through functions such as dynamic proxy generation, parameter parsing and result processing, developers do not need to write cumbersome Cypher statements and manually manage underlying details such as database connections, which greatly reduces the development workload and improves development efficiency.
[0169] 2. Enhance code maintainability: The device provides clear interfaces and encapsulation, allowing developers to operate graph data in an object-oriented manner. The code structure is more concise and easy to read, and is easy to maintain and expand.
[0170] 3. Simplified graph data processing: It provides a series of graph data-specific operations, such as obtaining associated nodes based on node IDs, which greatly simplifies developers' processing of graph data and enables them to focus on the development of business logic.
[0171] 4. Optimize performance: Through connection pool management, paging query, batch operation and result set processing optimization, the access efficiency of NebulaGraph database is effectively improved to meet the needs of various complex application scenarios.
[0172] 5. Strong scalability: With modular design, developers can customize or expand specific functions according to needs, such as custom parameter parsers, result processors, etc., which improves the adaptability of the device.
[0173] Although the spirit and principle of the present invention have been described with reference to several specific embodiments, it should be understood that the present invention is not limited to the disclosed specific embodiments, and the division of various aspects does not mean that the features in these aspects cannot be combined to benefit, and such division is only for the convenience of expression. The present invention is intended to cover various modifications and equivalent arrangements contained in the spirit and scope of the attached claims.
[0174] Regarding the limitation of the protection scope of the present invention, those skilled in the art should understand that, based on the technical solution of the present invention, various modifications or variations that can be made by those skilled in the art without creative work are still within the protection scope of the present invention.< / t> < / user> < / player> < / player> < / player> < / user>
Claims
1. A NebulaGraph graph database operation device driven by a dynamic proxy, characterized in that: The device includes: Dynamic proxy generation module, which is used to automatically generate corresponding dynamic proxy classes based on the DAO interface defined by the developer. These proxy classes encapsulate the interaction logic with NebulaGraph. The parameter parsing and result processing module is used to automatically convert parameters to Cypher statements and map database return results to Java objects based on the parameter types and return value types of the DAO method declared by the developer; The graph data operation module is used to provide common single-table CRUD operations and a series of graph data-specific operations; Performance optimization module, used to manage NebulaGraph connections using session pool; support paging query; provide batch insert and batch update functions; select the appropriate result set processor according to the return value type of the DAO method, and different result set processors are optimized for basic types and collection types; Extensibility modules are used to customize or extend specific functions according to requirements and are registered to the device.
2. The NebulaGraph graph database operation device driven by a dynamic proxy according to claim 1, characterized in that: When you customize methods in the DAO interface, you need to create a XXXDao.xml resource in the specified resource directory. When the application starts, the resource loader reads and parses the XXXDao.xml resource to obtain the method information and Cypher statement templates, and stores this information in the mapping context object in memory.
3. The NebulaGraph graph database operation device driven by a dynamic proxy according to claim 1, characterized in that: Use JDK dynamic proxy technology to generate a dynamic proxy class for the DAO interface. This dynamic proxy class implements all methods of the DAO interface, including methods inherited from NebulaDaoBasic and custom methods. The implementation logic of this dynamic proxy class is as follows: Parse the signature information of each method in the DAO interface and generate the corresponding Cypher statement template; Implement a proxy method for each method in the DAO interface and complete the following operations in the proxy method: Get the DAO method parameter value and convert it into the parameter required by the Cypher statement; Get a Session instance from the session pool; Use the Session instance to execute the generated Cypher statement and obtain the result set; Map the result set to the return value type of the DAO method and return it.
4. A method for operating a NebulaGraph graph database driven by a dynamic proxy, characterized in that: The method includes: Automatically generate corresponding dynamic proxy classes based on the DAO interface defined by the developer. These proxy classes encapsulate the interaction logic with NebulaGraph. According to the parameter types and return value types of the DAO methods declared by the developer, the conversion of parameters to Cypher statements and the mapping of database return results to Java objects are automatically implemented; Provides common single-table CRUD operations and a series of graph data-specific operations; Use session pool to manage NebulaGraph connections; support paging query; provide batch insert and batch update functions; select the appropriate result set processor according to the return value type of the DAO method, and different result set processors are optimized for basic types and collection types; Customize or expand specific functions as required and register.
5. The method for operating a NebulaGraph graph database driven by a dynamic proxy according to claim 4, characterized in that: When you customize methods in the DAO interface, you need to create a XXXDao.xml resource in the specified resource directory. When the application starts, the resource loader reads and parses the XXXDao.xml resource to obtain the method information and Cypher statement templates, and stores this information in the mapping context object in memory.
6. The method for operating a NebulaGraph graph database driven by a dynamic proxy according to claim 4, characterized in that: Use JDK dynamic proxy technology to generate a dynamic proxy class for the DAO interface. This dynamic proxy class implements all methods of the DAO interface, including methods inherited from NebulaDaoBasic and custom methods. The implementation logic of this dynamic proxy class is as follows: Parse the signature information of each method in the DAO interface and generate the corresponding Cypher statement template; Implement a proxy method for each method in the DAO interface and complete the following operations in the proxy method: Get the DAO method parameter value and convert it into the parameter required by the Cypher statement; Get a Session instance from the session pool; Use the Session instance to execute the generated Cypher statement and obtain the result set; Map the result set to the return value type of the DAO method and return it.
7. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 4 to 6 is implemented.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program for executing the method according to any one of claims 4 to 6.
Citation Information
Cited By
Dynamically loading graph database for fast queries
WO2025265074A1