CN101980207B - Method and system for implementing database access - Google Patents

Method and system for implementing database access Download PDF

Info

Publication number
CN101980207B
CN101980207B CN2010105365329A CN201010536532A CN101980207B CN 101980207 B CN101980207 B CN 101980207B CN 2010105365329 A CN2010105365329 A CN 2010105365329A CN 201010536532 A CN201010536532 A CN 201010536532A CN 101980207 B CN101980207 B CN 101980207B
Authority
CN
China
Prior art keywords
bucket
statement
database
instance
data
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
CN2010105365329A
Other languages
Chinese (zh)
Other versions
CN101980207A (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.)
China Telecom Corp Ltd
Original Assignee
China Telecom Corp 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 China Telecom Corp Ltd filed Critical China Telecom Corp Ltd
Priority to CN2010105365329A priority Critical patent/CN101980207B/en
Publication of CN101980207A publication Critical patent/CN101980207A/en
Application granted granted Critical
Publication of CN101980207B publication Critical patent/CN101980207B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

The invention discloses a method and a system for implementing database access. The method comprises the following steps of: forming a Bucket instance by using the same class of structured query language (SQL); configuring various SQL and Bucket in a data access configuration file; if non cross-statement database access is performed, acquiring Pooled Statement by using a borrow Statement () interface method; if cross-statement database access is performed, acquiring the Bucket by using a borrow Bucket () interface method, and acquiring the Pooled Statement therein one by one by using a get Statement () method provided by the Bucket; and performing data operation of the database access by using an interface method provided by the Pooled Statement. The method and the system can implement high-availability, high-performance, low-cost, and easily managed, adjusted and optimized database access for a distributed system of massive data.

Description

