Search in sources :

Example 1 with CSharpTableHost

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

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

the class CSharpCodeGeneratorOfTableProcessor method generateTableDao.

private List<Callable<ExecuteResult>> generateTableDao(CodeGenContext codeGenCtx, final File mavenLikeDir) {
    final CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
    final Progress progress = ctx.getProgress();
    List<Callable<ExecuteResult>> results = new ArrayList<>();
    Queue<CSharpTableHost> _tableViewHosts = ctx.getTableViewHosts();
    for (final CSharpTableHost host : _tableViewHosts) {
        Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {

            @Override
            public ExecuteResult call() throws Exception {
                // progress.setOtherMessage("正在生成 " + host.getClassName());
                ExecuteResult result = new ExecuteResult("Generate Table[" + host.getTableName() + "] Dao");
                progress.setOtherMessage(result.getTaskName());
                try {
                    VelocityContext context = GenUtils.buildDefaultVelocityContext();
                    context.put("host", host);
                    GenUtils.mergeVelocityContext(context, String.format("%s/Dao/%sDao.cs", mavenLikeDir.getAbsolutePath(), host.getClassName()), "templates/csharp/dao/standard/DAO.cs.tpl");
                    GenUtils.mergeVelocityContext(context, String.format("%s/Entity/%s.cs", mavenLikeDir.getAbsolutePath(), host.getClassName()), ctx.isNewPojo() ? "templates/csharp/PojoNew.cs.tpl" : "templates/csharp/Pojo.cs.tpl");
                    GenUtils.mergeVelocityContext(context, String.format("%s/IDao/I%sDao.cs", mavenLikeDir.getAbsolutePath(), host.getClassName()), "templates/csharp/dao/standard/IDAO.cs.tpl");
                    GenUtils.mergeVelocityContext(context, String.format("%s/Test/%sTest.cs", mavenLikeDir.getAbsolutePath(), host.getClassName()), "templates/csharp/test/DAOTest.cs.tpl");
                    GenUtils.mergeVelocityContext(context, String.format("%s/Test/%sUnitTest.cs", mavenLikeDir.getAbsolutePath(), host.getClassName()), "templates/csharp/test/DAOUnitTest.cs.tpl");
                    result.setSuccessal(true);
                } catch (Throwable e) {
                    throw e;
                }
                return result;
            }
        };
        results.add(worker);
    }
    return results;
}
Also used : CSharpTableHost(com.ctrip.platform.dal.daogen.host.csharp.CSharpTableHost) Progress(com.ctrip.platform.dal.daogen.entity.Progress) CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) VelocityContext(org.apache.velocity.VelocityContext) ArrayList(java.util.ArrayList) ExecuteResult(com.ctrip.platform.dal.daogen.entity.ExecuteResult) Callable(java.util.concurrent.Callable)

Example 3 with CSharpTableHost

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

the class CSharpDataPreparerOfSqlBuilderProcessor method prepareSqlBuilder.

