A database management method and device, electronic equipment and readable storage medium

By acquiring and utilizing annotation data from business modules, the business database is automatically built and managed, solving the problem of low efficiency in manual database sharding and improving the efficiency and stability of database management.

CN116881222BActive Publication Date: 2026-04-28SHENZHEN WORKEC TECH
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SHENZHEN WORKEC TECH
Filing Date
2023-07-07
Publication Date
2026-04-28

AI Technical Summary

Technical Problem

In existing technologies, manually performing database sharding is inefficient, and improper use of the database engine may lead to memory spikes and memory overflows.

Method used

By acquiring annotation data from various business modules, including class name annotations and attribute annotations, the system builds and manages the corresponding business databases for each business module, automating the database sharding and management process.

Benefits of technology

It improves the efficiency of database management, avoids memory spikes, and ensures the stability and high performance of the database.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116881222B_ABST
    Figure CN116881222B_ABST
Patent Text Reader

Abstract

The application is suitable for the technical field of database management, and provides a database management method, device, electronic equipment and readable storage medium, the method comprises the following steps: obtaining annotation data corresponding to each business module, wherein the annotation data comprises class name annotation and attribute annotation; constructing a business database corresponding to each business module according to the class name annotation and the attribute annotation; and performing database management based on the business database corresponding to each business module. The business database corresponding to each business module is constructed through the annotation data corresponding to each business module, and the database management of the business database corresponding to each business module is performed, so that the problem that the work efficiency of manually performing database management is not high in the optimization of the database in the database management is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of database management technology, and particularly relates to a database management method, apparatus, electronic device, and readable storage medium. Background Technology

[0002] SQLite is an embedded relational database engine widely used in mobile applications and other lightweight applications. As client-side business logic becomes increasingly complex, the number of SQLite tables used increases, along with the data volume. In certain situations, if a single table experiences a surge in batch inserts, other tables may become locked, preventing CRUD operations. Optimizing the database and manually implementing database sharding are solutions that developers must handle themselves, as sharding strategies are often inefficient and can lead to memory spikes and overflow issues if the database engine is used improperly. Summary of the Invention

[0003] This invention provides a database management method aimed at solving the problem of low efficiency in existing database optimization and manual database sharding processes. By constructing business databases corresponding to each business module using annotation data, and then managing these business databases, the method addresses the inefficiency of optimizing databases and manually managing database sharding.

[0004] This invention is implemented as follows: a database management method is provided, comprising the following steps:

[0005] Obtain the annotation data corresponding to each business module, wherein the annotation data includes class name annotations and attribute annotations;

[0006] Construct a business database corresponding to each business module based on the class name annotation and the attribute annotation;

[0007] Database management is performed based on the business databases corresponding to each of the aforementioned business modules.

[0008] Optionally, obtaining the annotation data corresponding to each business module includes:

[0009] Obtain business information from each business module;

[0010] Based on the business information, the corresponding class name annotation and attribute annotation are determined. The class name annotation includes library name parameters and table name parameters, and the attribute annotation includes column name, column type, and column default value.

[0011] Optionally, the step of constructing the business database corresponding to each business module based on the class name annotation and the attribute annotation includes:

[0012] Generate database code based on the database name parameter, and generate an initial database based on the database code;

[0013] Generate database table code based on the table name parameter, and generate an initial database table in the initial database based on the database table code;

[0014] Based on the column name, the column type, and the column default value, attribute column fields are generated in the initial database table to obtain the business database table;

[0015] The business database for each business module is obtained based on the business data tables corresponding to each business module.

[0016] Optionally, the database management based on the business database corresponding to each business module includes:

[0017] Upon detecting that a business module is enabled, the corresponding business database for that business module is enabled.

[0018] When a business module is detected to be closed, the business database corresponding to that business module is closed.

[0019] Optionally, the database management based on the business database corresponding to each business module includes:

[0020] When an external interface of a business module is detected to be called, it is determined whether the business module has been destroyed.

[0021] If the business module is destroyed, the business database corresponding to the business module is opened so that the caller of the external interface can obtain the result set of the business database;

[0022] If the business module is not destroyed, the caller of the external interface can directly obtain the result set through the business database corresponding to the business module.

[0023] Optionally, the database management based on the business database corresponding to each business module includes:

[0024] When the business module starts, it scans for updated annotation data;

[0025] Based on the updated annotation data, the business database corresponding to the business module is updated and managed.

[0026] Optionally, the step of updating and managing the business database corresponding to the business module based on the updated annotation data includes:

[0027] Based on the updated database name parameter, determine whether it exists in the business database corresponding to the updated database name parameter;

[0028] If a business database exists that corresponds to the updated database name parameter, then the existence of a business database table that corresponds to the updated table name parameter is determined based on the updated table name parameter.

[0029] If a business database table exists that corresponds to the updated table name parameter, then the business database table is updated and managed according to the updated attribute annotations.

