# Templates features

### New target languages

2 new predefined target languages have been added : **C++** and **Scala**&#x20;

To set these languages as the default target languages in a template file :

```
#set( $env.language = 'C++' )
```

```
#set( $env.language = 'Scala' )
```

### Files usage

It's now possible to use files located in a bundle folder, in a model folder or anywhere on the filesystem.

Examples :

```
## Get a file :
#set( $file = $fn.fileFromBundle("foo.txt") )
#set( $file = $fn.fileFromModel("foo.txt") )
#set( $file = $fn.file("/foo/bar/foo.txt") )

## File information :
file.name          : $file.name
file.parent        : $file.parent
file.path          : $file.path
file.absolutePath  : $file.absolutePath
file.canonicalPath : $file.canonicalPath
file.exists()      : $file.exists()
file.isFile()      : $file.isFile()
file.isDirectory() : $file.isDirectory()
file.isHidden()    : $file.isHidden()
file.length        : $file.length

## Load file content :
#set($content = $file.loadContent() )
#set($lines = $file.loadLines() )

#if( $file.exists() && $file.isFile() )
$file.loadContent(2)## NO EOL
#end

#foreach ( $line in $file.loadLines(3) )
 . $line
#end

## CSV file
#set( $file = $fn.fileFromBundle("enum-csv.txt") )
#set( $lines = $file.loadValues(",", 1) )
#foreach ( $line in $lines )
 $line.get(0) : $line.get(1) 
#else
```

### Java JPA improvements

In addition to the new JPA annotations in the model some JPA customizations have been added to define global default values in order to facilitate JPA entities generation and make it more flexible.

Examples :

Define default "**fetch type**" ("**LAZY**" or "**EAGER**") for all links cardinality ("ManyToMany", "OneToMany", "ManyToOne", "OneToOne" ) :

```
#set( $jpa.manyToManyFetchType = 'EAGER' )
#set( $jpa.manyToManyFetchType = 'LAZY' )

#set( $jpa.manyToOneFetchType = 'LAZY' )

#set( $jpa.oneToManyFetchType = 'EAGER' )

#set( $jpa.oneToOneFetchType = 'LAZY' )
```

Define the value for "**insertable**" and "**updatable**" attribute in "**@JoinColumn**" annotation

```
#set( $jpa.joinColumnInsertable = true )
#set( $jpa.joinColumnInsertable = false)

#set( $jpa.joinColumnUpdatable = true )
#set( $jpa.joinColumnUpdatable = false)
```

Define if "**targetEntity**" must be generated in JPA annotation (@ManyToMany, @OneToMany, etc)

```
#set( $jpa.genTargetEntity = true )
```

The **default collection type** to be used can defined in the current environement object (default is "java.util.List" )

```
#set($env.collectionType = "java.util.Set")
#set($env.collectionType = "java.util.Collection")
```

### #cancel directive

It's now possible to cancel the current file generation in a template.\
The cancel directive just stop the generation without writing the output file (with a message explaining why the generation has been canceled).

Example to avoid overwriting an existing file :

```
#if( $target.outputFileExists() )
#cancel("File already exists")
#end
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://news.telosys.org/version-3.3.0/templates-features.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
