Search in sources :

Example 1 with CSharpFreeSqlHost

use of com.ctrip.platform.dal.daogen.host.csharp.CSharpFreeSqlHost 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)

Example 2 with CSharpFreeSqlHost

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

the class GenTaskResource method buildFreesqlTaskMethodParam.

private String buildFreesqlTaskMethodParam(GenTaskByFreeSql task) {
    try {
        DalGenerator generator = null;
        CodeGenContext context = null;
        Progress progress = new Progress();
        if ("java".equalsIgnoreCase(task.getSql_style())) {
            generator = new JavaDalGenerator();
            context = generator.createContext(task.getProject_id(), true, progress, true, true);
            generator.prepareData(context);
            JavaCodeGenContext ctx = (JavaCodeGenContext) context;
            Queue<FreeSqlHost> freeSqlHosts = ctx.getFreeSqlHosts();
            FreeSqlHost freeSqlHost = null;
            while ((freeSqlHost = freeSqlHosts.poll()) != null) {
                List<JavaMethodHost> methods = freeSqlHost.getMethods();
                for (JavaMethodHost method : methods) {
                    if (task.getMethod_name().equalsIgnoreCase(method.getName())) {
                        String param = method.getParameterDeclaration();
                        param = param.replaceAll("<", "&lt;");
                        param = param.replaceAll(">", "&gt;");
                        return param;
                    }
                }
            }
        } else {
            generator = new CSharpDalGenerator();
            context = generator.createContext(task.getProject_id(), true, progress, true, true);
            generator.prepareData(context);
            CSharpCodeGenContext ctx = (CSharpCodeGenContext) context;
            Queue<CSharpFreeSqlHost> freeSqlHosts = ctx.getFreeSqlHosts();
            CSharpFreeSqlHost freeSqlHost = null;
            while ((freeSqlHost = freeSqlHosts.poll()) != null) {
                List<CSharpMethodHost> methods = freeSqlHost.getMethods();
                for (CSharpMethodHost method : methods) {
                    if (task.getMethod_name().equalsIgnoreCase(method.getName())) {
                        String param = method.getParameterDeclaration();
                        param = param.replaceAll("<", "&lt;");
                        param = param.replaceAll(">", "&gt;");
                        return param;
                    }
                }
            }
        }
    } catch (Exception e) {
    }
    return null;
}
Also used : CSharpDalGenerator(com.ctrip.platform.dal.daogen.generator.csharp.CSharpDalGenerator) JavaDalGenerator(com.ctrip.platform.dal.daogen.generator.java.JavaDalGenerator) DalGenerator(com.ctrip.platform.dal.daogen.DalGenerator) CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) CodeGenContext(com.ctrip.platform.dal.daogen.CodeGenContext) CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) JavaCodeGenContext(com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext) FreeSqlHost(com.ctrip.platform.dal.daogen.host.java.FreeSqlHost) CSharpFreeSqlHost(com.ctrip.platform.dal.daogen.host.csharp.CSharpFreeSqlHost) JavaDalGenerator(com.ctrip.platform.dal.daogen.generator.java.JavaDalGenerator) JavaMethodHost(com.ctrip.platform.dal.daogen.host.java.JavaMethodHost) EmailException(org.apache.commons.mail.EmailException) CSharpDalGenerator(com.ctrip.platform.dal.daogen.generator.csharp.CSharpDalGenerator) CSharpFreeSqlHost(com.ctrip.platform.dal.daogen.host.csharp.CSharpFreeSqlHost) CSharpMethodHost(com.ctrip.platform.dal.daogen.host.csharp.CSharpMethodHost) JavaCodeGenContext(com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)

Aggregations

CSharpCodeGenContext (com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext)2 CSharpFreeSqlHost (com.ctrip.platform.dal.daogen.host.csharp.CSharpFreeSqlHost)2 CodeGenContext (com.ctrip.platform.dal.daogen.CodeGenContext)1 DalGenerator (com.ctrip.platform.dal.daogen.DalGenerator)1 ExecuteResult (com.ctrip.platform.dal.daogen.entity.ExecuteResult)1 Progress (com.ctrip.platform.dal.daogen.entity.Progress)1 CSharpDalGenerator (com.ctrip.platform.dal.daogen.generator.csharp.CSharpDalGenerator)1 JavaCodeGenContext (com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)1 JavaDalGenerator (com.ctrip.platform.dal.daogen.generator.java.JavaDalGenerator)1 CSharpFreeSqlPojoHost (com.ctrip.platform.dal.daogen.host.csharp.CSharpFreeSqlPojoHost)1 CSharpMethodHost (com.ctrip.platform.dal.daogen.host.csharp.CSharpMethodHost)1 FreeSqlHost (com.ctrip.platform.dal.daogen.host.java.FreeSqlHost)1 JavaMethodHost (com.ctrip.platform.dal.daogen.host.java.JavaMethodHost)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 EmailException (org.apache.commons.mail.EmailException)1 VelocityContext (org.apache.velocity.VelocityContext)1