[0030] If there is no business database table corresponding to the updated table name parameter, then the business database is updated and managed according to the updated table name parameter and the updated attribute annotation.

[0031] If no business database exists corresponding to the updated database name parameter, then the business database corresponding to the business module is constructed based on the updated database name parameter, the updated table name parameter, and the updated attribute annotation.

[0032] This invention also provides a database management device, comprising:

[0033] The acquisition module is used to acquire annotation data corresponding to each business module. The annotation data includes class name annotations and attribute annotations.

[0034] The construction module is used to construct the business database corresponding to each business module based on the class name annotation and the attribute annotation;

[0035] The management module is used for database management based on the business databases corresponding to each of the business modules.

[0036] This invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and capable of running on the processor, wherein the processor executes the computer program to implement a database management method as described in any embodiment.

[0037] This invention also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements a database management method as described in any embodiment.

[0038] The beneficial effects achieved by this invention are as follows: This application obtains annotation data corresponding to each business module, the annotation data including class name annotations and attribute annotations; constructs a business database corresponding to each business module based on the class name annotations and attribute annotations; and performs database management based on the business database corresponding to each business module. By constructing and managing the business database corresponding to each business module using annotation data, this invention solves the problems of low efficiency in database management, such as optimizing the database and manually performing database sharding. Attached Figure Description

[0039] Figure 1 A flowchart illustrating a database management method provided in an embodiment of this application;

[0040] Figure 2 A schematic diagram illustrating another database management method provided in an embodiment of this application;

[0041] Figure 3 A schematic diagram of another database management method provided in an embodiment of this application is shown;

[0042] Figure 4 A schematic diagram illustrating another database management method provided in an embodiment of this application;

[0043] Figure 5 A schematic diagram illustrating another database management method provided in an embodiment of this application;

[0044] Figure 6 A schematic diagram illustrating another database management method provided in an embodiment of this application;

[0045] Figure 7 A schematic diagram illustrating another database management method provided in an embodiment of this application;

[0046] Figure 8 This is a schematic diagram of the structure of a database management device provided in an embodiment of this application;

[0047] Figure 9 This is a schematic diagram of the structure of the acquisition module provided in an embodiment of this application;

[0048] Figure 10 This is a schematic diagram of the structure of the building module provided in the embodiments of this application;

[0049] Figure 11 This is a schematic diagram of the structure of the management module provided in an embodiment of this application;

[0050] Figure 12 This is a schematic diagram of another management module provided in an embodiment of this application;

[0051] Figure 13 This is a schematic diagram of another management module provided in an embodiment of this application;

[0052] Figure 14 A schematic diagram of the structure of the management submodule provided in the embodiments of this application.

[0053] Figure 15 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0054] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.

[0055] Example 1

[0056] In this embodiment, Figure 1 A flowchart illustrating a database management method provided in an embodiment of this application is shown. Figure 1 As shown, the method includes steps S101 to S103. The specific implementation principle of each step is as follows:

[0057] S101. Obtain the annotation data corresponding to each business module.

[0058] In this embodiment of the invention, the database management method described above is used for an SQLite database. In database development, annotation data is mainly used to annotate and explain the structure and design of the database. The annotation data includes class name annotations and attribute annotations. The class name annotations are used to describe the database name and table name, and the attribute annotations are used to describe the column attributes in the database.

[0059] The aforementioned business module refers to an independent, self-contained functional module within a software system. Typically, a software system contains multiple business modules, each responsible for completing a specific task. For example, in an e-commerce website, user management, order management, and product management modules are all business modules. Each business module contains a set of related functional modules; for instance, the user module includes user registration, user login, and user information management modules. Each business module is an important component of the system, responsible for completing specific business logic. In database development, different database tables can be created based on different business modules, making database management and operation more convenient. The aforementioned business module could be a user management module, an order management module, a product management module, etc.

[0060] The above class name annotation has two parameters: the library name parameter and the table name parameter.

[0061] The `database_name` parameter above represents the module name, which is also the database name and is an important parameter for database sharding. The `table_name` parameter above represents the table name, indicating which database (module) the table belongs to. Module names can be repeated because a module can have multiple tables, but more than one module name and table name cannot be duplicated, as a module cannot have two identical tables.

[0062] The above attribute annotations represent database columns. Each attribute annotation has three parameters: database column name, column type, and default value. For TEXT type, the default value is "" (or can be filled in by the developer). For INTEGER type, the default value is 0, which can also be filled in by the developer.

[0063] It's worth noting that obtaining this annotation data makes database management and manipulation more convenient, improving development efficiency and code quality. Simultaneously, annotation data helps developers better understand the database's structure and design principles, thereby improving development and maintenance.

[0064] S102. Construct the business database corresponding to each business module based on class name annotations and attribute annotations.

[0065] In this embodiment of the invention, the annotation data includes class name annotations and attribute annotations. Based on the class name annotations and attribute annotations, a business database corresponding to each business module can be constructed.

