Select Peril From DataAccess


Hi,
My mind has been harrassed and tortured by yet another foray into the wild world of data access code generation and I’m feeling a bit at a loss.  Code that writes code is one of those funky, somewhat complex things that occasionally has you walking in circles.
 
Coming to the point; do your data generation at your own peril.  One thing which comes to mind is that when considering a strategy for code generation, always consider designing your templates and other parts so that they are easily extended.  Also remember that a data schema (if you are generating from a fixed schema) can only provide you with so much insight – you’re likely going to require three things as your code matures:
 
– custom, object-level attributes (objects being tables, columns etc)
– runtime settings (e.g. "I want to do this (x) at this time")
– save (remember) settings ("save configuration"), since you’ll often want to regen based on previous settings and this might include the ability to "import" and "export" settings.
 
Having listed all these points above, I’d say that User Interface design (for whatever tool your using) is also equally as important since it will constrain or help you interact with your application’s settings (be it codesmith, web service software factory, or a custom tool).
 
One of my favourite techniques for dealing with database code generation is to create an XML representation of tables and columns in a database which you can then add custom elements to. 
 
This gives you the flexibility of adding table-level or column-level attributes at any time, it also allows you the luxury of define and forget configuration (reusable) and only carries the overhead of implementation of functionality to actually do something with those new attributes.
 
Anyhow, I just thought this might be worthy of discussin on my blog, so here it is.  As usual, I’m more than happy to discuss code generation techniques with anyone who has questions.  I’ve been down this road many-a-time.  Too many, perhaps.
 
Cheers
/R

About Rob Sanders

IT Professional and TOGAF 9 certified architect with nearly two decades of industry experience, 18 years in commercial software development and 11 years in IT consulting. Check out the "About Rob" page for more information.

Leave a comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>