CN106469156B - Data base read-write method and device - Google Patents

Data base read-write method and device Download PDF

Info

Publication number
CN106469156B
CN106469156B CN201510505796.0A CN201510505796A CN106469156B CN 106469156 B CN106469156 B CN 106469156B CN 201510505796 A CN201510505796 A CN 201510505796A CN 106469156 B CN106469156 B CN 106469156B
Authority
CN
China
Prior art keywords
connection
master
application
read operation
database
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201510505796.0A
Other languages
Chinese (zh)
Other versions
CN106469156A (en
Inventor
郭威
熊元峰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huawei Device Co Ltd
Original Assignee
Huawei Device Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Huawei Device Co Ltd filed Critical Huawei Device Co Ltd
Priority to CN201510505796.0A priority Critical patent/CN106469156B/en
Publication of CN106469156A publication Critical patent/CN106469156A/en
Application granted granted Critical
Publication of CN106469156B publication Critical patent/CN106469156B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1474Saving, restoring, recovering or retrying in transactions
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2358Change logging, detection, and notification

Abstract

The embodiment of the invention discloses data base read-write method and devices.Database includes in the terminal, database has at least one main connection and at least two non-master connections, main connection is for executing the write operation to database, and non-master connection is for executing the read operation to database, which comprises terminal obtains the read operation to database;If read operation is initiated by the first application, read operation is executed using the first non-master connection;First application is the application in terminal;Wherein, the first non-master connection is the preset non-master connection for being only used for executing the read operation that the first application is initiated;At least two non-master connections include at least one first non-master connection.Using method and device provided by the embodiment of the present invention, the first non-master connection is only used for executing the read operation that the first application is initiated, therefore can guarantee that the execution efficiency for the read operation that the first application is initiated not will receive the influence of other application read operation.

Description

Data base read-write method and device
Technical field
The present embodiments relate to field of terminal more particularly to data base read-write method and devices.
Background technique
For the management convenient for contact information, existing terminal generallys use contact database and saves contact information.Eventually Application on end can realize the read-write of contact information by database manipulations such as read operation and write operations, to realize quick The functions such as dialing, contact information backup.With the increasingly diversification of terminal applies, need to read and write the application of contact information It is more and more, so that terminal read operation to be dealt with and write operation are also more and more.
In order to improve the execution efficiency of database manipulation, the prior art would generally use write-ahead log (Write- AheadLogging, abbreviation WAL) read operation initiated to each application of mode and write operation be scheduled.Under WAL mode, The connection of database is divided into main connection and two classes of non-master connection, wherein main connection can execute read operation and write operation, it is non-master Connection is served only for executing read operation.Terminal first detects whether there is the non-of free time after getting using the read operation initiated Main connection;If there is idle non-master connection, then the read operation is executed using idle non-master connection;If non-master connection is equal Occupied and main connection is idle, then main connection can be used and execute the read operation;If main connection and non-master connection are all occupied, The read operation can be then put into the tail of the queue of pending read operation queue, held one by one when waiting non-master connection idle according to queue sequence Each read operation in the pending read operation queue of row.Terminal is received using after the write operation initiated, and detects whether exist Idle main connection;If there is idle main connection, then the write operation is executed using idle non-master connection;If it is main all It is occupied, then the read operation can be put into the tail of the queue of pending write operation queue, according to queue sequence when waiting main connection idle Each write operation in pending write operation queue is executed one by one.
In actual use, there is the specific application more sensitive to read operation execution efficiency, such as contact application etc.. If the read operation execution efficiency that the specific application is initiated is too low, under the user experience that will cause these applications or entire terminal Drop.For example, will lead to terminal contact people's information interface opening if the read operation execution efficiency initiated of contact application is too low Slowly.And under WAL mode, read operation execution efficiency is influenced by concurrent number of read operations, and concurrent number of read operations is got over More, the execution efficiency of read operation is lower.Therefore the read operation each application initiated using existing WAL mode and write operation into Row scheduling can seriously affect the execution efficiency of read operation and write operation, cause specific application when concurrent read operation is more The execution efficiency of initiated read operation is low.
Summary of the invention
The embodiment of the invention provides data base read-write method and devices, to solve when the operation of concurrent data library is more, The low problem of the execution efficiency of read operation.
In a first aspect, the embodiment of the invention provides a kind of data base read-write method, the database include in the terminal, The database has at least one main connection and at least two non-master connections, and the main connection is for executing to the database Write operation, the non-master connection is for executing read operation to the database, this method comprises: terminal acquisition is to institute State the read operation of database;If the read operation is initiated by the first application, the read operation is executed using the first non-master connection; First application is the application in the terminal;Wherein, described first it is non-master connection be it is preset be only used for execute institute State the non-master connection for the read operation that the first application is initiated;At least two non-master connection includes that at least one is described first non-master Connection.
With reference to first aspect, in a first possible implementation of that first aspect, the method also includes: if the reading Operation is initiated by the second application, then executes the read operation using the second non-master connection;Wherein, second application and described the One application is different;The second non-master connection is other non-master connections in addition to the described first non-master connection.
With reference to first aspect or first aspect the first possible implementation, in second of first aspect possible realization In mode, the method also includes: if the read operation is initiated by the second application, the reading is executed using the second non-master connection Operation;Wherein, second application is different from first application;The second non-master connection is except the described first non-master connection Except other non-master connections.
Second of possible implementation with reference to first aspect, in first aspect in the third possible implementation, institute State method further include: when all described first is non-master connects occupied, detect whether in the presence of the second idle non-master company It connects;When there is the idle second non-master connection, the read operation is executed using the described second idle non-master connection;Its In, the second non-master connection is other non-master connections in addition to the described first non-master connection.
The third possible implementation with reference to first aspect, in the 4th kind of possible implementation of first aspect, institute State method further include: when all described second is non-master connects occupied, the read operation is put into the first team to be processed Position corresponding to the priority applied in column with described first.
With reference to first aspect or the possible implementation any of them of first to fourth kind of first aspect, in first aspect In 5th kind of possible implementation, the database is contact database.
With reference to first aspect or the first to five kind of first aspect possible implementation any of them, in first aspect In 6th kind of possible implementation, first application is contact application.
With reference to first aspect or the first to six kind of first aspect possible implementation any of them, in first aspect In 7th kind of possible implementation, the method also includes: the terminal obtains the write operation to the database;Detection is It is no to there is idle main connection;When there is idle main connection, the write operation is executed using the main connection;When all It is described it is main connection it is occupied when, if the write operation by it is described first application initiate, the write operation is put into second Corresponding position is applied with described first in queue to be processed.
Second aspect, the embodiment of the invention also provides a kind of data base read-write device, the database is included in terminal In, the database has at least one main connection and at least two non-master connections, and the main connection is for executing to the number According to the write operation in library, for executing the read operation to the database, described device includes: acquiring unit for the non-master connection, For obtaining the read operation to the database;First execution unit, for making when the read operation is initiated by the first application The read operation is executed with the first non-master connection;First application is the application in the terminal;Wherein, described first is non-master Connection is the preset non-master connection for being only used for executing the read operation that first application is initiated;Described at least two is non-master Connection includes at least one described first non-master connection.
In conjunction with second aspect, in second aspect in the first possible implementation, the device further include: second executes list Member, for executing the read operation using the second non-master connection when the read operation is initiated by the second application;Wherein, described Second application is different from first application;The second non-master connection is other non-master in addition to the described first non-master connection Connection.
In conjunction with second aspect or second aspect the first possible implementation, in second of second aspect possible realization In mode, first execution unit includes: detection sub-unit, is used for when the read operation is initiated by first application, It detects whether in the presence of the described first idle non-master connection;Subelement is executed, for there is the described first idle non-master company When connecing, the read operation is executed using the described first idle non-master connection.
In conjunction with second of second aspect possible implementation, in second aspect in the third possible implementation, institute Detection sub-unit is stated, is also used to detect whether when all described first non-master connections are occupied in the presence of idle second Non-master connection;The execution subelement is also used to when there is the idle second non-master connection, uses idle described the Two non-master connections execute the read operation;Wherein, the described second non-master connection is other in addition to the described first non-master connection Non-master connection.
The third possible implementation in conjunction with second aspect, in the 4th kind of possible implementation of second aspect, institute State the first execution unit further include: subelement of joining the team will be described for when all described second non-master connections are occupied Read operation is put into the first queue to be processed and position corresponding to the priority of first application.
In conjunction with second aspect or the possible implementation any of them of first to fourth kind of second aspect, in second aspect In 5th kind of possible implementation, the database is contact database.
In conjunction with second aspect or the first to five kind of second aspect possible implementation any of them, in second aspect In 6th kind of possible implementation, first application is contact application.
In conjunction with second aspect or the first to six kind of second aspect possible implementation any of them, in second aspect In 7th kind of possible implementation, the acquiring unit is also used to obtain the write operation to the database;Described device is also Including third execution unit, the third execution unit includes: main connecting detection subelement, for detecting whether there is the free time Main connection;Write operation executes subelement, for writing behaviour using described in the main connection execution when there is idle main connection Make;Write operation is joined the team subelement, for when all main connections are occupied, if the write operation is by described first Using initiation, then the write operation is put into the second queue to be processed and applies corresponding position with described first.
In the embodiment of the present invention, the database include in the terminal, the database have at least one it is main connection and At least two non-master connections, the main connection is for executing the write operation to the database, and the non-master connection is for executing Read operation to the database, the terminal obtain the read operation to the database;If the read operation is by the first application It initiates, then executes the read operation using the first non-master connection;First application is the application in the terminal;Wherein, institute Stating the first non-master connection is the preset non-master connection for being only used for executing the read operation that first application is initiated;It is described extremely Few two non-master connections include at least one described first non-master connection.Using method provided by the embodiment of the present invention and dress It sets, the first non-master connection is only used for executing the read operation that first application is initiated, therefore can guarantee what the first application was initiated The execution efficiency of read operation not will receive the influence of other application read operation.
Detailed description of the invention
To describe the technical solutions in the embodiments of the present invention more clearly, make required in being described below to embodiment Attached drawing is briefly described, it should be apparent that, for those of ordinary skills, do not making the creative labor Under the premise of property, it is also possible to obtain other drawings based on these drawings.
Fig. 1 is the flow diagram of data base read-write method one embodiment of the present invention;
Fig. 2 is the flow diagram of another embodiment of data base read-write method of the present invention;
Fig. 3 is the flow diagram of data base read-write method of the present invention;
Fig. 4 is the flow diagram of another embodiment of data base read-write method of the present invention;
Fig. 5 is the flow diagram of another embodiment of data base read-write method of the present invention;
Fig. 6 is the structural schematic diagram of data base read-write device one embodiment of the present invention;
Fig. 7 is the structural schematic diagram of another embodiment of data base read-write device of the present invention;
Fig. 8 is the structural schematic diagram of another embodiment of data base read-write device of the present invention;
Fig. 9 is the structural schematic diagram of terminal one embodiment of the present invention.
Specific embodiment
Following will be combined with the drawings in the embodiments of the present invention, and technical solution in the embodiment of the present invention carries out clear, complete Whole description, it is clear that described embodiments are only a part of the embodiments of the present invention, instead of all the embodiments.It is based on Embodiment in the present invention, it is obtained by those of ordinary skill in the art without making creative efforts every other Embodiment shall fall within the protection scope of the present invention.
It should be noted that the database in the embodiment of the present invention can be in accordance with atomicity (Atomicity), one Any one database of cause property (Consistency), isolation (Isolation), persistence (Durability).The data Library include in the terminal, and at least have one it is main connection and at least two non-master connections, wherein it is described it is main connection for holding Row is to the write operation of the database, and the non-master connection is for executing the read operation to the database.The non-master connection Including at least a first non-master connection and a second non-master connection, the first non-master connection is preset is only used for The non-master connection for the read operation that first application is initiated is executed, the second non-master connection is in addition to the described first non-master connection Other non-master connections.Wherein, the database can be contact database, and the information saved in the database is connection People's information.
It is the flow diagram of data base read-write method one embodiment of the present invention referring to Fig. 1.The embodiment is for showing The execution method of database read operation.As shown in Figure 1, this method comprises the following steps:
Step 101, terminal obtains the read operation to database.
Some in terminal is applied when needing to read the contact information in contact database, can initiate one it is right The read operation of the database, the available read operation of terminal.For example, contact application needs to show contact person's letter to user When breath, a read operation to contact database can be initiated, in order to read the contact information in contact database, And then contact information is shown.For another example, user data backup, which is applied, is backing up to clothes for the contact information in terminal When business device, a read operation to contact database can be initiated, in order to read the letter of the contact person in contact database Breath, and then by the information preservation read to server.
Step 102, if the read operation is initiated by the first application, the read operation is executed using the first non-master connection; First application is the application in the terminal.
After getting the read operation, terminal judges whether the read operation is initiated by the first application.Wherein, read operation Promoter can be determined by the information carried in read operation, or can also be determined by the source of read operation.
If the read operation is initiated by the first application, terminal executes the read operation using the first non-master connection;If The read operation is initiated by the second application, then terminal executes the read operation using the second non-master connection.Wherein, it described second answers With being different application with first application, first application is the application more demanding to read operation execution efficiency, such as Contact application etc.;Second application is application of less demanding to read operation execution efficiency, such as data backup application etc.. Using this executive mode, the first non-master connection is only used for executing the read operation that first application is initiated, therefore can guarantee the The execution efficiency for the read operation that one application is initiated not will receive the influence of other application read operation.
For the execution efficiency for further promoting the first initiated read operation of application, terminal is held using the first non-master connection When the row read operation, it can first detect whether in the presence of the described first idle non-master connection;When having idle described the When one non-master connection, the read operation is executed using the described first idle non-master connection;When the described first all non-master companies When connecing occupied, then it can detecte with the presence or absence of the second idle non-master connection;When the described second non-master company that there is the free time When connecing, the read operation is executed using the described second idle non-master connection.First is executed by using the second non-master connection to answer With the read operation initiated, more non-master connections can be made to apply initiated read operation for executing first, thus promotion the The execution efficiency of one the initiated read operation of application.
In actual use, to reduce detecting step, the execution efficiency of the first initiated read operation of application is further promoted, Terminal is after determining that the read operation is initiated by the first application, and whether idle, if deposited if can detect each non-master connection simultaneously In the first idle non-master connection, the read operation initiated by the first application is executed using the first idle non-master connection;If the One non-master connection is occupied but there is the second idle non-master connection, then can be used the non-master connection execution of idle second by The read operation that first application is initiated.
Due to the limited amount of non-master connection, and application different in the same period may concurrently be initiated to be more than non-master The read operation of quantity is connected, therefore still there may be all non-master occupied situations of connection in actual use.Non- In the main occupied situation of connection, read operation is needed to be put into the first queue to be processed;Then when there is idle non-master connection, The read operation in the first queue to be processed is executed one by one using idle non-master connection.
Different according to the promoter of read operation, the concrete mode that read operation is put into queue to be processed by terminal is not also identical. When the read operation is initiated by the second application, read operation directly can be put into the when the second connection is occupied by terminal One queue to be processed;And when the read operation is initiated by the first application, terminal can be non-master in the first non-master connection and second When connecting occupied, then read operation is put into the first queue to be processed.
Further, can be different according to the promoter of read operation when read operation is put into the first queue to be processed, it will read Operate the different location being put into the first queue to be processed.It, can for the execution efficiency for improving the read operation initiated by the first application The read operation initiated as the first application to be put into corresponding to the priority applied in the first queue to be processed with described first Position, and the read operation that the second application is initiated is put into the tail of the queue of the first queue to be processed.
For example, the read operation directly can be put into first wait locate when the read operation is initiated by second application Manage the tail of the queue of queue;And when the read operation is initiated by first application, it is to be processed which can be placed on first Position before the read operation that all second applications are initiated in queue.
In the present embodiment, the terminal obtains the read operation to the database;If the read operation is by the first application It initiates, then executes the read operation using the first non-master connection;First application is the application in the terminal.Using this reality Apply method described in example, the first non-master connection is only used for executing the read operation that first application is initiated, therefore can guarantee the The execution efficiency for the read operation that one application is initiated not will receive the influence of other application read operation, thereby may be ensured that the first application The execution efficiency of initiated read operation.
Due in actual use, using in addition to needing to read contact information, it is also possible to need to rewrite contact person's letter Breath, thus terminal except to application initiate read operation be scheduled execution in addition to, except the reading for realizing contact information, it is also necessary to The write operation initiated application is scheduled execution, realizes the rewriting of contact information.
It referring to fig. 2, is the flow diagram of another embodiment of data base read-write method of the present invention.The embodiment is for showing The execution method of database write operations out.Terminal can independently be scheduled write operation using method shown in the present embodiment It executes, on the basis of execution can also being scheduled to read operation in aforementioned embodiment illustrated in fig. 1, write operation is scheduled It executes.As shown in Fig. 2, this method comprises the following steps:
Step 201, the terminal obtains the write operation to the database.
Some in terminal is applied when needing to rewrite the contact information in contact database, can initiate one it is right The write operation of the database, the available write operation of terminal.For example, contact application needs the information inputted according to user When modifying contact information, one can be initiated, contact database write-read is operated, complete the modification of contact information.
Step 202, the terminal is detected whether in the presence of idle main connection.
Since main connection is for executing write operation, after getting the read operation, terminal can detecte no deposit Idle main connection.
Step 203, when there is idle main connection, the terminal executes the write operation using the main connection.
Step 204, when all main connections are occupied, if the write operation is sent out by first application It rises, then the write operation is put into the second queue to be processed and applies corresponding position with described first.
Since the quantity of main connection limits very much, database only has a main connection under normal conditions, and in the same period Multiple write operations are concurrently initiated in different applications.Therefore it may occur in which the occupied situation of the main connection.
If all main connections are not occupied, terminal can detecte the promoter of the write operation;According to write operation Write operation is put into position corresponding with write operation promoter by the difference of promoter, to guarantee that the first application is initiated to write behaviour The execution efficiency of work.Specifically, when all main connections are occupied, if the write operation is answered by described first With initiation, then the write operation is put into the second queue to be processed and applies corresponding position with described first;If described write Operation is initiated by second application, then the write operation is put into the second queue to be processed corresponding with second application Position.Wherein, the promoter of write operation can be determined by the information of the middle carrying of write operation, or can also pass through write operation Source determine.The write operation that first application is initiated is put into the second queue to be processed and applies corresponding position with described first It sets, it is ensured that write operation of the write operation of the first application preferentially with non-first application executes, and improves to formulate and applies the sending The execution efficiency of write operation.
For example, the write operation directly can be put into second wait locate when the write operation is initiated by second application Manage the tail of the queue of queue;And when the write operation is initiated by first application, it is to be processed which can be placed on second Position before the write operation that all second applications are initiated in queue.
In the present embodiment, the terminal obtains the write operation to the database;It detects whether in the presence of idle main company It connects;When there is idle main connection, the write operation is executed using the main connection;When all main connections are occupied The write operation is put into the second queue to be processed and institute by the used time if the write operation is initiated by first application It states first and applies corresponding position.Since main connection is only with write operation is executed, main connection is avoided shared by read operation With so as to improve the execution efficiency of write operation.
It should be noted that the present invention is not to holding between step 101 to step 102 and step 201 to step 204 Row sequence is defined.Step 101 can be first carried out in actual use to step 102, then execute step 201 again to step 204;Alternatively, step 201 can also be first carried out to step 204, step 101 is then executed again to step 102;Alternatively, can also be with Parallel execution of steps 101 is to step 102 and step 201 to step 204;Alternatively, can also independently execute step 101 to Step 102 or step 201 are to step 204.
It is a kind of flow diagram of data base read-write method of the present invention referring to Fig. 3.Wherein, contact person stores supplier (Contacts Provider), database connection pool (Connection Pool) and contact database (ContactsDatabase) it can be set in the same terminal, at least one first application be also provided in the terminal With at least one the second application.Wherein, contact person's storage supplier, database connection pool and contact database can be by terminals It is realized by the application in terminal, or can also be by the hardware and/or software realization of compositing terminal.
When the first application in terminal or second apply when needing to read the contact information in contact database, it can To initiate a read operation first, read operation is then sent to contact person and stores supplier;Contact person stores supplier and is connecing After receiving read operation, then read operation is sent to database connection pool;Database connection pool is after receiving read operation, first really Determine the promoter of read operation, if the promoter of read operation is the first application, executes the reading using the first non-master connection and grasp Make, if the promoter of read operation is the second application, executes the read operation using the second non-master connection.
When the first application in terminal or second apply when needing to rewrite the contact information in contact database, it can To initiate a write operation first, write operation is then sent to contact person and stores supplier;Contact person stores supplier and is connecing After receiving write operation, then write operation is sent to database connection pool;Database connection pool uses master after receiving write operation Connection executes the read operation.
Data base read-write method of the present invention is described further below with reference to Fig. 4.
It referring to fig. 4, is the flow diagram of another embodiment of data base read-write method of the present invention.Below with reference to Fig. 4 pairs It is described further using the process that data base read-write method of the present invention executes read operation.Method described in the embodiment of the present invention It can be completed by the database connection pool (ConnectionPool) in terminal.
Step 401, database connection pool obtains the read operation that application is initiated.
Step 402, database connection pool judges whether the read operation is initiated by the first application.
Step 403, if first application is initiated by first application, database connection pool detects the first non-master company It whether idle connects.
Step 404, when the first non-master connection is idle, database connection pool executes the reading using the first non-master connection and grasps Make.
When the read operation is initiated by the second application;Alternatively, initiated in the read operation by the first application, but first It is non-master connection it is occupied when, after step 402 or step 404, the method can also include:
Step 405, whether the non-master connection of database connection pool detection second is idle.
Step 406, when the second non-master connection is idle, database connection pool executes the reading using the second non-master connection and grasps Make.
If the second non-master connection is also occupied, after step 405, the method can also include:
Step 407, the read operation is put into the first queue to be processed by database connection pool.
When read operation is put into the first queue to be processed, if the promoter of read operation is the first application, just will Read operation, which is put into the first queue to be processed, applies corresponding position with first;If the promoter of read operation is the second application Etc. other applications, then read operation can be put into the tail of the queue of the first queue to be processed.
After the read operation is put into the first queue to be processed, it is also necessary to take out read operation and execute, therefore in step It can also include step 408 after 407 to 409, or also may include step 410 to 411.
Step 408, whether the non-master connection of database connection pool detection second is released.
Database connection pool can notify to determine whether the second non-master connection is released by Connection Release.Wherein, described Connection Release notice can be generated by the contact database in terminal, for being released in some main connection or some non-master connection After putting, the main connection of notification database connection pool or the non-master connection are released.Whether database connection pool can be with receiving Connection Release notice judges whether there is connection and is released, and whether judges the connection being released according to the content of Connection Release notice For the second non-master connection.
Step 409, after the second non-master connection is released, database connection pool, which takes out, is located at the described first queue to be processed Queue heads read operation, and return step 406.
It, can be from the number after database connection pool determines that certain second non-master connection is released by Connection Release notice Read operation, and return step 406 are taken out from the queue heads according to library connection pool, read operation is transferred to the second idle non-master company It connects.
Since the second non-master connection can be used for executing the initiated read operation of any application, no matter in first to The read operation for handling the column head of queue team is initiated by which application, can be transferred to after the second non-master Connection Release second non- Main connection executes.
Step 410, whether the non-master connection of database connection pool detection first is released.
Whether the connection that the content judgement that database connection pool can be notified according to Connection Release is released is first non-master Connection.
Step 411, after the first non-master connection is released, it is described for taking out promoter from the described first queue to be processed The read operation of first application, and return step 404.
After determining that certain first non-master connection is released by Connection Release notice, if existed in the first queue to be processed The read operation initiated by first application, then database connection pool can take out the read operation initiated by the first application, and Read operation is transferred to the non-master connection of idle first to execute by return step 404.
Using method provided by the present embodiment, the first non-master connection is only used for executing the reading behaviour that first application is initiated Make, therefore can guarantee that the execution efficiency for the read operation that the first application is initiated not will receive the influence of other application read operation.
It is the flow diagram of another embodiment of data base read-write method of the present invention referring to Fig. 5.Below with reference to Fig. 5 pairs It is described further using the process that data base read-write method of the present invention executes write operation.Method described in the embodiment of the present invention It can be completed by database connection pool.
Step 501, database connection pool obtains the write operation that application is initiated.
Step 502, whether the main connection of database connection pool detection is idle.
Step 503, if main connection is idle, database connection pool executes the write operation using the main connection.
Step 504, if main connection is occupied, database connection pool detects whether the write operation is sent out by the first application It rises.
Step 505, if the write operation is initiated by the first application, the write operation is put into second by database connection pool Corresponding position is applied with described first in queue to be processed.
Step 506, if the write operation is not initiated by the first application, the write operation is put into the by database connection pool The tail of the queue of two queues to be processed.
Whether different by the first application initiation according to write operation, terminal, which can choose, executes step 505 or step 506.? Can also include: after step 505 or step 506
Step 507, whether the database connection pool detection main connection is released.
After receiving Connection Release notice, database connection pool can judge to be released according to the content that Connection Release notifies It is connected based on the connection whether put, so that it is determined that whether main connection is released.
Step 508, after the main connection is released, the read operation for being located at the queue heads of the second queue to be processed is taken out, And return step 503.
Using method provided by the present embodiment, main connection, which is only used, executes write operation, therefore avoids main connection and read Occupied by operation, so as to improve the execution efficiency of write operation.
Corresponding with data base read-write method of the present invention, the present invention also provides data base read-write devices.
It is the structural schematic diagram of data base read-write device one embodiment of the present invention referring to Fig. 6.The data base read-write device It can be used for executing the data base read-write method in above-mentioned each implementation.
As shown in fig. 6, the device includes: acquiring unit 601 and the first execution unit 602.
Wherein, acquiring unit 601, for obtaining the read operation to the database;First execution unit 602 is used for When the read operation is initiated by the first application, the read operation is executed using the first non-master connection;First application is described Application in terminal;Wherein, the described first non-master connection is the preset reading for being only used for executing the first application initiation The non-master connection of operation;At least two non-master connection includes at least one described first non-master connection.The database is Contact database;First application is contact application.
Optionally, as shown in fig. 7, described device can also include: the second execution unit 603, in the read operation When being initiated by the second application, the read operation is executed using the second non-master connection;Wherein, second application is answered with described first With difference;The second non-master connection is other non-master connections in addition to the described first non-master connection.
Optionally, first execution unit 602 includes: detection sub-unit, is used in the read operation by described first When using initiating, detect whether in the presence of the described first idle non-master connection;Subelement is executed, for existing described in the free time When the first non-master connection, the read operation is executed using the described first idle non-master connection.Wherein, the detection sub-unit, It is also used to detect whether when all described first non-master connections are occupied in the presence of the second idle non-master connection;It is described Subelement being executed, being also used to when there is the idle second non-master connection, is held using the described second idle non-master connection The row read operation;Wherein, the described second non-master connection is other non-master connections in addition to the described first non-master connection.
Optionally, first execution unit 602 can also include subelement of joining the team, for non-in all described second It is main connection it is occupied when, by the read operation be put into the first queue to be processed with it is described first application priority corresponding to Position.
Read operation is executed using the device in the present embodiment, the first non-master connection is only used for executing the first application initiation Read operation, therefore can guarantee that the execution efficiency for the read operation that the first application is initiated not will receive the shadow of other application read operation It rings.
In another embodiment, as shown in figure 8, except acquiring unit 601, the first execution unit 602 and second execute list Except member 603, described device can also include: third execution unit 604.
Wherein, the acquiring unit 601, is also used to obtain the write operation to the database;The third execution unit 604 include: main connecting detection subelement, for detecting whether there is idle main connection;Write operation executes subelement, is used for When in the presence of idle main connection, the write operation is executed using the main connection;Write operation is joined the team subelement, for all It is described it is main connection it is occupied when, if the write operation by it is described first application initiate, the write operation is put into second Corresponding position is applied with described first in queue to be processed.Using this embodiment, is only used due to main connection and executes write operation, It therefore can be to avoid main connection occupied by read operation, so as to improve the execution efficiency of write operation.
When executing write operation using device in the present embodiment, main connection, which is only used, executes write operation, therefore can keep away Exempt from main connection occupied by read operation, so as to improve the execution efficiency of write operation.
It should be noted that in another embodiment, described device can only include acquiring unit 601 and at least the One of one execution unit 602, the second execution unit 603 and third execution unit 604.For example, described device can be wrapped only Include acquiring unit 601, the first execution unit 602 and the second execution unit 603;Alternatively, described device can also only include acquisition Unit 601 and third execution unit 604.The present invention is not limited to this.
It is the structural schematic diagram of terminal one embodiment of the present invention referring to Fig. 9.The terminal can be used to execute aforementioned each Data base read-write method shown in embodiment.
As shown in figure 9, the terminal may include: processor 901, memory 902.Optionally, the terminal can be with Including communication unit 903, input-output unit 904 etc..These components are communicated by one or more bus.This field skill Art personnel are appreciated that the structure of server shown in figure and do not constitute a limitation of the invention that it is either type trunk Structure is also possible to hub-and-spoke configuration, can also include than illustrating more or fewer components, perhaps combine certain components or Different component layouts.
Wherein, processor 901 is the control centre of electronic equipment, utilizes various interfaces and the entire electronic equipment of connection Various pieces, by running or execute the software program and/or module that are stored in memory 902, and call and be stored in Data in memory 902, to execute the various functions and/or processing data of electronic equipment.The processor 901 can be by collecting It is formed at circuit (Integrated Circuit, abbreviation IC), such as the IC that can be encapsulated by single is formed, it can also be by even It meets the encapsulation IC of more identical functions or different function and forms.For example, processor 901 can only include central processing unit (Central Processing Unit, abbreviation CPU) is also possible to GPU, digital signal processor (Digital Signal Processor, abbreviation DSP) and the control chip (such as baseband chip) in communication unit 903 combination.Implement in the present invention In mode, CPU can be single operation core, also may include multioperation core.
Memory 902 can be used for storing software program and module, and processor 901 is stored in memory 902 by operation Software program and module, thereby executing terminal various function application and realize data processing.Memory 902 mainly wraps Include program storage area and data storage area, wherein program storage area can answer needed for storage program area, at least one function With, for example the first application described in sound playing program, image playing program etc. and the embodiment of the present invention and second answer With;Data storage area, which can be stored, uses created data (such as audio data, phone directory etc.) etc. according to terminal, in this hair In bright embodiment, the data storage areas is for storing the database.Memory 902 may include volatile memory 902, such as non-volatile dynamic random access memory (NONVOLATILE RANDOM ACCESS MEMORY, abbreviation NVRAM), Phase change random access memory (PHASE CHANGE RAM, abbreviation PRAM), magnetic-resistance random access memory (MAGETORESISTIVE RAM, abbreviation MRAM) etc. can also include nonvolatile memory 902, for example, at least a disk Memory 902, (the ELECTRICALLY ERASABLE PROGRAMMABLE of Electrical Erasable programmable read only memory 902 READ-ONLY MEMORY, abbreviation EEPROM), flush memory device, such as anti-or flash memory (NOR FLASH MEMORY) or it is anti-and Flash memory (NAND FLASH MEMORY).Nonvolatile storage 902 stores operating system performed by processor 901 and applies journey Sequence.The processor 901 is stored from the 902 load operating program of nonvolatile storage and data to memory and by digital content In mass storage.The operating system includes for controlling and managing general system tasks, such as memory management, storage Equipment control, power management etc., and facilitate the various assemblies communicated between various software and hardwares and/or driver.In this hair In bright embodiment, the operating system can be the IOS system of the ANDROID system of GOOGLE Inc., the exploitation of APPLE company Or this kind of embedded OS of WINDOWS operating system etc. or VXWORKS of MICROSOFT company exploitation.
The communication unit 903 makes terminal by the communication channel to be connected to long-range clothes for establishing communication channel It is engaged in device, feasible remote server sends data or from media data under the remote server.The communication unit 903 can wrap Include WLAN (WIRELESS LOCAL AREA NETWORK, abbreviation WIRELESS LAN) module, bluetooth module, base band The communication modules such as (BASE BAND) module and the corresponding radio frequency of the communication module (RADIO FREQUENCY, abbreviation RF) Circuit is communicated for carrying out WLAN communication, Bluetooth communication, infrared communication and/or cellular communications system, such as Wideband code division multiple accesses (WIDEBAND CODE DIVISION MULTIPLE ACCESS, abbreviation W-CDMA) and/or high speed Downlink Packet Access (HIGH SPEED DOWNLINK PACKET ACCESS, abbreviation HSDPA).The communication module is for controlling The communication of each component in terminal processed, and can support direct memory access (DIRECT MEMORY ACCESS).
Input-output unit 904 for output information and/or information input into terminal, to realize user and terminal Interaction.The input-output unit 904 may include input subelement and output subelement, wherein the output subelement can It also may include other human-computer interaction interfaces, such as entity enter key, microphone etc. to include touch panel.Output Unit includes but is not limited to image output subelement and sound output subelement.Image output subelement is for output character, figure Piece and/or video.The image output subelement may include display panel, for example, by using LCD (Liquid Crystal Display, liquid crystal display), OLED (Organic Light-Emitting Diode, Organic Light Emitting Diode), Flied emission The forms such as display (field emission display, abbreviation FED) are come the display panel that configures.Or the image output Subelement may include reflected displaying device, such as electrophoresis-type (electrophoretic) display, or utilize interference of light modulation The display of technology (Interferometric Modulation of Light).Although inputting subelement and output subelement It is that the function that outputs and inputs of terminal is realized as two independent components, but in some embodiments it is possible to by touch-control Panel and display panel are integrated and that realizes terminal output and input function.For example, the image output subelement can be with Show various Graphic User Interfaces (Graphical User Interface, abbreviation GUI) to wrap as virtual controlling component Window, scroll bar, icon and scrapbook are included but are not limited to, so that user is operated by touch control manner.
In the present invention is implemented, the memory 902 library and application for storing data, wherein the database can be with For contact database, the application includes the first application and the second application, the database have at least one main connection and At least two non-master connections, the main connection is for executing the write operation to the database, and the non-master connection is for executing Read operation to the database, first application is contact application.The input-output unit can be used for terminal Middle inputting contact information, or can be used for showing contact information to user.
The processor 901, for obtaining the read operation to the database;It is initiated in the read operation by the first application When, the read operation is executed using the first non-master connection;First application is the application in the terminal;Wherein, described One non-master connection is the preset non-master connection for being only used for executing the read operation that first application is initiated;Described at least two A non-master connection includes at least one described first non-master connection.
The processor 901 is also used to execute when the read operation is initiated by the second application using the second non-master connection The read operation;Wherein, second application is different from first application;The second non-master connection is except described first is non- Other non-master connections except main connection.
The processor 901 is also used to detect whether there is the free time when the read operation is initiated by first application The described first non-master connection;When there is the idle first non-master connection, the described first idle non-master connection is used Execute the read operation.
The processor 901 is also used to detect whether there is sky when all described first non-master connections are occupied The second not busy non-master connection;When there is the idle second non-master connection, held using the described second idle non-master connection The row read operation;Wherein, the described second non-master connection is other non-master connections in addition to the described first non-master connection.
The processor 901 is also used to detect whether there is sky when all described first non-master connections are occupied The second not busy non-master connection;When there is the idle second non-master connection, held using the described second idle non-master connection The row read operation;Wherein, the described second non-master connection is other non-master connections in addition to the described first non-master connection.
In another embodiment, the processor 901 can be used for obtaining the write operation to the database;Detection is It is no to there is idle main connection;When there is idle main connection, the write operation is executed using the main connection;All It is described it is main connection it is occupied when, if the write operation by it is described first application initiate, the write operation is put into second Corresponding position is applied with described first in queue to be processed.
When executing the read operation that application is initiated, the first non-master connection is only used for executing described first terminal in this implementation Using the read operation of initiation, therefore it can guarantee that the execution efficiency for the read operation that the first application is initiated not will receive other application reading The influence of operation.
It is required that those skilled in the art can be understood that the technology in the embodiment of the present invention can add by software The mode of general hardware platform realize.Based on this understanding, the technical solution in the embodiment of the present invention substantially or Say that the part that contributes to existing technology can be embodied in the form of software products, which can deposit Storage is in storage medium, such as ROM/RAM, magnetic disk, CD, including some instructions are used so that computer equipment (can be with It is personal computer, server or the network equipment etc.) complete certain part institutes of each embodiment of the present invention or embodiment The method stated.
All the embodiments in this specification are described in a progressive manner, same and similar portion between each embodiment Dividing may refer to each other, and each embodiment focuses on the differences from other embodiments.Especially for device and For terminal embodiment, since it is substantially similar to the method embodiment, so being described relatively simple, related place is referring to method The part of embodiment illustrates.
The embodiments of the present invention described above are not intended to limit the scope of the present invention.It is any in the present invention Spirit and principle within made modifications, equivalent substitutions and improvements etc., should all be included in the protection scope of the present invention.

Claims (16)

1. a kind of data base read-write method, which is characterized in that the database includes that in the terminal, the database has at least One main connection and at least two non-master connections, the main connection are described non-master for executing the write operation to the database Connection is for executing the read operation to the database, which comprises
The terminal obtains the read operation to the database;
If the read operation is initiated by the first application, the read operation is executed using the first non-master connection;Wherein, described first Using for the application in the terminal;
The first non-master connection is the preset non-master connection for being only used for executing the read operation that first application is initiated;
At least two non-master connection includes at least one described first non-master connection.
2. the method as described in claim 1, which is characterized in that the method also includes:
If the read operation is initiated by the second application, the read operation is executed using the second non-master connection;
Wherein, second application is different from first application;The second non-master connection is except the described first non-master connection Except other non-master connections.
3. the method as described in claim 1, which is characterized in that if the read operation is initiated by the first application, use First non-master connection executes the read operation
If the read operation is initiated by first application, detect whether in the presence of the described first idle non-master connection;
When there is the idle first non-master connection, the read operation is executed using the described first idle non-master connection.
4. method according to claim 2, which is characterized in that the method also includes:
When all described first is non-master connects occupied, detect whether in the presence of the described second idle non-master connection;
When there is the idle second non-master connection, the read operation is executed using the described second idle non-master connection;
Wherein, the described second non-master connection is other non-master connections in addition to the described first non-master connection.
5. method as claimed in claim 4, which is characterized in that the method also includes:
When all described second non-master connections are occupied, by the read operation be put into the first queue to be processed with it is described Position corresponding to the priority of first application.
6. the method as described in any one of claims 1 to 5, which is characterized in that the database is contact database.
7. the method as described in any one of claims 1 to 5, which is characterized in that first application is contact application.
8. the method as described in any one of claims 1 to 5, which is characterized in that further include:
The terminal obtains the write operation to the database;
It detects whether in the presence of idle main connection;
When there is the idle main connection, the write operation is executed using the idle main connection;
When all main connections are occupied, if the write operation is initiated by first application, write described Operation, which is put into the second queue to be processed, applies corresponding position with described first.
9. a kind of data base read-write device, which is characterized in that the database includes that in the terminal, the database has at least One main connection and at least two non-master connections, the main connection are described non-master for executing the write operation to the database Connection is used to execute the read operation to the database, and described device includes:
Acquiring unit, for obtaining the read operation to the database;
First execution unit, for executing the reading using the first non-master connection when the read operation is initiated by the first application Operation;Wherein, first application is the application in the terminal;
The first non-master connection is the preset non-master connection for being only used for executing the read operation that first application is initiated;
At least two non-master connection includes at least one described first non-master connection.
10. device as claimed in claim 9, which is characterized in that further include:
Second execution unit, for executing the reading using the second non-master connection when the read operation is initiated by the second application Operation;
Wherein, second application is different from first application;The second non-master connection is except the described first non-master connection Except other non-master connections.
11. device as claimed in claim 9, which is characterized in that first execution unit includes:
Detection sub-unit, for when the read operation is initiated by first application, detecting whether in the presence of idle described the One non-master connection;
Subelement is executed, for using the described first idle non-master connection when there is the idle first non-master connection Execute the read operation.
12. device as claimed in claim 11, which is characterized in that
The detection sub-unit is also used to detect whether there is the free time when all described first non-master connections are occupied The second non-master connection;
The execution subelement is also used to when there is the idle second non-master connection, non-using idle described second Main connection executes the read operation;
Wherein, the described second non-master connection is other non-master connections in addition to the described first non-master connection.
13. device as claimed in claim 12, which is characterized in that first execution unit further include:
Join the team subelement, for when all described second non-master connections are occupied, by the read operation be put into first to Handle position corresponding to the priority applied in queue with described first.
14. such as the described in any item devices of claim 9 to 13, which is characterized in that the database is contact database.
15. such as the described in any item devices of claim 9 to 13, which is characterized in that first application is contact application.
16. such as the described in any item devices of claim 9 to 13, which is characterized in that described device further includes third execution unit,
The acquiring unit is also used to obtain the write operation to the database;
The third execution unit includes:
Main connecting detection subelement, for detecting whether there is idle main connection;
Write operation executes subelement, for being write using described in the idle main connection execution when there is idle main connection Operation;
Write operation is joined the team subelement, for when all main connections are occupied, if the write operation is by described the One application is initiated, then the write operation is put into the second queue to be processed and applies corresponding position with described first.
CN201510505796.0A 2015-08-17 2015-08-17 Data base read-write method and device Active CN106469156B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510505796.0A CN106469156B (en) 2015-08-17 2015-08-17 Data base read-write method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510505796.0A CN106469156B (en) 2015-08-17 2015-08-17 Data base read-write method and device

Publications (2)

Publication Number Publication Date
CN106469156A CN106469156A (en) 2017-03-01
CN106469156B true CN106469156B (en) 2019-10-18

Family

ID=58213819

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510505796.0A Active CN106469156B (en) 2015-08-17 2015-08-17 Data base read-write method and device

Country Status (1)

Country Link
CN (1) CN106469156B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108256589B (en) * 2018-02-14 2022-01-28 北京火花日志科技有限公司 Industrial equipment data application reading and writing method and device

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103513932A (en) * 2012-06-28 2014-01-15 深圳市腾讯计算机系统有限公司 Method and device for data processing
CN103793432A (en) * 2012-11-01 2014-05-14 深圳中兴网信科技有限公司 Method and device for splitting database reading and writing
CN104142868A (en) * 2013-05-10 2014-11-12 腾讯科技(深圳)有限公司 Connection establishment method and device

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8429374B2 (en) * 2010-01-28 2013-04-23 Sony Corporation System and method for read-while-write with NAND memory device

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103513932A (en) * 2012-06-28 2014-01-15 深圳市腾讯计算机系统有限公司 Method and device for data processing
CN103793432A (en) * 2012-11-01 2014-05-14 深圳中兴网信科技有限公司 Method and device for splitting database reading and writing
CN104142868A (en) * 2013-05-10 2014-11-12 腾讯科技(深圳)有限公司 Connection establishment method and device

Also Published As

Publication number Publication date
CN106469156A (en) 2017-03-01

Similar Documents

Publication Publication Date Title
US11868785B2 (en) Application program page processing method and device
CN110300328B (en) Video playing control method and device and readable storage medium
CN102654814B (en) Method and device for calling functions in application as well as electronic equipment
US20190361580A1 (en) Progressive presence user interface for collaborative documents
US10019298B2 (en) Middleware interface and middleware interface generator
CN110633032B (en) Icon display method and device for terminal equipment
CN107832113A (en) A kind of interface display method and device of android system application program
JP2007257642A (en) Apparatus, method and system for highlighting related user interface control
EP3485358B1 (en) Electronic device and method thereof for managing applications
US20070143335A1 (en) Partition-based undo of partitioned object graph
US20160188171A1 (en) Split button with access to previously used options
CN109766139B (en) Configuration method and device of configuration file
CN102662882A (en) Method and device for unloading mobile storage equipment
WO2019128571A1 (en) Resource management method and device, mobile terminal, as well as computer readable storage medium
CN110673887A (en) Application program starting method and device, terminal equipment and readable storage medium
CN106105168A (en) A kind of method, terminal and portable electric appts calling transfer
US9118756B2 (en) Recording method, recording device, and electronic device
CN106469156B (en) Data base read-write method and device
CA3148068A1 (en) Skill pack data processing method, device, computer equipment and storage medium
CN106371879A (en) Method and system for shielding non-deletable application of mobile terminal
CN108089781B (en) Interface display method and device
KR20060124047A (en) Mobile phone for supporting multi operating system loading and method therefor
CN104750553A (en) Application operating method and device
CN109710278A (en) A kind of method, apparatus and terminal device unloading application program
WO2022068370A1 (en) Terminal-use minus-2 screen interface display method, apparatus, terminal, and medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
CB02 Change of applicant information

Address after: 523808 Southern Factory Building (Phase I) Project B2 Production Plant-5, New Town Avenue, Songshan Lake High-tech Industrial Development Zone, Dongguan City, Guangdong Province

Applicant after: Huawei Device Co., Ltd.

Address before: 523808 Southern Factory Building (Phase I) Project B2 Production Plant-5, New Town Avenue, Songshan Lake High-tech Industrial Development Zone, Dongguan City, Guangdong Province

Applicant before: HUAWEI terminal (Dongguan) Co., Ltd.

CB02 Change of applicant information
GR01 Patent grant
GR01 Patent grant