Search in sources :

Example 1 with ExecuteResult

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

the class TaskUtils method log.

public static void log(Logger log, List<Future<ExecuteResult>> tasks) {
    for (Future<ExecuteResult> future : tasks) {
        try {
            ExecuteResult result = future.get();
            log.info(String.format("Execute [%s] task completed: %s", result.getTaskName(), result.isSuccessal()));
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
    }
}
Also used : ExecuteResult(com.ctrip.platform.dal.daogen.entity.ExecuteResult)

Example 2 with ExecuteResult

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

the class TaskUtils method invokeBatch.

public static void invokeBatch(List<Callable<ExecuteResult>> tasks) throws Exception {
    if (tasks == null || tasks.size() == 0)
        return;
    List<Future<ExecuteResult>> results = executor.invokeAll(tasks);
    List<String> exceptions = new ArrayList<>();
    for (Future<ExecuteResult> future : results) {
        try {
            ExecuteResult result = future.get();
        } catch (Throwable e) {
            exceptions.add(e.getMessage());
        }
    }
    if (exceptions.size() > 0) {
        StringBuilder sb = new StringBuilder();
        for (String exception : exceptions) {
            sb.append(exception);
        }
        throw new RuntimeException(sb.toString());
    }
}
Also used : ArrayList(java.util.ArrayList) ExecuteResult(com.ctrip.platform.dal.daogen.entity.ExecuteResult)

Example 3 with ExecuteResult

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

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

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

the class JavaCodeGeneratorOfViewProcessor method generateViewDao.

private List<Callable<ExecuteResult>> generateViewDao(CodeGenContext codeGenCtx, final File mavenLikeDir) {
    JavaCodeGenContext ctx = (JavaCodeGenContext) codeGenCtx;
    final Progress progress = ctx.getProgress();
    Queue<ViewHost> _viewHosts = ctx.getViewHosts();
    List<Callable<ExecuteResult>> results = new ArrayList<>();
    for (final ViewHost host : _viewHosts) {
        Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {

            @Override
            public ExecuteResult call() throws Exception {
                ExecuteResult result = new ExecuteResult("Generate View[" + host.getDbSetName() + "." + host.getViewName() + "] Dao");
                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.getPojoClassName()), "templates/java/ViewDAO.java.tpl");
                    GenUtils.mergeVelocityContext(context, String.format("%s/Entity/%s.java", mavenLikeDir.getAbsolutePath(), host.getPojoClassName()), "templates/java/Pojo.java.tpl");
                    GenUtils.mergeVelocityContext(context, String.format("%s/Test/%sDaoUnitTest.java", mavenLikeDir.getAbsolutePath(), host.getPojoClassName()), "templates/java/test/DAOByViewUnitTest.java.tpl");
                    result.setSuccessal(true);
                } catch (Throwable e) {
                    throw e;
                }
                return result;
            }
        };
        results.add(worker);
    }
    return results;
}
Also used : ViewHost(com.ctrip.platform.dal.daogen.host.java.ViewHost) Progress(com.ctrip.platform.dal.daogen.entity.Progress) VelocityContext(org.apache.velocity.VelocityContext) ArrayList(java.util.ArrayList) ExecuteResult(com.ctrip.platform.dal.daogen.entity.ExecuteResult) Callable(java.util.concurrent.Callable) JavaCodeGenContext(com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)

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