Search in sources :

Example 16 with ExecuteResult

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

the class CSharpDataPreparerOfTableViewSpProcessor method prepareTable.

private List<Callable<ExecuteResult>> prepareTable(final CSharpCodeGenContext ctx, final Progress progress, final GenTaskByTableViewSp tableViewSp, final String[] tableNames, final DatabaseCategory dbCategory, final Queue<CSharpTableHost> tableViewHosts) throws Exception {
    List<Callable<ExecuteResult>> results = new ArrayList<>();
    final List<StoredProcedure> allSpNames = DbUtils.getAllSpNames(tableViewSp.getAllInOneName());
    for (final String table : tableNames) {
        Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {

            @Override
            public ExecuteResult call() throws Exception {
                ExecuteResult result = new ExecuteResult("Build Table[" + tableViewSp.getAllInOneName() + "." + table + "] Host");
                progress.setOtherMessage(result.getTaskName());
                CSharpTableHost currentTableHost;
                try {
                    currentTableHost = buildTableHost(ctx, tableViewSp, table, dbCategory, allSpNames);
                    if (null != currentTableHost) {
                        tableViewHosts.add(currentTableHost);
                    }
                    result.setSuccessal(true);
                } catch (Throwable e) {
                    throw new Exception(String.format("Task Id[%s]:%s\r\n", tableViewSp.getId(), e.getMessage()), e);
                }
                return result;
            }
        };
        results.add(worker);
    }
    return results;
}
Also used : StoredProcedure(com.ctrip.platform.dal.daogen.domain.StoredProcedure) ExecuteResult(com.ctrip.platform.dal.daogen.entity.ExecuteResult) Callable(java.util.concurrent.Callable) SQLException(java.sql.SQLException)

Example 17 with ExecuteResult

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

the class CSharpDataPreparerOfTableViewSpProcessor method prepareSp.

private List<Callable<ExecuteResult>> prepareSp(final CSharpCodeGenContext ctx, final Progress progress, final Queue<CSharpTableHost> spHosts, final GenTaskByTableViewSp tableViewSp, final String[] spNames, final DatabaseCategory dbCategory) {
    List<Callable<ExecuteResult>> results = new ArrayList<>();
    for (final String spName : spNames) {
        Callable<ExecuteResult> spWorker = new Callable<ExecuteResult>() {

            @Override
            public ExecuteResult call() throws Exception {
                ExecuteResult result = new ExecuteResult("Build SP[" + tableViewSp.getAllInOneName() + "." + spName + "] Host");
                progress.setOtherMessage(result.getTaskName());
                try {
                    CSharpTableHost currentSpHost = buildSpHost(ctx, tableViewSp, dbCategory, spName);
                    if (null != currentSpHost) {
                        spHosts.add(currentSpHost);
                    }
                    result.setSuccessal(true);
                } catch (Throwable e) {
                    throw new Exception(String.format("Task Id[%s]:%s\r\n", tableViewSp.getId(), e.getMessage()), e);
                }
                return result;
            }
        };
        results.add(spWorker);
    }
    return results;
}
Also used : ExecuteResult(com.ctrip.platform.dal.daogen.entity.ExecuteResult) Callable(java.util.concurrent.Callable) SQLException(java.sql.SQLException)

Example 18 with ExecuteResult

use of com.ctrip.platform.dal.daogen.entity.ExecuteResult 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() throws Exception {
                // 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 (Throwable e) {
                    throw 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() throws Exception {
                // 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 (Throwable e) {
                    throw 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 19 with ExecuteResult

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

ExecuteResult (com.ctrip.platform.dal.daogen.entity.ExecuteResult)19 Callable (java.util.concurrent.Callable)17 Progress (com.ctrip.platform.dal.daogen.entity.Progress)11 SQLException (java.sql.SQLException)8 ArrayList (java.util.ArrayList)8 VelocityContext (org.apache.velocity.VelocityContext)7 JavaCodeGenContext (com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)6 CSharpCodeGenContext (com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext)5 CSharpTableHost (com.ctrip.platform.dal.daogen.host.csharp.CSharpTableHost)3 GenTaskByFreeSql (com.ctrip.platform.dal.daogen.entity.GenTaskByFreeSql)2 GenTaskBySqlBuilder (com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)2 FreeSqlHost (com.ctrip.platform.dal.daogen.host.java.FreeSqlHost)2 JavaMethodHost (com.ctrip.platform.dal.daogen.host.java.JavaMethodHost)2 JavaTableHost (com.ctrip.platform.dal.daogen.host.java.JavaTableHost)2 DaoByFreeSql (com.ctrip.platform.dal.daogen.dao.DaoByFreeSql)1 StoredProcedure (com.ctrip.platform.dal.daogen.domain.StoredProcedure)1 CSharpFreeSqlHost (com.ctrip.platform.dal.daogen.host.csharp.CSharpFreeSqlHost)1 CSharpFreeSqlPojoHost (com.ctrip.platform.dal.daogen.host.csharp.CSharpFreeSqlPojoHost)1 SpDbHost (com.ctrip.platform.dal.daogen.host.java.SpDbHost)1 SpHost (com.ctrip.platform.dal.daogen.host.java.SpHost)1