|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
IntroductionWhat is Yet Another Code Generator (YACGEN)?
This article is the first part of a series of articles on YACGEN. It covers the
concept and design of YACGEN, how to import and maintain database schemas and
generate output from templates. Details on template generation and maintenance
will be provided in future articles. A article covering template creation can be found here: YACGen Template Generation BackgroundWon't spend a lot of time on the merit's of code generation since
so much has been written elsewhere. In short code generation can eliminate time
consuming and repetitive coding and build consistent and (in theory) high quality
and error free code. I stress 'in theory' since the code generated is only as good as
the templates it is based upon. However, the beauty of code generation is if
there are issues with underlying templates code can be regenerated with little
effort. YACGEN requirements came out of the of how I approach most
projects (and I don't think they differ from the majority of developers out
there). I usually start with a relational database containing strongly defined
relationships. I would build data access through SQL stored procedures, provide supporting data access and business layers and finally a user interface. For an ASP.NET 3-tier C# application this would comprise of a 4-5 files per table. These would cover store procedure, data access, business logic and ASP.NET pages. The requirement was to create a system that could store database schemas and application specific information. I needed to be able to quickly and easily extend the processed database schema. So for any given field I could identify if it was included in a grid, part of a sub-form or needed to be handled different, such as a picture. These attributes would not hardcoded in the schema, they are simply flags that the appropriate template would read to determine the generated output.Ok, this sounds like a lot of other code generators available.
How is YACGEN different? YACGEN:
Extensive Schema SupportFor any given table or field object I wanted to be able to store a LOT of information but also make it easily accessible. YACGEN stores 15 user definable flags, multiple messages, evaluation logic, descriptions, code snippets and layout coordinates for any given field. If that's not enough you can add any number user defined values. This information is presented on a logically laid out form. The following images shows the two pages of properties available for each field. The bolded items are fixed elements imported from the database layout. All the other elements can be modified, the corresponding labels are suggestions. To determine the property name hover over any text or checkbox for a few seconds.
Execute Script During Schema Processing
YACGEN can execute user defined Python code snippets during database schema
processing. These code snippets can populate YACGEN schema elements.
Codeless TemplatesYACGEN requires no code to generate output. One thing I noticed with a great number of code generators is the fact they require code to generate code. There isn't anything wrong with this approach, it's a powerful approach since you have access to all programming constructs and debugging facilities the underlying language provides.Personally I find creating templates programmatically for large amounts of code, especially ASP.NET pages with large amounts of HTML, rather tedious. For such templates I would mock up the appropriate layout in Visual Studio, paste it into a YACGEN template and them make the appropriate modifications to insert field properties. The approach taken in YACGEN is to analogous to a report generator. There are several levels, similar to report bands, that contain pre, post and body templates, like report header, body and footer. Future implementations may use code templates as well. A single template can generate large modules of code. For example, one of the included templates builds C# business layer implementing delete, select, update, insert and paging methods. ![]() Using the ApplicationYACGEN is divided into 4 main areas:
To import database schema:
YACGEN will proceed to inventory the selected databases. If a
given database already exists in the schema YACGEN will update any changes. Once the schema is created you can proceed updating any custom
values. To save the layout, select the Save Database layout button. This will
prompt for layout name. The layout is stored in a file with .dbd extension.
![]() The included BuildSP.gpr generation file uses the TableSPs.tld template to build SQL server stored procedure code to delete, insert, update select and paging logic for whichever table(s) you specify. Each template contains the layout for one output file. So for a complete ASP.NET 3-tier application there would be a stored procedure, DAL, BLL and ASP.NET template file. For the ASP.NET there would be 2 templates, one for the designer code and one for the background code. The download includes 5 sample templates:
Using the GUI to generate logic for a large selection of table objects can be time consuming. There is a command line tool, yacgencl, that generates output. This allows for project batch building. The syntax is: yacgencl gprfile.gpr (key1 value1, key2, value2 , keyn, valuen) A generation template .gpr file is the only required file. The following command line would generate output based on settings in buildsp.gpr: yacgencl "c:\program files\YACGEN\templates\buildsp.gpr" YACGencl can take any number of key pair values as parameters. This allows for any generation or table properties to be set from the command line during generation. The following command line would generate output changing the TableName, OutputDirectory and Process properties: C:\Program Files\YACGEN>yacgencl "c:\program files\YACGEN\templates\buildsp.gpr" TableName Products OutputDirectory "c:\data\vs\nwind\sps\\" Process "Single Table or View" Future EnhancementsPossible future enhancements include improved interface, more database support and improved template processing. HistoryAug 14 2008 YACGen Beta 2 2008.08.14 - added association generation for ORM support July 17 2008 YACGen Beta 1 2008.07.17 Minor bug and interface fixes About The AuthorStein Borge is a developer living in Australia. Love computer and related technology, working and playing with computers over 20 years. Started with Turbo Pascal and worked with xBase, Clipper, C++,VB, VBScript, C# as well a working with a host of backend technologies. Published Windows scripting books Managing Enterprise Systems and Automating Windows Administration. Currently focusing on .NET based Web development and related technologies.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||