In this short article I want to show you how to execute another application from ORM Designer script. Since the version 1.4.2 ORM Designer has built-in a new script command called “execute-file” serving to launch the foreign applications from script. (1.4.2 is now obsolete, please download latest version from //http://www.skipper18.com/en/download)
As first, let me show you the simplest way how to use this command.
Using this snippet we defined a function called “Test” which launch our testing .bat file with parameter ‘unit-test’. Whole command syntax is defined in XML Schema file script.xsd and looks like this:
By using parameter “working-dir“ we can specify a working directory for executed command. If no param is passed, the directory where executable file is located is used. Parameter “show“ serves to launch application in invisible mode and parameter “wait-for-exit” servers to wait until external application has finished its work and then continues with script.
Overloading export script
Now let me show you another new feature of ORM Designer 1.4.2. It can happen that you need to call your own executable when ORM Designer finishes export from model to ORM framework definition files. So we prepared new overloading points in export script, where you can write your own functions which will be called in this points.
Method overloading in ORM Designer script is processed by method names and prefixes. The simplest way is by defining a function with specific name. ORM Designer runs this function when it is available.
Sometimes we need to distinguish functions for concrete type of ORM. In this case ORM Designer offers prefix overloading ability. ORM Designer tries to find several prefixes when searching for specific function.
These prefixes have fixed order and priority, so we can define a specific version of some ORMs and one common function for the rest of ORMs.
Order and prefixes are defined in following list. At first ORM Designer tries to find the function with “MVC.ORM.” prefix. As next ORM Designer tries “ORM.” prefix, then “default.” and then without prefix.
ORM Designer stops the function search after a function with correspond name has been found .
So, when you have following definitions, if project using Doctrine ORM is being processed, the first function will be called. When processed project uses any other ORM, the second function is called:
Overloading in export script
Every export script has in its end a located fragment which enables us to call our overloaded function. This fragment looks like:
Now, if you need to create a custom function which is called anytime when ORM Designer exports model to ORM Definitions, follow next steps. As first, we create a file onfinish-export.uscript.xml (or any other name with “.uscript.xml” extension) in user configuration directory (more about user configuration files). As next, enter following script snippet to the created file:
Now, every time when ORM Designer exports a model it will execute one of these functions, based on the project ORM type.
Currently, a support for user-callbacks in scripts is limited only to export scripts. In future, we would like to add more callbacks places depending on users’ requirements. If you have any questions about this topic, feel free to contact us.