Code at runtime in Java 5/6

One of the great features added in Java 5 was annotations. The meta data carried by annotations can be processed by the Annotation Processing Tool (apt), to generate new classes, more code or even data files (like Hibernate mapping files and such). However, annotations can also be stored in the byte codes and reflected at runtime. This becomes a truly amazing feature when you combine it with the Proxy class that was added in Java 1.2. How so? Imagine you create an interface with a bunch of methods, annotate them with what you want them to do, and then an API can generate an implementation for you, at runtime! The really awesome part of this thing? You won’t be generating any byte codes, it’s all done for you!

This is in fact, exactly how EoD SQL works. You annotate a method with your database queries (SELECT, INSERT, UPDATE, DELETE, etc), and it generates an implementation for you with it’s QueryTool class. So, how do you do it? Its actually really really easy. Read the rest of this entry »