[0066] The aforementioned business databases refer to a set of databases constructed based on the needs and characteristics of different business modules. These databases typically contain multiple tables, each corresponding to a specific business function or domain. For example, in the user management module, a user database can be constructed, containing multiple tables such as user tables, role tables, and permission tables. These tables can be connected through foreign key relationships, thereby enabling data interaction and sharing between different tables.

[0067] Annotated data can be used to create table structures and initialize data, allowing for the rapid construction of a complete business database. For example, in the user management module, the user table can be created by retrieving its annotation data, including table name, column names, column types, and column constraints. Then, test data can be inserted into the user table using SQL statements to verify the table structure. Similarly, for other business modules such as the order management and product management modules, corresponding database tables can be created and initialized using annotation data. This approach enables the rapid creation and maintenance of a complete business database, improving development efficiency and code quality.

[0068] S103. Perform database management based on the business databases corresponding to each business module.

[0069] In this embodiment of the invention, the above-mentioned database management refers to the process of managing and maintaining a database in a computer system, including creating and maintaining the database, ensuring the security and integrity of the database, backing up and restoring data, and optimizing database performance.

[0070] In a multi-module system, each business module has its own corresponding business database. Database management refers to the maintenance and management of these databases, including operations such as backup, recovery, and performance optimization. Managing databases based on the business databases corresponding to each business module means that each business module's database needs to be managed separately to ensure the stable operation and high performance of the system.

[0071] The aforementioned database management involves considering factors such as data structure, type, and scale when designing a database, and also optimizing SQL statements to improve database performance.

[0072] The aforementioned database management may require regular database backups to prevent data loss, and the setting of recovery strategies to ensure data integrity.

[0073] The aforementioned database management may require restricting user access permissions to protect data security, while also requiring the implementation of security measures such as firewalls to prevent malicious attacks.

[0074] The aforementioned database management may require database migration or upgrades based on business needs, while also ensuring data integrity and consistency.

[0075] In this embodiment of the invention, annotation data corresponding to each business module is obtained, including class name annotations and attribute annotations; a business database corresponding to each business module is constructed based on the class name annotations and attribute annotations; and database management is performed based on the business database corresponding to each business module. By constructing and managing the business database corresponding to each business module using the annotation data, the inefficiency of optimizing the database and manually managing database sharding in database management is solved.

[0076] Optionally, the steps to obtain annotation data corresponding to each business module include:

[0077] Obtain business information from each business module.

[0078] Determine the corresponding class name annotations and attribute annotations based on the business information.

[0079] In this embodiment of the invention, the class name annotation includes a library name parameter and a table name parameter, and the attribute annotation includes a column name, a column type, and a default value for the column. One library name parameter corresponds to N table name parameters, and one table name parameter corresponds to M attribute annotations, where N is greater than or equal to 1 and M is greater than or equal to 1.

[0080] The aforementioned business modules can be user management modules, order management modules, product management modules, etc. The business information includes user information, order information, and inventory information. Each business module typically contains a set of related business information, such as user information, order information, and inventory information.

[0081] Specifically, based on different business modules, obtain the relevant business information, such as user information, order information, and inventory information.

[0082] In this embodiment of the invention, the aforementioned business information refers to business-related data, such as user information, order information, and inventory information. When developing a business module, it is necessary to determine the corresponding database name parameters, table name parameters, and attribute annotations based on the business information.

[0083] The database name parameter is an annotation used to identify the database name, the table name parameter is an annotation used to identify the table name, and the attribute annotation is an annotation used to identify the attributes in the table.

[0084] It should be noted that the database name parameter specifies the database name, the table name parameter specifies the table name, and the attribute annotation specifies the attribute information in the table.

[0085] Optionally, the steps for constructing the business database corresponding to each business module based on class name annotations and attribute annotations include:

[0086] Generate database code based on the database name parameter, and generate the initial database based on the database code.

[0087] Generate database table code based on the table name parameter, and generate the initial database table in the initial database based on the database table code.

[0088] Based on the column name, the column type, and the column default value, attribute column fields are generated in the initial database table to obtain the business database table.

[0089] The business database for each business module is obtained based on the business database tables corresponding to each business module.

[0090] In this embodiment of the invention, the above-mentioned database name parameter is an annotation used to identify the database name, the above-mentioned table name parameter is an annotation used to identify the table name, the above-mentioned attribute annotation includes column name, column type and column default value, and the above-mentioned attribute annotation is an annotation used to identify the attributes in the table.

[0091] The library name parameter identifies the corresponding database in the code. During code compilation, these annotations automatically generate the corresponding database code and create the initial database based on the generated database code.

[0092] The table name parameter identifies the corresponding table in the code. During code compilation, these annotations automatically generate the code for the corresponding table and create the initial database table based on the generated database table code.

