Search in sources :

Example 1 with JavaCodeGenContext

use of com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext 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) SQLException(java.sql.SQLException) 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 JavaCodeGenContext

use of com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext in project dal by ctripcorp.

the class JavaCodeGeneratorOfFreeSqlProcessor method generateFreeSqlDao.

private List<Callable<ExecuteResult>> generateFreeSqlDao(CodeGenContext codeGenCtx, final File mavenLikeDir) {
    JavaCodeGenContext ctx = (JavaCodeGenContext) codeGenCtx;
    final Progress progress = ctx.getProgress();
    List<Callable<ExecuteResult>> results = new ArrayList<>();
    Map<String, JavaMethodHost> freeSqlPojoHosts = ctx.get_freeSqlPojoHosts();
    for (final JavaMethodHost host : freeSqlPojoHosts.values()) {
        if (host.isSampleType())
            continue;
        Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {

            @Override
            public ExecuteResult call() throws Exception {
                ExecuteResult result = new ExecuteResult("Generate Free SQL[" + host.getPojoClassName() + "] Pojo");
                progress.setOtherMessage(result.getTaskName());
                try {
                    VelocityContext context = GenUtils.buildDefaultVelocityContext();
                    context.put("host", host);
                    GenUtils.mergeVelocityContext(context, String.format("%s/Entity/%s.java", mavenLikeDir.getAbsolutePath(), host.getPojoClassName()), "templates/java/Pojo.java.tpl");
                    result.setSuccessal(true);
                } catch (Throwable e) {
                    throw e;
                }
                return result;
            }
        };
        results.add(worker);
    }
    Queue<FreeSqlHost> freeSqlHosts = ctx.getFreeSqlHosts();
    for (final FreeSqlHost host : freeSqlHosts) {
        Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {

            @Override
            public ExecuteResult call() throws Exception {
                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.java", mavenLikeDir.getAbsolutePath(), host.getClassName()), "templates/java/dao/freesql/FreeSqlDAO.java.tpl");
                    GenUtils.mergeVelocityContext(context, String.format("%s/Test/%sDaoUnitTest.java", mavenLikeDir.getAbsolutePath(), host.getClassName()), "templates/java/test/FreeSqlDaoUnitTest.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) FreeSqlHost(com.ctrip.platform.dal.daogen.host.java.FreeSqlHost) JavaMethodHost(com.ctrip.platform.dal.daogen.host.java.JavaMethodHost) Callable(java.util.concurrent.Callable) ExecuteResult(com.ctrip.platform.dal.daogen.entity.ExecuteResult) JavaCodeGenContext(com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)

Example 3 with JavaCodeGenContext

use of com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext in project dal by ctripcorp.

the class JavaCodeGeneratorOfSpProcessor method process.

@Override
public void process(CodeGenContext context) throws Exception {
    try {
        JavaCodeGenContext ctx = (JavaCodeGenContext) context;
        int projectId = ctx.getProjectId();
        File dir = new File(String.format("%s/%s/java", ctx.getGeneratePath(), projectId));
        List<Callable<ExecuteResult>> spCallables = generateSpDao(ctx, dir);
        TaskUtils.invokeBatch(spCallables);
    } catch (Throwable e) {
        LoggerManager.getInstance().error(e);
        throw e;
    }
}
Also used : File(java.io.File) Callable(java.util.concurrent.Callable) JavaCodeGenContext(com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)

Example 4 with JavaCodeGenContext

use of com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext 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)

Example 5 with JavaCodeGenContext

use of com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext in project dal by ctripcorp.

the class JavaCodeGeneratorOfViewProcessor method process.

@Override
public void process(CodeGenContext context) throws Exception {
    try {
        JavaCodeGenContext ctx = (JavaCodeGenContext) context;
        int projectId = ctx.getProjectId();
        File dir = new File(String.format("%s/%s/java", ctx.getGeneratePath(), projectId));
        List<Callable<ExecuteResult>> viewCallables = generateViewDao(ctx, dir);
        TaskUtils.invokeBatch(viewCallables);
    } catch (Throwable e) {
        LoggerManager.getInstance().error(e);
        throw e;
    }
}
Also used : File(java.io.File) Callable(java.util.concurrent.Callable) JavaCodeGenContext(com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)

Aggregations

JavaCodeGenContext (com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)22 Callable (java.util.concurrent.Callable)11 Progress (com.ctrip.platform.dal.daogen.entity.Progress)7 File (java.io.File)7 ExecuteResult (com.ctrip.platform.dal.daogen.entity.ExecuteResult)6 SQLException (java.sql.SQLException)6 VelocityContext (org.apache.velocity.VelocityContext)6 JavaMethodHost (com.ctrip.platform.dal.daogen.host.java.JavaMethodHost)4 ArrayList (java.util.ArrayList)4 AbstractParameterHost (com.ctrip.platform.dal.daogen.host.AbstractParameterHost)3 FreeSqlHost (com.ctrip.platform.dal.daogen.host.java.FreeSqlHost)3 JavaTableHost (com.ctrip.platform.dal.daogen.host.java.JavaTableHost)3 CodeGenContext (com.ctrip.platform.dal.daogen.CodeGenContext)2 DalGenerator (com.ctrip.platform.dal.daogen.DalGenerator)2 GenTaskBySqlBuilder (com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)2 CSharpCodeGenContext (com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext)2 CSharpDalGenerator (com.ctrip.platform.dal.daogen.generator.csharp.CSharpDalGenerator)2 JavaDalGenerator (com.ctrip.platform.dal.daogen.generator.java.JavaDalGenerator)2 DalConfigHost (com.ctrip.platform.dal.daogen.host.DalConfigHost)2 CSharpMethodHost (com.ctrip.platform.dal.daogen.host.csharp.CSharpMethodHost)2