wiki:metrics-adm
Last modified 7 years ago Last modified on 01/10/10 13:58:05

A practical experience with ADM

In this example we show how ADM can be put into practice through the building of a modernization tool whose purpose is to generate metric reports of legacy Oracle Forms applications in order to assess the migration effort. This example illustrates the two main tasks in an ADM process: KDM model extraction and the use of these models to generate the artifacts involved in a modernization process.

In this example, we use Gra2MoL for extracting KDM models from PL/SQL source code of Oracle Forms Application. The extraction process is split into two steps. First ASTM models are obtained from code, and then these intermediate models are transformed into KDM models. we have used Gra2MoL to extract an ASTM model from PL/SQL code, particularly from PL/SQL triggers, and KDM models have been obtained from the model-to-model transformations defined in RubyTL.

Once we have KDM models, we must define mappings among existing system elements and target elements in order to generate the desired solution, for instance, PL-SQL metric reports in this example. We have defined our own Metrics metamodel to account for the coupling of each trigger. Thus, we have obtained the reports by using RubyTL language for KDM-to-Metrics transformations, and Texplate to generate reports from Metrics models.

Query examples

The ASTM model extraction phase is performed by a Gra2MoL transformation. In this section we show some examples of Gra2MoL queries.

  • The query "ts" collects all "Trigger" grammar elements which are direct child of "cst" grammar element. Whereas the "cst" grammar element is the root of the concrete syntax tree, the "Trigger" grammar element represents a PL/SQL trigger.
    rule 'mapCompilationUnit'
    	from CST cst
    	to astm::gastm::CompilationUnit
    	queries
    		ts : /cst/#Trigger;
    	mappings
    	...
    end_rule
    
  • The query "stats" collects all "statement" grammar elements of a "trigger" grammar element. The "Trigger" grammar element is represents by the "t" variable, which is received by the rule. It is important to note that the "statement" grammar elements extracted must be direct children of "seq_of_statements" grammar elements. Likewise "seq_of_statements" grammar elements mmust be direct children of "Trigger" grammar elements.
    rule 'mapCompilationUnit'
    	from Trigger t
    	to astm::sastm::RDBTrigger
    	queries
    		stats : /t/seq_of_statements/#statement;
    	mappings
    	...
    end_rule
    
  • In this rule we are creating a "ReturnStatement?" metamodel element and we need to extract the expression which is returned by the statement. The type of the grammar element received by the rule is "return_statement" and the element is bounded to the "st" variable. The query "exp" extracts such expression, which is represented by the "expr_bool" grammar element. Note that we use the double slash operator to indicate that "plsql_expression" grammar element is an indirect child of "return_statement" grammar element. This operator allow us not to state all the navigation path.
    rule 'mapReturnStatement'
    	from statement/return_statement st
    	to astm::gastm::ReturnStatement
    	queries
    		exp : /st//plsql_expression/#expr_bool;
    	mappings
    	...
    end_rule
    
  • The following rule deals with function call expressions and locates the function declaration. The queries extract the information needed to create a "FunctionCallExpression?" element. The "calledFunction" attribute represents the reference to the function declaration invoked. This attribute has as type "IdentifierReference?" and has a reference called "refersTo" which points to the function declaration. We need to apply two queries to resolve this reference. The first query, which is named "container", locates the trigger which contains the function call expression. The "locFunc" query uses the previous query as root for locating the function declaration by comparing its identifier. Finally, we use the result of the last query for setting the "refersTo" attribute.
    rule 'mapFunctionCallExpression'
    	from function_call  fc
    	to astm::gastm::FunctionCallExpression
    	queries
    		container : //#Trigger//function_call {this.check(fc)};
    		locFunc   : /container//#function_body{function_name.ID.eq(fc.ID)};
    		...
    	mappings
    		calledFunction.refersTo = locFunc;
    		... 
    end_rule
    

Downloads

  • The example has been developed as an Eclipse project and it can be downloaded from here. Please, note that you must have AGE environment installed.
  • The metamodels used in the example can be downloaded from here.
  • The transformations used in the example can be downloaded from here.

If you have any problem, please send an e-mail to jlcanovas[at]um.es.

Attachments