[0093] Attribute annotations allow you to define attribute columns in a database table to obtain the business database table. You can use attribute annotations to comment on columns in the table, such as column names, column types, column constraints, and other information.

[0094] In this embodiment of the invention, the business database corresponding to each business module is obtained based on the business database table corresponding to each business module. Table structure and initialization data can be created using annotation data, thereby quickly constructing a complete business database. For example, in the user management module, the user table can be created by obtaining annotation data from the user table, including information such as table name, column names, column types, and column constraints.

[0095] Optionally, the steps for database management based on the business database corresponding to each business module include:

[0096] When a business module is detected to be running, the corresponding business database for that module is started.

[0097] When a business module is detected to be closed, the corresponding business database for that business module is also closed.

[0098] In this embodiment of the invention, the above-mentioned business modules may be user management modules, order management modules, product management modules, etc.

[0099] The aforementioned business databases refer to a set of databases constructed based on the needs and characteristics of different business modules. These databases typically contain multiple tables, each corresponding to a specific business function or domain. For example, in the user management module, a user database can be constructed, containing multiple tables such as user tables, role tables, and permission tables. These tables can be connected through foreign key relationships, thereby enabling data interaction and sharing between different tables.

[0100] It should be noted that when a business module is detected as running, its database engine is opened, allowing direct CRUD operations on the data tables. A module can have N sub-interfaces and sub-business data logic layers. When a business needs to manipulate a data table, it can directly perform CRUD operations on the database.

[0101] When a business module is detected to be closed, its data engine will be shut down, preventing the creation, deletion, modification, and querying of data tables.

[0102] Optionally, the steps for database management based on the business database corresponding to each business module include:

[0103] When an external interface of a business module is detected to be called, determine whether the business module has been destroyed.

[0104] If a business module is destroyed, the corresponding business database is opened so that the caller of the external interface can obtain the result set of the business database.

[0105] If the business module is not destroyed, the caller of the external interface can directly obtain the result set through the business database corresponding to the business module.

[0106] In this embodiment of the invention, the aforementioned external interface refers to the interface exposed by the business module for other modules to call. The aforementioned destruction refers to ending or shutting down the business module, causing it to cease operation.

[0107] The aforementioned caller refers to a program or system that calls a function, service, or interface in software development. The caller typically sends request data to the callee and processes the data returned by the callee.

[0108] It should be noted that when an external interface call to a business module is detected, it is necessary to determine whether the business module has been destroyed. If the business module has not been destroyed, the database engine is open, and the database table is directly manipulated to return the result set to the caller. If the business module has been destroyed, the database engine needs to be reopened before manipulating the database table to return the result set to the caller.

[0109] Optionally, the steps for database management based on the business database corresponding to each business module include:

[0110] When the business module starts, it scans for updated annotation data.

[0111] Based on the updated annotation data, update and manage the business database corresponding to the business module.

[0112] In this embodiment of the invention, the invention features automatic database upgrade and downgrade processing, whereas SQLite typically relies on version numbers. The aforementioned annotation data includes class name annotations and attribute annotations. Class name annotations include database name parameters and table name parameters, while attribute annotations include column names, column types, and default values.

[0113] It's important to note that when a business module starts, the program scans for updated database name parameters, table name parameters, and attribute annotations. It then retrieves the parameters for these parameters and updates and manages the corresponding business database based on them. This means the database structure and content will be modified or added to by the updated annotation data. This allows the business module to interact more effectively with the database.

[0114] Optionally, the steps for updating and managing the business database corresponding to the business module based on the updated annotation data include:

[0115] Based on the updated database name parameter, determine whether there exists a business database corresponding to the updated database name parameter.

[0116] If a business database exists that corresponds to the updated database name parameter, then the existence of a business database table that corresponds to the updated table name parameter is determined based on the updated table name parameter.

[0117] If a business database table exists that corresponds to the updated table name parameter, then the business database table will be updated and managed according to the updated attribute annotations.

[0118] If there is no business database table corresponding to the updated table name parameter, then the business database will be updated and managed according to the updated table name parameter and the updated attribute annotation.

[0119] If no business database exists corresponding to the updated database name parameter, then the business database corresponding to the business module is constructed based on the updated database name parameter, the updated table name parameter, and the updated attribute annotation.

[0120] In this embodiment of the invention, one database name parameter corresponds to N table name parameters, where N is greater than or equal to 1. If one database name parameter corresponds to an updated business database, it is necessary to determine whether a business database table corresponding to the updated table name parameter exists based on the updated table name parameter. This is because a business database table corresponding to the updated table name parameter may exist in the updated database. Therefore, it is necessary to determine whether the updated table name parameter exists.

[0121] In this embodiment of the invention, a table name parameter corresponds to M attribute annotations, where M is greater than or equal to 1. If the business database table corresponding to the updated table name parameter already exists, then the updated business database table will be managed and updated according to the updated attribute annotations.

