Skip to content

Second Tutorial Part 4: Generated Artifacts

Laurent Hasson edited this page Dec 3, 2019 · 2 revisions
Previous Main Next
<-- Part 3 Main Part 5 -->

When you run Gen, Tilda generates a number of artifacts. In the first tutorial, we looked at the SQL and database-side artifacts that could be used in and of themselves. In this tutorial, we look at the Java artifacts and the overall programming model they expose. First, you have to understand the basics of those artifacts:

  • By convention (you can make your own, but do establish one), we create a package called data where all the Tilda generated code and data-access layer is going to be located.
  • Tilda creates a folder called _Tilda where its generated artifacts are created. These files are fully javadoc'ed and are human readable (the 'T' in Tilda is for Transparency) but shouldn't be touched: they get completely rewritten every time Gen is executed. The name _Tilda has an underscore in front of it, an uncommon practice in Java regarding how to name packages, but most IDEs show packages and files by alphabetical order, so we wanted that package to show up first consistently across any project for easy identification.
  • As we have seen in the first tutorial, an SQL and an HTML file are generated for the DDL needed for defining the schema and all its objects, and the HTML documentation.
  • In addition, for every table/view generated in the model, 2 classes are generated: TILDA__XXX.java and TILDA__XXX_Factory.java. We will go into the details of those classes in more details later on. They are prefixed with TILDA__ for two reasons: (1) to make them look like generated things and avoid being used in your app, and (2) to also avoid these classes from getting auto-completed in modern IDEs vs the application-level classes.
  • Finally, there is a TILDA__1.0.java class that contains schema-level logic and reusable code for all the entity-related classes.
  • In the data folder, application-level classes are generated for developers to put their custom data access logic there. The class Xxx_Data.java inherits from _Tilda/TILDA__XXX.java and Xxx_Factory.java inherits from _Tilda/TILDA__XXX_Factory.java. All Tilda code creates instances of app-level classes, and the underlying Tilda classes are not instantiatable directly.
  • As their names indicate, the Xxx_Data class represents an instance of a record in a data store, and the Xxx_Factory class contains factory-level methods to create instances of the data class or handle various transformations (such as JSON or CSV serialization/deserialization).

🎈 NOTE: A single entity defined in the Tilda JSON definition file may result in multiple java-level objects to be generated (such as with View Realization which we use in this tutorial, or table cloning).

🎈 NOTE: The application-level classes are only generated once when Gen is run for the first time or when new entities are added during the development cycle. It is possible that these classes "break" over time if APIs generated by the entity definition in JSON change some semantics. The compiler is then use to flag issues and then developers can correct them.

Previous Main Next
<-- Part 3 Main Part 5 -->
Clone this wiki locally