Code snippets

Iterate over all entities defined in the model

1
#foreach( $e in $model.allEntites )
2
...
3
#end
Copied!

Iterate over entity attributes

1
#foreach( $attribute in $entity.attributes )
2
...
3
#end
4
5
#foreach( $attribute in $entity.keyAttributes)
6
...
7
#end
8
9
#foreach( $attribute in $entity.nonKeyAttributes)
10
...
11
#end
Copied!
1
#foreach( $link in $entity.links )
2
...
3
#end
4
Copied!

Execute a ".vm" file located in a model folder

The function "$fn.fileFromModel(fileName)" returns an instance of "file" located in the current model. If the file exists, its content is loaded and evaluated with "#evaluate" directive.
1
#set( $file = $fn.fileFromModel("model-init.vm") )
2
#if($file.exists())#evaluate($file.loadContent())#end
Copied!

Get the class of an object

As all Velocity references ( "$xxx" ) are references of Java objects, sometimes it could be useful to know the object's class. To do this, just use "class.name" (full name with package) or "class.simpleName" (only the class name without package)
1
#set( $v = 12 )
2
$v.class.name
3
$v.class.simpleName
4
5
#set( $s = "abc" )
6
$s.class.name
7
$s.class.simpleName
8
9
$entity.class.name
10
11
$now.class.simpleName
Copied!

Generate a file only once

Sometimes it can be useful to make sure you only generate a file once to avoid overwriting manual changes after project bootstrapping. Since Telosys 3.3.0 you can do that with #cancel directive.
1
##--- NB : do not rewrite the file if it already exists
2
#if($target.outputFileExists() )#cancel("File already exists")#end
3
Copied!
Last modified 3mo ago