A kind of implementation method of database access and system
Technical field
The present invention relates to the information application technology, be meant a kind of implementation method and system of database access especially.
Background technology
Data access technology is an emphasis problem will considering in the distributed system of mass data.
Present data storage generally adopts relevant database; In realizing with Java; Relevant database is called O-R Mapping to the conversion between the Java object, has had at present the scheme of a lot of O-R Mapping, wherein increase income like Hibernate (Object Relation Mapping framework).
The distributed system of the mass data of, high performance requirements available for height, these existing realizations are general exist following not enough:
1, be difficult to the characteristics of using the database of different reading and writing characteristics and different priority level connected and be optimized, exclusively enjoy database connection resource such as one type of database access, the shared database of several statements of writing connects; Some database connects always and keeps, and other databases connect release as early as possible etc.
2, SQL (Structured Query Language; SQL) statement is not by centralized configuration; Be difficult to carry out that other accent of SQL statement level is excellent, the management of fault analysis and concentrated database access statement, the managerial personnel of system development and data base administrator are difficult to the SQL of accessing database is managed and transfer excellent with a kind of concentrated mode.
3, adopt the reflex mechanism (reflect) of Java to realize O-R Mapping, have bigger performance consumption, can not satisfy requirement the extra high system of performance requirement.
4, in the distributed system of the available mass data of height, generally need a lot of database server of quantity, sometimes even thousands of, and data have a plurality of copies.In this case, the mass storage function of dependency database system needs database access layer that corresponding support is provided fully, and the support underaction of general existing realization this respect is like the strategy that does not provide multiple distribution to write.
5, stride the realization of the transaction management dependence application server of statement, performance consumption is bigger.
Summary of the invention
In view of this, the objective of the invention is to propose a kind of implementation method and system of database access, realize for the distributed system of mass data provides high available, high-performance, with low cost, manageability and the excellent data access layer of accent.
Implementation method based on above-mentioned purpose a kind of database access provided by the invention comprises:
SQL is classified;
Each Bucket of configuration in the data access configuration file comprises among the Bucket that the database of of a sort SQL and this Bucket connects;
If carry out non-database access of striding statement, then obtain Pooled Statement through borrowStatement () interface method; If stride the database access of statement, then obtain Bucket through borrowBucket () interface method, the getStatement () method that provides through Bucket obtains Pooled Statement wherein one by one;
The interface method that uses Pooled Statement to provide carries out the data manipulation of this database access.
Optional, if carry out non-database access of striding statement in this method, then, obtain Pooled Statement according to statement id through borrowStatement () interface method; If stride the database access of statement, then, obtain Bucket according to statement Bucket id through borrowBucket () interface method.
Optional, manage the Bucket instance through a two-dimensional array in this method, first dimension is the Bucket type under the Bucket instance, second dimension connects for the database that this instance takies;
When caller passed through borrowStatement () or borrowBucket () method application statement or Bucket, the parameter of importing into was " Bucket id " or " statement id ", and the pool manager operating process is following:
If parameter is " statement id ", then be converted into Bucket id through an index.
In the Bucket pond, find all Bucket instances that belong to this Bucket type, i.e. an one-dimension array according to Bucket id;
Scan this array,, be labeled as " using " if find the Bucket instance of " free time ",, then return this instance if that the caller application is Bucket; If application is statement, then in the statement that this Bucket instance comprises, find this statement to return according to " statement id "; If can not find the Bucket instance of " free time ", then process dormancy a period of time is waited for,, also can not find the instance of " free time " if after the stand-by period, the exception response that the expression of then dishing out " is done ".
Optional, give back Pooled Statement or Bucket through returnMe () method in this method.
Optional, this method further comprises: all Bucket centralized configuration in a data access-profile that a database access is required.
Optional, the said data access configuration file of this method adopts the Properties file of Java, and the collocation form of statement is " statement id=SQL ", and the collocation form of Bucket is following:
A plurality of statement id that the statement that comprises: class [bucket id] .stmts=comma separates have defined the SQL statement that comprises among the Bucket;
The database linking number that the database linking number that can use at most: class [bucket id] .conn=can use at most;
Whether database connects can write: class [bucket id] .update=true/false, be defaulted as false, and promptly read-only.
Optional, if the said database access of this method is a write operation, then adopt one of following three kinds of modes to carry out:
Only write a database: data are only write a database and are promptly accomplished;
A plurality of data sync are write: data are wanted a plurality of databases of writing of success, and affairs just are counted as merit;
A plurality of database asynchronous writes: attempt earlier writing data in a plurality of databases, if success, then affairs complete successfully; If one of them database write is then selected in failure, and writes down these data and need be synchronized in other databases, carry out data sync afterwards by the synchronization mechanism on backstage.
Optional, when appearance in the database access process was unusual, caller was not given back Pooled Statement or Bucket, will carry out mark to the database of makeing mistakes in this method, and refusal carries out write operation to it again.
Optional, this method still was not used if exceed this retention time free time statement in the idle retention time of said data access configuration file middle finger attribute sentence, then reclaimed the resource of this statement; If all statements in Bucket instance all are recovered, then this Bucket instance connects together with the data of its use and all can be recovered.
In another aspect of this invention, a kind of realization system of database access is provided also, has comprised:
Interface module is used to provide the interface of database access, for non-database access of striding statement, provides borrowStatement () interface method to obtain Pooled Statement; For the database access of striding statement, provide borrowBucket () interface method to obtain Bucket;
The Bucket module is formed a Bucket instance with of a sort SQL; Provide getStatement () method to be used to obtain the PooledStatement of Pooled Statement module;
Pooled Statement module, the interface method that provides carries out the data manipulation of database access;
Connect and statement pond administration module, be used for management and connect and the SQL statement pond;
The distributed data storehouse memorizer is used for the data of stored data base.
Optional, the said interface module of this system, if carry out non-database access of striding statement, then through borrowStatement () interface method, id obtains PooledStatement according to statement; If stride the database access of statement, then, obtain Bucket according to statement Bucket id through borrowBucket () interface method.
Optional, the said Bucket module of this system is managed the Bucket instance through a two-dimensional array, and first dimension is the Bucket type under the Bucket instance, and second dimension connects for the database that this instance takies;
When caller passed through borrowStatement () or borrowBucket () method application statement or Bucket, the parameter of importing into was " Bucket id " or " statement id ", and the pool manager operating process is following:
If parameter is " statement id ", then be converted into Bucket id through an index.
In the Bucket pond, find all Bucket instances that belong to this Bucket type, i.e. an one-dimension array according to Bucket id;
Scan this array,, be labeled as " using " if find the Bucket instance of " free time ",, then return this instance if that the caller application is Bucket; If application is statement, then in the statement that this Bucket instance comprises, find this statement to return according to " statement id "; If can not find the Bucket instance of " free time ", then process dormancy a period of time is waited for,, also can not find the instance of " free time " if after the stand-by period, the exception response that the expression of then dishing out " is done ".
Optional, the said interface module of this system is given back PooledStatement or Bucket through returnMe () method.
Saidly can find out that there are following advantage in the implementation method of database access provided by the invention and system from top:
SQL and database are connected centralized configuration in the data access-profile, and configuration file adopts the properties file of Java, and the collocation form of SQL is like " statement id=SQL ".
SQL is classified; Of a sort SQL is formed Bucket, and Bucket can be by instantiation, and a Bucket instance comprises the SQL statement instance that belongs to this Bucket; Statement instance shared data bank in Bucket instance connects, and can accomplish the affairs of striding statement.Different Bucket uses different databases to connect, and is the database linking number of the maximum of each Bucket assignment of allocation, and the attribute that connects, as the time that reads or writes, keeps connecting etc.Bucket is centralized configuration in the data access configuration file also, and form is like " a plurality of statement id that comma separates ".
Need not use Java reflect to accomplish O-R Mapping, to obtain more performance.
The programming mode aspect: all data accesses must be in the data access configuration file centralized configuration, do not allow SQL to occur in program and the configuration file outside the data access configuration file.
Description of drawings
Fig. 1 is the schematic flow sheet of embodiment of the invention database access implementation method;
Fig. 2 is the schematic flow sheet of the database access of another embodiment of the present invention;
Fig. 3 is the synoptic diagram of a data access-profile of embodiment of the invention generation;
Fig. 4 is the structural representation of the realization system of embodiment of the invention database access;
Fig. 5 is the non-schematic flow sheet of striding the statement access process of the embodiment of the invention;
Fig. 6 strides the schematic flow sheet of statement access process for the embodiment of the invention.
Embodiment
Block diagram and flow chart description the present invention below with reference to method according to an embodiment of the invention, device (being system) and computer program.Be appreciated that each piece of block diagram and process flow diagram and the combination of the piece in block diagram and the process flow diagram can be realized by computer program instructions respectively.These computer program instructions can be loaded on multi-purpose computer, special purpose computer or other programmable data treating apparatus; To produce product, so that the instruction of on computing machine or other programmable data treating apparatus, carrying out produces the device of the block diagram that is used for executive system or flow chart block appointment.
These computer program instructions also can be stored in the computer-readable memory; This computer-readable memory can instruct computing machine or other programmable data treating apparatus by ad hoc fashion work; So that the instruction that is stored in the computer-readable memory produces a product, wherein comprise the command device of realizing the function of appointment in one or more flow chart blocks.Computer program instructions also can be loaded on computing machine or other programmable data treating apparatus; To cause the sequence of operations step on computing machine or other programmable devices, to be performed; To produce computer implemented process, so that the instruction of on computing machine or other programmable devices, carrying out is provided for realizing the step of the function of appointment in one or more flow chart blocks.
Therefore, the piece support of block diagram and process flow diagram be used to carry out the device of appointed function combination, be used to carry out combination and the program instruction means that is used to carry out appointed function of the step of appointed function.It is also understood that each piece of block diagram and process flow diagram and the combination of the piece in block diagram and the process flow diagram can be realized by the combination of the hardware based dedicated computer system of carrying out appointed function or step or specialized hardware and computer instruction.
Referring to shown in Figure 1, the implementation method of database access provided by the invention mainly comprises:
Step 101 is classified to SQL;
Step 102 disposes Bucket in the data access configuration file, comprise among the Bucket after the configuration that of a sort SQL is connected with database, and of a sort SQL is subdivided into a Bucket instance;
Step 103 when carrying out database access, if carry out non-database access of striding statement, is then obtained Pooled Statement through borrowStatement () interface method; If stride the database access of statement, then obtain Bucket through borrowBucket () interface method, the getStatement () method that provides through Bucket obtains PooledStatement wherein one by one;
Step 104, the interface method that uses Pooled Statement to provide carries out the data manipulation of this database access.
As an embodiment; With the needed a plurality of Bucket of a database access (comprising SQL is connected with database) centralized configuration in a data access-profile; Configuration file adopts the properties file of Java, and the collocation form of SQL is like " statement id=SQL ".The programming mode aspect: all data accesses must be in the data access configuration file centralized configuration, do not allow SQL to occur in program and the configuration file outside the data access configuration file.Because SQL and database are connected centralized configuration in the data access configuration file, make Development of Software and maintainer (comprising the data base administrator) very clear to the operation to data in the system, conveniently manage and transfer excellent.In addition; The embodiment of the invention is put into a configuration file the inside owing to SQL is connected with database; The user can carry out system configuration through revising configuration file like this, thereby for system configuration provides an approach very easily, can be through revising SQL in this configuration file; Make the different data of system's visit, obtain different entity objects.This configuration can also be carried out very complicated expansion through the storing process of database.
As an embodiment, with the SQL classification, of a sort SQL is formed Bucket; Bucket can be by instantiation; A Bucket instance comprises the SQL statement instance that belongs to this Bucket, and the statement instance shared data bank in Bucket instance connects, and can accomplish the affairs of striding statement.Different Bucket instance uses different databases to connect, and is the database linking number of the maximum of each Bucket instance assignment of allocation, and the attribute that connects, as the time that reads or writes, keeps connecting etc.Bucket is centralized configuration in the data access configuration file also, and form is like " a plurality of statement id that comma separates ".
Wherein, the classification to SQL generally has Several principles:
● reading statement and write statement are assigned to different bucket.
● according to the application scenarios of statement, the statement that will in same things, will carry out is put into a bucket.
● according to the database resource that these statement needs consume, the statement that the consumption data base resource is many is put into independently bucket the inside, and what the consumption data base resource was few combines.
Do not use Java reflect to accomplish O-R Mapping in the present invention, to obtain more performance.
The upper strata caller comes the notebook data access layer is called through interface layer; Caller can obtain Pooled Statement and two types of entity objects that carry out database access of Bucket; Wherein Bucket is the entity that comprises a plurality of Pooled Statement, can stride the transaction operation of statement.The hard core control statement pond of data access layer and data connection pool, accomplish with the lower floor distributed environment under being connected of a plurality of databases.
Referring to shown in Figure 2, comprise the steps: as a concrete data base call process of embodiment
Step 201 configures Bucket in the data access configuration file, comprise among each Bucket that the database of one type of SQL and this Bucket is connected.
Step 202, caller obtains Pooled Statement or Bucket through borrowStatement () or borrowBucket () two class interface methods according to " statement id " or " Bucket id ".Wherein, carry out non-transaction operation of striding statement if desired, then obtain PooledStatement, directly get into step 204; Stride the transaction operation of statement if desired, should obtain Bucket earlier.
Step 203, if that acquisition is Bucket, the getStatement () method that then provides through Bucket obtains Pooled Statement wherein one by one.
Step 204, the various interface method of preparedStatment or callableStatment is carried out data manipulation among the JDBC of the similar Java that use Pooled Statement provides.
Step 205, caller is given back Pooled Statement or Bucket through returnMe () method.
Wherein, the Pooled Statement that uses in the step 204 is the encapsulation to preparedStatment among the Java JDBC, therefore, can support preparedStatment or callableStatment, the storing process of the corresponding database of the latter.Different with the preparedStatment method of JDBC is; For the data access that needs the return data collection; This programme has defined the IResultSetHandler interface; The function that this interface is realized is with the delegation in the database data that uses SQL to return, and is assembled into an object (Object), is put into these objects in the tabulation (List) and returns to caller.Wherein, said SQL configures in the data access configuration file that generates of said step 201.
As an embodiment, the data access configuration file adopts Java Properties file layout, and preferred version comprises following main points:
The collocation form of SQL statement is " a statement id=SQL statement ", and statement id is used for caller visit statement, is the integer since 0; Like " 0=select A; B from TableAwhere id=? ", can specify some parameters, the retention time during like the free time etc. for each statement.Can come the retention time of specify default with default.keep.alive; Be set to 30 seconds like default.keep.alive=30; Keep.alive0=0 representes that No. 0 statement keeps forever; Statement and connection pool manager do not discharge the resource of this statement and the connection of used database thereof, can be used for real-time and require extra high occasion.
Bucket also conducts interviews through id, and the statement with comprising among Bucket of " a plurality of statement id that comma separates " definition can be expressed as a plurality of statement id that class [bucket id] .stmts=comma separates; Like " class0.stmts=0; 1,5 ", defined among No. 0 Bucket and comprised 0; 1, No. 5 three SQL statement.Different Bucket uses different databases to connect; In an application, different data accesses has different important and priority levels, can for each Bucket specify at most can with the database linking number ensure; Can be expressed as the database linking number that class [bucketid] .conn=can use at most; Like class0.conn=3, specify this Bucket can be instantiated as 3 Bucket instances, each takies a database and connects.
Whether database connects can write: can be expressed as class [bucketid] .update=true/false, like class0.4update=true.The statement among the Bucket or all be the read-only operation statement wherein, or be the statement that comprises write operation all, specify with the 4update attribute of Bucket, be defaulted as read-only operation false.So just reading and writing on database and be connected and separate, so that to connecting the optimization of using.
Referring to shown in Figure 3, be the example of a data access-profile generating according to above-mentioned preferred version.
The present invention towards be distributed application, in these application, data access is main to read usually.In the available distributed system of height, critical data generally has a plurality of copies, exists in the different databases.For read operation, only need optional one of them database to carry out read operation.For writing, the present invention provides flexible three kinds tactful selective for using:
Only write a database: data are only write a database and are promptly accomplished, and are suitable for not too important situations such as data.
A plurality of data sync are write (abbreviation synchronous write): data are wanted a plurality of databases of writing of success, and affairs just are counted as merit.This mode has reduced the availability (because wanting the success simultaneously of a plurality of database writes) of these affairs itself, but has improved the reliability of data simultaneously.
A plurality of database asynchronous writes (abbreviation asynchronous write): attempt earlier writing data in a plurality of databases, if success, then affairs complete successfully; If one of them database write is then selected in failure, and writes down these data and need be synchronized in other databases, carry out data sync afterwards by the synchronization mechanism on backstage.
Through three kinds of WriteModes that provide, make that not relying on Database Systems can realize high available data storage, has greatly reduced cost.
In the data access process, all need carry out complicated abnormality processing, and in the distributed system of integration across database, it is complicated more that these abnormality processing become.This programme is handled common abnormal and is encapsulated significantly, and when appearance was unusual, caller need not given back PooledStatement or Bucket, need not be concerned about statement and the problems such as recovery that are connected yet.In the preferred embodiment of the present invention data are carried out special protection, when some taking place can cause database collapse unusual, will carry out mark to the database of makeing mistakes, refusal carries out write operation to it again.
In another aspect of this invention, a kind of realization system of database access is provided also,, has comprised referring to shown in Figure 4:
Interface module is used to provide the interface of database access, for non-database access of striding statement, provides borrowStatement () interface method to obtain Pooled Statement; For the database access of striding statement, provide borrowBucket () interface method to obtain Bucket;
The Bucket module is formed a Bucket instance with of a sort SQL; Provide getStatement () method to be used to obtain the PooledStatement of Pooled Statement module;
Pooled Statement module, the interface method that provides carries out the data manipulation of database access;
Connect and statement pond administration module, be used for management and connect and the SQL statement pond.
The distributed data storehouse memorizer is used for the data of stored data base.
Wherein, said Bucket module, Pooled Statement module and be connected and statement pond administration module can be positioned at data access layer.
As a preferred embodiment, said connection and statement pond administration module, regularly statement and the database in (time interval can dispose) scanning pond connects, and discharges no resource, and the database connection of unusual disconnection is attempted reconnecting by certain strategy.In the data access configuration file, can specify the idle retention time of statement; Surpassing this time statement is not used; Its resource will be recovered, if all statements in Bucket instance all are recovered, then this Bucket instance connects together with the data of its use and all can be recovered.Application can be set different maintenance strategies for the different pieces of information visit, to obtain best performance.
Connection and statement pond administration module are managed the Bucket instance through a two-dimensional array (being the Bucket pond), and first dimension is the Bucket type under the Bucket instance, the database connection that second dimension takies for this instance.When caller passed through borrowStatement () or borrowBucket () method application statement or Bucket, the parameter of importing into was " Bucket id " or " statement id ", and connection and the administration module operating process of SQL statement pond are generally following:
If parameter is " statement id ", then be converted into Bucket id through an index.
In the Bucket pond, find all Bucket instances that belong to this Bucket type, i.e. an one-dimension array according to Bucket id.
Scan this array,, be labeled as " using " if find the Bucket instance of " free time ",, then return this instance if that the caller application is Bucket; If application is statement, then in the statement that this Bucket instance comprises, find this statement to return according to " statement id ".If can not find the Bucket instance of " free time ", then process dormancy a period of time is waited for (time length can dispose),, also can not find the instance of " free time " if after the stand-by period, then dish out " hurry " unusually.
Referring to shown in Figure 5,, comprise the steps: for implementing non-schematic flow sheet of striding the statement access process based on said system
Step 501, caller are called borrowStatement () method and are obtained PooledStatement.
Step 502, class JDBCpreparedStatment that use Pooled Statement provides or the various interface method of callableStatment are carried out data manipulation.
Step 503 uses the returnMe () method of Pooled Statement to give back PooledStatement.
Fig. 6 comprises the steps: for implement to stride the schematic flow sheet of statement access process based on said system
Step 601, the borrowStatement () method of caller calling interface module obtain Pooled Statem ent.
Step 602, the borrowBucket () method of caller calling interface module obtains Bucket.
Step 603 uses the getStatement () method of Bucket module to obtain Pooled Statement wherein one by one.
Step 604, class JDBCpreparedStatment that use Pooled Statement module provides or the various interface method of callableStatment are carried out data manipulation.
Step 605 uses the returnMe () method of Bucket module to give back Bucket.
Below be the example of system of the present invention in practical application:
The Best Tone Service system of certain province; DATA DISTRIBUTION on 6 nodes, each node use a pair of (two) database (with call in the following text be equipped with mutually database to), critical data keeps two copies at this in to database; Have 12 databases altogether; Be distributed on 12 PC server hosts, the main frame in the system surpasses 50, is a large-scale Distributed Application.
This Best Tone Service system mainly provides local service for life information to the user, and the data owner in the database will comprise Business Information (information that contains its products & services that provide), user profile etc.Use scheme provided by the invention to carry out database access, following several kinds of access modes arranged:
Read-only: as to be equipped with the data that database centering all has copy mutually, only to need to select one of them to conduct interviews.
Only write a database: like some access logs, these access logs are by tabulate statistics regularly.
Synchronous write: some change little critical data and adopt synchronous write, like newly-increased businessman, revise merchant visitor's essential information etc.
Asynchronous write: critical datas that some often change, the clicks of being visited like businessman, when data break down after in, service needs to continue obtaining higher availability, after the database that the breaks down reparation, by background program completion synchronization of data.
Since this Best Tone Service system formally reaches the standard grade; The operation efficient stable; Wherein use data access scheme of the present invention to obtain very high performance and availability, and because of the shutdown of a database does not influence the main service of system, the well online database of back-up system upgrading.
This system deployment is used the (SuSE) Linux OS of increasing income and the MySQL Database Systems of increasing income on the PC server cluster, with low cost, has very high cost performance.
In the actual maintenance of this Best Tone Service system; The superiority of centralized configuration SQL of the present invention and database has obtained good embodiment; All SQL come into plain view with being connected in the configuration file; Can be easily visit is configured and transfers excellent to data, when breaking down, can accomplish to know very well in one's heart more to the adjustment of system; In the large-scale software development that many people participate in, be the link of easy error at data access, the present invention does not allow except that the data access-profile, in system, to introduce database access on programming mode, is convenient to management and control.
The those of ordinary skill in affiliated field is to be understood that: the above is merely specific embodiment of the present invention; Be not limited to the present invention; All within spirit of the present invention and principle, any modification of being made, be equal to replacement, improvement etc., all should be included within protection scope of the present invention.

