-
Notifications
You must be signed in to change notification settings - Fork 4
MOGLiCC Tutorial Part C
Let's assume that the requirement exists, that not only one big sql statement is needed but that in addition the insert statements for all tables must be bundled into a class specific file. To realize this feature two very different alternatives exist. First, to use only ModelBasedFileInserter, second, to use a combination of the ModelBasedFileInserter and the ClassBasedFileMaker. To demonstrate the ClassBasedFileMaker, the second way is followed in the tutorial part.
1 - The very first thing to do now is to create a new template file for the ClassBasedFileMaker. For this purpose create the file /input/VelocityClassBasedFileMaker/InsertSQL/Main.tpl with the following content:
@TargetFileName $classDescriptor.name.sql
@NameOfValidModel InsertSQL
@CreateNew true
#set( $tableName = $classDescriptor.getMetaInfoValueFor("tableName") )
INSERT INTO $tableName ($commaSeparatedListOfAttributes) VALUES ($commaSeparatedListOfTableValues);
2 - After executing MOGLiCC, several observations are worth to make. Firstly, the generation report tells that the FileMaker plugin has been active. Unfortunately, the file name is faulty. Secondly, since no property @targetDir is provided in the template header, the generation result is only present in the plugin's output directory /input/VelocityClassBasedFileMaker/InsertSQL. Thirdly, the content of the generated file contains only one line and obviously the used Velicity variables could not be replaced. What we now do is, that we correct the value of the @TargetFileName property. Velocity has to syntax alternatives for using a variable:
$firstSyntaxForCallingAVelocityVariable # this alternative is more readable, but requires a space or linebreak behind it
${secondSyntaxForCallingAVelocityVariable} # this alternative is less readable, but appropriate to embed its use into sequence of chars
To get along in our situation we apply the second alternative:
@TargetFileName ${classDescriptor.name}.sql