code generation - could I generate mybaits Mapper dynamically? -


<javaclientgenerator type="xmlmapper" targetpackage="com.aaa.${module}.domain.mapper"  targetproject="src/main/resources">   <property name="enablesubpackages" value="true" /> </javaclientgenerator> 

the var ${module} value of domainobjectname in table config.

    <table schema="test" tablename="account" domainobjectname="account" >       <property name="useactualcolumnnames" value="true"/>     </table> 

yes, need create custom javaclientgenerator. don't think enablesubpackages property works quite way. in config file have:

<javaclientgenerator type="com.mydomain.myjavamappergenerator" targetpackage="com.aaa.${module}.domain.mapper"  targetproject="src/main/java"> </javaclientgenerator> 

and need subclass existing javamappergenerator own version. option 1 or 2 below. option 2 1 go given unexpected complexity of option 1.

option 1 - makes difficult mapper type stored in private variable have create whole new interface object copying values on original:

public class myjavamappergenerator extends javamappergenerator {      @override     public list<compilationunit> getcompilationunits() {         list<compilationunit> compliationunits = super.getcompilationunits();         list<compilationunit> newcompliationunits = new arraylist<>();         interface mapper = (interface)compliationunits.get(0);         string mappertype = mapper.gettype().getfullyqualifiedname();         interface newmapper = new interface(mappertype.replace("${module}",             introspectedtable.getfullyqualifiedtable().getdomainobjectname().tolowercase()));          newmapper.getjavadoclines().addall(mapper.getjavadoclines());         newmapper.setvisibility(mapper.getvisibility());         newmapper.setstatic(mapper.isstatic());         newmapper.setfinal(mapper.isfinal());         newmapper.getannotations().addall(mapper.getannotations());          newmapper.addimportedtypes(mapper.getimportedtypes());         newmapper.getstaticimports().addall(mapper.getstaticimports());         newmapper.getsuperinterfacetypes().addall(mapper.getsuperinterfacetypes());         newmapper.getmethods().addall(mapper.getmethods());         newmapper.getfilecommentlines().addall(mapper.getfilecommentlines());          newcompliationunits.add(newmapper);          return newcompliationunits;     }  } 

option 2 - though it's little messy, copy-paste entire getcompilationsunits() method javamappergenerator , modify single line sets type:

public class myjavamappergenerator extends javamappergenerator {      @override     public list<compilationunit> getcompilationunits() {         ...         //fullyqualifiedjavatype type = new fullyqualifiedjavatype(         //        introspectedtable.getmybatis3javamappertype());         fullyqualifiedjavatype type = new fullyqualifiedjavatype(                 introspectedtable.getmybatis3javamappertype().replace("${module}",                 introspectedtable.getfullyqualifiedtable().getdomainobjectname()                                  .tolowercase()));         ...     }  } 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -