Search in sources :

Example 6 with Progress

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

the class JavaDataPreparerOfTableViewSpProcessor method prepareTableViewSp.

private List<Callable<ExecuteResult>> prepareTableViewSp(CodeGenContext codeGenCtx) throws Exception {
    final JavaCodeGenContext ctx = (JavaCodeGenContext) codeGenCtx;
    int projectId = ctx.getProjectId();
    boolean regenerate = ctx.isRegenerate();
    final Progress progress = ctx.getProgress();
    List<GenTaskByTableViewSp> tableViewSpTasks;
    List<GenTaskBySqlBuilder> sqlBuilderTasks;
    if (regenerate) {
        tableViewSpTasks = daoByTableViewSp.updateAndGetAllTasks(projectId);
        sqlBuilderTasks = daoBySqlBuilder.updateAndGetAllTasks(projectId);
        prepareDbFromTableViewSp(ctx, tableViewSpTasks, sqlBuilderTasks);
    } else {
        tableViewSpTasks = daoByTableViewSp.updateAndGetTasks(projectId);
        sqlBuilderTasks = daoBySqlBuilder.updateAndGetTasks(projectId);
        prepareDbFromTableViewSp(ctx, daoByTableViewSp.getTasksByProjectId(projectId), daoBySqlBuilder.getTasksByProjectId(projectId));
    }
    if (!ctx.isIgnoreApproveStatus() && tableViewSpTasks != null && tableViewSpTasks.size() > 0) {
        Iterator<GenTaskByTableViewSp> ite = tableViewSpTasks.iterator();
        while (ite.hasNext()) {
            int approved = ite.next().getApproved();
            if (approved != 2 && approved != 0) {
                ite.remove();
            }
        }
    }
    if (!ctx.isIgnoreApproveStatus() && sqlBuilderTasks != null && sqlBuilderTasks.size() > 0) {
        Iterator<GenTaskBySqlBuilder> ite = sqlBuilderTasks.iterator();
        while (ite.hasNext()) {
            int approved = ite.next().getApproved();
            if (approved != 2 && approved != 0) {
                ite.remove();
            }
        }
    }
    Queue<GenTaskBySqlBuilder> _sqlBuilders = ctx.getSqlBuilders();
    for (GenTaskBySqlBuilder _t : sqlBuilderTasks) {
        _sqlBuilders.add(_t);
    }
    final Queue<JavaTableHost> _tableHosts = ctx.getTableHosts();
    final Queue<ViewHost> _viewHosts = ctx.getViewHosts();
    final Queue<SpHost> _spHosts = ctx.getSpHosts();
    final Map<String, SpDbHost> _spHostMaps = ctx.getSpHostMaps();
    List<Callable<ExecuteResult>> results = new ArrayList<>();
    for (final GenTaskByTableViewSp tableViewSp : tableViewSpTasks) {
        final String[] viewNames = StringUtils.split(tableViewSp.getView_names(), ",");
        final String[] tableNames = StringUtils.split(tableViewSp.getTable_names(), ",");
        final String[] spNames = StringUtils.split(tableViewSp.getSp_names(), ",");
        final DatabaseCategory dbCategory;
        String dbType = DbUtils.getDbType(tableViewSp.getAllInOneName());
        if (null != dbType && !dbType.equalsIgnoreCase("Microsoft SQL Server")) {
            dbCategory = DatabaseCategory.MySql;
        } else {
            dbCategory = DatabaseCategory.SqlServer;
        }
        results.addAll(prepareTable(ctx, progress, _tableHosts, tableViewSp, tableNames, dbCategory));
        results.addAll(prepareView(ctx, progress, _viewHosts, tableViewSp, viewNames, dbCategory));
        results.addAll(prepareSp(ctx, progress, _spHosts, _spHostMaps, tableViewSp, spNames));
    }
    return results;
}
Also used : GenTaskByTableViewSp(com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp) GenTaskBySqlBuilder(com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder) Callable(java.util.concurrent.Callable) JavaCodeGenContext(com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext) Progress(com.ctrip.platform.dal.daogen.entity.Progress) DatabaseCategory(com.ctrip.platform.dal.daogen.enums.DatabaseCategory)

Example 7 with Progress

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

the class CSharpCodeGeneratorOfSpProcessor method process.

@Override
public void process(CodeGenContext context) throws Exception {
    CSharpCodeGenContext ctx = (CSharpCodeGenContext) context;
    int projectId = ctx.getProjectId();
    Progress progress = ctx.getProgress();
    final File dir = new File(String.format("%s/%s/cs", ctx.getGeneratePath(), projectId));
    List<Callable<ExecuteResult>> spCallables = generateSpDao(ctx, dir);
    TaskUtils.invokeBatch(log, spCallables);
    ProgressResource.addDoneFiles(progress, ctx.getSpHosts().size());
}
Also used : Progress(com.ctrip.platform.dal.daogen.entity.Progress) CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) File(java.io.File) Callable(java.util.concurrent.Callable)

