.. ******************************************************************************* * MetaFactory.io R2 * Technical Documentation * * File name : QuickStart.rst * Created by : MetaFactory (Marnix ?) * * MetaFactory BV Amsterdam ******************************************************************************* .. include:: /inline-images.txt .. include:: /external-links.txt QuickStart ========== .. rubric:: This guide will help you to get started with a demonstration project in 15 minutes. Now let’s create our first example. Create your first example ------------------------- Creating an application with a large amount of entities quickly results in tedious work. Entity classes contain fields, zero or more overloaded constructors and a set of getters and setters. All these entities need separate controllers, repositories and so on. Now to automate this process we will start by creating entity interfaces as well as the implementation classes. The following example shows how to produce java pojo classes and interfaces by a code instruction and a model. For a very first simple impression of how the Code Composer works, you may however want to read the :ref:`Tutorials/T01_HelloWorld:T01 Hello World` example first. First we define a model: .. code-block:: xml :caption: model.xml :name: QuickStart_model01 Various attribute values such as ‘type’, ‘length’ and ‘notnull’ are included in the above snippet. However you should know that these values by itself do nothing unless they are explicitly dealt with by the code instruction. The Code Composer is designed not to use any default or hidden implementations, thereby providing transparency and control to the programmer. Note that the element contains an attribute called ‘multiplicity’. This attribute tells the code instruction how many references of the given type the object can contain. For example ‘0..n’ means that the object may contain either zero or any other number of this reference type. The code instruction can for example use this attribute as a condition for creating the output code. Now let’s look at the code instruction that creates interfaces and implementations for this model data. .. code-block:: xml :caption: codeinstruction.xml :name: QuickStart_codeinstruction01 :linenos: :emphasize-lines: 36 java long primary key ${attribute.type} ${attribute.name} property I${reference.type} Reference to I${reference.type} object java.util.Set ]]> Set of I${reference.type} objects Utility method to add a object of type I${reference.type} to ${reference.name}Set I${reference.type} object to add to ${reference.name}Set I${reference.type} I${object.name} long primary key ${attribute.type} I${reference.type} java.util.Set java.util.HashSet ]]> ()]]> I${reference.type} ${firstLower(${reference.name})}.${getSetterName(${reference.type},${object.name})}(this); ${reference.name}Set.add(${firstLower(${reference.name})}); I${reference.type} ${firstLower(${reference.name})}.${getSetterName(${reference.type},${object.name})}(null); ${reference.name}Set.remove(${firstLower(${reference.name})}); A few explanations regarding this code instruction: - The element tells the name of the java package that the produced class will be in. This element also has a ‘package’ attribute which refers to the group of objects that is defined in model.xml. - Model objects are dynamically accessed using MetaFactory’s :ref:`expression language`. Expressions such as ${object.name} are known at the time of execution because a code instruction is always executed within the context of the part of the domain model that the Code Composer is iterating over, such as a package, object or property. Read more about expressions here. - tags (see line 36) are required sometimes to escape the XML reserved symbols, such as ‘<‘ - The attribute ‘access=”rw” (of the element) tells the Code Composer to generate getters and setters for this field. - The <:ref:`method `> element creates Java methods. Now that you have updated the code of our newly created project it is time to let the Code Composer run and generate all the code (menu Transform -> Run). You can find the generated code at see :numref:`QuickStart_codeinstruction01` line 15. |Light S| Add some new data entities of your own to the model and see how that works out in the output. Good job, you’ve just created your first code with the Code Composer. Evaluation ---------- While XML code instructions help you enforce structure and consistency both in your code instructions and in the resulting Java classes, using this technique only does come with limitations in flexibility. **Snippets** are the power tool in the Code Composer that overcome these limitations and provide you with the templating freedom of using Freemarker or Velocity. You can either evaluate a snippet into true or false as a condition to operate your xml code instruction on or write complete method bodies and even classes with it. Do you value the structured approach and out of the box functionality of xml more, or the templating freedom of snippets? Mind that a very basic XML code instruction is required as a container for your snippet, but other than that you are free in how you use snippets in your code instructions. |Glasses S| More information about the possibilities of snippets can be found at :ref:`Code Instructions Snippets `. |Glasses S| For more about calling snippets from your code instruction check out :ref:`SDA example using snippets `.