Search in sources :

Example 1 with SpHost

use of com.ctrip.platform.dal.daogen.host.java.SpHost 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;
}
Also used : Progress(com.ctrip.platform.dal.daogen.entity.Progress) VelocityContext(org.apache.velocity.VelocityContext) ArrayList(java.util.ArrayList) SpHost(com.ctrip.platform.dal.daogen.host.java.SpHost) Callable(java.util.concurrent.Callable) SpDbHost(com.ctrip.platform.dal.daogen.host.java.SpDbHost) ExecuteResult(com.ctrip.platform.dal.daogen.entity.ExecuteResult) JavaCodeGenContext(com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)

Aggregations

ExecuteResult (com.ctrip.platform.dal.daogen.entity.ExecuteResult)1 Progress (com.ctrip.platform.dal.daogen.entity.Progress)1 JavaCodeGenContext (com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)1 SpDbHost (com.ctrip.platform.dal.daogen.host.java.SpDbHost)1 SpHost (com.ctrip.platform.dal.daogen.host.java.SpHost)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 VelocityContext (org.apache.velocity.VelocityContext)1