Search in sources :

Example 1 with DalGenerator

use of com.ctrip.platform.dal.daogen.DalGenerator in project dal by ctripcorp.

the class GenTaskResource method buildAutoTaskMethodParam.

private String buildAutoTaskMethodParam(GenTaskBySqlBuilder 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<JavaTableHost> tableHosts = ctx.getTableHosts();
            JavaTableHost tableHost = null;
            while ((tableHost = tableHosts.poll()) != null) {
                List<JavaMethodHost> methods = tableHost.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<CSharpTableHost> tableHosts = ctx.getTableViewHosts();
            CSharpTableHost tableHost = null;
            while ((tableHost = tableHosts.poll()) != null) {
                List<CSharpMethodHost> methods = tableHost.getExtraMethods();
                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) JavaTableHost(com.ctrip.platform.dal.daogen.host.java.JavaTableHost) JavaDalGenerator(com.ctrip.platform.dal.daogen.generator.java.JavaDalGenerator) JavaMethodHost(com.ctrip.platform.dal.daogen.host.java.JavaMethodHost) EmailException(org.apache.commons.mail.EmailException) CSharpTableHost(com.ctrip.platform.dal.daogen.host.csharp.CSharpTableHost) CSharpDalGenerator(com.ctrip.platform.dal.daogen.generator.csharp.CSharpDalGenerator) CSharpMethodHost(com.ctrip.platform.dal.daogen.host.csharp.CSharpMethodHost) JavaCodeGenContext(com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)

Example 2 with DalGenerator

use of com.ctrip.platform.dal.daogen.DalGenerator in project dal by ctripcorp.

the class ProjectResource method generateProject.

@POST
@Path("generate")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Status generateProject(@Context HttpServletRequest request, @FormParam("project_id") int id, @FormParam("regenerate") boolean regen, @FormParam("language") String language, @FormParam("newPojo") boolean newPojo, @FormParam("random") String random) {
    Status status = null;
    Progress progress = null;
    try {
        String userNo = RequestUtil.getUserNo(request);
        progress = ProgressResource.getProgress(userNo, id, random);
        status = validatePermision(userNo, id);
        if (status.getCode().equals(Status.ERROR.getCode())) {
            progress.setStatus(ProgressResource.FINISH);
            return status;
        }
        log.info(String.format("begain generate project: [id=%s; regen=%s; language=%s]", id, true, language));
        DalGenerator generator = null;
        CodeGenContext context = null;
        HashSet<String> hashSet = getProjectSqlStyles(id);
        String code = "";
        if (hashSet.contains(JAVA)) {
            code = JAVA;
            generator = new JavaDalGenerator();
            context = generator.createContext(id, true, progress, newPojo, false);
            generateLanguageProject(generator, context);
        }
        if (hashSet.contains(CS)) {
            // cs
            code = "cs";
            generator = new CSharpDalGenerator();
            context = generator.createContext(id, true, progress, newPojo, false);
            generateLanguageProject(generator, context);
        }
        status = Status.OK;
        status.setInfo(code);
        log.info(String.format("generate project[%s] completed.", id));
    } catch (Exception e) {
        status = Status.ERROR;
        status.setInfo(e.getMessage());
        progress.setOtherMessage(e.getMessage());
        log.error(String.format("generate project[%s] failed.", id), e);
    } finally {
        progress.setStatus(ProgressResource.FINISH);
    }
    return status;
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) 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) CodeGenContext(com.ctrip.platform.dal.daogen.CodeGenContext) CSharpDalGenerator(com.ctrip.platform.dal.daogen.generator.csharp.CSharpDalGenerator) JavaDalGenerator(com.ctrip.platform.dal.daogen.generator.java.JavaDalGenerator) IOException(java.io.IOException)

Example 3 with DalGenerator

use of com.ctrip.platform.dal.daogen.DalGenerator 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

CodeGenContext (com.ctrip.platform.dal.daogen.CodeGenContext)3 DalGenerator (com.ctrip.platform.dal.daogen.DalGenerator)3 CSharpDalGenerator (com.ctrip.platform.dal.daogen.generator.csharp.CSharpDalGenerator)3 JavaDalGenerator (com.ctrip.platform.dal.daogen.generator.java.JavaDalGenerator)3 CSharpCodeGenContext (com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext)2 JavaCodeGenContext (com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)2 CSharpMethodHost (com.ctrip.platform.dal.daogen.host.csharp.CSharpMethodHost)2 JavaMethodHost (com.ctrip.platform.dal.daogen.host.java.JavaMethodHost)2 EmailException (org.apache.commons.mail.EmailException)2 Status (com.ctrip.platform.dal.daogen.domain.Status)1 CSharpFreeSqlHost (com.ctrip.platform.dal.daogen.host.csharp.CSharpFreeSqlHost)1 CSharpTableHost (com.ctrip.platform.dal.daogen.host.csharp.CSharpTableHost)1 FreeSqlHost (com.ctrip.platform.dal.daogen.host.java.FreeSqlHost)1 JavaTableHost (com.ctrip.platform.dal.daogen.host.java.JavaTableHost)1 IOException (java.io.IOException)1