private List<Callable<ExecuteResult>> prepareSqlBuilder(CodeGenContext context) {
    final CSharpCodeGenContext ctx = (CSharpCodeGenContext) context;
    final Progress progress = ctx.getProgress();
    List<Callable<ExecuteResult>> results = new ArrayList<>();
    Queue<GenTaskBySqlBuilder> sqlBuilders = ctx.getSqlBuilders();
    final Queue<CSharpTableHost> tableViewHosts = ctx.getTableViewHosts();
    if (sqlBuilders.size() > 0) {
        Map<String, GenTaskBySqlBuilder> tempSqlBuildres = sqlBuilderBroupBy(sqlBuilders);
        for (final Map.Entry<String, GenTaskBySqlBuilder> sqlBuilder : tempSqlBuildres.entrySet()) {
            Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {

                @Override
                public ExecuteResult call() throws Exception {
                    ExecuteResult result = new ExecuteResult("Build Extral SQL[" + sqlBuilder.getValue().getAllInOneName() + "." + sqlBuilder.getKey() + "] Host");
                    progress.setOtherMessage(result.getTaskName());
                    CSharpTableHost extraTableHost;
                    try {
                        extraTableHost = buildExtraSqlBuilderHost(ctx, sqlBuilder.getValue());
                        if (null != extraTableHost) {
                            tableViewHosts.add(extraTableHost);
                        }
                        result.setSuccessal(true);
                    } catch (Throwable e) {
                        throw new Exception(String.format("Task Id[%s]:%s\r\n", sqlBuilder.getValue().getId(), e.getMessage()), 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) Callable(java.util.concurrent.Callable) GenTaskBySqlBuilder(com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder) CSharpTableHost(com.ctrip.platform.dal.daogen.host.csharp.CSharpTableHost) ExecuteResult(com.ctrip.platform.dal.daogen.entity.ExecuteResult)

Example 4 with CSharpTableHost

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

the class CSharpCodeGeneratorOfSpProcessor method generateSpDao.

private List<Callable<ExecuteResult>> generateSpDao(CodeGenContext codeGenCtx, final File mavenLikeDir) {
    final CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
    final Progress progress = ctx.getProgress();
    List<Callable<ExecuteResult>> results = new ArrayList<>();
    Queue<CSharpTableHost> _spHosts = ctx.getSpHosts();
    for (final CSharpTableHost host : _spHosts) {
        Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {

            @Override
            public ExecuteResult call() throws Exception {
                // progress.setOtherMessage("正在生成 " + host.getClassName());
                ExecuteResult result = new ExecuteResult("Generate SP[" + host.getClassName() + "] Dao");
                progress.setOtherMessage(result.getTaskName());
                try {
                    VelocityContext context = GenUtils.buildDefaultVelocityContext();
                    context.put("host", host);
                    GenUtils.mergeVelocityContext(context, String.format("%s/Dao/%sDao.cs", mavenLikeDir.getAbsolutePath(), host.getClassName()), "templates/csharp/DAOBySp.cs.tpl");
                    GenUtils.mergeVelocityContext(context, String.format("%s/Entity/%s.cs", mavenLikeDir.getAbsolutePath(), host.getClassName()), "templates/csharp/PojoBySp.cs.tpl");
                    GenUtils.mergeVelocityContext(context, String.format("%s/Test/%sTest.cs", mavenLikeDir.getAbsolutePath(), host.getClassName()), "templates/csharp/test/SpTest.cs.tpl");
                    GenUtils.mergeVelocityContext(context, String.format("%s/Test/%sUnitTest.cs", mavenLikeDir.getAbsolutePath(), host.getClassName()), "templates/csharp/test/SpUnitTest.cs.tpl");
                    result.setSuccessal(true);
                } catch (Throwable e) {
                    throw e;
                }
                return result;
            }
        };
        results.add(worker);
    }
    return results;
}
Also used : CSharpTableHost(com.ctrip.platform.dal.daogen.host.csharp.CSharpTableHost) Progress(com.ctrip.platform.dal.daogen.entity.Progress) CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) VelocityContext(org.apache.velocity.VelocityContext) ArrayList(java.util.ArrayList) ExecuteResult(com.ctrip.platform.dal.daogen.entity.ExecuteResult) Callable(java.util.concurrent.Callable)

Aggregations

CSharpCodeGenContext (com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext)4 CSharpTableHost (com.ctrip.platform.dal.daogen.host.csharp.CSharpTableHost)4 ExecuteResult (com.ctrip.platform.dal.daogen.entity.ExecuteResult)3 Progress (com.ctrip.platform.dal.daogen.entity.Progress)3 Callable (java.util.concurrent.Callable)3 ArrayList (java.util.ArrayList)2 VelocityContext (org.apache.velocity.VelocityContext)2 CodeGenContext (com.ctrip.platform.dal.daogen.CodeGenContext)1 DalGenerator (com.ctrip.platform.dal.daogen.DalGenerator)1 GenTaskBySqlBuilder (com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)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 CSharpMethodHost (com.ctrip.platform.dal.daogen.host.csharp.CSharpMethodHost)1 JavaMethodHost (com.ctrip.platform.dal.daogen.host.java.JavaMethodHost)1 JavaTableHost (com.ctrip.platform.dal.daogen.host.java.JavaTableHost)1 SQLException (java.sql.SQLException)1 EmailException (org.apache.commons.mail.EmailException)1