[0122] If the business database table corresponding to the updated table name parameter does not exist, a new business database table will be created based on the updated table name parameter and the updated attribute annotation, and then updated and managed.

[0123] If no business database exists corresponding to the updated database name parameter, then the business database corresponding to the business module will be constructed based on the updated database name parameter, the updated table name parameter, and the updated attribute annotation, and then updated and managed.

[0124] Example 2

[0125] In this embodiment, please refer to Figure 2 , Figure 2 The diagram illustrates another database management method provided in an embodiment of this application. In this method, database creation does not require manual creation by the user; instead, the database and its table structure are automatically created based on annotation identifiers during program construction.

[0126] Developers use annotations to mark class names during compilation. The system then automatically scans all class files annotated with `@DataBase` and generates code to create the database and table structure based on the `modulename` (database name) and `tablename` (table name) parameters within the annotation. When scanning class files annotated with `@DataBase`, it automatically scans all classes annotated with `@Column` and generates code to create database columns based on the parameters in the annotation. The `@DataBase` annotation has two parameters: parameter 1, `modulename`, represents the module name, which is also the database name and is an important parameter for database sharding; parameter 2, `tablename`, identifies the table name—which is the database (module) under which the class belongs. The `modulename` parameter can be repeated because a module (database) can have multiple tables, but more than two `modulename` and `tablename` parameters cannot be duplicated because a module (database) cannot have two identical tables. Multiple properties can be created under the class. This property represents a column in the database. It is marked with the @Column property annotation. This annotation has 3 parameters: parameter 1: name (database column name), parameter 2: type (column type), and parameter 3: default value of the database column (if it is TEXT type, the default is "" string, or the developer can fill it in himself; INTEGER has a default value of 0, or the developer can fill it in himself).

[0127] Specifically, in the method of automatically creating database and table structures using annotations, each business module corresponds to a `@DataBase` class name annotation. The method creates the corresponding database and table based on the `modulename` (database name) and `tablename` (table name) parameters in the `@DataBase` class name annotation. Then, it scans all `@Column` attribute annotations in the class and creates the corresponding columns based on the parameters in the attribute annotations.

[0128] Example 3

[0129] In this embodiment, please refer to Figure 3 , Figure 3 This diagram illustrates another database management method according to an embodiment of this application. During program construction, all class files annotated with `@DataBase` are scanned, and database creation code is generated based on the `modulename` parameter in the annotation, providing it to developers. When a class file annotated with `@DataBase` is encountered, all `@Column` attribute annotations under that class are scanned, and the parameters in the attribute annotations are obtained. At this point, database table creation code is generated based on the `tablename` parameter in the `@DataBase` annotation, providing it to developers. During app runtime, the automatically generated database and table creation code described above is called, and automatic database sharding takes effect immediately.

[0130] Example 4