Claims (9)

1. the implementation method of a database access is characterized in that, comprising:
SQL is classified;
Each Bucket of configuration in the data access configuration file comprises among the Bucket that the database of of a sort SQL and this Bucket connects;
If carry out non-database access of striding statement, then, obtain Pooled Statement according to statement id through borrowStatement () interface method; If stride the database access of statement; Then through borrowBucket () interface method, obtain Bucket according to Bucket id, the getStatement () method that provides through Bucket obtains PooledStatement wherein one by one; Wherein when caller passes through borrowStatement () method application statement; The parameter of importing into is " statement id ", and when caller passed through borrowBucket () method application Bucket, the parameter of importing into was " Bucket id ";
The interface method that uses Pooled Statement to provide carries out the data manipulation of this database access.
2. method according to claim 1 is characterized in that, manages the Bucket instance through a two-dimensional array, and first dimension is the Bucket type under the Bucket instance, and second dimension connects for the database that this instance takies;
The pool manager operating process is following:
If parameter is " statement id ", then be converted into Bucket id through an index.
In the Bucket pond, find all Bucket instances that belong to this Bucket type, i.e. an one-dimension array according to Bucket id;
Scan this array,, be labeled as " using " if find the Bucket instance of " free time ",, then return this instance if that the caller application is Bucket; If application is statement, then in the statement that this Bucket instance comprises, find this statement to return according to " statement id "; If can not find the Bucket instance of " free time ", then process dormancy a period of time is waited for,, also can not find the instance of " free time " if after the stand-by period, the exception response that the expression of then dishing out " is done ".
3. method according to claim 1 is characterized in that, this method further comprises:
All Bucket centralized configuration in a data access-profile that a database access is required.
4. method according to claim 1 is characterized in that, said data access configuration file adopts the Properties file of Java, and the collocation form of statement is " statement id=SQL ", and the collocation form of Bucket is following:
A plurality of statement id that the statement that comprises: class [bucket id] .stmts=comma separates have defined the SQL statement that comprises among the Bucket;
The database linking number that the database linking number that can use at most: class [bucket id] .conn=can use at most;
Whether database connects can write: class [bucket id] .update=true/false, be defaulted as false, and promptly read-only.
5. method according to claim 1 is characterized in that, if said database access is a write operation, then adopts one of following three kinds of modes to carry out:
Only write a database: data are only write a database and are promptly accomplished;
A plurality of data sync are write: data are wanted a plurality of databases of writing of success, and affairs just are counted as merit;
A plurality of database asynchronous writes: attempt earlier writing data in a plurality of databases, if success, then affairs complete successfully; If one of them database write is then selected in failure, and writes down these data and need be synchronized in other databases, carry out data sync afterwards by the synchronization mechanism on backstage.
6. method according to claim 1 is characterized in that, when appearance in the database access process was unusual, caller was not given back Pooled Statement or Bucket, will carry out mark to the database of makeing mistakes, and refusal carries out write operation to it again.
7. method according to claim 1 is characterized in that, in the idle retention time of said data access configuration file middle finger attribute sentence, still is not used if exceed this retention time free time statement, then reclaims the resource of this statement; If all statements in Bucket instance all are recovered, then this Bucket instance connects together with the data of its use and all can be recovered.
8. the realization system of a database access is characterized in that, comprising:
Interface module is used to provide the interface of database access, for non-database access of striding statement, borrowStatement () is provided interface method, and id obtains PooledStatement according to statement; For the database access of striding statement; Provide borrowBucket () interface method to obtain Bucket; Obtain Bucket according to Bucket id, wherein when caller passed through borrowStatement () method application statement, the parameter of importing into was " statement id "; When caller passed through borrowBucket () method application Bucket, the parameter of importing into was " Bucketid ";
The Bucket module is formed a Bucket instance with of a sort SQL; Provide getStatement () method to be used to obtain the PooledStatement of Pooled Statement module;
Pooled Statement module, the interface method that provides carries out the data manipulation of database access;
Connect and statement pond administration module, be used for management and connect and the SQL statement pond;
The distributed data storehouse memorizer is used for the data of stored data base.
9. system according to claim 8 is characterized in that, said Bucket module is managed the Bucket instance through a two-dimensional array, and first dimension is the Bucket type under the Bucket instance, and second dimension connects for the database that this instance takies;
The pool manager operating process is following:
If parameter is " statement id ", then be converted into Bucket id through an index.
In the Bucket pond, find all Bucket instances that belong to this Bucket type, i.e. an one-dimension array according to Bucket id;
Scan this array,, be labeled as " using " if find the Bucket instance of " free time ",, then return this instance if that the caller application is Bucket; If application is statement, then in the statement that this Bucket instance comprises, find this statement to return according to " statement id "; If can not find the Bucket instance of " free time ", then process dormancy a period of time is waited for,, also can not find the instance of " free time " if after the stand-by period, the exception response that the expression of then dishing out " is done ".
CN2010105365329A 2010-11-09 2010-11-09 Method and system for implementing database access Active CN101980207B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN2010105365329A CN101980207B (en) 2010-11-09 2010-11-09 Method and system for implementing database access

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN2010105365329A CN101980207B (en) 2010-11-09 2010-11-09 Method and system for implementing database access

