CodeGen improvements

This is a work-in-progress, but should not break existing functionality.

I'm trying to make GenCode modular and then wedge Doctrine in... somehow...  I haven't decided whether to create a parallel class hierarchy to support Doctrine, or to somehow incorporate it into the DAO classes.

See CRM-13871