[0131] In this embodiment, as Figure 4 As shown, Figure 4This diagram illustrates another database management method according to an embodiment of this application. When a business module starts, its database engine is opened. As long as the business module is not closed, the database engine will not be closed. All business operations within this module that require CRUD operations on the database do not need to close the database engine. A module can have N sub-interfaces and sub-business data logic layers. When a business operation needs to manipulate a data table, the module's business operations that require CRUD operations on the database do not need to close the database engine. The business module's database operation class can also provide external interfaces for other business modules to use (of course, in more complex systems, N business modules can be started simultaneously, in which case business module A may need to operate on business module B's database table). When an external interface of a business module is called, it is necessary to determine whether the business module has been destroyed. If it has not been destroyed, the database table is directly manipulated and the result set is returned to the caller without closing the database engine. If the business module has been destroyed, the database engine needs to be reopened before the database table is manipulated and the result set is returned to the caller, and then the database engine is closed. When the entire business module is closed or destroyed, the database engine of the business module is closed, and the status of the external interface of the business module is changed to closed. The next time the external interface is called, it will be determined that the business module is destroyed.

[0132] Example 5

[0133] In this embodiment, as Figure 5 As shown, Figure 5This diagram illustrates another database management method according to an embodiment of this application. The database has an automatic upgrade / downgrade function. When the APP starts, it scans all classes annotated with `@DataBase` and iterates through them to obtain the `modulename` database name parameter and the `tablename` table name parameter. It then checks if the database exists using the `modulename` parameter. If it doesn't exist, it creates a database named `uid_modulename.db` (where `uid` represents the user ID; if no user ID exists, `modulename.db` is displayed; `modulename` is the value of the `modulename` parameter). After successful database creation, it creates tables within that database based on the `tablename` parameter and the database column values ​​of all `@Column` annotations under that class. It then checks if the database exists using the `modulename` parameter; if it does, it checks the `tablename` parameter of the database under that module. If the database does not exist, the database table and columns will be created according to the database creation and column creation logic. The `tablename` parameter of the database under this module will be checked. If `tablename` exists, all fields annotated with `@Column` under this annotation will be matched against the actual fields in the database table. If a field annotated with `@Column` does not exist in the database table, it will be added and assigned a default value. If a field in the database does not exist in the `@Column` annotation, the field in the database column will be deleted (the data of this column will be backed up to a backup table before deletion, in case it is needed again later; the backup period is 3 months). If the `type` attribute of `@Column` does not match the type of the column in the database table, the data in this column will be cleared and filled with a default value (`default`). The data of this column will be backed up to a backup table before deletion, in case it is needed again later; the backup period is 3 months.

[0134] Example 6

[0135] In this embodiment, as Figure 6 As shown, Figure 6The diagram illustrates another database management method according to an embodiment of this application. When the APP starts a business module and performs multi-threaded asynchronous database operations, which takes N minutes, the data table is in a waiting state. While the data table in module 1 is in a waiting state, the user opens an interface in business module 2 via a button in module 1. This interface still requires operations on complex data tables. Because the database is sharded by module, the database operations are completely unaffected by the time-consuming operations of the business module 1 data engine.

[0136] It should be noted that if the multi-threaded asynchronous database operation of business module 1 takes N minutes, and the data table of business module 1 is in a waiting state, and the user opens a certain interface of business module 2 through a button of business module 1, then because the database is sharded by module, the database operation of business module 2 will not be affected by the time-consuming operation of the data engine of business module 1.

[0137] Example 7

[0138] In this embodiment, as Figure 7 As shown, Figure 7 A schematic diagram of another database management method according to an embodiment of this application is shown. The automatic database sharding device is divided into the following main modules:

[0139] 1. The database name and table name can be automatically created by using the class name annotation @DataBase(modulename database name parameter, tablename table name parameter). When the program runs, it will automatically allocate the database name and then create the table name based on the modulename database name parameter.

[0140] 2. The attributes under the data model class name annotation @DataBase(modulename (database name parameter) and tablename (table name parameter) identify the database column. The data column is created according to the parameters defined in the @Column attribute annotation.

[0141] 3. The databases are completely isolated according to business needs, with no interference between them.

[0142] 4. The database engine is intelligent. It starts when the module starts and stays on until the module is closed. Infrequent database engine operations improve the performance of CRUD operations.

[0143] 5. Automatic database upgrade and downgrade.

[0144] 6. Supports multi-database join queries, enabling cross-database queries based on external interfaces.

[0145] Example 8

[0146] Corresponding to the above Figure 1 This illustrates a database management method. Figure 8 The diagram shown is a schematic diagram of a database management device provided in an embodiment of this application. The device M80 includes:

[0147] The acquisition module M801 is used to acquire annotation data corresponding to each business module. The annotation data includes class name annotations and attribute annotations.

[0148] Module M802 is used to construct the business database corresponding to each business module based on the class name annotation and the attribute annotation;

[0149] The management module M803 is used for database management based on the business databases corresponding to each of the business modules.

[0150] Optional, see reference Figure 9 As shown, Figure 9 A schematic diagram of the acquisition module provided in an embodiment of this application. The acquisition module M801 includes:

[0151] The first acquisition submodule M8011 is used to acquire business information from various business modules;

[0152] The determination submodule M8012 is used to determine the corresponding class name annotation and attribute annotation based on the business information. The class name annotation includes library name parameters and table name parameters, and the attribute annotation includes column name, column type, and column default value.

[0153] Optional, see reference Figure 10 As shown, Figure 10 A schematic diagram of the structure of the building module provided in an embodiment of this application. Building module M802 includes:

[0154] The first generation submodule M8021 is used to generate database code based on the database name parameter, and generate an initial database based on the database code;

[0155] The second generation submodule M8022 is used to generate database table code according to the table name parameter, and generate an initial database table in the initial database according to the database table code.

[0156] The third generation submodule M8023 is used to generate attribute column fields in the initial database table according to the column name, the column type and the column default value, so as to obtain the business database table.

[0157] The processing submodule M8024 is used to obtain the business database corresponding to each business module based on the business database table corresponding to each business module.

[0158] Optional, see reference Figure 11 As shown, Figure 11 A schematic diagram of the structure of the management module provided in this embodiment of the application. The management module M803 includes:

[0159] The first detection submodule M8031 is used to start the business database corresponding to the business module when the business module is detected to be started.

[0160] The second detection submodule M8032 is used to close the business database corresponding to the business module when the business module is detected to be closed.

[0161] Optional, see reference Figure 12 As shown, Figure 12 A schematic diagram of another management module provided in an embodiment of this application. Management module M803 includes:

[0162] The first judgment submodule M8033 is used to determine whether the business module has been destroyed when the external interface of the business module is called.

[0163] The second acquisition submodule M8034 is used to open the business database corresponding to the business module if the business module is destroyed, so that the caller of the external interface can obtain the result set of the business database.

[0164] The third acquisition submodule M8035 is used so that if the business module is not destroyed, the caller of the external interface can directly obtain the result set through the business database corresponding to the business module.

[0165] Optional, please refer to Figure 13 , Figure 13 A schematic diagram of another management module provided in an embodiment of this application. Management module M803 includes:

[0166] The scanning submodule M8036 is used to scan the updated annotation data when the business module starts.

[0167] The management submodule M8037 is used to update and manage the business database corresponding to the business module based on the updated annotation data.

[0168] Optional, please see Figure 14 , Figure 14 This is a schematic diagram of the structure of the management submodule provided in an embodiment of this application. The management submodule M8037 includes:

[0169] The first judgment unit M80371 is used to determine whether there is a business database corresponding to the updated database name parameter based on the updated database name parameter.

[0170] The second judgment unit M80372 is used to determine whether there is a business database table corresponding to the updated table name parameter if there is a business database corresponding to the updated database name parameter.

[0171] The first management unit M80373 is used to update and manage the business database table according to the updated attribute annotation if a business database table corresponding to the updated table name parameter exists.

[0172] The second management unit M80374 is used to update and manage the business database according to the updated table name parameters and the updated attribute annotations if there is no business database table corresponding to the updated table name parameters.

[0173] The construction unit M80375 is used to construct the business database corresponding to the business module based on the updated database name parameter, the updated table name parameter, and the updated attribute annotation if there is no business database corresponding to the updated database name parameter.

[0174] Example 9

[0175] Figure 15 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 15 As shown, the electronic device D15 of this embodiment includes: at least one processor D150 ( Figure 15 Only one is shown in the diagram. The device includes a memory D151, a network interface D152, and a computer program stored in the memory D151 that can run on at least one processor D150. The processor D150 is used to call the computer program stored in the memory D151 and perform the following steps:

[0176] Obtain the annotation data corresponding to each business module, wherein the annotation data includes class name annotations and attribute annotations;

[0177] Construct a business database corresponding to each business module based on the class name annotation and the attribute annotation;

[0178] Database management is performed based on the business databases corresponding to each of the aforementioned business modules.

[0179] Optionally, the process of obtaining annotation data corresponding to each business module executed by processor D150 includes:

[0180] Obtain business information from each business module;

[0181] Based on the business information, the corresponding class name annotation and attribute annotation are determined. The class name annotation includes library name parameters and table name parameters, and the attribute annotation includes column name, column type, and column default value.

[0182] Optionally, the process executed by processor D150 to construct the business database corresponding to each business module based on the class name annotation and the attribute annotation includes:

[0183] Generate database code based on the database name parameter, and generate an initial database based on the database code;

[0184] Generate database table code based on the table name parameter, and generate an initial database table in the initial database based on the database table code;

[0185] Based on the column name, the column type, and the column default value, attribute column fields are generated in the initial database table to obtain the business database table;

[0186] The business database for each business module is obtained based on the business data tables corresponding to each business module.

[0187] Optionally, the database management performed by the processor D150 based on the business database corresponding to each business module includes:

[0188] Upon detecting that a business module is enabled, the corresponding business database for that business module is enabled.

[0189] When a business module is detected to be closed, the business database corresponding to that business module is closed.

[0190] Optionally, the database management performed by the processor D150 based on the business database corresponding to each business module includes:

[0191] When an external interface of a business module is detected to be called, it is determined whether the business module has been destroyed.

[0192] If the business module is destroyed, the business database corresponding to the business module is opened so that the caller of the external interface can obtain the result set of the business database;

[0193] If the business module is not destroyed, the caller of the external interface can directly obtain the result set through the business database corresponding to the business module.

[0194] Optionally, the database management performed by the processor D150 based on the business database corresponding to each business module includes:

[0195] When the business module starts, it scans for updated annotation data;

[0196] Based on the updated annotation data, the business database corresponding to the business module is updated and managed.

[0197] Optionally, the process executed by processor D150 to update and manage the business database corresponding to the business module based on the updated annotation data includes:

[0198] Based on the updated database name parameter, determine whether it exists in the business database corresponding to the updated database name parameter;

[0199] If a business database exists that corresponds to the updated database name parameter, then the existence of a business database table that corresponds to the updated table name parameter is determined based on the updated table name parameter.

[0200] If a business database table exists that corresponds to the updated table name parameter, then the business database table is updated and managed according to the updated attribute annotations.

[0201] If there is no business database table corresponding to the updated table name parameter, then the business database is updated and managed according to the updated table name parameter and the updated attribute annotation.

[0202] If no business database exists corresponding to the updated database name parameter, then the business database corresponding to the business module is constructed based on the updated database name parameter, the updated table name parameter, and the updated attribute annotation.

[0203] The electronic device D15 provided in this embodiment of the invention can implement various implementation methods and corresponding beneficial effects in a database management method embodiment. To avoid repetition, these will not be described again here.

[0204] The electronic device provided in this embodiment of the invention can implement all the processes of the database management method in the above-described method embodiments, and can achieve the same beneficial effects. To avoid repetition, further details are omitted here.

[0205] This application also provides a computer-readable storage medium storing a computer program. When the computer program is executed by the processor D150, it implements various processes of the database management method embodiment provided in this invention and achieves the same technical effect. To avoid repetition, it will not be described again here.

[0206] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A database management method, characterized in that, Includes the following steps: Obtain the annotation data corresponding to each business module, wherein the annotation data includes class name annotations and attribute annotations; Construct a business database corresponding to each business module based on the class name annotation and the attribute annotation; Database management is performed based on the business databases corresponding to each of the aforementioned business modules; The step of obtaining the annotation data corresponding to each business module includes: Obtain business information from each business module; The corresponding class name annotation and attribute annotation are determined based on the business information. The class name annotation includes library name parameter and table name parameter. The attribute annotation includes column name, column type and column default value. During compilation, all class files annotated with the class name are scanned, and database creation code is generated based on the library name parameter, and database table creation code is generated based on the table name parameter. The step of constructing the business database corresponding to each business module based on the class name annotation and the attribute annotation includes: Generate database code based on the database name parameter, and generate an initial database based on the database code; Generate database table code based on the table name parameter, and generate an initial data table in the initial database based on the database table code; Based on the column name, the column type, and the column default value, attribute column fields are generated in the initial database table to obtain the business database table; The business database corresponding to each business module is obtained based on the business database table corresponding to each business module. The database management includes: when the multi-threaded asynchronous operation of the first business module causes its corresponding business database to be in a waiting state, the business database corresponding to the second business module can still perform data operations independently.

2. The database management method as described in claim 1, characterized in that, The database management based on the business databases corresponding to each business module includes: When a business module is detected to be running, the business database corresponding to that business module is started. When a business module is detected to be closed, the business database corresponding to that business module is closed.

3. The database management method as described in claim 1, characterized in that, The database management based on the business databases corresponding to each business module includes: When an external interface of a business module is detected to be called, it is determined whether the business module has been destroyed. If the business module is destroyed, the business database corresponding to the business module is opened so that the caller of the external interface can obtain the result set of the business database; If the business module is not destroyed, the caller of the external interface can directly obtain the result set through the business database corresponding to the business module.

4. The database management method as described in claim 1, characterized in that, The management based on the business database corresponding to each business module includes: When the business module starts, it scans for updated annotation data; Based on the updated annotation data, the business database corresponding to the business module is updated and managed.

5. The database management method as described in claim 4, characterized in that, The step of updating and managing the business database corresponding to the business module based on the updated annotation data includes: Based on the updated database name parameter, determine whether it exists in the business database corresponding to the updated database name parameter; If a business database exists that corresponds to the updated database name parameter, then the existence of a business database table that corresponds to the updated table name parameter is determined based on the updated table name parameter. If a business database table exists that corresponds to the updated table name parameter, then the business database table is updated and managed according to the updated attribute annotations. If the business database table corresponding to the updated table name parameter does not exist, then the business database is updated and managed according to the updated table name parameter and the updated attribute annotation. If the updated database name parameter does not exist in the business database corresponding to the updated database name parameter, the updated table name parameter, and the updated attribute annotation, then the business database corresponding to the business module is constructed.

6. A database management device, characterized in that, include: The acquisition module is used to acquire annotation data corresponding to each business module. The annotation data includes class name annotations and attribute annotations. The construction module is used to construct the business database corresponding to each business module based on the class name annotation and the attribute annotation; The management module is used for database management based on the business databases corresponding to each of the business modules; The step of obtaining the annotation data corresponding to each business module includes: Obtain business information from each business module; The corresponding class name annotation and attribute annotation are determined based on the business information. The class name annotation includes library name parameter and table name parameter. The attribute annotation includes column name, column type and column default value. During compilation, all class files annotated with the class name are scanned, and database creation code is generated based on the library name parameter, and database table creation code is generated based on the table name parameter. The step of constructing the business database corresponding to each business module based on the class name annotation and the attribute annotation includes: Generate database code based on the database name parameter, and generate an initial database based on the database code; Generate database table code based on the table name parameter, and generate an initial data table in the initial database based on the database table code; Based on the column name, the column type, and the column default value, attribute column fields are generated in the initial database table to obtain the business database table; The business database corresponding to each business module is obtained based on the business database table corresponding to each business module. The database management includes: when the multi-threaded asynchronous operation of the first business module causes its corresponding business database to be in a waiting state, the business database corresponding to the second business module can still perform data operations independently.

7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and capable of running on the processor, characterized in that, When the processor executes the computer program, it implements a database management method as described in any one of claims 1 to 5.

8. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements a database management method as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Database management method, electronic equipment and computer readable storage medium

    CN111797073A

  • Data processing method and device, electronic equipment and computer readable medium

    CN115964393A