use of com.ctrip.platform.dal.daogen.host.java.SpDbHost in project dal by ctripcorp.
the class JavaCodeGeneratorOfSpProcessor method generateSpDao.
private List<Callable<ExecuteResult>> generateSpDao(CodeGenContext codeGenCtx, final File mavenLikeDir) {
JavaCodeGenContext ctx = (JavaCodeGenContext) codeGenCtx;
final Progress progress = ctx.getProgress();
Map<String, SpDbHost> _spHostMaps = ctx.getSpHostMaps();
List<Callable<ExecuteResult>> results = new ArrayList<Callable<ExecuteResult>>();
for (final SpDbHost host : _spHostMaps.values()) {
Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {
@Override
public ExecuteResult call() throws Exception {
ExecuteResult result = new ExecuteResult("Generate SP[" + host.getDbSetName() + "] Dao, Pojo, Test");
progress.setOtherMessage(result.getTaskName());
try {
VelocityContext context = GenUtils.buildDefaultVelocityContext();
context.put("host", host);
GenUtils.mergeVelocityContext(context, String.format("%s/Dao/%sSpDao.java", mavenLikeDir.getAbsolutePath(), host.getDbSetName()), "templates/java/DAOBySp.java.tpl");
GenUtils.mergeVelocityContext(context, String.format("%s/Test/%sSpDaoUnitTest.java", mavenLikeDir.getAbsolutePath(), host.getDbSetName()), "templates/java/test/DAOBySpUnitTest.java.tpl");
for (SpHost sp : host.getSpHosts()) {
sp.setDbSetName(host.getDbSetName());
context.put("host", sp);
GenUtils.mergeVelocityContext(context, String.format("%s/Entity/%s.java", mavenLikeDir.getAbsolutePath(), sp.getPojoClassName()), "templates/java/Pojo.java.tpl");
}
result.setSuccessal(true);
} catch (Throwable e) {
throw e;
}
return result;
}
};
results.add(worker);
}
return results;
}
Aggregations