Search in sources :

Example 1 with CSharpFreeSqlPojoHost

use of com.ctrip.platform.dal.daogen.host.csharp.CSharpFreeSqlPojoHost in project dal by ctripcorp.

the class CSharpCodeGeneratorOfFreeSqlProcessor method generateFreeSqlDao.

private List<Callable<ExecuteResult>> generateFreeSqlDao(CodeGenContext codeGenCtx, final File mavenLikeDir) {
    final CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
    final Progress progress = ctx.getProgress();
    List<Callable<ExecuteResult>> results = new ArrayList<>();
    Map<String, CSharpFreeSqlPojoHost> _freeSqlPojoHosts = ctx.getFreeSqlPojoHosts();
    for (final CSharpFreeSqlPojoHost host : _freeSqlPojoHosts.values()) {
        Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {

            @Override
            public ExecuteResult call() {
                //progress.setOtherMessage("正在生成 " + host.getClassName());
                ExecuteResult result = new ExecuteResult("Generate Free SQL[" + host.getClassName() + "] Pojo");
                progress.setOtherMessage(result.getTaskName());
                try {
                    VelocityContext context = GenUtils.buildDefaultVelocityContext();
                    context.put("host", host);
                    GenUtils.mergeVelocityContext(context, String.format("%s/Entity/%s.cs", mavenLikeDir.getAbsolutePath(), CommonUtils.normalizeVariable(host.getClassName())), ctx.isNewPojo() ? "templates/csharp/PojoNew.cs.tpl" : "templates/csharp/Pojo.cs.tpl");
                    result.setSuccessal(true);
                } catch (Exception e) {
                    log.error(result.getTaskName() + "exception", e);
                }
                return result;
            }
        };
        results.add(worker);
    }
    ProgressResource.addDoneFiles(progress, _freeSqlPojoHosts.size());
    Queue<CSharpFreeSqlHost> _freeSqlHosts = ctx.getFreeSqlHosts();
    for (final CSharpFreeSqlHost host : _freeSqlHosts) {
        Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {

            @Override
            public ExecuteResult call() {
                //progress.setOtherMessage("正在生成 " + host.getClassName());
                ExecuteResult result = new ExecuteResult("Generate Free SQL[" + host.getClassName() + "] Dap, Test");
                progress.setOtherMessage(result.getTaskName());
                try {
                    VelocityContext context = GenUtils.buildDefaultVelocityContext();
                    context.put("host", host);
                    GenUtils.mergeVelocityContext(context, String.format("%s/Dao/%sDao.cs", mavenLikeDir.getAbsolutePath(), CommonUtils.normalizeVariable(host.getClassName())), "templates/csharp/dao/freesql/FreeSqlDAO.cs.tpl");
                    GenUtils.mergeVelocityContext(context, String.format("%s/Test/%sTest.cs", mavenLikeDir.getAbsolutePath(), CommonUtils.normalizeVariable(host.getClassName())), "templates/csharp/test/FreeSqlTest.cs.tpl");
                    GenUtils.mergeVelocityContext(context, String.format("%s/Test/%sUnitTest.cs", mavenLikeDir.getAbsolutePath(), CommonUtils.normalizeVariable(host.getClassName())), "templates/csharp/test/FreeSqlUnitTest.cs.tpl");
                    result.setSuccessal(true);
                } catch (Exception e) {
                    log.error(result.getTaskName() + "exception", e);
                }
                return result;
            }
        };
        results.add(worker);
    }
    return results;
}
Also used : Progress(com.ctrip.platform.dal.daogen.entity.Progress) CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) CSharpFreeSqlPojoHost(com.ctrip.platform.dal.daogen.host.csharp.CSharpFreeSqlPojoHost) VelocityContext(org.apache.velocity.VelocityContext) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) ExecuteResult(com.ctrip.platform.dal.daogen.entity.ExecuteResult) CSharpFreeSqlHost(com.ctrip.platform.dal.daogen.host.csharp.CSharpFreeSqlHost)

Aggregations

ExecuteResult (com.ctrip.platform.dal.daogen.entity.ExecuteResult)1 Progress (com.ctrip.platform.dal.daogen.entity.Progress)1 CSharpCodeGenContext (com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext)1 CSharpFreeSqlHost (com.ctrip.platform.dal.daogen.host.csharp.CSharpFreeSqlHost)1 CSharpFreeSqlPojoHost (com.ctrip.platform.dal.daogen.host.csharp.CSharpFreeSqlPojoHost)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 VelocityContext (org.apache.velocity.VelocityContext)1