Applying Templates to Lists of Data

Building an object-relational database mapping is an excellent use of code generation. In this section, we’re going to build one component of such a mapping by generating SQL schemas from Java class definitions. To keep things simple, we’ll restrict ourselves to fields whose Java types maps easily to SQL types (such as integers, strings, floats, doubles, and Date objects).

To build this generator, we’re going to use Java’s reflection API as an input model and create a nested template hierarchy as we did in the previous section. This application is going to require some new skills, though. We have to get comfortable sifting and filtering the input model and then applying templates to that data. Since ST is a ...

Get Language Implementation Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.