Hey all,
hibernate 3.2.4.ga, hibtools 3.2.0.ga.
I would like to create a custom exporter.
1) is there any good documentation/guideline/wiki/blog that will help someone get started on writing a custom exporter. Google and searching this forum didn't produce anything useful that I could find.
The intent of the custom exporter I'm trying to create is to generate a util class for all known stored procedures (haven't found a way to do this normally, so if there is please show me).
Ideally, I would like to create the exporter class, but have the exporter class not actually do anything, but be used simply as user-defined 'functions' for the template. Looking through the existing exporters, they all define .ftl's within the class itself which is why I'm asking if this is a reasonable expectation to have the exporter just be a util/function class to be used in a manually defined template or not.
Code:
<!-- template is required, exporterclass by itself for my custom exporter doesn't do anything -->
<hbmtemplate
template="sproc.ftl"
exporterclass="SprocExporter"
>
sample sproc.ftl trying to get too:
Code:
<#foreach singlesproc in sproc.getProcedures()>
System.out.println( ${sproc.getCatalog(singlesproc)} );
System.out.println( ${sproc.getSchema(singlesproc)} );
System.out.println( ${sproc.getProcedureName(singlesproc)} );
System.out.println( ${sproc.getProcedureRemark(singlesproc)} );
<#foreach sproccolumn in sprocdetail.getProcedureColumns(singlesproc)>
System.out.println( ${sprocdetail.getProcedureName(singlesproc)} );
System.out.println( ${sprocdetail.getColumnName(singlesproc)} );
System.out.println( ${sprocdetail.getColumnTypeName(singlesproc)} );
System.out.println( ${sprocdetail.getColumnNullable(singlesproc)} );
System.out.println( ${sprocdetail.getColumnRemark(singlesproc)} );
</#foreach>
</#foreach>
Now, for the real meat -- how to I pull this off? I'm guessing I need to identify the freemarker user-defined function with just the getTemplateHelper().putInContext(), and the getName() is not used?
Also assuming you want to extend AbstractExporter instead of GenericExporter, or should I be using GenericExporter?
Code:
public class SprocExporter extends AbstractExporter {
@Override
protected void doStart() {
// TODO Auto-generated method stub
}
public String getName() {
return "sproc"; //is this really needed?
}
/**
* Setup the context variables used by the exporter. Subclasses should call super.setupContext() to ensure all needed variables are in the context.
**/
protected void setupContext() {
super.setupContext();
getTemplateHelper().putInContext("sproc", this);
getTemplateHelper().putInContext("sprocdetail", this);
if(!getProperties().containsKey("ejb3")) {
getProperties().put("ejb3", "false");
}
if(!getProperties().containsKey("jdk5")) {
getProperties().put("jdk5", "false");
}
}
//how do I add this as a sub-method for freemarker template?
private String[] getProcedures(){
//impl
return "to be implemented";
}
//how do I add this as a sub-method for freemarker template, and
//what should the parameter look like.
private String getProcedureName(String procedure){
//impl
return "to be implemented";
}
//should sprocdetail equivalent be it's own class?
private String getSprocDetailColumnName(String procedure){
//impl
return "to be implemented";
}
//use existing hibernate database connection...?
}
Sorry for the long post a lot of questions, I'm kinda jumping in both feet into the dark here.....