Search in sources :

Example 11 with Progress

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

the class ProgressResource method poll.

@Path("/poll")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Progress poll(@Context HttpServletRequest request, @QueryParam("project_id") int project_id, @QueryParam("regenerate") boolean regen, @QueryParam("language") String language, @QueryParam("random") String random) {
    try {
        TimeUnit.SECONDS.sleep(1);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    String userNo = RequestUtil.getUserNo(request);
    Progress progress = getProgress(userNo, project_id, random);
    if (FINISH.equals(progress.getStatus())) {
        release(progress);
        Progress success = new Progress();
        success.setPercent(100);
        success.setStatus(FINISH);
        success.setOtherMessage(SUCCESS_MESSAGE);
        return success;
    }
    updatePercent(progress);
    return progress;
}
Also used : Progress(com.ctrip.platform.dal.daogen.entity.Progress) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 12 with Progress

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

the class CSharpDataPreparerOfSqlBuilderProcessor method prepareSqlBuilder.

private List<Callable<ExecuteResult>> prepareSqlBuilder(CodeGenContext codeGenCtx) {
    final CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
    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> _table : _TempSqlBuildres.entrySet()) {
            Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {

                @Override
                public ExecuteResult call() throws Exception {
                    /*progress.setOtherMessage("正在整理表 "
                                + _table.getValue().getClass_name());*/
                    ExecuteResult result = new ExecuteResult("Build Extral SQL[" + _table.getValue().getAllInOneName() + "." + _table.getKey() + "] Host");
                    progress.setOtherMessage(result.getTaskName());
                    CSharpTableHost extraTableHost;
                    try {
                        extraTableHost = buildExtraSqlBuilderHost(ctx, _table.getValue());
                        if (null != extraTableHost) {
                            _tableViewHosts.add(extraTableHost);
                        }
                        result.setSuccessal(true);
                    } catch (Exception e) {
                        log.error(result.getTaskName() + " exception.", 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 13 with Progress

use of com.ctrip.platform.dal.daogen.entity.Progress 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() {
                //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 (Exception e) {
                    log.error(result.getTaskName() + "exception", 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 14 with Progress

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

the class CSharpDataPreparerOfFreeSqlProcessor method prepareFreeSql.

private List<Callable<ExecuteResult>> prepareFreeSql(CodeGenContext codeGenCtx) throws Exception {
    final CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
    int projectId = ctx.getProjectId();
    boolean regenerate = ctx.isRegenerate();
    final Progress progress = ctx.getProgress();
    final String namespace = ctx.getNamespace();
    List<GenTaskByFreeSql> freeSqlTasks;
    if (regenerate) {
        freeSqlTasks = daoByFreeSql.updateAndGetAllTasks(projectId);
        prepareDbFromFreeSql(ctx, freeSqlTasks);
    } else {
        freeSqlTasks = daoByFreeSql.updateAndGetTasks(projectId);
        prepareDbFromFreeSql(ctx, daoByFreeSql.getTasksByProjectId(projectId));
    }
    if (!ctx.isIgnoreApproveStatus() && freeSqlTasks != null && freeSqlTasks.size() > 0) {
        Iterator<GenTaskByFreeSql> ite = freeSqlTasks.iterator();
        while (ite.hasNext()) {
            int approved = ite.next().getApproved();
            if (approved != 2 && approved != 0) {
                ite.remove();
            }
        }
    }
    // 首先按照DbName以及ClassName做一次GroupBy,且ClassName不区分大小写
    final Map<String, List<GenTaskByFreeSql>> groupBy = freeSqlGroupBy(freeSqlTasks);
    List<Callable<ExecuteResult>> results = new ArrayList<>();
    final Map<String, CSharpFreeSqlPojoHost> _freeSqlPojoHosts = ctx.getFreeSqlPojoHosts();
    final Queue<CSharpFreeSqlHost> _freeSqlHosts = ctx.getFreeSqlHosts();
    // 随后,以DbName以及ClassName为维度,为每个维度生成一个DAO类
    for (final Map.Entry<String, List<GenTaskByFreeSql>> entry : groupBy.entrySet()) {
        Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {

            @Override
            public ExecuteResult call() throws Exception {
                ExecuteResult result = new ExecuteResult("Build  Free SQL[" + entry.getKey() + "] Host");
                progress.setOtherMessage(result.getTaskName());
                try {
                    List<GenTaskByFreeSql> currentTasks = entry.getValue();
                    if (currentTasks.size() < 1)
                        return result;
                    CSharpFreeSqlHost host = new CSharpFreeSqlHost();
                    host.setDbSetName(currentTasks.get(0).getDatabaseSetName());
                    host.setClassName(CommonUtils.normalizeVariable(WordUtils.capitalize(currentTasks.get(0).getClass_name())));
                    host.setNameSpace(namespace);
                    host.setDatabaseCategory(getDatabaseCategory(currentTasks.get(0).getAllInOneName()));
                    List<CSharpMethodHost> methods = new ArrayList<>();
                    // 每个Method可能就有一个Pojo
                    for (GenTaskByFreeSql task : currentTasks) {
                        CSharpMethodHost method = buildFreeSqlMethodHost(ctx, task);
                        if (!_freeSqlPojoHosts.containsKey(task.getPojo_name()) && method.getPojoName() != null && !method.getPojoName().isEmpty() && (!method.isFirstOrSingle() || !method.isSampleType()) && !"update".equalsIgnoreCase(task.getCrud_type())) {
                            CSharpFreeSqlPojoHost freeSqlPojoHost = buildFreeSqlPojoHost(ctx, task);
                            if (null != freeSqlPojoHost) {
                                _freeSqlPojoHosts.put(task.getPojo_name(), freeSqlPojoHost);
                            }
                        }
                        methods.add(method);
                    }
                    host.setMethods(methods);
                    _freeSqlHosts.add(host);
                    result.setSuccessal(true);
                } catch (Exception e) {
                    log.error(result.getTaskName() + "exception", 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) GenTaskByFreeSql(com.ctrip.platform.dal.daogen.entity.GenTaskByFreeSql) Callable(java.util.concurrent.Callable) ExecuteResult(com.ctrip.platform.dal.daogen.entity.ExecuteResult)

Example 15 with Progress

use of com.ctrip.platform.dal.daogen.entity.Progress 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() {
                //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 (Exception e) {
                    log.error(result.getTaskName() + "exception", 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() {
                //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 (Exception e) {
                    log.error(result.getTaskName() + "exception", 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)

Aggregations

Progress (com.ctrip.platform.dal.daogen.entity.Progress)18 Callable (java.util.concurrent.Callable)15 ExecuteResult (com.ctrip.platform.dal.daogen.entity.ExecuteResult)11 CSharpCodeGenContext (com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext)8 JavaCodeGenContext (com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)7 ArrayList (java.util.ArrayList)7 VelocityContext (org.apache.velocity.VelocityContext)7 GenTaskBySqlBuilder (com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)4 CSharpTableHost (com.ctrip.platform.dal.daogen.host.csharp.CSharpTableHost)3 GenTaskByFreeSql (com.ctrip.platform.dal.daogen.entity.GenTaskByFreeSql)2 GenTaskByTableViewSp (com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp)2 DatabaseCategory (com.ctrip.platform.dal.daogen.enums.DatabaseCategory)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 File (java.io.File)2 DaoByFreeSql (com.ctrip.platform.dal.daogen.dao.DaoByFreeSql)1 AbstractParameterHost (com.ctrip.platform.dal.daogen.host.AbstractParameterHost)1 CSharpFreeSqlHost (com.ctrip.platform.dal.daogen.host.csharp.CSharpFreeSqlHost)1 CSharpFreeSqlPojoHost (com.ctrip.platform.dal.daogen.host.csharp.CSharpFreeSqlPojoHost)1