Search code examples
code-generationtelosys

Telosys : How can i get database table records in template?


I am using Telosys tools for code generation. It's very nice tool and help me a lot.

But there is one problem, that is, it provides database schema information and i can access in templates (templates are formerly velocity templates), which is good, but how can i get selected entity's data from database? There is no way i can find, by which i can get that selected table data.

Please provide solution if any, or provide alternate way to do it.

Thanking You!


Solution

  • Telosys Tools is designed to retrieve the model from the database, not the data stored in the tables.

    But it allows to create your own specific tooling classes usable in the templates, so it's possible to create a specific Java Class to retrieve the data from the database.

    There's an example of this kind of specific class in the "database-doc" bundle https://github.com/telosys-tools/database-doc-bundle-TT210 ( in classes folder ) To simplify the loading the simplest way is to create the class in the "default package" (no java package)

    NB: The problem is that the jar containing the JDBC driver is not accessible by the generator class-loader, so you will have to use a specific class-loader and to connect directly with the JDBC driver.

    Here is an example : https://gist.github.com/l-gu/ed0c8726807e5e8dd83a Don't use it as is (the connection is never closed) but it can be easily adapted.