CN103309650B - The generation method and apparatus of persistent layer code - Google Patents
The generation method and apparatus of persistent layer code Download PDFInfo
- Publication number
- CN103309650B CN103309650B CN201210067610.4A CN201210067610A CN103309650B CN 103309650 B CN103309650 B CN 103309650B CN 201210067610 A CN201210067610 A CN 201210067610A CN 103309650 B CN103309650 B CN 103309650B
- Authority
- CN
- China
- Prior art keywords
- entity name
- file
- function
- name
- source profile
- 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
Links
Landscapes
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
This application provides the generation method and apparatus of a kind of persistent layer code, wherein, the method includes: according to source profile and the entity name generating run configuration file received, wherein, running configuration file includes entity name;From running configuration file, obtain entity name, and be passed to be accessed in the corresponding function function in the function enhancing example that object BaseDAO statement obtains by master data as the entity input parameter of power function using entity name;Select the power function corresponding with action command as persistent layer code according to the action command received from function enhancing example.The problem that present application addresses the waste memory space caused in correlation technique owing to code redundancy is relatively big, thus reduce the redundancy of persistent layer code, save memory space, decrease the system resource safeguarded needed for code.
Description
Technical field
The application relates to computer realm, in particular to the generation method and apparatus of a kind of persistent layer code.
Background technology
In today of a large amount of rise of enterprise's application, each enterprise is the various demands meeting consumer, and every day all must carry out substantial amounts of
Application and development, thus cause the size of code on the one hand developed to expand rapidly, on the other hand, although have in these application and developments
Institute is different, but through long-term exploitation it is found that many codes are all the most similar, especially persistent layer.
Especially for the exploitation of J2EE application, for a long time, due to three-tier architecture (persistent layer, business that program frame is general
Layer, represent layer) be regarded as classics in each company, each company this framework of substantially all employing, in this framework,
The lower floor of code, the mode of data storage, by initial relationship type DB to cache, KV, NoSQL and object-oriented number
According to storehouse etc., concept emerges in an endless stream, but relevant database is still the first absolute selection.
In the three-tier architecture that program frame is general, the difference of the business of each company directly translates into operation layer and represents layer and be respectively arranged with not
With, persistent layer operating database is essentially identical, and for relevant database, the task operating that persistent layer does all does not has
Beyond the category of CRUD operation, simply the complexity of operation is had nothing in common with each other, and therefore, database table is embodied as holding by use instrument
Layer identification code, is feasible in theory for a long time.
Currently, in J2EE project, different according to the Floor layer Technology that persistent layer uses, the realization side of persistent layer Code automatic build
Case is broadly divided into three kinds, and a kind of is to realize based on primary jdbc, a kind of realizes based on Hibernate, one be based on
Ibatis realizes, and on the whole, in large-scale application, latter two is most popular framework.It addition, according to the number used
Different according to storehouse interaction technique, there is the implementation of many different persistent layer Code automatic build, such as:
1) software such as MyEclipse provides user-selected number according to storehouse table, then automatically generates based on Hibernate framework
DO (Data Object), mapped file, DAO (Data Access Object) file state and realization, in the better simply feelings of scene
Under condition, the implementation of this persistent layer Code automatic build complies fully with demand.
2) for Ibatis framework, do at present reasonable be Ibator, by xml document formulate data base's connection, user name,
Password and table name etc., can be just each database table according to data base's connection, user name, password and table name etc.
Automatic code generating, this code mainly includes sqlmap file, Data Object file, DAO file state and realization.
Both the above code building, all provides reasonable convenience, and user is in the case of simple operations, it is possible to obtaining can
Code, opinion its principle, on the whole, be all by obtain database table metadata: field name, field length and
The series attribute such as field length, map, and Database field name is converted into the Java type variable name of hump type, and presses
According to type of database and the mapping relations of Java type, according to generating a series of file.
But, two kinds of above-mentioned main Code Generators also suffer from obvious shortcoming, such as:
For 1) plant the implementation of persistent layer Code automatic build for, Hibernate framework compares under complicated demand scene and entangles
Knot, programmer must be by a kind of HQL (similar sql like language, can be converted into SQL when finally performing) language ability number
Operating according to storehouse, therefore, user, when carrying out similar exploitation, needs additionally to go to grasp HQL language, writes substantial amounts of code, and
And, in parsing program data-generating process, finally need in relevant database, performing SQL statement to obtain number
According to, but, if it is breakneck that these SQL statement are not the most known to the user, it addition, in present enterprise's application,
The maximum bottleneck of whole application is exactly data base, and sometimes, inefficient SQL just can allow data base delay machine, causes answering
With machine of the most and then delaying.
For 2) plant persistent layer Code automatic build implementation for, Ibatis to ORM encapsulation granularity relatively low, exploit person
Member can grasp SQL statement with oneself, and the execution efficiency of SQL statement is more secure, but, for meeting all of business scenario,
Ibator uses Criteria to support the work such as all conditions inquiry, for meeting possible complex query need when automatic code generating
Ask (the most even so, also could not realize all of demand), Ibator according to the mode entirely enumerated to be supported possible answering
Miscellaneous query demand, result in the problem that code drastically expands, such as, the database table of 100 fields, supports class for one
Code close to 5500 row, this is for follow-up maintenance, is exactly a disaster simply, say, that if an application has
A large amount of codes do not use, and retain to get up again, and do so not only wastes memory space, also likely in long-term maintenance
In, cause huge problem, thus increase the system resource safeguarding that code is used.
Summary of the invention
This application provides the generation method and apparatus of a kind of persistent layer code, at least to solve in correlation technique due to persistent layer generation
The problem of the waste memory space that code redundancy is relatively big and causes.
An aspect according to the application, it is provided that a kind of generation method of persistent layer code, comprising: according to source profile
With the entity name generating run configuration file received, wherein, running configuration file includes entity name;From running configuration
File obtains entity name, and using entity name as the entity of power function input parameter be passed to be accessed by master data right
The function obtained as BaseDAO statement strengthens in the corresponding function function in example;Increase from function according to the action command received
Strong example select the power function corresponding with action command as persistent layer code.
Preferably, include according to the step of source profile with the entity name generating run configuration file received: obtain current
The name of business DAO accessed is referred to as entity name, and wherein, the statement of business DAO is inherited BaseDAO and stated file;Judge
Whether entity name is included in the backup file of source profile;If the backup file of source profile does not include entity name,
Then entity name is included in the backup file of source profile, and the backup file including entity name is joined as operation
Put file;If the backup file of source profile includes entity name, then will back up file as running configuration file.
Preferably, before the entity name received being updated source profile obtains running configuration file, above-mentioned persistently
The generation method of layer identification code also includes: arranging BaseDAO and state file, wherein, the BaseDAO statement file of setting includes
Each power function, entity name is inputted parameter as entity by each power function.
Preferably, before according to source profile and the entity name generating run configuration file that receives, above-mentioned persistent layer generation
The generation method of code also includes: the metadata of reading database table obtains the field information of database table;The data base that will read
Field information in table is as entity name.
Preferably, the step of the field information that the metadata of reading database table obtains database table includes: by the SQL of input
The metadata of query statement reading database table, to obtain the field information of database table, wherein, field information includes: field
Name, the table name of database table.
Another aspect according to the application, it is provided that the generating means of a kind of persistent layer code, comprising: the first signal generating unit,
For according to source profile and the entity name generating run configuration file received, wherein, running configuration file includes reality
Body title;Processing unit, for obtaining entity name, and using entity name as the reality of power function from running configuration file
Body input parameter is passed to be accessed the corresponding function function in the function enhancing example that object BaseDAO statement obtains by master data
In;Select unit, for strengthening, from function, the function letter that example, selection is corresponding with action command according to the action command received
Number is as persistent layer code.
Preferably, the first signal generating unit includes: acquisition module, and the name of business DAO for obtaining current accessed is referred to as entity
Title, wherein, the statement of business DAO is inherited BaseDAO and is stated file;Judge module, is used for judging whether entity name wraps
Include in the backup file of source profile;Generation module, if not including entity name in the backup file of source profile,
Then entity name is included in the backup file of source profile, and the backup file including entity name is joined as operation
Put file;If the backup file of source profile includes entity name, then will back up file as running configuration file.
Preferably, the generating means of above-mentioned persistent layer code also includes: arrange unit, in the entity name that will receive more
Newly to before source profile obtains running configuration file, BaseDAO is set and states file, wherein, the BaseDAO of setting
Statement file includes each power function, and entity name is inputted parameter as entity by each power function.
Preferably, the generating means of above-mentioned persistent layer code also includes: read unit, for according to source profile and reception
Before the entity name generating run configuration file arrived, the metadata of reading database table obtains the field information of database table;The
Two signal generating units, the field information in the database table that will read is as entity name.
Preferably, read unit and include: read module, for first number of the SQL query statement reading database table by input
According to, to obtain the field information of database table, wherein, field information includes: field name, the table name of database table.
In this application, the function obtained in BaseDAO statement strengthens each power function needed for persistent layer defined in example,
Without all functions of persistent layer code support are all enumerated in persistent layer code, when needs generate persistent layer code,
Entity name user inputted is as being accessed the correspondence in the function enhancing example that object BaseDAO statement obtains by master data
Power function enter ginseng, and strengthen example from function according to the order received and select and order corresponding power function as holding
Layer identification code for a long time, thus reduce the redundancy of persistent layer code, save memory space, decrease needed for safeguarding persistent layer code
System resource;It addition, in the persistent layer code building scheme of the application, user has only to input entity name with corresponding
Action command can obtain corresponding persistent layer code, which decreases the complexity of user operation.
Accompanying drawing explanation
Accompanying drawing described herein is used for providing further understanding of the present application, constitutes the part of the application, and the application shows
Meaning property embodiment and explanation thereof are used for explaining the application, are not intended that the improper restriction to the application.In the accompanying drawings:
Fig. 1 is a kind of preferably structure chart of the generation system of the persistent layer code according to the embodiment of the present application;
Fig. 2 is a kind of preferably structure chart of the generating means of the persistent layer code according to the embodiment of the present application;
Fig. 3 is the another kind of preferably structure chart of the generating means of the persistent layer code according to the embodiment of the present application;
Fig. 4 is another preferred structure chart of the generating means of the persistent layer code according to the embodiment of the present application;
Fig. 5 is a kind of preferably structure chart of the first signal generating unit according to the embodiment of the present application;
Fig. 6 is a kind of preferably structure chart reading unit according to the embodiment of the present application;
Fig. 7 is a kind of preferably schematic diagram arranging BaseDAO statement file according to the embodiment of the present application;
Fig. 8 is a kind of preferably flow chart of the generation method of the persistent layer code according to the embodiment of the present application.
Detailed description of the invention
Below with reference to accompanying drawing and describe the application in detail in conjunction with the embodiments.It should be noted that in the case of not conflicting,
Embodiment in the application and the feature in embodiment can be mutually combined.
Before describing the further detail below of present embodiments, can be used for realizing the former of the application by being described with reference to Figure 1
One suitable counting system structure of reason.In the following description, except as otherwise noted, otherwise will be with reference to by one or more meters
Action and the symbol of operation that calculation machine performs represent to describe present embodiments.As such, it will be understood that sometimes referred to as
This kind of action that computer performs includes the behaviour of the processing unit of the computer signal of telecommunication to representing data with structured form with operation
Vertical.Safeguarding it in this manipulation transforms data or position in the accumulator system of computer, this is with those skilled in the art
The mode that member understands reconfigures or changes the operation of computer.The data structure safeguarding data is that the form with data is determined
The physical location of the memorizer of the particular community of justice.But, though the application described in the above-mentioned context, it is not intended to
Restrictive, as understood by those skilled in the art, action described below and each side of operation also can use hardware
Realize.
Turning to accompanying drawing, the most identical reference number refers to identical element, and the principle of the application is shown in a suitable meter
Calculate in environment and realize.Hereinafter describe based on described embodiments herein, and be not considered as about not specifically described herein
Alternative embodiment and limit the application.
Fig. 1 shows the schematic diagram of the example computer architecture that can be used for these equipment.For purposes of illustration, institute
The architecture painted is only an example of proper environment, and not range or function to the application propose any limitation.Also
This calculating Solutions of Systems should not being interpreted as, any component shown in Fig. 1 or a combination thereof are had any dependence or demand.
The principle of the application can use other universal or special calculating or communication environment or configuration to operate.It is applicable to the application's
The example of well-known calculating system, environment and configuration includes but not limited to, personal computer, server, multiprocessor system
System, system based on micro-process, minicomputer, mainframe computer and include the Distributed Calculation of arbitrary said system or equipment
Environment.
In the configuration that it is most basic, the generation system 100 of the persistent layer code in Fig. 1 at least includes: the service of a website
Device 102 and one or more client 104.Server 102 can include but not limited to Micro-processor MCV or able to programme patrol
Collect the processing means of device FPGA etc., for storing the storage device of data and the transmitting device with client communication;Client
End 104 may include that the transmitting device of Micro-processor MCV and server communication and the display device that user is mutual.At this
In specification and claims, " the generation system of persistent layer code " can also be defined as being able to carry out software, firmware or micro-
Code realizes any nextport hardware component NextPort or the combination of nextport hardware component NextPort of function.The generation system 100 of persistent layer code can even is that point
Cloth, to realize distributed function.
As used in this application, term " module ", " assembly " or " unit " can refer to the generation system at persistent layer code
The software object performed on 100 or routine.Different assembly described herein, module, unit, engine and service can be implemented as
The generation system 100 of persistent layer code performs object or the process of (such as, as single thread).Although this place
The system and method described preferably realizes with software, but the realization of the combination of hardware or software and hardware is also possible and quilt
Conception.
In each embodiment following, communication can be realized by the combination of wireless connections or wired connection or both, the application
This is not limited.
Embodiment 1
As it is shown in figure 1, the generation system 100 of persistent layer code includes: the server 102 of website and client 104.Persistently
The work process of the generation system 100 of layer identification code can be as follows:
S1: server 102 is according to source profile and the entity name generating run configuration file received, and wherein, operation is joined
Put file and include entity name, it is preferable that above-mentioned running configuration file includes bean configuration file and sql file, above-mentioned reality
Body title can preferably be the physical name (such as: student) that user is inputted by user end to server, remembers in source profile
Having recorded the entity name of system default, such as, the entity name of system default is: teacher;In this step, source profile
Being that system previously generates, when source profile can include operation, the sql statement configuration file of needs and other some are real
Example configuration file, such as, the bean file of Spring framework, and the content of source profile record can not change, and at needs
When generating persistent layer code, need to judge whether described entity name is included in the backup file of described source profile, if institute
State in the backup file of source profile and do not include described entity name, then described entity name is included in described source profile
Backup file in, and using include described entity name backup file as described running configuration file;If described source configures
The backup file of file includes described entity name, then using described backup file as described running configuration file.
S2: server 102 obtains entity name (such as: student) from running configuration file, and using entity name as function
The entity input parameter of function is passed to be accessed the correspondence in the function enhancing example that object BaseDAO statement obtains by master data
In power function;Preferably, accessed defined in the function enhancing example that object BaseDAO statement obtains persistently in master data
Each power function needed for Ceng, such as, creates function create (A), increases function add (A), delete function delete (A),
Wherein, form enters to join A presentation-entity title, this form enter ginseng can by from running configuration file obtain entity name (such as:
Student) replaced, thus realize the entity name of power function is configured flexibly, in order to met different user's requests.
S3: input the action command (such as, create order " create ") corresponding with business demand by client 104 user
Afterwards, server 102 strengthens, from function, the power function that example, selection is corresponding with action command according to the action command received
As persistent layer code, such as, strengthen selection example from function and create function create (student) as persistent layer code.
In above-mentioned preferred embodiment, each needed for the BaseDAO function that obtains of statement strengthens persistent layer defined in example
Power function, without all enumerating in persistent layer code by all functions of persistent layer code support, when needs generate persistently
During layer identification code, entity name user inputted strengthens real as the function obtained by master data access object BaseDAO statement
Corresponding function function in example enter ginseng, and strengthen example from function according to the order received and select and order corresponding function
Function is as persistent layer code, thus reduces the redundancy of persistent layer code, saves memory space, decreases maintenance persistently
System resource needed for layer identification code;It addition, in the persistent layer code building scheme of the application, user has only to input physical name
Claim and corresponding action command can obtain corresponding persistent layer code, which decrease the complexity of user operation.
Based on above-mentioned preferred embodiment, this application provides the generating means of a kind of preferred persistent layer code, in order to reach fall
The redundancy of low persistent layer code, saves memory space, reduces the technique effect safeguarding the system resource needed for code, it is preferred that
The generating means of the persistent layer code in the present embodiment can be arranged in the server 102 of Fig. 1.To achieve these goals,
Specifically, as in figure 2 it is shown, the generating means of above-mentioned persistent layer code includes such as lower component:
1) the first signal generating unit 202, is used for according to source profile and the entity name generating run configuration file received, its
In, running configuration file includes entity name;Preferably, above-mentioned running configuration file includes bean configuration file and sql literary composition
Part, above-mentioned entity name can preferably be the physical name (such as: student) that user is inputted by user end to server, and source is joined
Putting the entity name that have recorded system default in file, such as, the entity name of system default is: teacher;In this step,
Source profile is that system previously generates, when source profile can include operation the sql statement configuration file of needs and its
His some exemplary configuration files, such as, the bean file of Spring framework, and the content of its record of source profile can not change
Become, and when needs generate persistent layer code, need to judge the backup whether described entity name is included in described source profile
In file, if the backup file of described source profile does not include described entity name, then described entity name is included in institute
State in the backup file of source profile, and using include described entity name backup file as described running configuration file;
If the backup file of described source profile includes described entity name, then described backup file is run configuration literary composition as described
Part.
2) processing unit 204, communicate with the first signal generating unit 202, for obtaining entity name from running configuration file, and
It is passed to be accessed, by master data, the merit that object BaseDAO statement obtains as the entity input parameter of power function using entity name
Can strengthen in the corresponding function function in example;Preferably, access, in master data, the function increasing that object BaseDAO statement obtains
Each power function needed for persistent layer defined in strong example, such as, creates function create (A), increases function add (A),
Deleting function delete (A), wherein, form enters to join A presentation-entity title, and this form enters ginseng can be by from running configuration file
The entity name that obtains (as: student) replace, thus the entity name of power function is configured flexibly by realization, with
Just different user's requests is met.
3) select unit 206, communicate with processing unit 204, for strengthening example from function according to the action command received
Select the power function corresponding with action command as persistent layer code, such as, strengthen from function and example selects create function
Create (student) is as persistent layer code.Preferably, action command may include that user passes through client 104 and inputs and business
The action command (such as, creating order " create ") that demand is corresponding.
In the above-described embodiments, each power function needed for BaseDAO declaration definition persistent layer, without by persistent layer
All functions of code support are all enumerated in persistent layer code, when needs generate persistent layer code, and the entity that user is inputted
Name is referred to as being entered ginseng by what master data accessed that the object BaseDAO function that obtains of statement strengthens corresponding function function in example,
And strengthen example from function according to the order received and to select and to order corresponding power function as persistent layer code, thus drop
The low redundancy of persistent layer code, saves memory space, decreases the system resource safeguarded needed for persistent layer code;It addition,
In the persistent layer code building scheme of the application, user has only to input entity name and corresponding action command can obtain phase
The persistent layer code answered, which decreases the complexity of user operation.
On the basis of above-described embodiment, the generating means of above-mentioned persistent layer code is improved by the application, in order to reach contracting
Time needed for short generation persistent layer code, improve the technique effect of the autgmentability of the application.To achieve these goals, specifically
Ground, as it is shown on figure 3, the generating means of above-mentioned persistent layer code includes: arrange unit 302, at the physical name that will receive
Title updates before obtaining running configuration file in source profile, arranges BaseDAO and states file, wherein, setting
BaseDAO statement file includes each power function, and entity name is inputted parameter as entity by each power function.Preferably,
Each power function needed for master data accesses object BaseDAO declaration definition persistent layer, such as, creates function
Create (A), increases function add (A), deletes function delete (A), and wherein, form enters to join A presentation-entity title, this form
Enter ginseng to be replaced by the entity name (such as: student) obtained from running configuration file, thus realize power function
Entity name is configured flexibly, in order to meet different user's requests.
In the present embodiment, BaseDAO is set and states file, to provide each power function needed for different operating demand,
Can to strengthen example from function when receiving the action command that user is inputted by client and selecting required function letter
Number, to generate persistent layer code, thus contributes to shortening the time generated needed for persistent layer code, improves the extension of the application
Property.Preferably, can be configured obtaining BaseDAO in the way of JDK agency or cgLib and state file, by all of can
The primary demand of energy is all abstracted in a unified DAO to be stated, to arrange BaseDAO statement file, certainly,
This kind of example, this is not limited by the application.
On the basis of above preferred embodiment, the generating means of above-mentioned persistent layer code has been done further improvement by the application,
To reach to obtain exactly the technique effect of entity name.To achieve these goals, specifically, as shown in Figure 4, above-mentioned
The generating means of persistent layer code includes: read unit 402, for generating according to source profile and the entity name received
Before running configuration file, the metadata of reading database table obtains the field information of database table;Second signal generating unit 404, with
Reading unit 402 to communicate, the field information in the database table that will read is as entity name.In the present embodiment,
Before according to source profile and the entity name generating run configuration file that receives, can be by the unit of reading database table
The mode of data obtains the field information in the field information of database table, then the database table that will read as entity name,
Such that it is able to obtain entity name exactly, and then it is easy to successfully generate persistent layer code according to entity name.
On the basis of the various embodiments described above, this application provides a kind of preferred first signal generating unit 202, in order to reduce this
The technique effect of the code redundancy of application.To achieve these goals, specifically, as it is shown in figure 5, above-mentioned first generates list
Unit 202 includes: acquisition module 2022, and the name of business DAO for obtaining current accessed is referred to as entity name, wherein, and industry
Business DAO statement is inherited BaseDAO and is stated file;Judge module 2024, communicates with acquisition module 2022, is used for judging reality
Whether body title is included in the backup file of source profile;Generation module 2026, communicates with judge module 2024, if for
The backup file of source profile does not include entity name, then entity name is included in the backup file of source profile,
And using include entity name backup file as running configuration file;If the backup file of source profile includes physical name
Claim, then will back up file as running configuration file.In the present embodiment, source profile is that system previously generates, its note
The content of record can not change, and by being pre-configured with required entity name, thus the entity name inputted user is included in source and joins
When putting in file, can directly using the backup of source profile as running configuration file, it is preferable that template instruction can be used
The mode rendered is by the backup generating run configuration file of source profile, to improve the speed generating configuration file.
On the basis of above-mentioned each preferred embodiment, this application provides a kind of preferably reading unit 402, in order to reach to improve this
The technique effect of the practicality of application.To achieve these goals, specifically, as shown in Figure 6, above-mentioned reading unit 402 wraps
Include: read module 4022, for the metadata of the SQL query statement reading database table by input, to obtain database table
Field information, wherein, field information includes: field name, the table name of database table.In the present embodiment, by input
The metadata of SQL query statement reading database table, in order to obtain the field such as table name of the field name of database table, database table
Information, i.e. when new database table is abandoned automatically generating by user, only need to write the SQL query statement first number with reading database table
According to obtaining the field information of new database table, substantially increasing the practicality of the application, the code enhancing the application expands
Malleability.
Further, on the basis of above-mentioned each preferred embodiment, describe in detail below in conjunction with Fig. 7 and BaseDAO statement literary composition is set
Part process, states as it is shown in fig. 7, be all abstracted in BaseDAO by all of major demands, to arrange BaseDAO
Statement file, and provide realization by various PersistenceProvider, for example, it is possible to pass through IbatispersistenceProvider
There is provided the realization of acquiescence, when Business Entity (such as, mode such as reflection, cglib) by the way of code strengthens is configured in
After in running configuration file, during operationally stating running configuration file, system can automatically generate the DAO of each related service
Realize.Preferably, in BaseDAO statement file, generate each power function, the corresponding api interface of each power function
And reserved api interface gives other more complicated functions, wherein, api interface is for supporting to enter according to SQL name and parameter Map
The inquiry of row, renewal, deletion action, make for meeting many scenes to strengthen the practicality of the application, operating flexibility, meanwhile
Purpose, API Name can not retain the table name of database table, only describe the action of operation, the table in api interface parameter
Name can be represented by pattern, to support all of operation, thus strengthens the practicality of the application, operating flexibility.
Embodiment 2
On the basis of Fig. 1-7, this application provides a kind of generation method of preferred persistent layer code, in order to reduce persistently
The redundancy of layer identification code, saves memory space, reduces the technique effect safeguarding the system resource needed for code.Above-mentioned in order to realize
Purpose, specifically, as shown in Figure 8, the generation method of above-mentioned persistent layer code includes:
S802: according to source profile and the entity name generating run configuration file received, wherein, in running configuration file
Including entity name;Preferably, above-mentioned running configuration file includes bean configuration file and sql file, and above-mentioned entity name is excellent
Selection of land can be the physical name (such as: student) that user is inputted by user end to server, have recorded system in source profile
The entity name of acquiescence, such as, the entity name of system default is: teacher;In this step, source profile is that system is pre-
First generating, when source profile can include operation, sql statement configuration file and other some exemplary configuration of needs are civilian
Part, such as, the bean file of Spring framework, and the content of its record of source profile can not change, and hold in needs generation
For a long time during layer identification code, need to judge whether described entity name is included in the backup file of described source profile, if described source is joined
Put in the backup file of file and do not include described entity name, then described entity name is included in the backup of described source profile
In file, and using include described entity name backup file as described running configuration file;If described source profile
Backup file includes described entity name, then using described backup file as described running configuration file.
S804: obtain entity name from running configuration file, and entity name is passed as the entity input parameter of power function
Enter in the corresponding function function being accessed in the function enhancing example that object BaseDAO statement obtains by master data;Preferably,
Each function letter needed for master data has accessed defined in the function enhancing example that object BaseDAO statement obtains persistent layer
Number, such as, creates function create (A), increases function add (A), delete function delete (A), and wherein, form enters to join A table
Showing entity name, this form enters ginseng and can be replaced by the entity name (such as: student) obtained from running configuration file, from
And realize the entity name of power function is configured flexibly, in order to meet different user's requests.
S806: select the power function corresponding with action command as holding from function enhancing example according to the action command received
Layer identification code for a long time.Such as, strengthen selection example from function and create function create (student) as persistent layer code.Preferably,
Action command may include that user passes through the client 104 input action command corresponding with business demand and (such as, creates order
“create”)。
In the above-described embodiments, the function obtained in BaseDAO statement strengthens each function letter needed for persistent layer defined in example
Number, without all enumerating in persistent layer code by all functions of persistent layer code support, when needs generate persistent layer code
Time, entity name user inputted accesses in the function enhancing example that object BaseDAO statement obtains as by master data
Corresponding function function enter ginseng, and strengthen example from function according to the order received and select to make with ordering corresponding power function
For persistent layer code, thus reduce the redundancy of persistent layer code, save memory space, decrease and safeguard persistent layer code
Required system resource;It addition, in the persistent layer code building scheme of the application, user has only to input entity name and phase
The action command answered can obtain corresponding persistent layer code, which decreases the complexity of user operation.
On the basis of above-described embodiment, the generation method of above-mentioned persistent layer code is improved by the application, in order to reach contracting
Time needed for short generation persistent layer code, improve the technique effect of the autgmentability of the application.To achieve these goals, specifically
Ground, the generation method of above-mentioned persistent layer code includes: run the entity name received being updated in source profile
Before configuration file, arranging BaseDAO and state file, wherein, the BaseDAO statement file of setting includes each function letter
Number, entity name is inputted parameter as entity by each power function.Preferably, in master data accesses object BaseDAO
Define each power function needed for persistent layer, such as, create function create (A), increase function add (A), delete function
Delete (A), wherein, form enters to join A presentation-entity title, and this form enters the reality that ginseng can be obtained from running configuration file
Body title (as: student) replace, thus realize the entity name of power function is configured flexibly, in order to meet not
Same user's request.
In the present embodiment, BaseDAO is set and states file, to provide each power function needed for different operating demand, with
Just can strengthen example from function when receiving the action command that user is inputted by client and select required power function,
To generate persistent layer code, thus contribute to shortening the time generated needed for persistent layer code, improve the autgmentability of the application.
Preferably, can be configured obtaining BaseDAO in the way of JDK agency and state file, by all of possible primary demand
All being abstracted in a unified DAO and state, to arrange BaseDAO statement file, certainly, this is a kind of
Example, this is not limited by the application.
On the basis of above preferred embodiment, the generation method of above-mentioned persistent layer code is improved by the application, in order to reach
Obtain the technique effect of entity name exactly.To achieve these goals, specifically, the generation method of above-mentioned persistent layer code
Also include: before according to source profile and the entity name generating run configuration file that receives, the unit of reading database table
Data obtain the field information of database table;Field information in the database table that will read is as entity name.In this enforcement
In example, before according to source profile and the entity name generating run configuration file that receives, reading database can be passed through
The mode of the metadata of table obtains the field information in the field information of database table, then the database table that will read as reality
Body title, such that it is able to obtain entity name exactly, and then is easy to successfully generate persistent layer code according to entity name.
In order to reduce the technique effect of the code redundancy of the application, this application provides one and according to source profile and connect
The method of the entity name generating run configuration file received, specifically, raw according to source profile and the entity name received
The step becoming running configuration file includes: the name of business DAO obtaining current accessed is referred to as entity name, wherein, and business
DAO statement is inherited BaseDAO and is stated file;Judge whether entity name is included in the backup file of source profile;If
The backup file of source profile does not include entity name, then entity name is included in the backup file of source profile,
And using include entity name backup file as running configuration file;If the backup file of source profile includes physical name
Claim, then will back up file as running configuration file.In the present embodiment, source profile is that system previously generates, its note
The content of record can not change, and by being pre-configured with required entity name, thus the entity name inputted user is included in source and joins
When putting in file, can directly using the backup of source profile as running configuration file, it is preferable that template instruction can be used
The mode rendered is by the backup generating run configuration file of source profile, to improve the speed generating configuration file.
On the basis of above preferred embodiment, this application provides a kind of metadata preferably through reading database table and obtain
The method of the field information of database table, in order to reach to improve the practicality of the application, strengthen the skill of the code extensions of the application
Art effect.To achieve these goals, specifically, the metadata above by reading database table obtains the field of database table
The method of information includes: by the metadata of the SQL query statement reading database table of input, to obtain the field of database table
Information, wherein, field information includes: field name, the table name of database table.In the present embodiment, looked into by the SQL of input
Ask the metadata of statement reading database table, in order to obtain the field information such as table name of the field name of database table, database table,
I.e. when new database table is abandoned automatically generating by user, only need to write SQL query statement and obtain with the metadata of reading database table
Obtain the field information of new database table, substantially increase the use motility of the application, enhance the code extensions of the application
Property.
Further, on the basis of above-mentioned each preferred embodiment, describe in detail below in conjunction with Fig. 7 and BaseDAO statement literary composition is set
Part process, states as it is shown in fig. 7, be all abstracted in BaseDAO by all of major demands, to arrange BaseDAO
Statement file, and provide realization by various PersistenceProvider, for example, it is possible to pass through IbatispersistenceProvider
There is provided the realization of acquiescence, when Business Entity (such as, mode such as reflection, cglib) by the way of code strengthens is configured in
After in running configuration file, during operationally stating running configuration file, system can automatically generate the DAO of each related service
Realize.Preferably, to arrange BaseDAO statement file, in BaseDAO statement file, each power function is generated, respectively
The corresponding api interface of individual power function reserved api interface give other more complicated functions, and wherein, api interface is used for
The inquiry supporting to carry out according to SQL name and parameter Map, renewal, deletion action, to strengthen the practicality of the application, operation spirit
Activity, meanwhile, for meeting the purpose that many scenes use, can not retain the table name of database table, only describe operation in API Name
Action, the table name in api interface parameter can be represented by pattern, to support all of operation, thus strengthens the application's
Practicality, operating flexibility.
Obviously, those skilled in the art should be understood that each module of above-mentioned the application or each step can be with general calculating
Device realizes, and they can concentrate on single calculating device, or is distributed on the network that multiple calculating device is formed,
Alternatively, they can realize with calculating the executable program code of device, it is thus possible to be stored in storing device
In perform by calculating device, and in some cases, can with the order being different from herein perform shown or described by step
Suddenly, or they are fabricated to respectively each integrated circuit modules, or the multiple modules in them or step are fabricated to single
Integrated circuit modules realizes.So, the application is not restricted to the combination of any specific hardware and software.
The foregoing is only the preferred embodiment of the application, be not limited to the application, for those skilled in the art
For, the application can have various modifications and variations.All within spirit herein and principle, any amendment of being made, etc.
With replacement, improvement etc., within should be included in the protection domain of the application.
Claims (10)
1. the generation method of a persistent layer code, it is characterised in that including:
The source profile previously generated according to system and the entity name generating run configuration file received, wherein, institute
State running configuration file and include described entity name;
Described entity name is obtained from described running configuration file, and using described entity name as the entity of power function
Input parameter is passed to be accessed the corresponding function letter in the function enhancing example that object BaseDAO statement obtains by master data
In number;
Strengthen, from described function, the power function that example, selection is corresponding with described action command according to the action command received
As persistent layer code.
Method the most according to claim 1, it is characterised in that the source profile that previously generates according to system and receiving
The step of entity name generating run configuration file includes:
The name of business DAO obtaining current accessed is referred to as described entity name, and wherein, the statement of described business DAO continues
Hold BaseDAO and state file;
Judge whether described entity name is included in the backup file of described source profile;
If the backup file of described source profile does not include described entity name, then described entity name is included in institute
State in the backup file of source profile, and the backup file including described entity name is run configuration literary composition as described
Part;
If the backup file of described source profile includes described entity name, then using described backup file as described fortune
Row configuration file.
Method the most according to claim 1, it is characterised in that at the source profile previously generated according to system and receiving
Entity name generating run configuration file before, also include:
Arranging BaseDAO and state file, wherein, the described BaseDAO statement file of setting includes each function described
Function, entity name is inputted parameter as entity by each power function.
The most according to the method in any one of claims 1 to 3, it is characterised in that in the source configuration previously generated according to system
Before file and the entity name generating run configuration file that receives, also include:
The metadata of reading database table obtains the field information of described database table;
Field information in the described database table that will read is as described entity name.
Method the most according to claim 4, it is characterised in that the metadata of reading database table obtains described database table
The step of field information includes:
By the metadata of the SQL query statement reading database table of input, to obtain the field information of described database table,
Wherein, described field information includes: field name, the table name of database table.
6. the generating means of a persistent layer code, it is characterised in that including:
First signal generating unit, for the source profile previously generated according to system and the entity name generating run received
Configuration file, wherein, described running configuration file includes described entity name;
Processing unit, for obtaining described entity name from described running configuration file, and using described entity name as
The entity input parameter of power function is passed to be accessed, by master data, the function enhancing example that object BaseDAO statement obtains
In corresponding function function in;
Select unit, for strengthening selection and described action command example according to the action command received from described function
Corresponding power function is as persistent layer code.
Device the most according to claim 6, it is characterised in that described first signal generating unit includes:
Acquisition module, the name of business DAO for obtaining current accessed is referred to as described entity name, wherein, described industry
Business DAO statement is inherited BaseDAO and is stated file;
Judge module, for judging whether described entity name is included in the backup file of described source profile;
Generation module, if do not include described entity name, then by described reality in the backup file of described source profile
Body title is included in the backup file of described source profile, and using the backup file that includes described entity name as
Described running configuration file;If the backup file of described source profile includes described entity name, then by described backup
File is as described running configuration file.
Device the most according to claim 6, it is characterised in that also include:
Unit is set, for joining at the source profile previously generated according to system and the entity name generating run received
Before putting file, arranging BaseDAO and state file, wherein, the described BaseDAO statement file of setting includes described
Each power function, entity name is inputted parameter as entity by each power function.
9. according to the device according to any one of claim 6 to 8, it is characterised in that also include:
Read unit, for joining at the source profile previously generated according to system and the entity name generating run received
Before putting file, the metadata of reading database table obtains the field information of described database table;
Second signal generating unit, the field information in the described database table that will read is as described entity name.
Device the most according to claim 9, it is characterised in that described reading unit includes:
Read module, for the metadata of the SQL query statement reading database table by input, to obtain described data
The field information of storehouse table, wherein, described field information includes: field name, the table name of database table.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201210067610.4A CN103309650B (en) | 2012-03-14 | 2012-03-14 | The generation method and apparatus of persistent layer code |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201210067610.4A CN103309650B (en) | 2012-03-14 | 2012-03-14 | The generation method and apparatus of persistent layer code |
Publications (2)
Publication Number | Publication Date |
---|---|
CN103309650A CN103309650A (en) | 2013-09-18 |
CN103309650B true CN103309650B (en) | 2016-08-24 |
Family
ID=49134913
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201210067610.4A Active CN103309650B (en) | 2012-03-14 | 2012-03-14 | The generation method and apparatus of persistent layer code |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN103309650B (en) |
Families Citing this family (9)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103530123A (en) * | 2013-10-21 | 2014-01-22 | 济南政和科技有限公司 | Code generation method and system |
CN105373536B (en) * | 2014-08-19 | 2019-01-18 | 阿里巴巴集团控股有限公司 | A kind of method and device for realizing DAO interface |
CN106598554B (en) * | 2015-10-14 | 2021-03-23 | 上海汽车集团股份有限公司 | Code generation device |
CN105389339A (en) * | 2015-10-20 | 2016-03-09 | 咸亨国际(杭州)物联网信息产业有限公司 | Tool for rapid generation of database sql statement and entity class |
CN105550349A (en) * | 2015-12-28 | 2016-05-04 | 北京邮电大学 | Persistent layer device and database operation method |
CN108509201A (en) * | 2018-03-20 | 2018-09-07 | 深圳神州数码云科数据技术有限公司 | A kind of code generating method and device |
CN109240906B (en) * | 2018-07-24 | 2021-08-06 | 平安科技(深圳)有限公司 | Database configuration information adaptation method and device, computer equipment and storage medium |
CN109491649A (en) * | 2018-11-20 | 2019-03-19 | 北京千丁互联科技有限公司 | Dao code generating method and terminal |
CN111414162B (en) * | 2019-01-07 | 2024-04-09 | 阿里巴巴集团控股有限公司 | Data processing method, device and equipment thereof |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101819530A (en) * | 2010-04-30 | 2010-09-01 | 山东中创软件工程股份有限公司 | Program object generation method and device and computer |
CN102023861A (en) * | 2010-12-08 | 2011-04-20 | 中兴通讯股份有限公司 | Method and system for generating test script and test suite |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP4978233B2 (en) * | 2007-02-22 | 2012-07-18 | 富士通セミコンダクター株式会社 | Simulator development system and simulator development method |
-
2012
- 2012-03-14 CN CN201210067610.4A patent/CN103309650B/en active Active
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101819530A (en) * | 2010-04-30 | 2010-09-01 | 山东中创软件工程股份有限公司 | Program object generation method and device and computer |
CN102023861A (en) * | 2010-12-08 | 2011-04-20 | 中兴通讯股份有限公司 | Method and system for generating test script and test suite |
Non-Patent Citations (1)
Title |
---|
Hibernate数据持久化技术在粉螨亚目螨种文库构建中的应用;石文兵 等;《河南科技大学学报:自然科学版》;20070630;第28卷(第3期);第54-57页 * |
Also Published As
Publication number | Publication date |
---|---|
CN103309650A (en) | 2013-09-18 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN103309650B (en) | The generation method and apparatus of persistent layer code | |
CN107370786B (en) | General information management system based on micro-service architecture | |
Tian et al. | Optimized cloud resource management and scheduling: theories and practices | |
CN105808428B (en) | A method of unified performance test is carried out to distributed file system | |
KR101368068B1 (en) | Method of constructing database, server performing the same and storage media storing the same | |
CN102999537A (en) | System and method for data migration | |
CN105760192B (en) | Registration method and device for service module of system server | |
Hasani et al. | Lambda architecture for real time big data analytic | |
CN103853759B (en) | A kind of generation method and system of adaptive list | |
CN108132987A (en) | A kind of data query system and method | |
CN103914290A (en) | Operating command processing method and device | |
CN103390018B (en) | A kind of Web service data modeling and searching method based on SDD | |
CN115544183A (en) | Data visualization method and device, computer equipment and storage medium | |
Teng et al. | Design and implementation of the information system of retired veteran cadres bureau based on springboot framework | |
CN115017182A (en) | Visual data analysis method and equipment | |
CN104866508B (en) | The method and apparatus of file is managed under cloud environment | |
Chullipparambil | Big data analytics using Hadoop tools | |
CN115543428A (en) | Simulated data generation method and device based on strategy template | |
Yu et al. | Design of seat selecting system for self-study room in library based on smart campus | |
Krstić et al. | Testing the performance of NoSQL databases via the database benchmark tool | |
Choudhary et al. | Cloud computing and big data analytics | |
CN117009327B (en) | Data processing method and device, computer equipment and medium | |
US20220398228A1 (en) | Implementing tenancy isolation for entities | |
Ekblom | Applied Representational State Transfer | |
Khan et al. | Evaluating google app engine for enterprise application development |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
REG | Reference to a national code |
Ref country code: HK Ref legal event code: DE Ref document number: 1185677 Country of ref document: HK |
|
C14 | Grant of patent or utility model | ||
GR01 | Patent grant | ||
REG | Reference to a national code |
Ref country code: HK Ref legal event code: GR Ref document number: 1185677 Country of ref document: HK |