Background technology
In prior art, find that the means that smart mobile phone application data upgrades mainly contain: the Trigger mechanism of Observer Pattern (android Observer) and application data base table.
Observer Pattern is called again Publish-subscribe (Publish/Subscribe) pattern, Model-View (Model/View) pattern, source-audiomonitor (Source/Listener) pattern or subordinate (Dependents) pattern.Observer Pattern defines a kind of dependence of one-to-many, allows multiple observer's object monitor some subject simultaneously.When this subject changes in state, all observer's objects can be notified, enable them automatically upgrade oneself.
The Trigger mechanism of application data base table, it is closely connected with table, sets up, a part for visual tabulation based on table.It can not be called by explicit, and after user creates trigger, when the data in showing are inserted, delete or revised, trigger can run automatically.Trigger mechanism can make multiple different user keeping modifying under data integrity and conforming good environment operation.
Above-mentioned Observer Pattern, can only monitor table level, that is, can only determine which table there occurs change, can not navigate to which bar record and there occurs change by Observer.Trigger mechanism is when the change monitoring record, and excite treatment S QL to operate, application processing function is skipped in the change of data record, makes user cannot do further process to the change of application record.
Summary of the invention
In order to solve the deficiency that prior art exists, the object of the present invention is to provide a kind of method that quick position mobile phone application data upgrades, for the tables of data that will monitor, first base table is created to record the state before Data Update, then utilize Observer Pattern (android Observer) when Data Update, determine Data Update tables of data occurs, the state of the tables of data after comparison upgrades and the data mode of base table record, find out the record that both are inconsistent, determine the record of Data Update.
To achieve these goals, the method for a kind of rapid data classification provided by the invention, comprises the following steps:
1) select need the tables of data of monitoring and need the field of monitoring, create base table, then utilize Observer Pattern, when Data Update, determine Data Update tables of data occurs;
2) comparison upgrade after the state of tables of data and the data mode of base table record, find out both inconsistent records, determine the record of Data Update;
3) that records above-mentioned Data Update is recorded to database.
Other features and advantages of the present invention will be set forth in the following description, and, partly become apparent from instructions, or understand by implementing the present invention.
Embodiment
Below in conjunction with accompanying drawing, the preferred embodiments of the present invention are described, should be appreciated that embodiment described herein is only for instruction and explanation of the present invention, is not intended to limit the present invention.
Method of the present invention, for the tables of data that will monitor, record original state, based on Observer Pattern (android Observer) monitoring and measuring application data, when data variation, can determine to there occurs change to which tables of data of which application; Then, compare the tables of data state after change and original state, find out change, determine which bar record there occurs change.
Fig. 1 is the method flow diagram upgraded according to quick position mobile phone application data of the present invention, below with reference to Fig. 1, is described in detail the method that quick position mobile phone application data of the present invention upgrades:
First, in step 101, select want the tables of data at monitoring and measuring application data place and need the field of monitoring, and find out the field that can indicate and need monitoring field whether to change.These field values that Monitoring Data can be indicated whether to change are linked to be character string, and the cryptographic hash of calculating character string, according to these cryptographic hash, be recorded as the original state of Monitoring Data table, create base table; The main field of base table comprises: " _ id " (Monitoring Data table mark), " state_value " (state value), " uri " (tables of data of instruction monitoring), " recordId " (in tables of data of monitoring corresponding _ id).State value is the cryptographic hash of the monitoring field calculating according to Monitoring Data table.Here the field of tables of data and the monitoring of monitoring is selected to be need to select according to user, the tables of data record original state of scanning monitoring;
In step 102, when android Observer monitors Data Update, determine the tables of data of Data Update according to " uri ", the original state of contrast base table, finds out the physical record of data variation.
The methods contrasting two tables are: order that " recordId " successively decrease takes out data D1 from base table first to utilize " uri " press, and the order utilizing uri to successively decrease by " _ id " to be fetched data D2 from the tables of data of renewal.Then, get D1 successively, D2 record compares.
If a) " recordId " of D1 is greater than " _ the id " of D2, illustrate that the record that " _ id " in the Monitoring Data table that D2 is corresponding equals " recordId " is deleted.Get next record of D1, D2 records constant, compares next time.As shown in table 1, recordId > _ id, deletes _ id=6.
Table 1: data are deleted
(D1)recordId |
(D2) _id |
9 |
9 |
8 |
8 |
6 |
|
5 |
5 |
4 |
4 |
If b) " recordId " of D1 is less than " _ the id " of D2, illustrate that this record in the Monitoring Data table that D2 is corresponding is the new record added.Get next record of D2, D1 records constant, compares next time.As shown in table 2, recordId < _ id, interpolation _ id=9.
Table 2: data are added
(D1)recordId |
(D2) _id |
|
9 |
8 |
8 |
6 |
6 |
5 |
5 |
4 |
4 |
If c) " recordId " of D1 equals " _ the id " of D2, then calculate the cryptographic hash that the field of the monitoring of the tables of data of monitoring is corresponding, and " state_value " corresponding with base table compares, if two values are identical, represent that data do not upgrade, if different, illustrate that this record in the Monitoring Data table that D2 is corresponding have updated.Get next record of D1, D2, compare next time.As shown in table 3, when corresponding cryptographic hash is different, there is Data Update.
Table 3: Data Update
(D1)recordId |
(D2) _id |
9 |
9 |
8 |
8 |
6 |
6 |
5 |
5 |
4 |
4 |
If d) there is no record in D1, in D2, also have record, illustrate that in D2, these records are all new interpolations.As shown in table 4, do not have record in D1, also have record in D2, these data corresponding in Monitoring Data table are new interpolations.
Table 4:
(D1)recordId |
(D2) _id |
|
5 |
|
4 |
|
3 |
|
2 |
|
1 |
If e) there is no record in D2, in D1 also have record, illustrate in D2 " _ id " equal " recordId " these records all delete.As shown in table 5, do not have record in D2, also have record in D1, these data corresponding in Monitoring Data table all delete.
Table 5:
(D1)recordId |
(D2) _id |
9 |
|
8 |
|
6 |
|
5 |
|
4 |
|
In step 103, that records above-mentioned change is recorded to database, for other application.
At present, on smart mobile phone, there is the change of a lot of application to some data of other application to be extremely concerned about, wish the change information obtaining these application.Such as, handset dialing needs the change knowing address book data, to be dialled by address list, needs the change knowing short message, knows which contact person contacts often, so that user the most easily finds these contact persons.Search for for another example, need the change knowing each application data, so that user search is to existing information, search less than non-existent information, etc.But currently can find that the means of other application change are also nowhere near, adopt the method that quick position mobile phone application data of the present invention upgrades, can upgrade by Real-time Monitoring Data, determine the data occurring to upgrade, and the application that notice needs.
One of ordinary skill in the art will appreciate that: the foregoing is only the preferred embodiments of the present invention, be not limited to the present invention, although with reference to previous embodiment to invention has been detailed description, for a person skilled in the art, it still can be modified to the technical scheme that foregoing embodiments is recorded, or carries out equivalent replacement to wherein portion of techniques feature.Within the spirit and principles in the present invention all, any amendment done, equivalent replacement, improvement etc., all should be included within protection scope of the present invention.