Example: Use model transactions in a workflow

<project default="main">
  
  <!-- ANT Taskdefs for ant-contrib -->
  <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>  
  
  <target name="loadModels">
    <epsilon.emf.register file="tree.ecore"/>    
    <epsilon.emf.loadModel name="M" modelfile="tree.model" 
        metamodeluri="Tree" read="false" store="true"/>
  </target>
  
  <target name="Transformation1">
    <epsilon.eol>
      <model ref="M"/>
      
      var t : new Tree;
      t.label = 't1';
      
    </epsilon.eol>
  </target>
  
  <target name="Transformation2">
    <epsilon.eol>
      <model ref="M"/>
      
      var t : new Tree;
      t.label = 't2';
      
    </epsilon.eol>
  </target>

  <target name="Validation1">
    <epsilon.evl>
      <model ref="M"/>
      
      context Tree {
        constraint C1 {
          check : true
        }
      }
      
    </epsilon.evl>
  </target>
  
  <target name="Validation2">
    <epsilon.evl>
      <model ref="M"/>
      
      context Tree {
        constraint C2 {
          check : true -- Switch to false to make validation fail
        }
      }</epsilon.evl>
  </target>
  
  <target name="Evaluation">
    <epsilon.eol>
      <model ref="M"/>
      
      Tree.all.size().println();
      
    </epsilon.eol>
  </target>
  
  <target name="main" depends="loadModels">
    <runtarget target="Transformation1"/>
    <runtarget target="Validation1"/>    
    
    <trycatch>
      <try>
        <!--Start a transaction on M so that we can roll it back later on.-->
        <epsilon.startTransaction name="Transaction1" models="M"/>
        <runtarget target="Transformation2"/>
        <runtarget target="Validation2"/>
        <!-- No errors in the validation. Commit the transaction.-->
        <epsilon.commitTransaction name="Transaction1"/>
      </try>
      <catch>
        <!--If validation fails, roll back the transaction.-->
        <epsilon.rollbackTransaction name="Transaction1"/>
      </catch>
    </trycatch>
    
    <runtarget target="Evaluation"/>
  </target>
  
</project>
@namespace(uri="Tree", prefix="Tree")
package Tree;

class Tree {
   val Tree[*]#parent children;
   ref Tree#children parent;
   attr String label;
}

Check out the code from the SVN:

  • go to the SVN repository
  • navigate to trunk/examples
  • check out the org.eclipse.epsilon.examples.workflow.transactions project

What's this?

In this example we demonstrate using the ant-contrib try/catch tasks and the Epsilon model transactions tasks to conditionally rollback changes in models modified in a workflow.

What are .emf files?

.emf files are Ecore metamodels expressed using the Emfatic textual syntax.

More examples...

Epsilon Object Language
Epsilon Transformation Language
Epsilon Generation Language
Epsilon Validation Language
Epsilon Merging Language
Epsilon Flock
Combining the Epsilon Languages
EuGENia
EUnit

Even more examples...

More examples are available in the examples folder of the SVN repository.