{"id":3607,"date":"2018-05-22T08:54:22","date_gmt":"2018-05-22T08:54:22","guid":{"rendered":"https:\/\/modeling-languages.com\/?p=3607"},"modified":"2019-12-18T16:51:32","modified_gmt":"2019-12-18T16:51:32","slug":"telosys-tools-the-concept-of-lightweight-model-for-code-generation","status":"publish","type":"post","link":"https:\/\/modeling-languages.com\/telosys-tools-the-concept-of-lightweight-model-for-code-generation\/","title":{"rendered":"Telosys – a lightweight and pragmatic code-generator"},"content":{"rendered":"
Telosys<\/strong> <\/a>is a simple and pragmatic code generator. Provided as a Command Line Interface tool<\/a> and as an Eclipse Plugin<\/a>, it uses an original approach based on 2 kinds of\u00a0 \u201clightweight models\u201d ( \u201cdatabase model\u201d and “DSL\/text model”).\u00a0This tool aims to provide an alternative to the classical “UML first” approach\u00a0that requires a significant workload at the beginning of the project to create a reliable and accurate model.<\/p>\n Unlike conventional tools (tools based on MDA\/XMI approach), Telosys is very light and can be considered as a “tactical tool”. It has been designed by developers for developers and focuses on a quick start (its motto is “remain simple”).\u00a0The typical usage of Telosys can be described in 3 steps:<\/p>\n The first step is the setup of a lightweight model<\/strong> containing the entities definitions that will be used to generate the code.\u00a0\u00a0There are two ways to do that: with a “Database Model” or with a “DSL Model”<\/p>\n If you have an existing relational database<\/strong> it can be used by Telosys to create automatically a “database model<\/strong>“.<\/p>\n Indeed the database schema is by itself a “model”. Telosys will connect to the database and discover all the tables and their relationships in order to create the model for you.\u00a0This kind of model is stored in XML format in a single file (the “.dbrep” file)\u00a0and contains an entity for each table. Once the model has been created, it can be updated and enriched in order to provide exactly what is expected\u00a0 for the code generation (it\u2019s the refining step)<\/p>\n The Database model editor in Eclipse :<\/p>\n <\/a><\/p>\n If you want to start from scratch you can create a “DSL model<\/strong>“. This model is defined as a set of text files (one “.entity” file for each entity) with a very simple syntax. This model is a kind of\u00a0entity\u2013relationship model.\u00a0Each entity has a set of attributes, each attribute can define :<\/p>\n Otherwise, complementary information can be added to each attribute in order to characterize them more precisely (eg: @Id, @Min(12), @NotNull, etc ). The model can be improved gradually over time just by editing the entities’ files.<\/p>\n The DSL model editor in Eclipse ( extensions are also available for VSCode and Atom ) :<\/p>\n <\/a><\/p>\n These two types of models ( database model and DSL model) are different but are used in the same way by the generator thanks to a “generic model<\/strong>” interface which exposes an abstract view of the model<\/p>\n <\/a><\/p>\n <\/p>\n Once the model is ready, you need a set of templates<\/strong> in order to define the way the code will be generated.\u00a0The generator is based on the \u201cVelocity<\/a>\u201d engine, hence the well-known Velocity syntax is used to define the templates. Templates are organized in “bundles”, a bundle is a set of templates focusing a specific goal\u00a0(for example web interface, persistence layer, etc)<\/p>\n Some ready-to-use templates are\u00a0available\u00a0on GitHub<\/a> (each Git repository is a bundle of templates, predefined templates for Java, JavaScript, Python, etc are available in the repository). All the templates can be adapted to conform with specific project requirements, and new templates can be created if necessary.<\/p>\n The templates editor :<\/p>\n <\/a><\/p>\n <\/p>\n Finally, the last and simplest step is the generation<\/strong>.\u00a0The generation will apply the selected templates on the selected entities as shown below (entities on the left part, templates on the right part).<\/p>\n1. Create your lightweight model<\/h2>\n
\n
\n
\n
2. Choose the code-generation template<\/h2>\n
3. Generate your application code<\/h2>\n