Example 8 with Progress

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

the class CSharpCodeGeneratorOfTableProcessor method process.

@Override
public void process(CodeGenContext context) throws Exception {
    CSharpCodeGenContext ctx = (CSharpCodeGenContext) context;
    int projectId = ctx.getProjectId();
    Progress progress = ctx.getProgress();
    final File dir = new File(String.format("%s/%s/cs", ctx.getGeneratePath(), projectId));
    List<Callable<ExecuteResult>> tableCallables = generateTableDao(ctx, dir);
    TaskUtils.invokeBatch(log, tableCallables);
    ProgressResource.addDoneFiles(progress, ctx.getTableViewHosts().size());
}
Also used : Progress(com.ctrip.platform.dal.daogen.entity.Progress) CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) File(java.io.File) Callable(java.util.concurrent.Callable)

Example 9 with Progress

use of com.ctrip.platform.dal.daogen.entity.Progress 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() {
                //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 (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 10 with Progress

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

the class CSharpDataPreparerOfTableViewSpProcessor method prepareTableViewSp.

private List<Callable<ExecuteResult>> prepareTableViewSp(CodeGenContext codeGenCtx) throws Exception {
    final CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
    int projectId = ctx.getProjectId();
    boolean regenerate = ctx.isRegenerate();
    final Progress progress = ctx.getProgress();
    List<GenTaskByTableViewSp> tableViewSpTasks;
    List<GenTaskBySqlBuilder> sqlBuilderTasks;
    if (regenerate) {
        tableViewSpTasks = daoByTableViewSp.updateAndGetAllTasks(projectId);
        sqlBuilderTasks = daoBySqlBuilder.updateAndGetAllTasks(projectId);
        prepareDbFromTableViewSp(ctx, tableViewSpTasks, sqlBuilderTasks);
    } else {
        tableViewSpTasks = daoByTableViewSp.updateAndGetTasks(projectId);
        sqlBuilderTasks = daoBySqlBuilder.updateAndGetTasks(projectId);
        prepareDbFromTableViewSp(ctx, daoByTableViewSp.getTasksByProjectId(projectId), daoBySqlBuilder.getTasksByProjectId(projectId));
    }
    if (!ctx.isIgnoreApproveStatus() && tableViewSpTasks != null && tableViewSpTasks.size() > 0) {
        Iterator<GenTaskByTableViewSp> ite = tableViewSpTasks.iterator();
        while (ite.hasNext()) {
            int approved = ite.next().getApproved();
            if (approved != 2 && approved != 0) {
                ite.remove();
            }
        }
    }
    if (!ctx.isIgnoreApproveStatus() && sqlBuilderTasks != null && sqlBuilderTasks.size() > 0) {
        Iterator<GenTaskBySqlBuilder> ite = sqlBuilderTasks.iterator();
        while (ite.hasNext()) {
            int approved = ite.next().getApproved();
            if (approved != 2 && approved != 0) {
                ite.remove();
            }
        }
    }
    Queue<GenTaskBySqlBuilder> _sqlBuilders = ctx.getSqlBuilders();
    for (GenTaskBySqlBuilder _t : sqlBuilderTasks) {
        _sqlBuilders.add(_t);
    }
    final Queue<CSharpTableHost> _spHosts = ctx.getSpHosts();
    List<Callable<ExecuteResult>> results = new ArrayList<>();
    for (final GenTaskByTableViewSp tableViewSp : tableViewSpTasks) {
        final String[] viewNames = StringUtils.split(tableViewSp.getView_names(), ",");
        final String[] tableNames = StringUtils.split(tableViewSp.getTable_names(), ",");
        final String[] spNames = StringUtils.split(tableViewSp.getSp_names(), ",");
        final DatabaseCategory dbCategory;
        String dbType = DbUtils.getDbType(tableViewSp.getAllInOneName());
        if (null != dbType && !dbType.equalsIgnoreCase("Microsoft SQL Server")) {
            dbCategory = DatabaseCategory.MySql;
        } else {
            dbCategory = DatabaseCategory.SqlServer;
        }
        final Queue<CSharpTableHost> _tableViewHosts = ctx.getTableViewHosts();
        results.addAll(prepareTable(ctx, progress, tableViewSp, tableNames, dbCategory, _tableViewHosts));
        results.addAll(prepareView(ctx, progress, tableViewSp, viewNames, dbCategory, _tableViewHosts));
        results.addAll(prepareSp(ctx, progress, _spHosts, tableViewSp, spNames, dbCategory));
    }
    return results;
}
Also used : Progress(com.ctrip.platform.dal.daogen.entity.Progress) CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) GenTaskByTableViewSp(com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp) GenTaskBySqlBuilder(com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder) Callable(java.util.concurrent.Callable) DatabaseCategory(com.ctrip.platform.dal.daogen.enums.DatabaseCategory)

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