CN105205103B - The method and apparatus for accessing database - Google Patents

The method and apparatus for accessing database Download PDF

Info

Publication number
CN105205103B
CN105205103B CN201510528428.8A CN201510528428A CN105205103B CN 105205103 B CN105205103 B CN 105205103B CN 201510528428 A CN201510528428 A CN 201510528428A CN 105205103 B CN105205103 B CN 105205103B
Authority
CN
China
Prior art keywords
value
class
database
filling
entity
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
CN201510528428.8A
Other languages
Chinese (zh)
Other versions
CN105205103A (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.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology 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 Beijing Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201510528428.8A priority Critical patent/CN105205103B/en
Publication of CN105205103A publication Critical patent/CN105205103A/en
Application granted granted Critical
Publication of CN105205103B publication Critical patent/CN105205103B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • 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/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Mathematical Physics (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The present invention provides a kind of method and apparatus for accessing database, helps to improve system performance and development efficiency, additionally assists in and solve the problems, such as interface specification.The method of access database of the invention includes: the class object and value mapping table for the common interface class for receiving persistent layer;The class object is class object obtained from persistent layer to be abstracted as to a common interface class;Value object is obtained according to the class object, and according to described value mapping table and the class object, the filling of father's entity is carried out to the value object;The value object for completing the filling is converted into persistent object;Data in the persistent object are saved in database.

Description

The method and apparatus for accessing database
Technical field
The present invention relates to field of computer technology, a kind of particularly method and apparatus for accessing database.
Background technique
JDBC (connection of Java Data Base Connectivity, java database) is a kind of for executing SQL statement Java API, unified access can be provided for a variety of relational databases, the class and interface that it is write by one group with Java language Composition.JDBC provides a kind of benchmark, can construct more advanced tool and interface accordingly, database development personnel is enable to compile Write database application.Rarely J2EE is applied and can be carried out database access directly in a manner of JDBC at present.After all, face is used Carry out access relational databases to the programming language of object, the workload in development process is very big.When most of, J2EE is answered With all data access can be carried out with ORM frame, ORM (Object Relational Mapping) frame using metadata come One relationship map details of description object, metadata generally use XML format, and are stored in special one mapped file of object In.As long as providing the mapping relations of lasting classification and table, ORM frame at runtime can referring to mapped file information, Object Persistence is into database.There are mainly three types of current ORM frames: Hibernate (Nhibernate), iBATIS, EclipseLink.In all ORM frames, with it, the blueness of numerous developers has been won in dexterous, light encapsulation to Hibernate It looks at.Although Hibernate is the condition that developer provides convenience, primary frame might not be fully met in reality Exploitation requirement, on the norm-setting of project can it is restricted, be unfavorable for the subsequent upgrade and maintenance of project.Therefore, how right These frames carry out secondary encapsulation, need to be a critical issue to meet exploitation, this problem is mainly reflected in three aspects Hold: first is that meet the development specifications of project itself, second is that the coupling between dropping to a lower level, third is that improving system performance and exploitation Efficiency.
In current usual way, usually using Spring IOC container as core, form a connecting link.It is mentioned by Spring The following three tool-class (or interface) of confession supports the realization of persistent layer: HibernateDaoSupPOrt, HibernateTemplate and HibernateCallback.By Spring IOC container, by SessionFactory Bean injects DAO component, once DAO component obtains the reference of SessionFactory Bean, so that it may complete actual number It is accessed according to library.
During actual development, it will usually find that the interface of service layer and persistent layer is essentially the same, difference is exactly to service Layer has the processing of some service logics, the control of affairs;The physical layer interface that the interface of persistent layer can then call directly frame comes Database access is carried out, these interfaces are substantially the same processing logic: increasing, deletes, modification, inquiry.It is every to realize one Business requires that identical interface is called to realize similar function, generates the phenomenon that code repeats, this is virtually increased out The workload of hair personnel.And developer needs frequently to convert persistent object (PO) and value object (VO), not only Workload is wasted, and consumes very much memory, influences system performance.
In terms of decoupling, although realizing the injection of Bean by Spring IOC, it appears that lower coupling is realized, it is real On border not, because there are many interface of persistent layer exposure, substantially each business can have a series of interfaces, if really needed Persistent layer is adjusted, it is desired nonetheless to modify a large amount of code, that is to say, that there are still the high problems of coupling.
Herein, current usual way is not easy unified problem there is also code specification.Specifically, Hibernate Although the HQL language of offer solves the problems, such as integration across database, but Hibernate frame itself all supports HQL and SQL, If not being difficult to realize interface consistency from the enterprising professional etiquette model of frame, also hide some dangers for the upgrading replacement of database.
Summary of the invention
In view of this, the present invention provides a kind of method and apparatus for accessing database, helps to improve system performance and open Efficiency is sent out, additionally assists in and solves the problems, such as interface specification.
To achieve the above object, according to an aspect of the invention, there is provided a kind of method for accessing database.
The method of access database of the invention includes: class object and the value mapping for the common interface class for receiving persistent layer Table;The class object is class object obtained from persistent layer to be abstracted as to a common interface class;It is obtained according to the class object Value object, and according to described value mapping table and the class object, the filling of father's entity is carried out to the value object;Described in completing The value object of filling is converted to persistent object;Data in the persistent object are saved in database.
Optionally, the step of value object for completing the filling being converted to persistent object includes: for completing institute The value object for stating filling is converted into persistent object using BeanUtils tool.
Optionally, the step of filling for carrying out father's entity includes: the member that the class object is obtained by session factory Data information;The type for checking each field of the class object, in the feelings that the type of the present field checked is entity type Under condition, according in described value mapping table mapping relations and external key find the corresponding entity of the present field, then by the reality Body is filled into the value object.
Optionally, in the case where needing to carry out database update operation, this method further include: receive the public of persistent layer The class object and value mapping table of interface class;Father's entity is carried out to value object according to described value mapping table and the class object to fill out It fills;The metadata information of the class object is searched to obtain field name;Using HQLBulider tool-class, reflected according to described value Firing table assembles HQL sentence;Query object is generated according to the HQL sentence, then uses query.setParameter tool The parameter of the HQL sentence is set, then executes the HQL sentence to update the database.
Optionally, in the case where needing to carry out database query operations, this method further include: use Query object List method obtains the data in database, which pack by value mapping table and value table then exporting.
According to another aspect of the present invention, a kind of device for accessing database is provided.
The device of access database of the invention includes: receiving module, the class of the common interface class for receiving persistent layer Object and value mapping table;The class object is class object obtained from persistent layer to be abstracted as to a common interface class;Acquisition is filled out Mold filling block, for obtaining value object according to the class object, and according to described value mapping table and the class object, to the value pair Filling as carrying out father's entity;Conversion module, for the value object for completing the filling to be converted to persistent object;Save mould Block, for the data in the persistent object to be saved in database.
Optionally, the conversion module is also used to the value object for completing the filling, will using BeanUtils tool It is converted to persistent object.
Optionally, further includes: module is obtained, for obtaining the metadata information of the class object by session factory;Inspection Filling module is looked into, is entity class in the type of the present field checked for checking the type of each field of the class object In the case where type, according in described value mapping table mapping relations and external key find the corresponding entity of the present field, then The entity is filled into the value object.
Optionally, further includes: filling module, the value for more new database for being received according to the receiving module Mapping table and class object carry out the filling of father's entity to value object;Searching module, the metadata for searching the class object are believed Breath is to obtain field name;Assembling module assembles HQL according to described value mapping table for using HQLBulider tool-class Sentence;Operation module is updated, for generating Query object according to the HQL sentence, then uses query.setParameter The parameter of the HQL sentence is arranged in tool, then executes the HQL sentence to update the database.
It optionally, further include inquiry output module, for using the list method of Query object to obtain the number in database According to, by the data by value mapping table and value table pack then export.
According to the technique and scheme of the present invention, by the encapsulation to Hibernate, persistent layer is hidden, developer only needs Service logic is paid close attention to, does not have to consider persistent layer exploitation, does not also need to carry out duplicate code copies, substantially increase exploitation effect Rate.The native interface access for also remaining frame simultaneously, provides more possibility for the extension of system.By to PO, VO's Encapsulation, the conversion process of the two is realized by frame, reduces the workload of developer, decreases memory overhead, is improved The performance of system.Persistent layer only exposes an interface to upper layer, only one zinc plant engineering in the application, reduce level it Between coupling, substantially increase the scalability and elasticity of system.All database manipulations are completed by HQL, on the one hand It can be compatible with multiple database, on the other hand ensure that the normalization of system, while also providing the access interface of SQL statement, side Just the subsequent extension of system and maintenance.
Detailed description of the invention
Attached drawing for a better understanding of the present invention, does not constitute an undue limitation on the present invention.Wherein:
Fig. 1 is the core classes figure for realizing the traversal to result mapping table;
Fig. 2 is the schematic diagram of the basic step for save to database operation of embodiment according to the present invention;
Fig. 3 is the schematic diagram of the basic step that operation is updated to database of embodiment according to the present invention;
Fig. 4 is the schematic diagram for executing database and saving a kind of detailed process of operation of embodiment according to the present invention;
Fig. 5 is a kind of schematic diagram of the detailed process for executing database update operation of embodiment according to the present invention;
Fig. 6 is the core classes figure for realizing database query operations of embodiment according to the present invention;
Fig. 7 is the schematic diagram of the detailed process of the realization HQLUtil example of embodiment according to the present invention;
Fig. 8 is the specific flow chart of the addition character string of embodiment according to the present invention and the method for parameter;
Fig. 9 is the signal of the detailed process based on the H QL assembly tool-class processing value object in embodiment of the present invention Figure;
Figure 10 is the class figure about service layer interface of embodiment according to the present invention;
Figure 11 is the schematic diagram of the main modular of the device of the access database of embodiment according to the present invention.
Specific embodiment
It explains below in conjunction with attached drawing to exemplary embodiment of the invention, including embodiment of the present invention Various details should think them only exemplary to help understanding.Therefore, those of ordinary skill in the art should recognize Know, various changes and modifications can be made to embodiment described herein, without departing from scope and spirit of the present invention. Equally, for clarity and conciseness, descriptions of well-known functions and structures are omitted from the following description.
In embodiments of the present invention, PO, VO are packaged to improve system performance in the form of Map. Hibernate is the table being mapped to entity class in data, defines a parent in embodiments of the present invention BaseObject, inherit such object will table in correspondence database, conversely, each table in database is corresponding One entity class.Adopted value mapping table (ValueMap) is packaged VO, is completed the extraction of form data by view layer and is turned Turn to VO, i.e. ValueMap;PO is packaged using result mapping table (ResultMap), persistent layer is first after getting VO The filling of father's entity can be first carried out to VO according to the entity mapping relations of Hibernate, this mainly copes with one-to-many (OneToMany) and the case where many-one (ManyToOne), PO then is converted by VO again, finally executes database manipulation, this A process is realized that developer does not need to pay close attention to by Persistence Layer Framework completely;ResultMap needs to rewrite the get of Map (Object key) method, for from returning the result middle value.ResultList and ResultIterator realize List respectively With Iterator interface, in order to realize the traversal to ResultMap, core classes figure is as shown in Figure 1.Fig. 1 is for realizing to knot The core classes figure of the traversal of fruit mapping table.
In order to improve development efficiency, Hibernate is packaged in embodiments of the present invention, be packaged into it is general more New interface and query interface.More new interface includes the increase, deletion, modification to object;Query interface can be by single object, collection Splitting or integrating page result set is inquired.Persistent layer is abstracted as an interface to serve upper layers, is injected by Spring IOC To Service layers.Specifically, persistent layer is abstracted into a common interface IRePOsitory, such is at the beginning of when system starts Shi Hua session factory (SessionFactory), this class only one zinc plant engineering in Web application, top service is by being somebody's turn to do The example of case-based system CommonUpdate and CommonQuery complete the inquiry of persistent layer and additions and deletions change, and all operations are logical HQL is crossed to complete, CommonUpdate remains the traditional PO access interface of persistent layer, facilitate subsequent expansion, For CommonNativeUpdate and CommonNativeQuery with the formal operations database of SQL statement, the two interfaces are main It is to prepare for particular service, such as statistically analyze, general business not will use the two interfaces.Lasting layer interface is mainly logical The Query interface for crossing Hibernate realizes database manipulation, operates for saving, and process shown in Fig. 2 can be used in persistent layer It carries out, Fig. 2 is the schematic diagram of the basic step for save to database operation of embodiment according to the present invention.
Step S21: the class object and value mapping table of the common interface class of persistent layer are received.Here class object is will be lasting Layer is abstracted as class object obtained from a common interface class.
Step S22: obtaining value object according to above-mentioned class object, and according to above-mentioned value mapping table and above-mentioned class object, right The filling of value object progress father's entity.
Step S23: the value object for completing above-mentioned filling is converted into persistent object.It here can be using use BeanUtils tool carries out the conversion of VO/PO.
Step S24: the data in above-mentioned persistent object are saved in database.
In above-mentioned steps, value mapping table is provided by developer, and lasting layer interface, VO are passed in the form of Map Conversion with PO is then completed after carrying out the filling of father's entity by persistent layer, and developer does not need to pay close attention to, and improves exploitation effect Rate;And this approach reduces calculator memory expenses, improve system performance.
In the case where needing to carry out database update operation, can be as shown in Figure 3 the step of, is completed.Fig. 3 is according to this The schematic diagram of the basic step that operation is updated to database of invention embodiment.
Step S31: the class object and value mapping table of the common interface class of persistent layer are received.
Step S32: the filling of father's entity is carried out to value object according to above-mentioned value mapping table and above-mentioned class object.
Step S33: the metadata information of above-mentioned class object is searched to obtain field name.
Step S34: HQLBulider tool-class is used, assembles HQL sentence according to above-mentioned value mapping table.
Step S35: Query object is generated according to above-mentioned HQL sentence.
Step S36: the parameter of above-mentioned HQL sentence is set using query.setParameter tool.
Step S37: above-mentioned HQL sentence is executed with more new database.
Specific implementation of the invention is further illustrated below in conjunction with the encapsulation of Hibernate.In reality of the invention It applies in mode, lasting layer interface can realize database manipulation by the Query interface of Hibernate, operate for saving, business End needs incoming class object and valueMap, and persistent layer obtains VO by class object first, then passes through valueMap and class pair Filling as carrying out father's entity to the VO, the process of filling father's entity are to obtain class object by sessionFactory first Then metadata information checks the type of each field of class object, if type is entity type, according to mapping relations and external key The entity is found, and is filled into VO, the conversion of VO and PO is then realized by BeanUtils, finally by Session.save, which is realized, to be saved.Above procedure is as shown in figure 4, the execution database that Fig. 4 is embodiment according to the present invention is protected Deposit a kind of schematic diagram of detailed process of operation.
It is operated for updating, persistent layer is also the father's entity object for being first filled with VO, then searches the metadata information of class Field name is obtained, by HQLBuilder tool-class combination valueMap come assembled hql sentence, the hql sentence of generation is logical Crossing createQuery () generates Query object, and parameter is arranged by query.setParameter, finally by ExecuteUpdate, which is realized, updates operation, and persistent layer also supports the update sentence of hql, and detailed process is as shown in figure 5, Fig. 5 is root According to a kind of schematic diagram of the detailed process for executing database update operation of embodiment of the present invention.
It for delete operation, can directly be deleted by HQL sentence, bottom layer realization is also to call Query interface;It can also be with Entity is deleted according to some field of entity class, is needed by HQLBuilder and in conjunction with VO come assembled HQL sentence.
Inquiry operation is to realize that obtained result passes through ResultMap and ResultList by the list method of Query It is packed, returns to foreground use;In order to realize that foreground paging is shown, a paging class Page can be encapsulated, such is main The total number of records is recorded, every page of size, initial position, foreground, which is shown, can carry out paging according to these attributes.Core classes figure is such as Shown in Fig. 6, Fig. 6 is the core classes figure for realizing database query operations of embodiment according to the present invention.
In embodiments of the present invention, in order to solve the problems, such as interface specification, the interface of persistent layer encapsulation is used uniformly HQL Mode service is externally provided;The assembly of HQL is handled using general tool-class.Below for realization HQL assembly tool Class is illustrated.In embodiments of the present invention, the tool-class HQLUtil of fluent style, such main auxiliary activities are realized Layer and persistent layer realize that the dynamic of HQL sentence is assembled, and are configured by VO to parameter, the core methed and category of HQLUtil Property is as shown in table 1.
Table 1
Parameters parameter stores the parameter value of vo in the form of map, and newInstance () method is used to obtain one HQLUtil example;Append (String subhql) is used to add HQL clause.
AppendUpdateSet (String alias, Map updateMap) method is used to increase Update sentence Set clause, operation layer pseudocode are as follows:
……
HQLUtil hqlbuild=HQLUtil.newInstance ();
Hqlbuild.append("update Model1m1").appendUpdateSet("m1",values);
Hqlbuild.append("where");
Hqlbuild.appendWhere (" m1.pkId=:pkId ", " pkId ", pkid);
……
UpdateMap can be traversed inside appendUpdateSet method, assembly is then started by HQLUtil Update sentence, and by the parameter setting in updateMap into parameters, finally return to the example, process such as Fig. 7 institute Show, Fig. 7 is the schematic diagram of the detailed process of the realization HQLUtil example of embodiment according to the present invention.
AppendUpdate (String alias, String key, Object val) increases the column of Update sentence more New clause, this method update specific column, and detailed process is similar with appendUpdateSet method.appendWhere (String subwhere, String key, Object val) additional character string and parameter, use, business in dynamic queries Layer pseudocode is as follows:
……
Hqlbuild.append (" update Model1m1set m1.attrkey=attrval where ");
hqlbuild.appendWhere("m1.attrey2:attrval2","attrval2"attrval2);
……
……
hqlbuild.append("from Model2m2,Model3m3where");
Hqlbuild.appendWhere (" m2.pkid=:pkid ", " pkid ", pkid);
Hqlbuild.append (" and m2.foreginId=m3.pkid ");
……
AppendWhere method first determines whether val is empty, the additional sub- hql sentence without being sky, and VO parameter is arranged Into parameters, if it is sky, is operated for delete operation and update, need to replace the corresponding parameter of paramKey It is changed to " is null ", detailed process is as shown in figure 8, Fig. 8 is addition character string and the side of parameter of embodiment according to the present invention The specific flow chart of method.
SetParameter method and fillQuery method are private methods, and the parameter in VO is packaged into map by the former; FillQuery method creates query object according to assembled good hql sentence, and replaces the ginseng in hql by parameters Number finally returns to query object and executes database manipulation.
If that operation layer is passed to is VO, persistent layer obtains HQLUtil example first, and obtains field name according to class object Claim, then traverses VO and carry out hql assembly, and replace the parameter in hql, finally execute database manipulation, flow chart such as Fig. 9 institute Show, Fig. 9 is the schematic diagram of the detailed process based on the H QL assembly tool-class processing value object in embodiment of the present invention.
It is illustrated below for the abstract service layer interface in embodiment of the present invention.In embodiments of the present invention In, construct the top layer parent interface Service an of service layer;The parent interface for needing to access persistent layer is The service class of RepositoryService, any need access persistent layer require to realize the interface, for not accessing persistent layer Service do not need then.The interface is injected IRepository by Spring IOC.Class figure is as shown in Figure 10, Figure 10 It is the class figure about service layer interface of embodiment according to the present invention.
Figure 11 is the schematic diagram of the main modular of the device of the access database of embodiment according to the present invention.Such as Figure 11 institute Show, persistent layer mainly includes receiving module 111, obtain filling module 112, turn as a kind of device 110 for accessing database Change the mold block 113, preserving module 114.
Receiving module 111 is used to receive the class object and value mapping table of the common interface class of persistent layer;The class object is Persistent layer is abstracted as class object obtained from a common interface class;Filling module 112 is obtained to be used for according to the class object Value object is obtained, and according to described value mapping table and the class object, the filling of father's entity is carried out to the value object;Modulus of conversion Block 113 is used to the value object for completing the filling being converted to persistent object;Preserving module 114 is used for will be in the persistent object Data be saved in database.
The device 110 for accessing database can also include acquisition module and check filling module (not shown), wherein Module is obtained, for obtaining the metadata information of the class object by session factory;Check filling module, it is described for checking The type of each field of class object is reflected in the case where the type of the present field checked is entity type according to described value Mapping relations and external key in firing table find the corresponding entity of the present field, and the entity is then filled into the value object In.
The device 110 for accessing database can also include filling module, searching module, assembling module and update operation Module (not shown), wherein filling module according to the value for more new database that the receiving module receives for reflecting Firing table and class object carry out the filling of father's entity to value object;Searching module is used to search the metadata information of the class object To obtain field name;Assembling module is used to use HQLBulider tool-class, assembles HQL language according to described value mapping table Sentence;It updates operation module to be used to generate Query object according to the HQL sentence, then uses query.setParameter work The parameter of the HQL sentence is arranged in tool, then executes the HQL sentence to update the database.
The device 110 of access database may also include inquiry output module (not shown), for using Query object List method obtain database in data, by the data by value mapping table and value table pack then output.
Beneficial effects of the present invention are as follows:
By the encapsulation to Hibernate, persistent layer is hidden, developer need to only pay close attention to service logic, not have to consider Persistent layer exploitation, does not need to carry out duplicate code copies yet, substantially increases development efficiency.The original of frame is also remained simultaneously Raw interface access, provides more possibility for the extension of system.
By the way that PO, the encapsulation of VO is realized the conversion process of the two by frame, reduce the workload of developer, Memory overhead is decreased, the performance of system is improved.
Persistent layer only exposes an interface to upper layer, only one zinc plant engineering, reduces between level in the application Coupling, substantially increases the scalability and elasticity of system.
All database manipulations are completed by HQL, on the one hand can be compatible with multiple database, on the other hand be ensure that The normalization of system, while the access interface of SQL statement is also provided, facilitate the subsequent extension of system and maintenance.
Above-mentioned specific embodiment, does not constitute a limitation on the scope of protection of the present invention.Those skilled in the art should be bright It is white, design requirement and other factors are depended on, various modifications, combination, sub-portfolio and substitution can occur.It is any Made modifications, equivalent substitutions and improvements etc. within the spirit and principles in the present invention, should be included in the scope of the present invention Within.

Claims (8)

1. a kind of method for accessing database characterized by comprising
Receive the class object and value mapping table of the common interface class of incoming persistent layer;The persistent layer is based on ORM framework encapsulation and obtains It arrives, and is conceptualized as the common interface class, described only one zinc plant engineering of common interface class;Wherein, described value is reflected Firing table is packaged with value object;
According to described value mapping table and the class object, the filling of father's entity is carried out to the value object;Wherein, described pair of value pair As carry out father's entity filling the step of include: the metadata information that the class object is obtained by session factory;Described in inspection The type of each field of class object, in the case where the type of the present field checked is entity type, according to mapping relations The corresponding entity of the present field is found with external key, then the entity is filled into the value object;
The value object for completing the filling is converted into persistent object;
Data in the persistent object are saved in database.
2. the method for access database according to claim 1, which is characterized in that turn the value object for completing the filling The step of being changed to persistent object includes: the value object for completing the filling, is converted into and is held using BeanUtils tool Long object.
3. the method for access database according to claim 1, which is characterized in that needing to carry out database update operation In the case where, this method further include:
Receive the class object and value mapping table of the common interface class of persistent layer;
The filling of father's entity is carried out to value object according to described value mapping table and the class object;
The metadata information of the class object is searched to obtain field name;
Using HQLBulider tool-class, HQL sentence is assembled according to described value mapping table;
Query object is generated according to the HQL sentence, the HQL language then is set using query.setParameter tool The parameter of sentence, then the HQL sentence is executed to update the database.
4. the method for access database according to claim 1, which is characterized in that needing to carry out database query operations In the case where, this method further include:
The data in database are obtained using the list method of Query object, which is carried out by value mapping table and value table Then packaging exports.
5. a kind of device for accessing database characterized by comprising
Receiving module, for receiving the class object and value mapping table of the common interface class of incoming persistent layer;The persistent layer is based on ORM framework encapsulation obtains, and is conceptualized as the common interface class, described only one zinc plant engineering of common interface class; Wherein, described value mapping table is packaged with value object;
Filling module is obtained, for carrying out the filling of father's entity to the value object according to described value mapping table and the class object; Wherein, the filling that the described pair of value object carries out father's entity includes: the metadata letter that the class object is obtained by session factory Breath;The type for checking each field of the class object, in the case where the type of the present field checked is entity type, root The corresponding entity of the present field is found according to mapping relations and external key, then the entity is filled into the value object;
Conversion module, for the value object for completing the filling to be converted to persistent object;
Preserving module, for the data in the persistent object to be saved in database.
6. the device of access database according to claim 5, which is characterized in that the conversion module is also used to for complete At the value object of the filling, persistent object is converted into using BeanUtils tool.
7. the device of access database according to claim 5, which is characterized in that further include:
Module is filled, the value mapping table and class object for more new database for receiving according to the receiving module are right The filling of value object progress father's entity;
Searching module, for searching the metadata information of the class object to obtain field name;
Assembling module assembles HQL sentence according to described value mapping table for using HQLBulider tool-class;
Operation module is updated, for generating Query object according to the HQL sentence, then uses query.setParameter The parameter of the HQL sentence is arranged in tool, then executes the HQL sentence to update the database.
8. the device of access database according to claim 5, which is characterized in that further include inquiry output module, be used for The data in database are obtained using the list method of Query object, which is packed by value mapping table and value table Then it exports.
CN201510528428.8A 2015-08-25 2015-08-25 The method and apparatus for accessing database Active CN105205103B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510528428.8A CN105205103B (en) 2015-08-25 2015-08-25 The method and apparatus for accessing database

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510528428.8A CN105205103B (en) 2015-08-25 2015-08-25 The method and apparatus for accessing database

Publications (2)

Publication Number Publication Date
CN105205103A CN105205103A (en) 2015-12-30
CN105205103B true CN105205103B (en) 2019-09-20

Family

ID=54952787

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510528428.8A Active CN105205103B (en) 2015-08-25 2015-08-25 The method and apparatus for accessing database

Country Status (1)

Country Link
CN (1) CN105205103B (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109213789A (en) * 2017-07-07 2019-01-15 北京京东尚科信息技术有限公司 A kind of analysis method and device about business SQL
CN110019287B (en) * 2017-07-20 2021-09-14 华为技术有限公司 Method and device for executing Structured Query Language (SQL) instruction
CN107506189A (en) * 2017-08-15 2017-12-22 四川长虹电器股份有限公司 A kind of iOS data persistence methods realized based on factory mode
CN111506303A (en) * 2019-01-30 2020-08-07 北大方正信息产业集团有限公司 Data interaction method and device
CN115495398B (en) * 2022-09-28 2023-06-30 北京亚控科技发展有限公司 Interface resource operation method, device, electronic equipment and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101290625A (en) * 2008-06-11 2008-10-22 华东师范大学 XML document storage and search method
CN101901140A (en) * 2009-05-27 2010-12-01 北京正辰科技发展有限责任公司 System global structure of enterprise-level application development platform
CN101996071A (en) * 2009-08-20 2011-03-30 上海杉达学院 Software architecture of information control system and architecting method
CN102004634A (en) * 2009-09-01 2011-04-06 上海杉达学院 Hierarchical business management system
CN102004741A (en) * 2009-09-01 2011-04-06 上海杉达学院 Database access system

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101290625A (en) * 2008-06-11 2008-10-22 华东师范大学 XML document storage and search method
CN101901140A (en) * 2009-05-27 2010-12-01 北京正辰科技发展有限责任公司 System global structure of enterprise-level application development platform
CN101996071A (en) * 2009-08-20 2011-03-30 上海杉达学院 Software architecture of information control system and architecting method
CN102004634A (en) * 2009-09-01 2011-04-06 上海杉达学院 Hierarchical business management system
CN102004741A (en) * 2009-09-01 2011-04-06 上海杉达学院 Database access system

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
Hibernate三种继承关系;pursure211;《http://blog.csdn.net/pursure211/article/details/17318379》;20131214;第1、6、11页 *
Hibernate之Configuration,SessionFactory,Session;xw13106209;《http://blog.csdn.net/xw13106209/article/details/7041483》;20111205;全文 *
rigger21.hibernate hql 大全.《http://blog.csdn.net/rigger21/article/details/1733821》.2007, *

Also Published As

Publication number Publication date
CN105205103A (en) 2015-12-30

Similar Documents

Publication Publication Date Title
CN105205103B (en) The method and apparatus for accessing database
CN108038222B (en) System of entity-attribute framework for information system modeling and data access
CN103377148B (en) The method and system that executable portion merges in a kind of unified dial framework structure
CN103377290B (en) Delete the record in multistage storage architecture
CN100557609C (en) A kind of persistent layer generation method and device
EP2660732B1 (en) Unified table query processing
US20170185642A1 (en) Logless atomic data movement
US8838654B1 (en) Data modeling system for runtime schema extensibility
US9507820B1 (en) Data modeling system for runtime schema extensibility
US20030208493A1 (en) Object relational database management system
US20140136788A1 (en) Deleting Records In A Multi-Level Storage Architecture Without Record Locks
CN102841889A (en) Method and device for achieving efficient database access based on ORM (object relational mapping) architecture
CN103226478A (en) Method for automatically generating and using code
CN111125440B (en) Monad-based persistent layer composite condition query method and storage medium
CN107291471A (en) A kind of Meta model framework system for supporting customizable data acquisition
CN108959626B (en) Efficient automatic generation method for cross-platform heterogeneous data profile
Blakeley et al. The ado. net entity framework: Making the conceptual level real
CN104573086A (en) Database access component and generating method thereof
CN108845793B (en) ORM design method and device
CN116450110A (en) Automatic generation method and system for access codes of database based on custom attributes
Aboulsamh et al. Towards a model-driven approach to information system evolution
CN110019522A (en) Multi-source heterogeneous data integrated system based on XML
Harrison et al. Legacy 4GL application migration via knowledge-based software engineering technology: a case study
Fouad et al. Extracting OCL Integrity Constraints from Object Relational Database
JPH03226837A (en) Generation of repository

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant