I recently started using sql2java and MySql. All is working nicely.
However, I would like to extend sql2java, so that it handles MySql ENUM columns.
I have no previous experience with velocity. As far as I can understand from the velocity manuals the following steps are necessary in order to expose a new object:
1. Add the object to the velocity context
2. Only the public methods of the object may be referenced. The methods should be named getXX().
For testing purposes I first tried to add a new method to the Column class like the following:
public String getMySqlEnum(){
return "hello";
}
I tried to reference that method in the vm file as follows:
#foreach ($column in $columns)
$column.getName()
$column.getMySqlEnum()
#end
The getName method shows normally.
The getMySqlEnum method wasn't found, causing an reference not found error in the velocity log file.
Then I tried to create a test class (MySqlEnum). In the CodeWriter class where the velocity context is set up I added the following line:
vc.put("MySqlEnum", new MySqlEnum());
The MySqlEnum class contained one method as follows:
public String getEnum(){
return "hello";
}
Again, I tried to reference it from the vm file as follows:
$MySqlEnum.getEnum()
The same error occured.
Any ideas what I'm doing wrong?
/Stefan
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I recently started using sql2java and MySql. All is working nicely.
However, I would like to extend sql2java, so that it handles MySql ENUM columns.
I have no previous experience with velocity. As far as I can understand from the velocity manuals the following steps are necessary in order to expose a new object:
1. Add the object to the velocity context
2. Only the public methods of the object may be referenced. The methods should be named getXX().
For testing purposes I first tried to add a new method to the Column class like the following:
public String getMySqlEnum(){
return "hello";
}
I tried to reference that method in the vm file as follows:
#foreach ($column in $columns)
$column.getName()
$column.getMySqlEnum()
#end
The getName method shows normally.
The getMySqlEnum method wasn't found, causing an reference not found error in the velocity log file.
Then I tried to create a test class (MySqlEnum). In the CodeWriter class where the velocity context is set up I added the following line:
vc.put("MySqlEnum", new MySqlEnum());
The MySqlEnum class contained one method as follows:
public String getEnum(){
return "hello";
}
Again, I tried to reference it from the vm file as follows:
$MySqlEnum.getEnum()
The same error occured.
Any ideas what I'm doing wrong?
/Stefan