Using PowerDesigner for code generation

Source: Internet
Author: User
Tags powerdesigner

Many code generators have chosen to generate the domain model from the table structure, the premise is that the domain model and database table structure is isomorphic, that is, the class in the domain model and the database record structure is very consistent, so that the database table structure can be easily mapped directly to the domain model.

However, in the case of complex business logic, the object schema and the relationship scheme often do not match, usually there is a data mapper between the two to isolate the two, when the two are invisible to each other and evolve independently. Thus, the class of the code generation domain model based on the table structure would not work, but the object model should be used. And such code generation almost does not need itself in writing code generators, you can use PowerDesigner9.

PowerDesigner9 already has the code generation function, you just have to build a object_oriented Model (language selection C #, Class diagram), complete the class design, using the language menu under "Generate C # Code". After the build, look at the code file, all the properties do not have get and set method, in order to generate these two methods, you have to modify the PowerDesigner code generation template, you can choose the Language menu under the "Edit current Object Language , modify the code template in the popup window:


You can see the code-generated script in the Value section, and if you write a template using a code generation tool such as Codesmith, this script is easy to understand, as long as you modify it, for example, I put the third line: [%visibility%][%flags%]% Datatype% _%code%[=%initialvalue%];

This sentence is changed to:

Private%datatype% _%code%[=%initialvalue%];

Public%datatype%%code%

{

Get

{

return _%code%;

}

Set

{

value = _%code%;

}

}

The other two if branches also make corresponding changes, and then generate a look, get and set functions have.

The code template for C # is powerdesigner under the installation directory of resource Files\object The Csharp.xol file in the languages directory opens and you can see that it is actually an XML file, so you can define your own code-generated template.

Source: http://tech.it168.com/m/2007-08-29/200708291905519.shtml

Related articles:

PowerDesigner automatic generation of code modificationsPowerDesigner class Diagrams generate Java code

Using PowerDesigner for code generation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.