Background technology
In embedded database, diversity and particularity due to the business rule of system, this just causes the complicacy of business datum Relations Among, is difficult to come with existing constraint rule (as codomain constraint, external key, table mutual exclusion etc.) relation of this complexity of perfect representation.For the restriction relation that realizes this complexity just must realize this constraint rule at allocation window, because the isolation in allocation window and database data district must relate to the action of tabling look-up, like this will inevitably very complex, and also efficient is not high yet.
Random, concurrent to database manipulation in wireless communication system, certain upper layer application is after operating database like this, cause the data in database to change, another may be also worked remaining under original data, the consistance that keeps this data, a kind of method is the mutual notice of upper layer application, and another kind is to use regularly Query Database, the consistance of service data.Can increase so unnecessary reciprocal process a lot of between application, increase the degree of coupling of application module.
In database, trigger is the special storing process of a class, is defined in and automatically performs special business rule when his-and-hers watches or view are sent out UPDATE, INSERT or DELET statement.The function that realizes trigger in embedded database can be to the data check of recording or field has special constraint rule to require, and making the data that record in database is composite services rule " legal " data.Can in time notify related application when simultaneously a kind of trigger of notification message can the data in database has any variation, guarantee the operation of business and the consistance of data, improve system's treatment effeciency.
Summary of the invention
The object of the present invention is to provide a kind of reliable implementation method of trigger in built-in database, the trigger function in its existing database is extended, to form a kind of trigger with powerful notification message.
To achieve these goals, the present invention adopts following technical scheme:
Method of the present invention comprises following treatment step:
A, to the trigger of database registration notification message;
B, when database being detected retouching operation arranged, send the notification message that contains the database change state to described application module.
Wherein, described steps A is further comprising the steps of: the correctness of the trigger of database verification Application module registration, and after verification is passed through is inserted into the registration content of trigger in internal memory.
Wherein, described method is carried out the verification of trigger correctness by following steps:
By trigger is carried out the constraint rule inspection, and the value in the trigger registration content is carried out the legitimacy check.
Wherein, described internal memory comprises the trigger registration table.
Wherein, described step B comprises the following steps:
B1, application module are to the database operation of modifying;
B2, database judge whether the retouching operation instruction from described application module; If so, carry out B3;
B3, traversal trigger registration table judge whether to exist the trigger of the notification message of described application module registration; If so, step B4;
B4, database carry out constraint checking to the data of retouching operation;
B5, database carry out the data modification operation;
B6, execution trigger send a notification message to described application module;
B7, described application module carry out the self operation according to the content of described notification message.
Wherein, further comprising the steps of between described step B4 and step B3:
When there was the trigger of notification message of described application module registration in judgement, database sent notification message about confirming whether retouching operation continues to carry out to described application module.
Wherein, whether described application module continues to carry out to retouching operation and confirms according to the notification message that receives, if described application module stops retouching operation, sends and interrupts preventing the database operation of modifying.
Wherein, in described step B6, database to what described application module sent is: about the notification message of database update state.
Wherein, comprise in described notification message: the interior perhaps trend of data variation in database.
The present invention is by sending a notification message to application module, come the consistance of data in real-time ensuring business datum and database, use method of the present invention can realize removing the complicated business rule restriction relation such as index constraint, value constraint, foreign key constraint in embedded database, guarantee that in database, data are the legal data that meet business need; The present invention utilizes the trigger of notification message to guarantee in real time the consistance of data in business datum and database, has guaranteed the normal operation of system, has improved the operational efficiency of system.
Embodiment
Describe technical scheme of the present invention in detail below in conjunction with accompanying drawing.
As shown in Figure 1, the core concept of the reliable implementation method of trigger in built-in database of the present invention is: if application module (being the functional module of completing a certain business in embedded OS) needs the variation of monitor database, can have to database registration the trigger of notification message, when in case database has modification, this trigger can send the notification message record modification information to application module, and application module can keep the consistance with database at any time so.Its method mainly comprises the following steps:
Step 1, application module are to the database registration trigger.
Data in database generally have a plurality of application modules to read and write or retouching operation, the constraint rule of each application module also is not quite similar, general constraint rule function is first collected business rule by the database design personnel, then retrains according to different business realizing in function.
The registration content of the trigger of notification message comprises following information:
Application identities number: expression is the trigger which uses registration.
Table: table handle or table name or table sequence number etc.
Triggered time: before (before data change), after (after data change).
Trigger rank: record level or field level.
Trigger event: insert (insertion), update (renewal), delete (deletion) etc., when level record, three kinds of methods had, during field level generally only for update.
Field description: generally use field name.
The correctness of step 2, database detection triggers.
The condition that at first trigger of application module registration must satisfy is: meet the general constraint rules such as index constraint, value constraint, foreign key constraint.For the special rules of application module customization, realize in the mode of function, general passes through code walkthrough or goes in actual applications verification.And for the trigger of notification message, can be to wherein time, method, type these get specific value and carry out the legitimacy verification, and his-and-hers watches, index, field etc. judge relatively with data in database whether it exists, and also will prevent duplicate registration content simultaneously.After registration content is by verification, registration content is saved in internal memory.For the ease of searching, the application module registration content can be saved in corresponding data structure, such as being saved in the trigger registration table.
Step 3, application module are to the database operation of modifying, and its retouching operation comprises: the insertion of record level, deletion, renewal operation, and the renewal of field value is revised.
Step 4, judge whether the retouching operation instruction from described application module; If so, execution in step 5; If not, return to step 3.
Step 5, traversal trigger registration table judge whether to exist the trigger of the notification message of this application module registration; If so, step 6; If not, return to the trigger that step 3 continues to seek at the trigger registration table coupling, if do not find all the time the trigger of coupling, flow process is carried out the retouching operation of database routinely.
Step 6, database send the notification message that whether continues to carry out about the confirmation retouching operation to application module.
When certain retouching operation is carried out this step, can first send to application module the notification message that whether continues to carry out about the confirmation retouching operation.Whether above-mentioned application module continues to carry out to retouching operation and confirms according to the notification message that receives, if application module stops retouching operation in advance, sends and interrupts preventing the database operation of modifying, and stops carrying out following step 8.Can avoid the maloperation of database like this.
Step 7, database carry out constraint checking according to flow sequence to the data of retouching operation.
Step 8, database carry out data and carry out actual retouching operation, such as amendment record or field.
Step 9, execution trigger are to the notification message of described application module transmission about the database update state.
Receive the operational order of application module at database, and before will carrying out actual operation, at first want the special constraint rule of check data, when only having all constraint rules all to satisfy, database just can carry out actual operation, particularly about the additions and deletions operation of data, said constraint rule comprises index constraint, value constraint, foreign key constraint etc. here.When having the variation of record or field for database, when having carried out constraint checking, and check has been when having registered the trigger of notification message, operated database just effective after, also to send a notification message to application module.Singularity due to service application, the interior perhaps trend that comprises variation in the business need notification message just must be preserved " new and old data " in notification message, only preserves new record during as increase, only preserve old record during deletion, when upgrading operation, new and old record is all preserved.
Step 10, the notified message of application module are also correspondingly processed.
After using notified message, carry out the renewal of its data, can safeguard the data of other module relevant with self module simultaneously, guarantee the normal operation of system.
Step 11, application module are nullified the trigger Register as required.
If application module is not nullified trigger, repeating step 3 to 10 goes on foot.If the cancellation trigger is just disposed the related data in notification message trigger registration table.
The present invention extends the trigger function in database, realized a kind of trigger of powerful notification message, it is applied to the embedded database in a kind of wireless system, the particular service rule limits is being arranged, carry out constraint checking, guarantee " legitimacy " of data, the notice related service is used when data change, in time correctly process, guarantee the consistance of application and database internal data.
Illustrating of above-mentioned each concrete steps is comparatively concrete, can not therefore think the restriction to scope of patent protection of the present invention, and scope of patent protection of the present invention should be as the criterion with claims.