Applying Code Generation Approach in Fabrique

Business Objects Framework Showcase

Here we proceed with a simple showcase to highlight cool features of code generation.

Building the model

With Visual Fabrique we draw a simple diagram:

figure 3

Here we defined two business objects: Project and Developer, and a relationship between them that says for each project there can be zero or many developers and each developer always participates in one project.

For each business object there is a predefined finder method Find All () (which we call "query") that returns all objects for a given type. In Visual Fabrique we can simply add a new query for Developer that would return all developers who participate in a given project. We code this in FabQL:

figure 4

Then, we add some business logic to the Developer object by writing a method in FabScript that would say whether a given developer participates in a specified project:

figure 5

Running the Code Generator

Up to this point we have been modifying Business Object Model. Now it's time to use it. We can now run Fabrique Compiler to generate an actual implementation for the persistence level. But first, we should decide on target platform. There're two options currently available:

In either case, the complier will generate all necessary classes and deployment descriptors and prepare them for deployment. However, regardless of the target platform, there is always part which is the same (what we called "Platform independent code" above). For each business object, two interfaces are generated:

It's safe to depend on these two interfaces from any part of the model. We will consider use cases in the next chapter.

So, what has the compiler done for us? If we run the complier against the EJB/Orion configuration the following things will be generated:

If we run the compiler against the Hibernate/Tomcat configuration it will result in the following output:

Page
Kirill's photo

Kirill Kalishev
JetBrains

Kirill is Senior Software Developer at JetBrains. He was instrumental in the creation of the company's award-winning IntelliJ IDEA IDE. He now works on core parts of the Fabrique project.

Contact Kirill via email: kirill(.)kalishev
(at) jetbrains.com

:: onBoard issues ::
Issue #2
February 2005