Data access control method and device, electronic equipment and storage medium
By classifying and instantiating database access information, generating structured query statements, and executing batch access when conditions are met, the problem of reduced application performance in complex business scenarios is solved, and more efficient database access control is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-09
- Publication Date
- 2026-03-27
AI Technical Summary
In existing technologies, frequent database access requests by applications in complex business scenarios lead to a large number of repetitive rule judgments, consuming resources and reducing application performance.
By obtaining database access information, determining the target category and instantiating objects, generating structured query statements, and performing batch access operations when preset conditions are met, the number of rule judgments and database access requests is reduced.
This reduced the number of database access requests, improved application performance, and ensured the normal operation of business functions.
Smart Images

Figure CN116257542B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a database access control method and device, electronic equipment and storage medium. BACKGROUND
[0002] With the popularity of intelligent terminals, more and more application programs are installed in intelligent terminals, and with the iteration of business, the complexity of application programs is also increasing. A large amount of data is generated during the running of the application program. In order to store the generated data for subsequent data collection and analysis, the generated data needs to be written into the database.
[0003] In the related art, each database access request generated by the application program for the business will be judged by rules. If the access request meets the cache query rule, the access request is processed in the distributed cache system. If the access request does not meet the cache query rule, the access request is processed in the relational database such as MySQL database, wherein the data in the relational database is synchronized with the data in the distributed cache system. In this way, when the business involved in the application program is complex, a large number of database access requests generated by the business will result in a large number of repeated rule judgments and consume a large amount of resources, thereby reducing the performance of the application program. For example, when the user clicks some buttons on the application program page, the click data will be recorded in the user behavior statistics database every time. When the user's click volume is too large, the frequency of writing statistical data will be too high, thereby reducing the performance of the application program. SUMMARY
[0004] In order to solve the problems of the prior art, the embodiments of the present application provide a database access control method and device, electronic equipment and storage medium. The technical solution is as follows:
[0005] On the one hand, a database access control method is provided, and the method comprises:
[0006] Obtaining database access information, wherein the database access information represents an access operation on a database;
[0007] Determining a target classification to which the database access information belongs;
[0008] Instantiating the database access information to obtain an instantiated object, and storing the instantiated object in an instantiated object set corresponding to the target classification;
[0009] When a preset condition is met, generating a structured query statement corresponding to each instantiated object according to attribute information carried by each instantiated object in the instantiated object set;
[0010] According to the structured query statements corresponding to each of the instantiation objects, the first access module performs corresponding access operations on the database.
[0011] In another aspect, a database access control apparatus is provided, the apparatus comprising:
[0012] An access information obtaining module is configured to obtain database access information, the database access information representing an access operation on a database.
[0013] A classification module is configured to determine a target classification to which the database access information belongs.
[0014] An object instantiation module is configured to instantiate the database access information into an object to obtain an instantiation object, and store the instantiation object into an instantiation object set corresponding to the target classification.
[0015] A first query statement generating module is configured to, when a preset condition is met, generate a structured query statement corresponding to each of the instantiation objects according to attribute information carried by each of the instantiation objects in the instantiation object set.
[0016] The first access module is configured to perform corresponding access operations on the database according to the structured query statements corresponding to each of the instantiation objects.
[0017] In an exemplary embodiment, the first query statement generating module comprises:
[0018] A mutex lock assigning module is configured to traverse the instantiation objects in the instantiation object set, and assign a pre-created mutex lock to a current instantiation object that is traversed.
[0019] A generating submodule is configured to generate a structured query statement corresponding to the current instantiation object according to attribute information carried by the current instantiation object, the assigned mutex lock, and a preset conversion rule.
[0020] In an exemplary embodiment, the preset condition comprises:
[0021] The number of instantiation objects in the instantiation object set reaches a preset number threshold; or
[0022] A timing duration corresponding to the instantiation object set reaches a preset duration, the timing duration being a duration from a time when a structured query statement of the instantiation object set is last generated.
[0023] In an exemplary embodiment, the apparatus further comprises:
[0024] A target instantiation object determination module is configured to determine a target instantiation object in the instantiation object set in response to an instruction of a failed access operation on the database; the target instantiation object includes an instantiation object corresponding to an unexecuted structured query statement and an instantiation object associated with the instantiation object corresponding to the unexecuted structured query statement;
[0025] An object file generation module is configured to generate an object file according to the target instantiation object; the object file includes file header information and a data storage area, the file header information is used to describe attributes of the object file, the attributes of the object file include a current offset of a database table in the database, and the data storage area is used to store the target instantiation object.
[0026] In an exemplary embodiment, the apparatus further includes:
[0027] An object file reading module is configured to acquire the target instantiation object in response to a reading instruction of the object file;
[0028] A second query statement generation module is configured to generate a structured query statement corresponding to the target instantiation object according to attribute information carried by the target instantiation object;
[0029] A second access module is configured to perform a corresponding access operation on the database according to the structured query statement corresponding to the target instantiation object and the current offset.
[0030] In an exemplary embodiment, the first access module includes:
[0031] An operation type determination module is configured to determine an operation type of an access operation corresponding to each structured query statement;
[0032] An encapsulation module is configured to encapsulate the structured query statements of a same operation type to obtain a structured query statement encapsulation package corresponding to each operation type;
[0033] An access submodule is configured to perform a corresponding access operation on the database according to each structured query statement encapsulation package.
[0034] In an exemplary embodiment, the classification module includes:
[0035] A source service determination module is configured to determine a source service of the database access information;
[0036] The classification submodule is configured to determine a target classification to which the database access information belongs according to a preset classification rule corresponding to the source service.
[0037] In another aspect, an electronic device is provided, which includes a processor and a memory having stored therein at least one instruction or at least one program, the at least one instruction or the at least one program being loaded and executed by the processor to implement the above-described database access control method.
[0038] In another aspect, a computer-readable storage medium is provided, which has stored therein at least one instruction or at least one program, the at least one instruction or the at least one program being loaded and executed by a processor to implement the above-described database access control method.
[0039] In another aspect, a computer program product or computer program is provided, which includes computer instructions stored in a computer-readable storage medium. A processor of an electronic device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions to cause the electronic device to perform the above-described database access control method.
[0040] The embodiments of the present application obtain database access information, determine a target classification to which the database access information belongs, instantiate the database access information to obtain an instantiated object, and store the instantiated object in an instantiated object set corresponding to the target classification. Then, when a preset condition is met, a structured query statement corresponding to each instantiated object is generated according to attribute information carried by each instantiated object in the instantiated object set, and a corresponding access operation is performed on the database according to the structured query statement corresponding to each instantiated object. Thus, the number of access requests to the database is reduced, a large number of rule judgments can be filtered out, the access to the database is reduced while the business function is ensured, and the performance of the application program is improved. BRIEF DESCRIPTION OF DRAWINGS
[0041] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative effort based on these drawings.
[0042] Figure 1 is a schematic diagram of an implementation environment provided by the embodiments of the present application;
[0043] Figure 2is a schematic diagram of an architecture for implementing database access control provided by an embodiment of the present application;
[0044] Figure 3 is a schematic diagram of a flow of a database access control method provided by an embodiment of the present application;
[0045] Figure 4 is a schematic diagram of a flow of another database access control method provided by an embodiment of the present application;
[0046] Figure 5 is a schematic diagram of a flow of another database access control method provided by an embodiment of the present application;
[0047] Figure 6 is a structural block diagram of a database access control device provided by an embodiment of the present application;
[0048] Figure 7 is a hardware structural block diagram of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0049] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, but not all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the scope of the present application.
[0050] It should be noted that the terms "first", "second", and the like in the specification and claims of the present application and the above-described drawings are used to distinguish similar objects, and do not necessarily indicate a specific order or a chronological sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product, or server including a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but can include other steps or units not clearly listed or inherent to the process, method, product, or device.
[0051] It can be understood that in the specific embodiments of the present application, data related to user information and the like is involved, and when the above embodiments of the present application are applied to specific products or technologies, user permission or consent needs to be obtained, and the collection, use, and processing of related data need to comply with relevant laws, regulations, and standards of relevant countries and regions.
[0052] Please refer to Figure 1As shown in the figure, an implementation environment provided by an embodiment of the application is shown, which can include a terminal 110 and a database 120. The terminal 110 and the database 120 can be directly or indirectly connected through wired or wireless communication, which is not limited in the present application.
[0053] The terminal 110 can include but is not limited to a mobile phone, a computer, a smart voice interaction device, a smart home appliance, a vehicle-mounted terminal, etc. The terminal 110 is installed with an application (Application, APP for short) providing a service function, which can be an independent application or a subprogram in the application.
[0054] The database 120 can be used to store data generated by the application in the terminal 110 during running, for example, if a user clicks a certain button of the application page in the terminal 110, the click data can be stored in the database 120. It should be noted that the database 120 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDNs, and basic cloud computing services such as big data and artificial intelligence platforms.
[0055] The service function provided by the application can be realized through different service function modules in the application. For some rapidly iterated service function modules, H5, RN (React Native) or Flutter cross-platform technologies are generally used for development, and the access of the application to the database 120 is controlled by the bridge layer of the application Native end.
[0056] As shown in the figure, an implementation environment provided by an embodiment of the application is shown, which can include a terminal 110 and a database 120. The terminal 110 and the database 120 can be directly or indirectly connected through wired or wireless communication, which is not limited in the present application. Figure 2 As shown in the figure, an implementation environment provided by an embodiment of the application is shown, which can include a terminal 110 and a database 120. The terminal 110 and the database 120 can be directly or indirectly connected through wired or wireless communication, which is not limited in the present application.
[0057] In an exemplary embodiment, the terminal 110 and the database 120 can be node devices in a blockchain system, capable of sharing the acquired and generated information to other node devices in the blockchain system, realizing information sharing between multiple node devices. The multiple node devices in the blockchain system can be configured with the same blockchain, which is composed of multiple blocks, and the adjacent blocks have a correlation relationship, so that when the data in any block is tampered with, it can be detected through the next block, so as to avoid the data in the blockchain being tampered with, and ensure the security and reliability of the data in the blockchain.
[0058] The database access control method provided by the embodiment of the application relates to cloud technology. The cloud technology refers to a kind of hosting technology that unifies series resources such as hardware, software and network in wide area network or local area network, realizes the calculation, storage, processing and sharing of data. The cloud technology is based on network technology, information technology, integration technology, management platform technology, application technology and the like applied in cloud computing business model, can constitute resource pool, and is used on demand, flexible and convenient. Cloud computing technology will become an important support. The background service of technical network system needs a large amount of computing and storage resources, such as video website, picture website and more portal website. With the high development and application of internet industry, every item may have its own identification mark in the future, and needs to be transmitted to the background system for logical processing. Different levels of data will be processed separately, and data of various industries need strong system support. Only through cloud computing can it be realized.
[0059] Database (Database), in short, can be regarded as an electronic file cabinet - a place to store electronic files, users can add, query, update, delete and other operations on the data in the file. So-called "database" is a collection of data stored together in a certain way, can be shared by multiple users, has the smallest possible redundancy, and is independent of application programs.
[0060] A Database Management System (DBMS) is a computer software system designed to manage databases, generally possessing basic functions such as storage, retrieval, security, and backup. DBMSs can be classified according to the database model they support, such as relational or XML (Extensible Markup Language); or according to the type of computer they support, such as server clusters or mobile devices; or according to the query language used, such as SQL (Structured Query Language) or XQuery; or according to performance priorities, such as maximum scale or maximum operating speed; or other classification methods. Regardless of the classification method used, some DBMSs can cross categories, for example, supporting multiple query languages simultaneously.
[0061] In this embodiment of the invention, the database 120 can be a relational database that supports SQL, such as a MySQL database.
[0062] Please see Figure 3 The diagram shown is a flowchart illustrating a database access control method provided in an embodiment of the present invention. This database access control method can be applied to... Figure 2 The application shown is a bridging layer. It should be noted that this specification provides the operational steps of the methods described in the embodiments or flowcharts, but based on conventional or non-inventive labor, more or fewer operational steps may be included. The order of steps listed in the embodiments is merely one possible execution order among many and does not represent the only execution order. In actual system or product execution, the methods shown in the embodiments or drawings can be executed sequentially or in parallel (e.g., in a parallel processor or multi-threaded processing environment). Specifically, as shown... Figure 3 As shown, the method may include:
[0063] S301, obtain database access information.
[0064] Database access information represents the operations performed on the database. This information can be determined based on business behavior data, such as click behavior data of a specific business module in an application. Database access information can include fields, attributes, and actions related to the database access operation, such as creating a database file, manipulating database tables (e.g., adding, deleting, and modifying data in the corresponding database table), opening, and closing the database.
[0065] In a specific implementation, the address access to a relational database (such as sqLite) when a page component starts to load can be intercepted by using a method of intercepting data start transmission, and the generated database access information can be recorded by using a pre-created SQLWrapper (SQL wrapper) in a bridge layer.
[0066] S303, determine a target classification to which the database access information belongs.
[0067] In the embodiment of the application, the rules of classification can be pre-set based on the functions of the business function modules, for example, the list display of an end page is classified by a query operation; and the download module is classified by an insertion dimension, for example, the insertion dimension can include an audio / video dimension, a file dimension, and a picture dimension.
[0068] Based on this, in an exemplary embodiment, the step S303 of determining the target classification to which the database access information belongs can include:
[0069] determining a source business of the database access information;
[0070] determining a target classification to which the database access information belongs according to a preset classification rule corresponding to the source business;
[0071] The preset classification rule is a rule pre-configured based on a business function corresponding to the source business.
[0072] In a specific implementation, the source business corresponding to the database access information can be determined based on the business behavior data corresponding to the database access information, and then the preset classification rule of the source business is obtained, and the database access information is classified according to the preset classification rule to obtain the target classification to which the database access information belongs.
[0073] In the above embodiment, by determining the source business of the database access information, and since the preset classification rule is configured based on the business function corresponding to the source business, when the target classification to which the database access information belongs is determined based on the preset classification rule corresponding to the source business, the accuracy of classification can be improved, and then the accuracy of subsequent database access can be improved.
[0074] S305, instantiating the database access information to obtain an instantiated object, and storing the instantiated object into an instantiated object set corresponding to the target classification.
[0075] Instantiation refers to a process of creating an object by using a class in object-oriented programming, which is a process of specifically realizing an abstract concept class. In most languages, instantiating an object can allocate memory space for the object.
[0076] The instantiation manner of the object can adopt any one of the following: directly new an object; generating an object by using a reflection mechanism through Class.forName("fully qualified name of the class"); and generating an object by using a constructor through Class.forName("fully qualified name of the class") and then obtaining a construction method.
[0077] Taking the instantiation manner of generating an object by using a reflection mechanism as an example, the database access information can be subjected to serialization processing, and then the serialized database access information is subjected to object generation by using a reflection mechanism, wherein the reflection mechanism is that, in a running state, all attributes and methods of any class can be known, and any method and attribute of any object can be called, and the functions of dynamically obtaining information and dynamically calling the method of the object are referred to as the reflection mechanism of the java language.
[0078] According to the object instantiation of the database access information, the operation data flow of the database can be converted into the memory space, so that there are the instantiation object sets corresponding to each category in the memory space, and each instantiation object set can include a plurality of instantiation objects corresponding to the same category.
[0079] It should be noted that each instantiation object carries corresponding attribute information, and the attribute information is used for positioning the operation of the database file and the database table.
[0080] S307, when a preset condition is met, generating a structured query statement corresponding to each instantiation object according to the attribute information carried by each instantiation object in the instantiation object set.
[0081] The preset condition can include:
[0082] The number of instantiation objects in the instantiation object set reaches a preset number threshold; or,
[0083] The timing duration corresponding to the instantiation object set reaches a preset duration, and the timing duration refers to the duration from the last time the structured query statement of the instantiation object set is generated.
[0084] The preset number threshold can be pre-set according to actual experience, for example, 50. The preset duration can also be pre-set according to actual experience, for example, 5 minutes.
[0085] Based on this, in one specific embodiment, the number of instantiated objects in the instantiated object set corresponding to the target classification can be counted, and when the number of counted instantiated objects reaches a preset number threshold, it indicates that the preset condition is currently met. The attribute information carried by each instantiated object in the instantiated object set corresponding to the target classification can be used to generate a structured query statement SQL statement corresponding to each instantiated object, thereby obtaining a SQL statement set corresponding to the instantiated object set.
[0086] In another specific embodiment, a timer can be configured for each instantiated object set, which is used to record the time length from the last time the SQL statement of the corresponding instantiated object set is generated. When the timing length of the timer reaches a preset time length, it indicates that the preset condition is currently met. The attribute information carried by each instantiated object in the corresponding instantiated object set can be used to generate a structured query statement SQL statement corresponding to each instantiated object, thereby obtaining a SQL statement set corresponding to the instantiated object set.
[0087] In the embodiment of the application, the above step S307 can be implemented based on a preset conversion rule to obtain the attribute information carried by the instantiated object, and then convert the attribute information of the instantiated object into a corresponding SQL statement. The preset conversion rule is usually referred to as a runtime generation mapping method, i.e. SQLMap method. The parameters in the method can include a mapping start address beginAddress, which is generally allocated by the system; a mapping region length length, which is in units of bytes; a database file handle fileHandle; a flag indicating whether the region is a protected region, which is a Boolean value and consistent with the setting of the fileHandle opening.
[0088] S309, performing corresponding access operations on the database according to the structured query statements corresponding to each of the instantiated objects.
[0089] Specifically, the bridge layer performs batch access operations on the database according to the structured query statements corresponding to each instantiated object, thereby reducing the number of access requests to the database, filtering out a large number of rule judgments, ensuring business functions while reducing read and write operations on the database, and improving the performance of the application program.
[0090] In one exemplary embodiment, in order to improve the efficiency of performing access operations on the database, the above step S309 can include the following steps when implemented:
[0091] determining the operation type of the access operation corresponding to each of the structured query statements;
[0092] packaging the structured query statements of the same operation type to obtain a structured query statement packaging package corresponding to each of the operation types;
[0093] According to each of the structured query statement encapsulation packages, a corresponding access operation is performed on the database.
[0094] The operation type of the access operation can include adding, changing, querying, and deleting. By encapsulating SQL statements of the same operation type and performing a corresponding access operation on the database based on each SQL statement encapsulation package, the efficiency of the access operation on the database can be improved.
[0095] In an example embodiment, in order to uniformly protect the access operation on the database and prevent crashes or data disorder caused by multi-threaded access to data, as shown in Figure 4 When the structured query statement corresponding to each of the instantiated objects is generated according to the attribute information carried by each of the instantiated objects in the instantiated object set, the step S307 can include:
[0096] S401, iterating through the instantiated objects in the instantiated object set, and for a current instantiated object that is iterated through, assigning a pre-created mutex to the current instantiated object;
[0097] S403, generating a structured query statement corresponding to the current instantiated object according to the attribute information carried by the current instantiated object, the assigned mutex, and a preset conversion rule.
[0098] In the above embodiment, when the SQL statement conversion is performed, a mutex is assigned to each instantiated object, and the mutex protection is started, so that only one thread can access the instantiated object at any time, and crashes or data disorder caused by multi-threaded access to data are avoided.
[0099] In actual application, after the instantiated object set is created, there can be a situation that the application program exits, resulting in that no corresponding access operation is performed on the database or only part of the access operation is performed. In order to avoid data loss caused by this situation, in an example embodiment, as shown in Figure 5 The method can further include:
[0100] S501, in response to an instruction that an access operation on the database fails, determining a target instantiated object in the instantiated object set.
[0101] The target instantiated object includes an instantiated object corresponding to an unexecuted structured query statement and an instantiated object associated with the instantiated object corresponding to the unexecuted structured query statement. In a specific implementation, the instruction that the access operation on the database fails can be an instruction issued when the application program exits.
[0102] Assuming that the preset condition is met, the target classification corresponds to a set of instantiated objects, and the set of instantiated objects includes five instantiated objects, i.e., {instantiated object 1, instantiated object 2, instantiated object 3, instantiated object 4, and instantiated object 5}. Correspondingly, the set of SQL statements is {SQL statement 1, SQL statement 2, SQL statement 3, SQL statement 4, and SQL statement 5}. The bridge layer performs batch access operations on the database based on the set of SQL statements. At a certain moment, the bridge layer receives an instruction that the access operation on the database fails. Assuming that SQL statement 1, SQL statement 2, and SQL statement 3 have been executed at this moment, in response to the instruction, the target instantiated objects can be determined to include instantiated object 4 (the instantiated object corresponding to the unexecuted SQL statement 4) and instantiated object 5 (the instantiated object corresponding to the unexecuted SQL statement 5). If instantiated object 4 is associated with instantiated object 2, the target instantiated objects further include instantiated object 2. That is, the finally determined target instantiated objects are {instantiated object 2, instantiated object 4, and instantiated object 5}.
[0103] S503, generating an object file according to the target instantiated object.
[0104] The object file includes file header information and a data storage area. The file header information is used to describe the properties of the object file, and the properties of the object file include the current offset of the database table in the database. The data storage area is used to store the target instantiated object.
[0105] It can be understood that the properties of the object file can also include other information, such as the class name of the target classification corresponding to the set of instantiated objects, the number of target instantiated objects, and the like.
[0106] The above embodiment saves the target instantiated object by generating an object file, so that the access operation on the database can be performed in a timely and accurate manner based on the object file in the future, and data loss is avoided.
[0107] In an exemplary embodiment, please continue to refer to Figure 5 After generating the object file according to the target instantiated object, the method can further include:
[0108] S505, in response to a read instruction for the object file, the target instantiated object is obtained.
[0109] The read instruction for the object file can be issued when the application is started again, or can be issued when the preset condition is met after being started again, so that the bridge layer can read the object file to obtain the target instantiated object in response to the read instruction, and can also obtain the file header information of the object file.
[0110] S507, generating a structured query statement corresponding to the target instantiated object according to attribute information carried by the target instantiated object.
[0111] The specific implementation process of this step can be referred to the related description in the foregoing step S307 of the embodiment of the present application, which will not be described here again.
[0112] S509, performing a corresponding access operation on the database according to the structured query statement corresponding to the target instantiated object and the current offset.
[0113] The current offset of the database table can be used to locate data at a corresponding position in the database table, and then the access operation corresponding to the structured query statement corresponding to the target instantiated object can be quickly and accurately performed on the database.
[0114] As can be seen from the above technical solutions of the embodiment of the present application, the embodiment of the present application pre-processes the access information of the business in the application program to the database by using the bridge layer, and then performs a batch access operation on the database on the pre-processed data when the preset condition is met, so as to reduce the access to the database while ensuring the business function, and improve the performance of the application program.
[0115] Corresponding to the database access control method provided by the above several embodiments, the embodiment of the present application also provides a database access control device. Since the database access control device provided by the embodiment of the present application corresponds to the database access control method provided by the above several embodiments, the implementation mode of the foregoing database access control method is also applicable to the database access control device provided by the present embodiment, which will not be described in detail in the present embodiment.
[0116] Please refer to Figure 6 which is a structural schematic diagram of a database access control device provided by the embodiment of the present application. The device has the function of implementing the database access control method in the above method embodiments. The function can be realized by hardware, or the corresponding software can be executed by hardware. As shown in Figure 6 The database access control device 600 can include:
[0117] The access information acquisition module 610 is configured to acquire database access information, and the database access information represents an access operation on a database.
[0118] The classification module 620 is configured to determine a target classification to which the database access information belongs.
[0119] The object instantiation module 630 is configured to instantiate the object based on the database access information to obtain an instantiated object, and store the instantiated object in an instantiated object set corresponding to the target category.
[0120] The first query statement generation module 640 is configured to generate a structured query statement corresponding to each instantiated object in the instantiated object set according to attribute information carried by each instantiated object in the instantiated object set when a preset condition is met.
[0121] The first access module 650 is configured to perform a corresponding access operation on the database according to the structured query statement corresponding to each instantiated object.
[0122] In an exemplary embodiment, the first query statement generation module 640 includes:
[0123] The mutex allocation module is configured to traverse the instantiated objects in the instantiated object set, and allocate a pre-created mutex to a current instantiated object that is traversed.
[0124] The generation sub-module is configured to generate a structured query statement corresponding to the current instantiated object according to attribute information carried by the current instantiated object, the allocated mutex, and a preset conversion rule.
[0125] In an exemplary embodiment, the preset condition includes:
[0126] The number of instantiated objects in the instantiated object set reaches a preset number threshold; or
[0127] A timing duration corresponding to the instantiated object set reaches a preset duration, and the timing duration refers to a duration from a time when a structured query statement of the instantiated object set is last generated.
[0128] In an exemplary embodiment, the apparatus 600 further includes:
[0129] The target instantiated object determination module is configured to determine a target instantiated object in the instantiated object set in response to an instruction that an access operation on the database fails; the target instantiated object includes an instantiated object corresponding to an unexecuted structured query statement, and an instantiated object associated with the instantiated object corresponding to the unexecuted structured query statement.
[0130] An object file generation module is configured to generate an object file according to the target instantiation object; the object file comprises file header information and a data storage area; the file header information is used to describe attributes of the object file, and the attributes of the object file comprise a current offset of a database table in the database; and the data storage area is used to store the target instantiation object.
[0131] In an exemplary embodiment, the apparatus 600 further comprises:
[0132] An object file reading module is configured to acquire the target instantiation object in response to a reading instruction of the object file.
[0133] A second query statement generation module is configured to generate a structured query statement corresponding to the target instantiation object according to attribute information carried by the target instantiation object.
[0134] A second access module is configured to perform a corresponding access operation on the database according to the structured query statement corresponding to the target instantiation object and the current offset.
[0135] In an exemplary embodiment, the first access module 650 comprises:
[0136] An operation type determination module is configured to determine an operation type of an access operation corresponding to each structured query statement.
[0137] An encapsulation module is configured to encapsulate the structured query statements of a same operation type to obtain a structured query statement encapsulation package corresponding to each operation type.
[0138] An access submodule is configured to perform a corresponding access operation on the database according to each structured query statement encapsulation package.
[0139] In an exemplary embodiment, the classification module 620 comprises:
[0140] A source service determination module is configured to determine a source service of the database access information.
[0141] A classification submodule is configured to determine a target classification to which the database access information belongs according to a preset classification rule corresponding to the source service; the preset classification rule is a rule preconfigured based on a service function corresponding to the source service.
[0142] It should be noted that the apparatus provided by the above embodiments, in realizing its functions, only divides the above-mentioned various functional modules by way of example, and in actual application, the above-mentioned functions can be completed by different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the above-described functions. In addition, the apparatus and method embodiments provided by the above embodiments belong to the same concept, and the specific implementation process is detailed in the method embodiments, which will not be repeated here.
[0143] The electronic device provided by the embodiment of the present application comprises a processor and a memory, and the memory stores at least one instruction or at least one program, which is loaded and executed by the processor to realize the database access control method provided by the above method embodiment.
[0144] The memory can be used to store software programs and modules, and the processor executes various functional applications and data processing by running the software programs and modules stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, application programs required by functions, etc.; the data storage area can store data created according to the use of the device, etc. In addition, the memory can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other volatile solid-state memory device. Accordingly, the memory can also include a memory controller to provide access of the processor to the memory.
[0145] The method embodiment provided by the embodiment of the present application can be executed in a computer terminal, a server or a similar computing device. Figure 7 is the hardware structure block diagram of the electronic device running a database access control method provided by the embodiment of the present application, as Figure 7 shown, the internal structure of the electronic device can include but is not limited to a processor, a network interface and a memory. Among them, the processor, the network interface and the memory in the electronic device can be connected through a bus or other ways, in the embodiment of the present application Figure 7 is taken as an example to connect through a bus.
[0146] The processor (or CPU (Central Processing Unit)) is the computing core and control core of the electronic device. The network interface can optionally include a standard wired interface, a wireless interface (such as WI-FI, a mobile communication interface, etc.). The memory is a memory device in the electronic device, used to store programs and data. It can be understood that the memory here can be a high-speed RAM memory device, or a non-volatile memory device (non-volatile memory), such as at least one disk storage device; optionally, it can also be at least one storage device located away from the aforementioned processor. The memory provides a storage space that stores the operating system of the electronic device, which can include but is not limited to: a Windows system (an operating system), a Linux (an operating system), an Android (a mobile operating system) system, an IOS (a mobile operating system) system, etc., and the present application does not limit this; and in the storage space, one or more instructions suitable for being loaded and executed by the processor are also stored, and these instructions can be one or more computer programs (including program codes). In the embodiment of the present application, the processor loads and executes one or more instructions stored in the memory to implement the database access control method provided by the above method embodiment.
[0147] Those of ordinary skill in the art can understand that, Figure 7 The structure shown is only a schematic, which does not limit the structure of the above-mentioned electronic device. For example, the electronic device 700 can also include more or fewer components than those shown in the figure, or have a different configuration from that shown in the figure. Figure 7 Figure 7 The structure shown is only a schematic, which does not limit the structure of the above-mentioned electronic device. For example, the electronic device 700 can also include more or fewer components than those shown in the figure, or have a different configuration from that shown in the figure.
[0148] The embodiment of the present application also provides a computer readable storage medium, which can be arranged in an electronic device to save at least one instruction or at least one program related to a database access control method, and the at least one instruction or the at least one program is loaded and executed by the processor to implement the database access control method provided by the above method embodiment.
[0149] The embodiment of the present application also provides a computer program product or computer program, which includes computer instructions stored in a computer readable storage medium. The processor of the electronic device reads the computer instructions from the computer readable storage medium, and the processor executes the computer instructions to make the electronic device execute the database access control method provided by the above method embodiment.
[0150] Optionally, in the embodiment, the storage medium can include, but is not limited to, a U disk, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and various storage medium capable of storing program codes.
[0151] It should be noted that the above-mentioned sequence of the embodiments of the application is only for description, not representing the advantages and disadvantages of the embodiments. The above-mentioned embodiments of the present application are described. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be executed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multi-task processing and parallel processing are possible or can be advantageous.
[0152] Each embodiment in the specification is described in a progressive manner, and the same or similar parts between each embodiment can be referred to each other. Each embodiment focuses on the difference from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the part of the method embodiment.
[0153] A person of ordinary skill in the art can understand that all or part of the steps of the above-mentioned embodiments can be completed by hardware, or by program instructing relevant hardware, and the program can be stored in a computer readable storage medium, and the storage medium mentioned above can be a read-only memory, a magnetic disk or an optical disk, etc.
[0154] The above-mentioned is only the preferred embodiment of the application, and is not used to limit the application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the application shall be included in the protection scope of the application.
Claims
1. A database access control method characterized by, The method comprises: acquiring database access information, the database access information representing an access operation on a database; determining a target category to which the database access information belongs; instantiating the database access information to obtain an instantiated object, and storing the instantiated object in an instantiated object set corresponding to the target category; when a preset condition is met, generating a structured query statement corresponding to each instantiated object in the instantiated object set according to attribute information carried by each instantiated object in the instantiated object set; the attribute information is used for locating an operation on a database file and a database table; performing a corresponding access operation on the database according to the structured query statement corresponding to each instantiated object.
2. The database access control method according to claim 1, characterized by, The generating of the structured query statement corresponding to each instantiated object in the instantiated object set according to the attribute information carried by each instantiated object in the instantiated object set comprises: traversing the instantiated objects in the instantiated object set, and assigning a pre-created mutex lock to a current instantiated object traversed; generating the structured query statement corresponding to the current instantiated object according to the attribute information carried by the current instantiated object, the assigned mutex lock, and a preset conversion rule.
3. The database access control method of claim 1, wherein, The preset condition comprises: the number of instantiated objects in the instantiated object set reaches a preset number threshold; or, a timing duration corresponding to the instantiated object set reaches a preset duration, the timing duration being a duration from a time when the structured query statement of the instantiated object set is last generated.
4. The database access control method according to any one of claims 1 to 3, characterized by, The method further comprises: in response to an instruction that an access operation on the database fails, determining a target instantiated object in the instantiated object set; the target instantiated object comprises an instantiated object corresponding to an unexecuted structured query statement, and an instantiated object associated with the instantiated object corresponding to the unexecuted structured query statement; generating an object file according to the target instantiated object; the object file comprises file header information and a data storage area, the file header information being used for describing attributes of the object file, the attributes of the object file comprising a current offset of a database table in the database, and the data storage area being used for storing the target instantiated object.
5. The database access control method according to claim 4, characterized by, The method further comprises: in response to a reading instruction on the object file, acquiring the target instantiated object; generating a structured query statement corresponding to the target instantiated object according to attribute information carried by the target instantiated object; performing a corresponding access operation on the database according to the structured query statement corresponding to the target instantiated object and the current offset.
6. The database access control method of claim 1, wherein, The performing of the corresponding access operation on the database according to the structured query statement corresponding to each instantiated object comprises: determining an operation type of an access operation corresponding to each structured query statement; encapsulating the structured query statements of a same operation type to obtain a structured query statement encapsulation package corresponding to each operation type; performing a corresponding access operation on the database according to each structured query statement encapsulation package.
7. The database access control method of claim 1, wherein, The determining the target classification to which the database access information belongs comprises: determining a source service of the database access information; determining the target classification to which the database access information belongs according to a preset classification rule corresponding to the source service; the preset classification rule is a rule preconfigured based on a service function corresponding to the source service.
8. A database access control apparatus characterized by comprising: The apparatus comprises: an access information acquisition module configured to acquire database access information, the database access information representing an access operation on a database; a classification module configured to determine a target classification to which the database access information belongs; an object instantiation module configured to perform object instantiation on the database access information to obtain instantiated objects, and store the instantiated objects in an instantiated object set corresponding to the target classification; a first query statement generation module configured to, when a preset condition is met, generate a structured query statement corresponding to each instantiated object according to attribute information carried by each instantiated object in the instantiated object set; the attribute information is used for locating an operation on a database file and a database table; a first access module configured to perform a corresponding access operation on the database according to the structured query statement corresponding to each instantiated object.
9. An electronic device, comprising: The computer program is executed by the processor to implement the database access control method in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer program is executed by the processor to implement the database access control method in any one of claims 1-7.
11. A computer program product comprising a computer program, characterized in that, The computer program is executed by the processor to implement the database access control method in any one of claims 1-7.
Citation Information
Patent Citations
Long lasting implementing method for data
CN101339559A
Database access system and access method thereof
CN106126540A