Publications (2)

Publication Number Publication Date
CN101980207A CN101980207A (en) 2011-02-23
CN101980207B true CN101980207B (en) 2012-05-30

Family

ID=43600709

Family Applications (1)

Application Number Title Priority Date Filing Date
CN2010105365329A Active CN101980207B (en) 2010-11-09 2010-11-09 Method and system for implementing database access

Country Status (1)

Country Link
CN (1) CN101980207B (en)

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102945264B (en) * 2012-10-24 2017-02-15 浪潮通用软件有限公司 Method for intelligently starting distributed transaction
CN102955851B (en) * 2012-10-30 2016-05-11 北京奇虎科技有限公司 A kind of switching method and apparatus of database
CN102999575B (en) * 2012-11-12 2015-10-14 北京华通伟业科技发展有限公司 A kind of collocation method of Hibernate Map Profile and system
CN102999392B (en) * 2012-11-23 2016-12-21 北京奇虎科技有限公司 The method and apparatus of allocation database operation requests
CN103150344A (en) * 2013-02-06 2013-06-12 湖北微驾技术有限公司 Driving training examination system data access method based on ORM (object relational mapping) framework
CN105653356B (en) * 2016-01-05 2018-12-11 数贸科技(北京)有限公司 Handle the method and device of multiserver concurrent operations
CN106126540B (en) * 2016-06-15 2019-07-09 中国传媒大学 Data base access system and its access method
CN108255852B (en) * 2016-12-29 2020-09-11 中国移动通信集团浙江有限公司 SQL execution method and device
WO2018120171A1 (en) * 2016-12-30 2018-07-05 华为技术有限公司 Method, device and system for executing stored procedure

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100395710C (en) * 2005-05-27 2008-06-18 华为技术有限公司 Method for access data base by multi-line program applied program
US7685109B1 (en) * 2005-12-29 2010-03-23 Amazon Technologies, Inc. Method and apparatus for data partitioning and replication in a searchable data service
US9047354B2 (en) * 2008-07-31 2015-06-02 Sybase, Inc. Statement categorization and normalization
CN101840352B (en) * 2010-04-29 2014-09-10 中兴通讯股份有限公司 Method and device for monitoring database connection pool

