Database operation method and device, system, electronic device and storage medium
Patent Information
- Application Number
- CN202010220492.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-03-25
- Publication Date
- 2024-11-26
- Estimated Expiration
- 2040-03-25
Smart Images

Figure CN113448995B_ABST
Abstract
Description
Background Art
[0002] With the rapid development of mobile Internet technology, mobile devices such as mobile phones have gradually become popular in people's lives, and a large number of mobile applications (APPlication, APP) have been generated. Databases are almost a must-have capability for all medium and large mobile application APPs. Mobile application databases can be used to cache data, such as chat records, configuration data, etc. The next time the APP is started, the APP will not need to re-acquire all data from the server, which can improve the APP's response speed and improve user experience.
[0003] At present, there are several relatively mature database object relational mapping (ORM) frameworks, such as Google's Room framework, etc. After configuring the entity through simple annotations, the database can be operated through the entity, which is very convenient.
[0004] However, the above database ORM framework does not support cross-process operations. An application in the Android system can be composed of multiple processes. In a multi-process environment, the ORM framework cannot support cross-process operations. In addition, if SDK development has database requirements, a new software development kit (SDK) needs to be introduced, which will increase the difficulty of SDK access.
[0005] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present disclosure, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention
[0006] The purpose of the present disclosure is to provide a database operation method, a database operation device, a database operating system, an electronic device and a computer-readable storage medium, thereby at least to a certain extent overcoming the problem that the existing database ORM framework cannot perform cross-process data operations.
[0007] Other features and advantages of the present disclosure will become apparent from the following detailed description, or may be learned in part by the practice of the present invention.
[0008] According to a first aspect of the present disclosure, a database operation method is provided, comprising: obtaining a database operation instruction for an entity to be processed; wherein the database operation instruction comprises entity annotation information and a data operation type; determining a target class name and a target application package name corresponding to the entity to be processed, and generating an entity identifier of the entity to be processed based on the target class name and the target application package name; determining a target data table corresponding to the entity to be processed according to the entity annotation information and through a reflection mechanism; determining a target function corresponding to the entity to be processed according to the data operation type and the entity identifier and through a content provider component; and executing the target function based on the target data table to perform a database operation corresponding to the data operation type.
[0009] Optionally, the data operation type includes one or more of a data adding operation, a data deleting operation, a data modifying operation and a data query operation.
[0010] Optionally, the data operation type includes a data addition operation. After determining the target data table corresponding to the entity to be processed based on the entity annotation information and through the reflection mechanism, the above method also includes: determining the entity attributes and entity attribute values corresponding to the entity to be processed; mapping the entity attributes and entity attribute values to the target data class to generate target data corresponding to the entity to be processed; wherein the target data class is a data type corresponding to the content provider component.
[0011] Optionally, determining entity attributes and entity attribute values corresponding to the entity to be processed includes: obtaining the entity attributes corresponding to the entity to be processed through a reflection mechanism; determining the entity attribute values corresponding to the entity attributes and the attribute type of the entity attribute values from the target data table according to the entity annotation information.
[0012] Optionally, the target function includes execution parameters, and the target function is executed based on the target data table to perform a database operation corresponding to the data operation type, including: obtaining a data table set, and determining whether the data table set includes the target data table; if the data table set includes the target data table, executing a data insertion function based on the target data table to perform a data addition operation.
[0013] Optionally, the above method also includes: if the data table set does not include the target data table, executing a data table creation operation; wherein the data table creation operation includes: parsing the entity identifier to determine the bytecode object corresponding to the entity to be processed; determining the field name corresponding to the entity attribute and the field value corresponding to the entity attribute value according to the bytecode object; generating a data table creation statement according to the field name and the field value, and executing the data table creation operation according to the data table creation statement.
[0014] Optionally, the data operation type includes a data query operation, the target function includes a query function, and the target function is executed based on the target data table to perform a database operation corresponding to the data operation type, including: executing the query function, and determining whether the data table set includes the target data table corresponding to the entity to be processed; if the data table set includes the target data table corresponding to the entity to be processed, obtaining the data object corresponding to the entity to be processed according to the target data table; mapping and converting the data object through a reflection mechanism to generate a target entity corresponding to the entity to be processed, and returning the target entity.
[0015] According to a second aspect of the present disclosure, there is provided a database operation device, comprising: an instruction acquisition module, for acquiring database operation instructions for an entity to be processed; wherein the database operation instructions include entity annotation information and a data operation type; an identifier generation module, for determining a target class name and a target application package name corresponding to the entity to be processed, and generating an entity identifier of the entity to be processed based on the target class name and the target application package name; a data table determination module, for determining a target data table corresponding to the entity to be processed according to the entity annotation information and through a reflection mechanism; a target function determination module, for determining a target function corresponding to the entity to be processed according to the data operation type and the entity identifier and through a content provider component; and an operation module, for executing the target function based on the target data table to perform a database operation corresponding to the data operation type.
[0016] Optionally, the database operation device also includes a parameter generation module, which is used to determine the entity attributes and entity attribute values corresponding to the entity to be processed; map the entity attributes and entity attribute values to a target data class to generate target data corresponding to the entity to be processed; wherein the target data class is a data type corresponding to the content provider component.
[0017] Optionally, the parameter generation module includes an attribute determination unit, which is used to obtain entity attributes corresponding to the entity to be processed through a reflection mechanism; determine entity attribute values corresponding to the entity attributes and attribute types of the entity attribute values from the target data table according to the entity annotation information.
[0018] Optionally, the operation module includes an adding operation unit, which is used to obtain a data table set and determine whether the data table set includes a target data table; if the data table set includes the target data table, a data insertion function is executed based on the target data table to perform a data adding operation.
[0019] Optionally, the operation module also includes a data table creation unit, which is used to perform a data table creation operation if the data table set does not include the target data table; wherein the data table creation operation includes: parsing the entity identifier to determine the bytecode object corresponding to the entity to be processed; determining the field name corresponding to the entity attribute and the field value corresponding to the entity attribute value according to the bytecode object; generating a data table creation statement according to the field name and the field value, and performing the data table creation operation according to the data table creation statement.
[0020] Optionally, the operation module also includes a query operation unit, which is used to execute the query function and determine whether the data table set includes a target data table corresponding to the entity to be processed; if the data table set includes a target data table corresponding to the entity to be processed, then the data object corresponding to the entity to be processed is obtained according to the target data table; the data object is mapped and converted through a reflection mechanism to generate a target entity corresponding to the entity to be processed, and the target entity is returned.
[0021] According to a third aspect of the present disclosure, there is provided a database operating system, comprising: an annotation module, for storing a mapping relationship between an entity to be processed and a target data table corresponding to the entity to be processed; a data providing module, for determining an entity identifier of the entity to be processed, and converting the entity to be processed into corresponding target data, so as to perform database operations according to the target data; a database operation module, for performing database operations according to database operation instructions for the entity to be processed; wherein the database operation module comprises an operation statement generation submodule and a mapping submodule, the operation statement generation submodule being used to generate an operation statement for performing database operations, and the mapping submodule being used to perform conversion processing on the entity to be processed.
[0022] According to a fourth aspect of the present disclosure, there is provided an electronic device, comprising: a processor; and a memory, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the database operation method according to any one of the above items is implemented.
[0023] According to a fifth aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the database operation method according to any one of the above items is implemented.
[0024] The technical solution provided by the present disclosure may have the following beneficial effects:
[0025] The database operation method in the exemplary embodiment of the present disclosure obtains a database operation instruction for the entity to be processed; wherein the database operation instruction includes entity annotation information and data operation type; determines the target class name and target application package name corresponding to the entity to be processed, and generates an entity identifier of the entity to be processed based on the target class name and target application package name; determines the target data table corresponding to the entity to be processed according to the entity annotation information and through the reflection mechanism; determines the target function corresponding to the entity to be processed according to the data operation type and the entity identifier, and through the content provider component; executes the target function based on the target data table to perform a database operation corresponding to the data operation type. Through the database operation method of the present disclosure, on the one hand, according to the entity identifier and through the content provider component to determine the target function to perform database operations, that is, using the cross-process standard of the content provider component, the problem of cross-process database operations of APP applications can be solved. On the other hand, database operations similar to the ORM framework form can be provided through entity annotation information and reflection mechanisms, which can make database operations more lightweight. On the other hand, if SDK development has database development requirements, the SDK package size in application development can be reduced, and the SDK access cost can be reduced.
[0026] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] The drawings herein are incorporated into the specification and constitute a part of the specification, showing embodiments consistent with the present disclosure, and together with the specification, are used to explain the principles of the present disclosure. Obviously, the drawings described below are only some embodiments of the present disclosure, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0028] Figure 1 A flowchart schematically shows a database operation method according to an exemplary embodiment of the present disclosure;
[0029] Figure 2 A flowchart schematically illustrates a data adding operation according to an exemplary embodiment of the present disclosure;
[0030] Figure 3 A flowchart of obtaining an entity identifier of an entity to be processed according to an exemplary embodiment of the present disclosure is schematically shown;
[0031] Figure 4 A flowchart of obtaining target data corresponding to an entity to be processed according to an exemplary embodiment of the present disclosure is schematically shown;
[0032] Figure 5A flowchart of an operation of creating a data table according to an exemplary embodiment of the present disclosure is schematically shown;
[0033] Figure 6 A flowchart schematically illustrates a data query operation according to an exemplary embodiment of the present disclosure;
[0034] Figure 7 A block diagram schematically shows a database operating device according to an exemplary embodiment of the present disclosure;
[0035] Figure 8 A schematic diagram of a database operating system according to an exemplary embodiment of the present disclosure is shown;
[0036] Fig. 9 A block diagram of an electronic device according to an exemplary embodiment of the present disclosure is schematically shown;
[0037] Fig.10 A schematic diagram of a computer-readable storage medium according to an exemplary embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION
[0038] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in many forms and should not be construed as limited to the embodiments set forth herein; rather, these embodiments are provided so that this disclosure will be comprehensive and complete and will fully convey the concepts of the example embodiments to those skilled in the art. The same reference numerals in the figures represent the same or similar parts, and thus their repeated description will be omitted.
[0039] In addition, the described features, structures or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced without one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known structures, methods, devices, implementations, materials or operations are not shown or described in detail to avoid blurring the various aspects of the present disclosure.
[0040] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or these functional entities or parts of functional entities may be implemented in one or more software hardened modules, or these functional entities may be implemented in different networks and / or processor devices and / or microcontroller devices.
[0041] Database is a necessary capability for almost all medium and large mobile applications. Currently, there are multiple database ORM frameworks used to implement database operations for mobile applications. Existing ORM frameworks do not support cross-process operations. An application on the Android system can be composed of multiple processes. For multi-process applications, extra care must be taken when operating the database. If the processes for operating the data are inconsistent, serious problems of data inconsistency will result. In a multi-process environment, the ORM framework must run under the ContentProvider standard, that is, it must be packaged by ContentProvider to support cross-process operations. In addition, the ORM framework also needs to introduce a new SDK package. In addition to increasing the package size of the access party, the newly introduced package will also bring the access party the learning cost of the new framework and increase the difficulty of SDK access.
[0042] Based on this, in this example embodiment, a database operation method is first provided. The database operation method of the present disclosure can be implemented using a server, or the method described in the present disclosure can be implemented using a terminal device, wherein the terminal described in the present disclosure may include mobile terminals such as mobile phones, tablet computers, laptops, PDAs, personal digital assistants (PDAs), and fixed terminals such as desktop computers. Figure 1 The following is a schematic diagram schematically showing the flow of a database operation method according to some embodiments of the present disclosure. Figure 1 , the database operation method may include the following steps:
[0043] Step S110, obtaining a database operation instruction for the entity to be processed; wherein the database operation instruction includes entity annotation information and data operation type.
[0044] Step S120: determine the target class name and target application package name corresponding to the entity to be processed, and generate an entity identifier of the entity to be processed based on the target class name and the target application package name.
[0045] Step S130: determining a target data table corresponding to the entity to be processed according to the entity annotation information and through a reflection mechanism.
[0046] Step S140: determining the target function corresponding to the entity to be processed according to the data operation type and the entity identifier and through the content provider component.
[0047] Step S150, executing the target function based on the target data table to perform a database operation corresponding to the data operation type.
[0048] According to the database operation method in this example embodiment, on the one hand, the target function is determined according to the entity identifier and through the content provider component to perform database operations, that is, the cross-process standard of the content provider component is adopted, which can solve the problem of cross-process database operations of APP applications. On the other hand, database operations similar to the ORM framework can be provided through entity annotation information and reflection mechanisms, which can make database operations more lightweight. On the other hand, if the SDK development has database development requirements, the SDK package size in application development can be reduced, reducing the SDK access cost.
[0049] Next, the database operation method in this exemplary embodiment will be further described.
[0050] In step S110, a database operation instruction for the entity to be processed is obtained; wherein the database operation instruction includes entity annotation information and data operation type.
[0051] In some exemplary embodiments of the present disclosure, the database operation instruction may be an operation instruction generated according to the operation of the operation requester. The entity to be processed may be an entity contained in the database operation instruction. For example, when implementing database operations of the Android system, the entity to be processed may be a JavaBean entity. The present disclosure will take the specific operation process of the JavaBean entity as an example for explanation. The entity annotation information may be the annotation information corresponding to the JavaBean entity to be processed. Java annotations (Annotation) are also called Java annotations. Annotations can associate any information or metadata with program elements (classes, methods, member variables, etc.). Java annotations can obtain annotation content through reflection. The data operation type may be the specific type of this database operation. Specifically, the data operation type includes one or more of data addition operations, data deletion operations, data modification operations, and data query operations. The data addition operation may be an operation to add data to the database. Reference Figure 2 , Figure 2 The flowchart of the data adding operation is schematically shown. The data deleting operation may be an operation of deleting a certain data item in the database. The data modifying operation may be an operation of modifying a certain data in the database. The data querying operation may be an operation of querying whether a certain data is contained in the database.
[0052] When an operation request is received from an operation requester, a corresponding database operation instruction may be generated according to the operation request, and the database operation instruction may be acquired so as to perform subsequent data operations according to the database operation instruction.
[0053] In step S120, a target class name and a target application package name corresponding to the entity to be processed are determined, and an entity identifier of the entity to be processed is generated based on the target class name and the target application package name.
[0054] In some exemplary embodiments of the present disclosure, the target class name may be the name of the program class to which the entity to be processed belongs. The target application package name may be the name of the application package corresponding to the entity to be processed. The entity identifier may be a Uniform Resource Identifier (URI), i.e., a string used to identify the name of the entity to be processed.
[0055] refer to Figure 3 , Figure 3 The flowchart for obtaining the entity identifier of the entity to be processed is schematically shown. In step S310, when a database operation instruction is received, the entity to be processed can be determined from the database operation instruction, and the full class name and application package name corresponding to the entity to be processed can be determined. In step S320, it can be queried in the database whether there is a cache of the entity identifier of the entity to be processed. If the entity identifier of the entity to be processed is cached in the database, the entity identifier is returned and the step of determining the entity identifier is terminated. In step S330, if there is no cache record of the entity identifier in the database, after the full class name and application package are determined, the name of the entity to be processed can be concatenated with the full class name and application package name to generate an entity identifier corresponding to the entity to be processed. For example, the full class name of the entity User to be processed is "com.jingdong.manto.entity", and the application package name is "com.jingdong.app.mall". The format of the URI corresponding to the entity to be processed is: "content: / / application package name / class:full class name". Therefore, by concatenating the full class name and the application package name, a globally unique URI corresponding to the entity to be processed can be generated as "content: / / com.jingdong.app.mall / class:com.jingdong.manto.entity.User".
[0056] In step S130, a target data table corresponding to the entity to be processed is determined according to the entity annotation information and through a reflection mechanism.
[0057] In some exemplary embodiments of the present disclosure, the reflection mechanism, i.e., the reflection mechanism of Java, means that in the running state of the program, an object of any class can be constructed, the class to which any object belongs can be understood, the member variables and methods of any class can be understood, and the properties and methods of any object can be called. The target data table can be the data table corresponding to the entity to be processed in the database. The entity annotation information of the entity to be processed may include a mapping relationship between the entity to be processed and the corresponding target data table. When the entity annotation information is obtained, the database table name configured on the class annotation of the entity to be processed can be obtained through annotation and reflection technology to determine the target data table.
[0058] According to some exemplary embodiments of the present disclosure, when the data operation type is a data addition operation, the entity attributes and entity attribute values corresponding to the entity to be processed are determined; the entity attributes and entity attribute values are mapped to a target data class to generate target data corresponding to the entity to be processed; wherein the target data class is a data type corresponding to a content provider component. Entity attributes may be attributes contained in the entity to be processed, and the entity to be processed may contain multiple attributes. Entity attribute values may be attribute values corresponding to the target entity. The target data class may be a data type used when converting and storing the entity to be processed; the target data class may be a data type supported by the content provider. Since the ContentProvider component is used in the present disclosure for cross-process data operations, and ContentProvider needs to use the ContentValues class to load data, the target data class may be the ContentValues class. The target data may be the target data generated by converting the entity to be processed and storing it in the target data class.
[0059] refer to Figure 2 , Figure 2The flowchart of the data adding operation is schematically shown. In steps S210 to S220, when the data adding operation of the data requesting party is received, the entity to be processed in the data adding operation can be obtained. In step S230, the sub-process of obtaining the identifier corresponding to the entity to be processed can be executed. When the target class name and the target application package name corresponding to the entity to be processed are determined, the entity identifier can be determined according to the target class name and the target application package name. In step S240, after the entity attributes and entity attribute values of the entity to be processed are determined, the entity attributes and entity attribute values of the JavaBean of the entity to be processed can be mapped to the ContentValues class through the Java reflection mechanism to generate the target data loaded by the ContentValues class. After the target data is generated, the target data can be transferred to the ContentProvider so that the ContentProvider performs subsequent operations according to the data of the ContentValues type.
[0060] According to some exemplary embodiments of the present disclosure, entity attributes corresponding to the entity to be processed are obtained through a reflection mechanism; entity attribute values corresponding to the entity attributes and attribute types of the entity attribute values are determined from a target data table according to entity annotation information. The attribute type may be a basic data type corresponding to the entity attribute, such as an integer (Int), a string (String), a Boolean (Bool), etc.
[0061] refer to Figure 4 , Figure 4The flowchart for obtaining the target data corresponding to the entity to be processed is schematically shown. In step S410, the JavaBean entity to be processed can be determined. In step S420, all the attributes of the JavaBean entity can be obtained through the reflection mechanism, and it can be determined whether the entity attribute has entity annotation information (i.e., configuration annotation). According to the entity annotation information, the corresponding field name can be obtained from the target data table corresponding to the entity to be processed. Then, according to the attribute type of the entity attribute, the field value corresponding to the entity attribute, i.e., the entity attribute value, is obtained by reflection one by one. In step S430, after determining the entity attribute and the entity attribute value, the entity attribute and the corresponding entity attribute value can be stored one by one in the target data class ContentValues. For example, the entity to be processed can be a user information entity containing information of a certain user, i.e., "User", and the attributes in the User entity can include attributes such as name, ID number, gender, age, and occupation. Each attribute in the User entity can correspond to its own attribute value. For example, the attribute values of the User entity can be "Xiao Ming", "101411199006060812", "Male", "30", and "Programmer". The attribute type can be the data type corresponding to the entity attribute value, for example, the name attribute can be of String type, the age attribute can be of Int type, etc. The entity attributes and entity attribute values can be stored in ContentValues in the form of "key-value" to generate target data.
[0062] In step S140, the target function corresponding to the entity to be processed is determined according to the data operation type and the entity identifier and through the content provider component.
[0063] In some exemplary embodiments of the present disclosure, a content provider component (ContentProvider) can provide data from one application to other applications through a request. For example, obtaining mobile phone contacts can be done through the content provider. When an external APP needs to operate contacts, operations on mobile phone contacts can be performed through the ContentProvider standard interface. In the present disclosure, the database can be operated through the ContentProvider natively provided by Android to solve the problem of inconsistent cross-process data operations. The target function can be an execution function corresponding to the entity to be processed determined from the content provider component.
[0064] When receiving a database operation instruction, the data operation to be performed on the entity to be processed can be determined according to the database operation instruction. For example, when the data operation type is a data addition operation, the insert method of ContentProivder will be triggered, and the parameters of the insert method include the URI of the entity to be processed and the target data. The parameter URI of the insert method contains the entity class name information of the entity to be processed, so the entity name of the entity to be processed can be obtained for subsequent database operations.
[0065] In step S150 , the target function is executed based on the target data table to perform a database operation corresponding to the data operation type.
[0066] In some exemplary embodiments of the present disclosure, the database operation may be a database operation performed on the entity to be processed according to the data operation type, and may include adding data to the database, deleting, modifying or querying data in the database, etc. After determining the target data table corresponding to the target entity, the target function in the content provider may be called based on the target data table to perform the corresponding database operation.
[0067] According to some exemplary embodiments of the present disclosure, a data table set is obtained, and it is determined whether the data table set includes a target data table; if the data table set includes the target data table, a data insertion function is executed based on the target data table to perform a data addition operation. In this exemplary embodiment, the target function may be a data insertion function, and the target insertion function may include execution parameters, which may be parameters required when executing the target function, and the execution parameters may include entity identifiers corresponding to entities to be processed. The data table set may be an information set representing a data table stored in a record database. In mobile applications, a lightweight database (SQLite) can usually be used for data storage, and the sqlite_master table may be a system table of SQLite, which records tables, indexes, views, and trigger information stored in the database, with each row recording one item.
[0068] When the data operation type is a data addition operation, after the entity to be processed is converted and stored as the target data, the content provider can perform database operations based on the target data. Figure 2In step S250, since the data operation type is a data addition operation, the data insertion function (insert method) of the content provider is triggered, and the insert method carries a parameter URI. The URI contains the entity class name information of the entity to be processed, so the entity name of the entity to be processed can be determined according to the URI. According to the entity name, and through annotation and reflection technology, the data table name configured on the annotation of the entity to be processed can be obtained, that is, the target data table can be determined. In step S260, after the target data table is determined, it can be determined whether the target data table exists by querying the sqlite_master table. In step S270, if the target data table exists in the sqlite_master table, the data addition operation is performed by executing the data insertion function.
[0069] According to another exemplary embodiment of the present disclosure, if the data table set does not include the target data table, a data table creation operation is performed; wherein the data table creation operation includes: parsing the entity identifier to determine the bytecode object corresponding to the entity to be processed; determining the field name corresponding to the entity attribute and the field value corresponding to the entity attribute value according to the bytecode object; generating a data table creation statement according to the field name and the field value, so as to perform the data table creation operation according to the data table creation statement. The parsing process may be a process of parsing the entity identifier into a bytecode object. The bytecode object may be an object of the Class type corresponding to a bytecode file. The data table creation statement may be a database operation statement used to create a data table.
[0070] refer to Figure 2 In step S280, if the data table set does not contain the target data table, a data table creation operation is called. Specifically, the data table creation operation is implemented by the following steps. Figure 5 , Figure 5The flowchart of the data table creation operation is schematically shown. In step S510, when the data insertion function of the content provider is triggered, the execution parameters in the data insertion function can be obtained, wherein the execution parameters include the entity identifier. In step S520, the entity identifier is parsed and processed to obtain the bytecode object corresponding to the JavaBean entity, and the target data table name corresponding to the entity attribute can be determined based on the bytecode object. In step S530, it can be determined whether the data table set contains the target data table. If the data table set contains the target data table name, the data table creation operation ends. In step S540, if the data table set does not contain the target data table name, all attributes in the bytecode object are obtained, and the field names corresponding to each entity attribute are obtained through annotations. In addition, in combination with the data columns corresponding to the field names in the target data table, a data table creation statement for creating the target data table is generated so that the data table creation operation is performed according to the data table creation statement.
[0071] Through the above data table creation operation, when the APP starts, ConentProvider will not create a table, but will create a table when a certain data table is used, which delays the creation process of the data table and can greatly reduce the time-consuming APP startup problem caused by ContentProvider initialization.
[0072] According to another exemplary embodiment of the present disclosure, a query function is executed, and it is determined whether the data table set includes a target data table corresponding to the entity to be processed; if the data table set includes a target data table corresponding to the entity to be processed, a data object corresponding to the entity to be processed is obtained according to the target data table; the data object is mapped and converted through a reflection mechanism to generate a target entity corresponding to the entity to be processed, and the target entity is returned. The query function can be a data query function in a content provider. The data object can be an object type corresponding to the entity to be processed. The mapping conversion process can be a data conversion operation that converts the data object into a target entity.
[0073] refer to Figure 6 , Figure 6The flowchart of the data query operation is schematically shown. In step S610, when the data operation type is a data query operation, the database operation instruction may include the bytecode of the JavaBean entity to be processed. In step S620, the corresponding data column set of the Structured Query Language (SQL) query can be obtained by combining reflection and attribute annotation, the filter parameters are determined, and the where sub-statement is generated according to the filter parameters. In step S630, the URI corresponding to the JavaBean entity is obtained. The process of obtaining the URI is similar to the process of obtaining the URI above, and will not be repeated here. According to the URI, the target data table corresponding to the JavaBean entity can be determined. The target data table and the SQL statement are combined and can be used as the execution parameter of the query function. In step S640, when the query function in the content provider is triggered, it can be determined whether the target data table is included in the data table set. If the target data table is included in the data table set, the query operation is performed based on the target data table, and the data object corresponding to the target entity is returned. In step S650, each data record of the returned data object is mapped to a JavaBean entity through the reflection mechanism, and the JavaBean entity is returned to the data caller to complete the query operation.
[0074] It is easy for technicians in this field to understand that the process of data deletion operation is: first perform a data query operation, and after determining the target data corresponding to the entity to be processed, delete the target data. The operation process of data modification operation can be: obtain the target data corresponding to the entity to be processed through data query operation, delete the target data, and then perform data addition operation to replace the original target data. The above execution steps can all be achieved by combining the data addition operation and the data query operation, so this disclosure will not elaborate on this.
[0075] In summary, the database operation method disclosed in the present invention obtains database operation instructions for the entity to be processed; wherein the database operation instructions include entity annotation information and data operation type; determines the target class name and target application package name corresponding to the entity to be processed, and generates the entity identifier of the entity to be processed based on the target class name and target application package name; determines the target data table corresponding to the entity to be processed according to the entity annotation information and through the reflection mechanism; determines the target function corresponding to the entity to be processed according to the data operation type and the entity identifier, and through the content provider component; executes the target function based on the target data table to perform the database operation corresponding to the data operation type. Through the database operation method disclosed in the present invention, the target function is determined by the content provider, that is, the ContentProvider provided by Android natively is used to operate the database, which can solve the problem of inconsistent cross-process data operations. On the other hand, combined with annotation and reflection technology, a form similar to the ORM framework can be provided to operate the database, and the operation scheme is very lightweight. On the other hand, the creation time of the data table can be delayed, and the data table is created only when the data table is used, which can greatly reduce the time-consuming problem of APP startup caused by ContentProvider initialization. On the other hand, when database operation requirements are required during SDK development, database operation capabilities can be quickly implemented without introducing other ORM frameworks, which can reduce the size of the SDK package and reduce the SDK access cost.
[0076] It should be noted that, although the steps of the method of the present invention are described in a specific order in the drawings, this does not require or imply that the steps must be performed in this specific order, or that all the steps 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, etc.
[0077] In addition, in this exemplary embodiment, a database operation device is also provided. Figure 7 The database operation device 700 may include: an instruction acquisition module 710, an identifier generation module 720, a data table determination module 730, an objective function determination module 740 and an operation module 750.
[0078] Specifically, the instruction acquisition module 710 can be used to obtain database operation instructions for the entity to be processed; wherein the database operation instructions include entity annotation information and data operation type; the identifier generation module 720 can be used to determine the target class name and target application package name corresponding to the entity to be processed, and generate an entity identifier of the entity to be processed based on the target class name and target application package name; the data table determination module 730 can be used to determine the target data table corresponding to the entity to be processed according to the entity annotation information and through the reflection mechanism; the target function determination module 740 can be used to determine the target function corresponding to the entity to be processed according to the data operation type and the entity identifier, and through the content provider component; the operation module 750 can be used to execute the target function based on the target data table to perform a database operation corresponding to the data operation type.
[0079] The database operation device 700 can determine the target data table corresponding to the entity to be processed through annotation and reflection technology. The use of annotation and reflection technology can provide database operations similar to the ORM framework, making database operations more lightweight; operating the database through the content provider component can solve the problem of inconsistent cross-process data operations, and when performing cross-process database operations, there is no need to introduce a new SDK package, which can reduce the size of the SDK package and reduce the SDK access cost. It is an effective database operation device.
[0080] In an exemplary embodiment of the present disclosure, based on the aforementioned scheme, the database operation device also includes a parameter generation module, which is used to determine the entity attributes and entity attribute values corresponding to the entity to be processed; map the entity attributes and entity attribute values to the target data class to generate target data corresponding to the entity to be processed; wherein the target data class is a data type corresponding to the content provider component.
[0081] In an exemplary embodiment of the present disclosure, based on the aforementioned scheme, the parameter generation module includes an attribute determination unit, which is used to obtain entity attributes corresponding to the entity to be processed through a reflection mechanism; determine the entity attribute values corresponding to the entity attributes and the attribute types of the entity attribute values from the target data table according to the entity annotation information.
[0082] In an exemplary embodiment of the present disclosure, based on the aforementioned scheme, the operation module includes an adding operation unit, which is used to obtain a data table set and determine whether the data table set includes a target data table; if the data table set includes the target data table, a data insertion function is executed based on the target data table to perform a data adding operation.
[0083] In an exemplary embodiment of the present disclosure, based on the aforementioned scheme, the operation module also includes a data table creation unit, which is used to perform a data table creation operation if the data table set does not include a target data table; wherein the data table creation operation includes: parsing the entity identifier to determine the bytecode object corresponding to the entity to be processed; determining the field name corresponding to the entity attribute and the field value corresponding to the entity attribute value according to the bytecode object; generating a data table creation statement according to the field name and the field value, so as to perform the data table creation operation according to the data table creation statement.
[0084] In an exemplary embodiment of the present disclosure, based on the aforementioned scheme, the operation module also includes a query operation unit, which is used to execute a query function and determine whether the data table set includes a target data table corresponding to the entity to be processed; if the data table set includes a target data table corresponding to the entity to be processed, then the data object corresponding to the entity to be processed is obtained according to the target data table; the data object is mapped and converted through a reflection mechanism to generate a target entity corresponding to the entity to be processed, and the target entity is returned.
[0085] Furthermore, in another exemplary embodiment, a database operating system is provided. Figure 8 The database operating system 800 may include: an annotation module 810 , a data providing module 820 and a database operating module 830 .
[0086] Specifically, the annotation module 810 may be used to store a mapping relationship between an entity to be processed and a target data table corresponding to the entity to be processed.
[0087] The data providing module 820 can be used to determine the entity identifier of the entity to be processed, and convert the entity to be processed into the corresponding target data, so as to perform database operations according to the target data. The data providing module 820 can include an identifier operation submodule 821 and a target data determination submodule 822. The identifier operation submodule 821 can obtain the unique entity identifier corresponding to the entity to be processed through the content provider component, so as to determine the corresponding target data table according to the entity identifier; the target data determination submodule 822 can convert the entity to be processed into the corresponding target data, and transmit the target data to the content provider component, so that the content provider component completes the database operation in the database 840.
[0088] The database operation module 830 is used to perform database operations according to the database operation instructions for the entity to be processed; wherein, the database operation module includes an operation statement generation submodule 831 and a mapping submodule 832, the operation statement generation submodule 831 can be used to generate an operation statement for performing database operations, so as to perform database operations according to the operation statement and through the data providing module. The mapping submodule 832 can be used to perform conversion processing on the entity to be processed.
[0089] The database operating system 800 can mark the mapping between the JavaBean entity and the corresponding data table through the annotation module; then, use the content provider component provided by the data provision module to obtain the unique entity identifier corresponding to the JavaBean entity to determine the data table corresponding to the entity, and realize the conversion between the JavaBean entity and the target data, so that the content provider component can complete the database operation based on the target data; in addition, database operations such as adding, deleting, modifying, checking, and batch operations are performed through the database operation module.
[0090] The specific details of each virtual database operation device module mentioned above have been described in detail in the corresponding database operation method, so they will not be repeated here.
[0091] It should be noted that although several modules or units of the database operation device are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided into multiple modules or units for embodiment.
[0092] In addition, in an exemplary embodiment of the present disclosure, an electronic device capable of implementing the above method is also provided.
[0093] It will be appreciated by those skilled in the art that various aspects of the present invention may be implemented as systems, methods or program products. Therefore, various aspects of the present invention may be specifically implemented in the following forms, namely: complete hardware embodiments, complete software embodiments (including firmware, microcode, etc.), or embodiments combining hardware and software aspects, which may be collectively referred to herein as "circuits", "modules" or "systems".
[0094] Reference below Fig. 9 An electronic device 900 according to such an embodiment of the present invention will be described. Fig. 9 The electronic device 900 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0095] like Fig. 9As shown, the electronic device 900 is in the form of a general computing device. The components of the electronic device 900 may include, but are not limited to: the at least one processing unit 910, the at least one storage unit 920, a bus 930 connecting different system components (including the storage unit 920 and the processing unit 910), and a display unit 940.
[0096] The storage unit stores program codes, which can be executed by the processing unit 910, so that the processing unit 910 executes the steps according to various exemplary embodiments of the present invention described in the above “Exemplary Method” section of this specification.
[0097] The storage unit 920 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 921 and / or a cache memory unit 922 , and may further include a read-only memory unit (ROM) 923 .
[0098] The storage unit 920 may include a program / utility 924 having a set (at least one) of program modules 925, such program modules 925 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0099] Bus 930 may represent one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
[0100] The electronic device 900 may also communicate with one or more external devices 970 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 900, and / or communicate with any device that enables the electronic device 900 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 950. Furthermore, the electronic device 900 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via a network adapter 960. As shown, the network adapter 960 communicates with other modules of the electronic device 900 via a bus 930. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 900, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, etc.
[0101] Through the description of the above embodiments, it is easy for those skilled in the art to understand that the example embodiments described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the embodiment of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the embodiment of the present disclosure.
[0102] In an exemplary embodiment of the present disclosure, a computer-readable storage medium is also provided, on which a program product capable of implementing the above method of the present specification is stored. In some possible embodiments, various aspects of the present invention can also be implemented in the form of a program product, which includes a program code, and when the program product is run on a terminal device, the program code is used to enable the terminal device to perform the steps according to various exemplary embodiments of the present invention described in the above "Exemplary Method" section of the present specification.
[0103] refer to Fig.10 As shown, a program product 1000 for implementing the above method according to an embodiment of the present invention is described, which can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited thereto. In this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, an apparatus or a device.
[0104] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0105] Computer readable signal media may include data signals propagated in baseband or as part of a carrier wave, in which readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Readable signal media may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0106] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing.
[0107] Program code for performing the operations of the present invention may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., through the Internet using an Internet service provider).
[0108] In addition, the above-mentioned figures are only schematic illustrations of the processes included in the method according to an exemplary embodiment of the present invention, and are not intended to be limiting. It is easy to understand that the processes shown in the above-mentioned figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.
[0109] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary technical means in the art that are not disclosed in the present disclosure. The specification and examples are to be considered as exemplary only, and the true scope and spirit of the present disclosure are indicated by the claims.
[0110] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A database operation method, characterized in that: include: Obtaining a database operation instruction for the entity to be processed; wherein the database operation instruction includes entity annotation information and data operation type; Determine a target class name and a target application package name corresponding to the entity to be processed, and generate an entity identifier of the entity to be processed based on the target class name and the target application package name; Determine the target data table corresponding to the entity to be processed according to the entity annotation information and through the reflection mechanism; According to the data operation type and the entity identifier, and through the content provider component, determine the target function corresponding to the entity to be processed; The target function is executed based on the target data table to perform a database operation corresponding to the data operation type.
2. The database operation method according to claim 1, characterized in that: The data operation type includes one or more of a data adding operation, a data deleting operation, a data modifying operation and a data query operation.
3. The database operation method according to claim 1, characterized in that: The data operation type includes a data adding operation. After determining the target data table corresponding to the entity to be processed through a reflection mechanism according to the entity annotation information, the method further includes: Determine entity attributes and entity attribute values corresponding to the entity to be processed; The entity attributes and entity attribute values are mapped to a target data class to generate target data corresponding to the entity to be processed; wherein the target data class is a data type corresponding to the content provider component.
4. The database operation method according to claim 3, characterized in that: The determining of the entity attribute and entity attribute value corresponding to the entity to be processed includes: Obtaining entity attributes corresponding to the entity to be processed through a reflection mechanism; An entity attribute value corresponding to the entity attribute and an attribute type of the entity attribute value are determined from the target data table according to the entity annotation information.
5. The database operation method according to claim 3, characterized in that: The target function includes a data insertion function, and executing the target function based on the target data table to perform a database operation corresponding to the data operation type includes: Acquire a data table set, and determine whether the data table set includes the target data table; If the data table set includes the target data table, the data insertion function is executed based on the target data table to perform the data adding operation.
6. The database operation method according to claim 5, characterized in that: The method further comprises: If the data table set does not include the target data table, executing a data table creation operation; The step of executing the data table creation operation includes: Parsing the entity identifier to determine the bytecode object corresponding to the entity to be processed; Determine, according to the bytecode object, a field name corresponding to the entity attribute and a field value corresponding to the entity attribute value; A data table creation statement is generated according to the field name and the field value, so as to perform the data table creation operation according to the data table creation statement.
7. The database operation method according to claim 1, characterized in that: The data operation type includes a data query operation, the target function includes a query function, and executing the target function based on the target data table to perform a database operation corresponding to the data operation type includes: Execute the query function and determine whether the data table set includes a target data table corresponding to the entity to be processed; If the data table set includes a target data table corresponding to the entity to be processed, acquiring a data object corresponding to the entity to be processed according to the target data table; The data object is mapped and converted through a reflection mechanism to generate a target entity corresponding to the entity to be processed, and the target entity is returned.
8. A database operation device, characterized in that: include: An instruction acquisition module, used to acquire a database operation instruction for an entity to be processed; wherein the database operation instruction includes entity annotation information and a data operation type; An identifier generation module, used to determine a target class name and a target application package name corresponding to the entity to be processed, and generate an entity identifier of the entity to be processed based on the target class name and the target application package name; A data table determination module, used to determine a target data table corresponding to the entity to be processed according to the entity annotation information and through a reflection mechanism; An objective function determination module, configured to determine an objective function corresponding to the entity to be processed according to the data operation type and the entity identifier and through a content provider component; An operation module is used to execute the target function based on the target data table to perform a database operation corresponding to the data operation type.
9. A database operating system, characterized in that: include: An annotation module, used for storing a mapping relationship between an entity to be processed and a target data table corresponding to the entity to be processed; A data providing module, used to determine the entity identifier of the entity to be processed, and convert the entity to be processed into corresponding target data, so as to perform database operations according to the target data; A database operation module, used to perform database operations according to the database operation instructions for the entity to be processed; wherein the database operation instructions include entity annotation information and data operation types, and the database operation module includes an operation statement generation submodule and a mapping submodule, wherein the operation statement generation submodule is used to generate an operation statement for performing database operations, and the mapping submodule is used to perform conversion processing on the entity to be processed; The database operation module is also used to determine the target function corresponding to the entity to be processed according to the data operation type and the entity identifier and through the content provider component; execute the target function based on the target data table to perform the database operation corresponding to the data operation type.
10. An electronic device, characterized in that: include: processor; as well as A memory having computer-readable instructions stored thereon, wherein the computer-readable instructions, when executed by the processor, implement the database operation method according to any one of claims 1 to 7.
11. A computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the database operation method according to any one of claims 1 to 7 is implemented.
