Java 2 Ada - Tag UML2014-05-18T12:42:00+00:00Stephane Carrezurn:md5:d12e23c53b2436d6becce3d51ddbdf38AWAAda Web Application: Building the UML modelurn:md5:1144b71bd4841657c3e45a3a65c14e5c2014-05-18T12:42:00+00:002014-05-18T12:42:00+00:00Stephane CarrezTutorialAdaUML
<div class="post-text"><p>In the <a href="http://blog.vacs.fr/vacs/blogs/post.html?post=2014/05/08/Ada-Web-Application-Setting-up-the-project">Ada Web Application: Setting up the project</a> we have seen how to create a new <a href="http://code.google.com/p/ada-awa">AWA</a> project. In this second article, we will see how to design the UML model, generate the Ada code and create the database tables from our UML design.</p><h2>Introduction</h2><p>A Model driven engineering or <a href="http://en.wikipedia.org/wiki/Model-driven_engineering">MDE</a> promotes the use of models to ease the development of software and systems. The <a href="http://en.wikipedia.org/wiki/Unified_Modeling_Language">Unified Modeling Language</a> is used to modelize various parts of the software. UML is a graphical type modelling language and it has many diagrams but we are only going to use one of them: the <a href="http://en.wikipedia.org/wiki/Class_diagram">Class Diagram</a>.</p><p>The class diagram is probably the most powerful diagram to design, explain and share the data model of any application. It defines the most important data types used by an application with the relation they have with each other. In the class diagram, a class represents an abstraction that encapsulates data member attributes and operations. The class may have relations with others classes.</p><p>For the UML model, we are going to use <a href="http://argouml.tigris.org/">ArgoUML</a> that is a free modelization tool that works pretty well. For the <a href="http://argouml.tigris.org/">ArgoUML</a> setup, we will use two profiles:</p><ul><li>The <a href="https://code.google.com/p/ada-gen/">Dynamo</a> profile that describes the base data types for our UML model. These types are necessary for the code generator to work correctly.</li><li>The <a href="http://code.google.com/p/ada-awa">AWA</a> profile that describes the tables and modules provided by <a href="http://code.google.com/p/ada-awa">AWA</a>. We will need it to get the user UML class definition.</li></ul><p>These UML profiles are located in the <code>/usr/share/dynamo/base/uml</code> directory after <a href="https://code.google.com/p/ada-gen/">Dynamo</a> and <a href="http://code.google.com/p/ada-awa">AWA</a> are installed. To configure <a href="http://argouml.tigris.org/">ArgoUML</a>, go in the <code>Edit -> Settings</code> menu and add the directory in the <code>Default XMI directories</code> list. Beware that you must restart <a href="http://argouml.tigris.org/">ArgoUML</a> to be able to use the new profiles.</p><p><div class="wiki-img-center"><div class="wiki-img-inner"><img src="/images/samples/demo-awa-argouml-setup.png" longdesc="ArgoUML profile setup" alt="demo-awa-argouml-setup.png"></img></div></div></p><h2>Modelize the domain model in UML</h2><p>The UML model must use a number of <a href="https://code.google.com/p/ada-gen/">Dynamo</a> artifacts for the code generation to work properly. The artifact describes some capabilities and behavior for the code generator to perform its work. Stereotype names are enclosed within markers. <a href="https://code.google.com/p/ada-gen/">Dynamo</a> uses the following stereotypes:</p><ul><li>The <code>DataModel</code> stereotype must be applied on the package which contains the model to generate. This stereotype activates the code generation (other packages are not generated).</li><li>The <code>Table</code> stereotype must be applied to the class. It controls which database table and Ada type will be generated.</li><li>The <code>PK</code> stereotype must be defined in at most one attribute of the class. This indicates the primary key for the database table. The attribute type must be an integer or a string. This is a limitation of the Ada code generator.</li><li>The <code>Version</code> stereotype must be applied on the attribute that is used for the <a href="http://en.wikipedia.org/wiki/Optimistic_concurrency_control">optimistic locking</a> implementation of the database layer.</li></ul><p><div class="wiki-img-center"><div class="wiki-img-inner"><img src="/images/samples/demo-awa-uml-review-table.png" longdesc="The Review Table UML Model" alt="demo-awa-uml-review-table.png"></img></div></div></p><p>In our UML model, the <code>Review</code> table is assigned the <code>Table</code> stereotype so that an SQL table will be created as well as an Ada tagged type to represent our table. The <code>id</code> class attribute represents the primary key and thus has the <code>PK</code> stereotype. The <code>version</code> class attribute is the database column used by the <a href="http://en.wikipedia.org/wiki/Optimistic_concurrency_control">optimistic locking</a> implementation provided by <a href="http://code.google.com/p/ada-ado">ADO</a>. This is why is has the <code>Version</code> stereotype. The <code>title</code>, <code>site</code>, <code>create_date</code>, <code>text</code> and <code>allow_comments</code> attributes represent the information we want to store in the database table. They are general purpose attributes and thus don't need any specific stereotype. For each attribute, the <a href="https://code.google.com/p/ada-gen/">Dynamo</a> code generator will generate a getter and a setter operation that can be used in the Ada code.</p><p>To tune the generation, several UML tagged values can be selected and added on the table or on a table attribute. By applying a stereotype to the class, several tagged values can be added. By selecting the <code>Tagged Values</code> tab in ArgoUML we can edit and setup new values. For the <code>Review</code> table, the <code>dynamo.table.name</code> tagged value defines the name of the SQL database table, in our case <code>atlas_review</code>.</p><p><div class="wiki-img-center"><div class="wiki-img-inner"><img src="/images/samples/demo-awa-argouml-review-tagged.png" longdesc="The tagged value for the Review table" alt="demo-awa-argouml-review-tagged.png"></img></div></div></p><p>The <code>text</code> attribute in the <code>Review</code> table is a string that can hold some pretty long text. To control the length of the SQL column, we can set the <code>dynamo.sql.length</code> tagged value and tell what is that length.</p><p><div class="wiki-img-center"><div class="wiki-img-inner"><img src="/images/samples/demo-awa-argouml-text-tagged.png" longdesc="The tagged value for the text column in review table" alt="demo-awa-argouml-text-tagged.png"></img></div></div></p><p>Once the UML model is designed, it is saved in the project directory <code>uml</code>. <a href="https://code.google.com/p/ada-gen/">Dynamo</a> will be able to read the ArgoUML file format (<code>.zargo</code> extension) so there is no need to export the UML in XMI.</p><h3>The Review application UML model</h3><p>The final UML model of our review application is fairly simple. We just added a table and a bean declaration. To benefit from the <a href="https://code.google.com/p/ada-awa/wiki/AWA_Users_Modules">user management</a> in <a href="http://code.google.com/p/ada-awa">AWA</a>, we can use the <code>AWA::Users::Models::User</code> class that is defined in the AWA UML model. The <code>reviewed-by</code> association will create an attribute <code>reviewer</code> in our class. The code generator will generate a <code>Get_Reviewer</code> and <code>Set_Reviewer</code> operation in the Ada code. The SQL table will contain an additional column <code>reviewer</code> that will hold the primary key of the reviewer.</p><p><div class="wiki-img-center"><div class="wiki-img-inner"><img src="/images/samples/demo-awa-uml-review-model.png" longdesc="The Review Web Application UML Model" alt="demo-awa-uml-review-model.png"></img></div></div></p><p>The <code>Review_Bean</code> class is an <a href="https://code.google.com/p/ada-util/wiki/AdaBeans">Ada Bean</a> abstract class that will be generated by the code generator. The <code>Bean</code> stereotype activates the bean code generator and the generator will generate some code support that is necessary to turn the <code>Review_Bean</code> tagged record into an <a href="https://code.google.com/p/ada-util/wiki/AdaBeans">Ada Bean</a> aware type. We will see in the next tutorial that we will only have to implement the <code>save</code> and <code>delete</code> operation that are described in this UML model.</p><h3>Makefile setup</h3><p>The <code>Makefile.in</code> that was generated by the <a href="https://code.google.com/p/ada-gen/">Dynamo</a> <code>create-project</code> command must be updated to setup a number of generation arguments for the UML to Ada code generator. Edit the <code>Makefile.in</code> to change:</p><pre><code>DYNAMO_ARGS=--package Atlas.Reviews.Models db uml/atlas.zargo
</code></pre><p>The <code>--package</code> option tells <a href="https://code.google.com/p/ada-gen/">Dynamo</a> to generate only the model for the specified package. The <code>db</code> directory is the directory that will contain the SQL model files.</p><p>Once the <code>Makefile.in</code> is updated, the <code>Makefile</code> must be updated by using the following command:</p><pre><code>./config.status
</code></pre><p>Or if you prefer, you may run again the <code>configure</code> script to re-configure the whole project.</p><h3>We need the code!!</h3><p>To run the generator, we can use the <code>generate</code> make target:</p><pre><code>make generate
</code></pre><p>The <a href="http://code.google.com/p/ada-gen/">Dynamo</a> code generator reads the file <code>uml/atlas.zargo</code> and the UML model it contains and generates:</p><ul><li>the Ada package <code>Atlas.Reviews.Models</code> which contains the definition of the <code>Review</code> table. The model files are created in the directory <code>src/models</code> which is separate from your Ada sources.</li><li>the SQL files to create the MySQL or SQLite database. Depending on the <a href="http://code.google.com/p/ada-awa">AWA</a> modules which are used, the generated SQL files will contain additional tables that are used by the <a href="http://code.google.com/p/ada-awa">AWA</a> modules. The SQL files are generated in the <code>db/mysql</code> and <code>db/sqlite</code> directories.</li></ul><h3>Let's create the database</h3><p>Until now we designed our application UML model, we have our Ada code generated, but we need a database with the tables for our application. We can do this by using the <code>create-database</code> command in <a href="https://code.google.com/p/ada-gen/">Dynamo</a>. This command needs several arguments:</p><ol><li>The directory that contains the SQL model files. In our case, this is <code>db</code>.</li><li>The information to connect to the database, the database name, the user and its password. This information is passed in the form of a database connection string.</li><li>The name of the database administration account to connect to the server and create the new database.</li><li>The optional password for the database administration account.</li></ol><p>If the MySQL server is running on your host and the admin account does not have any password, you can use the following command:</p><pre><code>dynamo create-database db 'mysql://localhost/demo_atlas?user=demo&password=demo' root
</code></pre><p>The <code>create-database</code> creates the database (<code>demo_atlas</code>) with the tables that are necessary for the application. It also creates the <code>demo</code> user and give it the necessary MySQL grants to connect to the <code>demo_atlas</code> database.</p><h3>The Review Web Application UML video</h3><p>To help you in building the UML model and see who the whole process looks like in reality, I've created the following short video that details the above tutorial steps.</p><iframe width="560" height="315" src="https://www.youtube.com/embed/Mwo6Q2NCsIY" frameborder="0" allowfullscreen></iframe>
<h3>Conclusion</h3><p>Thanks to <a href="http://argouml.tigris.org/">ArgoUML</a> and <a href="https://code.google.com/p/ada-gen/">Dynamo</a>, generating the Ada model and database tables becomes a simple and fun task. We have not written any line of code yet in this Review Web Application project, everything has been generated but we achieved a big progress:</p><ul><li>The Review Web Application server is built and can be launched,</li><li>The database is initialized and contains our application data model schema.</li></ul><p>The next tutorial will explain how to design the review form, implement the operations to create and populate the database with the new review.</p></div> Dynamo 0.7.0 is availableurn:md5:0c85b61b2cf36654e04ed478a2e7504f2014-05-12T19:28:07+00:002014-05-12T19:28:07+00:00Stephane CarrezreleaseAdaMDEUMLgenerator
<div class="post-text"><p><a href="https://code.google.com/p/ada-gen/">Dynamo</a> is a code generator used to generate <a href="https://code.google.com/p/ada-gen/">Ada Web Application</a> or database mappings.</p><ul><li>New project template to generate Gtk Ada application</li><li>Register the new module in the application when they are added</li><li>Update the current testsuite when new tests are added</li><li>New stereotype for Ada bean generation</li><li>Support for the creation of Debian packages</li><li>New command <code>add-form</code> and <code>add-module-operation</code></li></ul><p>You can download the new version at <a href="http://download.vacs.fr/dynamo/dynamo-0.7.0.tar.gz">http://download.vacs.fr/dynamo/dynamo-0.7.0.tar.gz</a></p></div> Ada Web Application 0.3.0 is availableurn:md5:6829cd9f30f9b3a361025d8cc5e27b4a2013-02-15T21:29:00+00:002013-02-15T21:29:00+00:00Stephane CarrezAdaMDEUMLrelease
<div class="post-text"><p><a href="http://code.google.com/p/ada-awa/">Ada Web Application</a> is a framework to build web applications.</p><ul><li>AWA uses <a href="http://code.google.com/p/ada-asf/">Ada Server Faces</a> for the web framework. This framework is using several patterns from the Java world such as Java Server Faces and Java Servlets.</li><li>AWA provides a set of ready to use and extendable modules that are common to many web application. This includes managing the login, authentication, users, permissions.</li><li>AWA uses an Object Relational Mapping that helps in writing Ada applications on top of MySQL or SQLite databases. The <a href="http://code.google.com/p/ada-ado/">ADO</a> framework allows to map database objects into Ada records and access them easily.</li><li>AWA is a model driven engineering framework that allows to design the application data model using UML and generate the corresponding Ada code.</li></ul><p><div class="wiki-img-center"><div class="wiki-img-inner"><img src="/images/Ada/.awa_architecture_overview_m.jpg" longdesc="Ada Web Application Architecture, f&#E9;v. 2013" alt="Ada Web Application Architecture"></img></div></div></p><p>The new version of AWA provides:</p><ul><li>New jobs plugin to manage asynchronous jobs,</li><li>New storage plugin to manage a storage space for application documents,</li><li>New votes plugin to allow voting on items,</li><li>New question plugin to provide a general purpose Q&A.</li></ul><p>AWA can be downloaded at <a href="http://code.google.com/p/ada-awa/downloads/list">http://code.google.com/p/ada-awa/downloads/list</a></p><p>A live demonstration of various features provided by AWA is available at <a href="http://demo.vacs.fr/atlas">http://demo.vacs.fr/atlas</a></p></div> Dynamo 0.6.0 is availableurn:md5:e17c073fa27df4c54e7f847105f8279a2013-02-10T22:15:26+00:002013-02-10T22:15:26+00:00Stephane CarrezAdaMDEUMLgeneratorrelease
<div class="post-text"><p>Dynamo is a tool to help developers write some types of Ada Applications which use the <a href="http://code.google.com/p/ada-asf">Ada Server Faces</a> or <a href="http://code.google.com/p/ada-ado">Ada Database Objects</a> frameworks. Dynamo provides several commands to perform one specific task in the development process: creation of an application, generation of database model, generation of Ada model, creation of database.</p><p>The new version of Dynamo provides:</p><ul><li>A new command <code>build-doc</code> to extract some documentation from the sources,</li><li>The generation of MySQL and SQLite schemas from UML models,</li><li>The generation of Ada database mappings from UML models,</li><li>The generation of Ada beans from the UML models,</li><li>A new project template for command line tools using ADO,</li><li>A new distribution command to merge the resource bundles.</li></ul><p>The most important feature is probably the Ada code generation from a UML class diagram. With this, you can design the data model of an application using <a href="http://argouml.tigris.org/">ArgoUML</a> and generate the Ada model files that will be used to access the database easily through the <a href="http://code.google.com/p/ada-ado">Ada Database Objects</a> library. The tool will also generate the SQL database schema so that everything is concistent from your UML model, to the Ada implementation and the database tables.</p><p>The short tutorial below indicates how to design a UML model with <a href="http://argouml.tigris.org/">ArgoUML</a>, generate the Ada model files, the SQL files and create the MySQL database.</p><div style='width: 100%; float: left;'>
<iframe width="640" height="480" src="http://www.youtube.com/embed/5q542_gVDd0" frameborder="0" allowfullscreen></iframe>
</div>
<p>The Dynamo tool is available at <a href="http://code.google.com/p/ada-gen">http://code.google.com/p/ada-gen</a>.</p><p>To build Dynamo, you will need:</p><ul><li><a href="http://code.google.com/p/ada-asf/downloads/list">Ada ASF 0.5.0</a></li><li><a href="http://code.google.com/p/ada-ado/downloads/list">Ada ADO 0.4.0</a></li><li><a href="http://code.google.com/p/ada-el/downloads/list">Ada EL 1.4.2</a></li><li><a href="http://code.google.com/p/ada-util/downloads/list">Ada Util 1.6.1</a></li><li><a href="http://libre.adacore.com/libre/tools/xmlada/">XML Ada 4.x or 3.x</a></li></ul></div>