Also Published As

Publication number Publication date
CN101980207A (en) 2011-02-23

Similar Documents

Publication Publication Date Title
CN101980207B (en) Method and system for implementing database access
CN109445802B (en) Privatized Paas platform based on container and method for publishing application thereof
US20110154339A1 (en) Incremental mapreduce-based distributed parallel processing system and method for processing stream data
CN101360123B (en) Network system and management method thereof
CN103905537A (en) System for managing industry real-time data storage in distributed environment
CN111061788A (en) Multi-source heterogeneous data conversion integration system based on cloud architecture and implementation method thereof
CN103390041A (en) Method and system for providing data service based on middleware
CN111400326A (en) Smart city data management system and method thereof
CN102164184A (en) Computer entity access and management method for cloud computing network and cloud computing network
CN101763347A (en) GIS (Geographical Information System) interface platform as well as network GIS management system and management method
CN105069151A (en) HBase secondary index construction apparatus and method
CN109885642B (en) Hierarchical storage method and device for full-text retrieval
CN109669975B (en) Industrial big data processing system and method
US5884311A (en) Method and system for dynamically configuring a relational database
CN111126852A (en) BI application system based on big data modeling
CN108228725A (en) GIS application systems based on distributed data base
CN113051263A (en) Metadata-based big data platform construction method, system, equipment and medium
CN112925767A (en) Multi-data-source dynamic data synchronization management method and system based on internet supervision
CN105956041A (en) Data model processing method based on Spring Data for MongoDB cluster
CN107291938B (en) Order inquiry system and method
Li et al. Hadoop-Based University Ideological and Political Big Data Platform Design and Behavior Pattern Mining
CN101458628A (en) Program edition management method
CN113032385B (en) Easily-extensible configurable data backup system and method
CN101968747A (en) Cluster application management system and application management method thereof
CN110909057B (en) Numerical pool virtual test data middleware system and working method thereof

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
EE01 Entry into force of recordation of patent licensing contract

Application publication date: 20110223

Assignee: Tianyiyun Technology Co.,Ltd.

Assignor: CHINA TELECOM Corp.,Ltd.

Contract record no.: X2024110000020

Denomination of invention: An Implementation Method and System for Database Access

Granted publication date: 20120530

License type: Common License

Record date: 20240315

EE01 Entry into force of recordation of patent licensing contract